# Makefile for Channelflow library
# $Date: 2005/10/18 15:52:41 $
# $Author: gibson17 $

# Default C flags
CFLAGS = -Wall -O3 -DNDEBUG 
DCFLAGS = -Wall -g -DDEBUG 

# If called as "make profile=1 lib", set profiling options
ifneq (,$(profile))
  PFLAGS = -pg
  PROFILE = -profile
endif

# Define a library name based on debug and profiling flags.
LIBCHANNEL = libchannel$(PROFILE).a
DLIBCHANNEL = libchannel-debug$(PROFILE).a

HEADERS = mathdefs.h complexdefs.h cfvector.h bandedtridiag.h chebyshev.h basisfunc.h helmholtz.h tausolver.h flowfield.h diffops.h dns.h turbstats.h poissonsolver.h cfarray.h utilfuncs.h #cfmatrix.h
 
SOURCES = mathdefs.cpp cfvector.cpp bandedtridiag.cpp chebyshev.cpp basisfunc.cpp helmholtz.cpp tausolver.cpp flowfield.cpp diffops.cpp dns.cpp turbstats.cpp poissonsolver.cpp utilfuncs.cpp #cfmatrix.cpp
 
OBJECTS = mathdefs.o cfvector.o bandedtridiag.o chebyshev.o  basisfunc.o helmholtz.o tausolver.o flowfield.o diffops.o dns.o turbstats.o poissonsolver.o utilfuncs.o #cfmatrix.o

DOBJECTS = mathdefs.do cfvector.do bandedtridiag.do chebyshev.do basisfunc.do helmholtz.do  tausolver.do flowfield.do diffops.do dns.do turbstats.do poissonsolver.do utilfuncs.do #cfmatrix.do

LIBS = -lfftw3 -lm

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

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

# Make a library from the objects. 
../lib/$(LIBCHANNEL) : $(OBJECTS) 
	rm -f ../lib/$(LIBCHANNEL)
	ar rc ../lib/$(LIBCHANNEL) $(OBJECTS)

# Make a library from the objects. 
../lib/$(DLIBCHANNEL) : $(DOBJECTS) 
	rm -f ../lib/$(DLIBCHANNEL)
	ar rc ../lib/$(DLIBCHANNEL) $(DOBJECTS)

# Build a library from objects. Relies on user to make sure that 
# objects were compiled with the right options. This is tricky, but
# useful, for example, if you want a specific object file without
# debugging symbols, and all others with them.
lib : ../lib/$(LIBCHANNEL) 
	rm -f ../include/*.h
	cp $(HEADERS) ../include

dlib :  ../lib/$(DLIBCHANNEL)	
	rm -f ../include/*.h
	cp $(HEADERS) ../include

libs : dlib lib
	rm -f ../include/*.h
	cp $(HEADERS) ../include

# Get rid of binary files.
clean :
	rm -f *.o 
	rm -f *.do 

# Use gcc to generate dependency information for the Makefile
depend : $(SOURCES) 
	g++ -MM $(SOURCES) > depend
	cat depend | sed s/'\.o'/'\.do'/g >> depend

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

%.dx : %.do lib/lib$(DLIBCHANNEL).a
	g++ -o $@ $(DCFLAGS) $(PFLAGS) $< $(DOBJECTS) $(DLIBS)

# Include the automatically generated dependencies into the Makefile.
include depend


