Reputation: 1395
I have a Makefile suppose to compile my app in multiple host, some of them has built in intel compiler (icpc) and others just have g++. I would like that makefile automatically detect availability of icpc and if it is available, compile application with intel compiler, otherwise just compile it with g++.
How do I have to change Makefile to automatically detect availability of icpc compiler ?
Here is my try which simply did not work
ERR = $(shell icpc 2>/dev/null ; echo $? )
ifeq "$(ERR)" "127"
CXX = g++
else
CXX = icpc
endif
Upvotes: 3
Views: 2040
Reputation: 74078
You can use which
for detecting icpc
instead. Also better check against 0
instead of 127
, since there may be differences from one system to another
ERR = $(shell which icpc >/dev/null; echo $$?)
ifeq "$(ERR)" "0"
CXX = icpc
else
CXX = g++
endif
all:
echo $(CXX)
Upvotes: 1