# Makefile for Channelflow library
# $Date: 2003/11/03 14:51:55 $
# $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 vector.h bandedtridiag.h chebyshev.h basisfunc.h helmholtz.h tausolver.h flowfield.h nsintegrator.h turbstats.h 
 
SOURCES = mathdefs.cpp vector.cpp bandedtridiag.cpp chebyshev.cpp basisfunc.cpp helmholtz.cpp tausolver.cpp flowfield.cpp nsintegrator.cpp turbstats.cpp 
 
OBJECTS = mathdefs.o vector.o bandedtridiag.o chebyshev.o  basisfunc.o helmholtz.o tausolver.o flowfield.o nsintegrator.o turbstats.o 

DOBJECTS = mathdefs.do vector.do bandedtridiag.do chebyshev.do basisfunc.do helmholtz.do  tausolver.do flowfield.do nsintegrator.do turbstats.do 

LIBS = -ldrfftw -ldfftw -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


