# Makefile for Channelflow executables
# $Date$
# $Author$

# Define where ChannelFlow is installed
CHANNELDIR = ../..

# Define default C flags
CFLAGS = -Wall -O2 -DNDEBUG
DCFLAGS = -Wall -g -DDEBUG 

# Reset C flags if make is run as "make debug=1 ..."
# Set a profiling flags if make is run as "make profile=1"
ifneq (,$(profile))
  PFLAGS = -pg
  PROFILE = -profile
endif

INCLUDEDIR = -I$(CHANNELDIR)/include 
LIBCHANNEL = channel$(PROFILE)
LIBS = -L$(CHANNELDIR)/lib -l$(LIBCHANNEL) -lfftw3 -lm

DLIBCHANNEL = channel-debug$(PROFILE)
DLIBS = -L$(CHANNELDIR)/lib -l$(DLIBCHANNEL) -lfftw3 -lm 


# Make executables from objects and libraries
%.x: %.o $(CHANNELDIR)/lib/lib$(LIBCHANNEL).a
	g++ -o $@ $(PFLAGS) $< $(OBJECTS) $(LIBS)

# Make objects from source
%.o : %.cpp
	g++ $(CFLAGS) $(PFLAGS) $(INCLUDEDIR) -c $< 

# Make executables from objects and libraries
%.dx: %.do $(CHANNELDIR)/lib/lib$(DLIBCHANNEL).a
	g++ -o $@ $(PFLAGS) $< $(OBJECTS) $(DLIBS)

# Make objects from source
%.do : %.cpp
	g++ $(DCFLAGS) $(PFLAGS) $(INCLUDEDIR) -o $@ -c $< 

clean :
	rm *.o *.x *.do *.dx