Monday, December 8, 2008

Makefile to work with both icc and gcc

I need to compile my code with gcc on some computer, but icc on others. So I dig a little bit and come up with this makefile to comply with both compiler with minimum change. The trick here is that GNU make can have conditional expressions, which I don't know before.

Reference: http://www.gnu.org/software/make/manual/make.html

Makefile:


#COMP = intel

C_FLAGS= -g -Wall
#C_FLAGS = -O2

BIN_DIR= $(HOME)/local/bin
NLIB = $(HOME)/proj/nlib

CXX = g++
F77 = gfortran
CXXFLAGS = $(C_FLAGS)
F77FLAGS = $(C_FLAGS) -ffixed-line-length-none
ifeq ($(COMP),intel)
CXX = icc
F77 = ifort
CXXFLAGS = $(C_FLAGS)
F77FLAGS = -O2 -132
endif

EXE = toi

...

# link

$(EXE): $(OBJS)
ifeq ($(COMP),intel)
$(F77) -nofor_main -cxxlib -o $@ $(OBJS) $(FLIBS)
else
$(CXX) $(CXXFLAGS) -I$(NLIB) -MMD -o $@ $(OBJS) $(FLIBS)
endif

No comments:

 
Creative Commons License All contents on this page are licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.