#/bin/sh
###############################################################
#  $Author: hkmoffa $
#  $Date: 2006/04/30 22:15:06 $
#  $Revision: 1.11 $
#
#  Copyright 2001 California Institute of Technology
#
###############################################################

.SUFFIXES :
.SUFFIXES :  .cpp .d .o .f90 .mod

CXX_FLAGS = @CXXFLAGS@ $(CXX_OPT)
FORT_FLAGS = @F90BUILDFLAGS@


CXX_OBJS = fct.o fctxml.o

INTERFACE_MODULE_OBJS = fct_interface.o fctxml_interface.o 

USER_MODULE_OBJS = cantera_xml.o cantera_thermo.o cantera_kinetics.o \
                   cantera_transport.o cantera_funcs.o cantera.o

MODULES = $(INTERFACE_MODULE_OBJS:_interface.o=.mod) $(USER_MODULE_OBJS)
OBJS = $(CXX_OBJS) $(USER_MODULE_OBJS)

DEPENDS = $(CXX_OBJS:.o=.d)
MODFILES = $(MODULES:.o=.mod)

# Fortran libraries
FORT_LIBS = @FLIBS@

# the C++ compiler
CXX = @CXX@

# the Fortran 90/95 compiler
F90 = @F90@

# external libraries
EXT_LIBS = @LOCAL_LIBS@ 

# the directory where the Cantera libraries are located
CANTERA_LIBDIR=@buildlib@

# ../../../lib
LIB_DEPS = $(CANTERA_LIBDIR)/libcantera.a \
           $(CANTERA_LIBDIR)/libtransport.a

# the directory where Cantera include files may be found.
CANTERA_INCDIR=../../src

# the directory where module .mod files should be put
MODULE_DIR = @buildinc@/cantera

CXX_INCLUDES = -I$(CANTERA_INCDIR)  

# flags passed to the C++ compiler/linker for the linking step
LCXX_FLAGS = -L$(CANTERA_LIBDIR) @CXXFLAGS@

# how to compile C++ source files to object files
%.o : %.cpp
	$(CXX) -c $< $(CXX_INCLUDES) $(CXX_FLAGS)

%.o : %.f90
	$(F90) -c $< $(FORT_FLAGS)

%.mod : %_interface.f90
	$(F90) -c $< $(FORT_FLAGS)

%.mod : %.f90
	$(F90) -c $< $(FORT_FLAGS)

LIB_NAME=libfct.a

FTLIB = @buildlib@/$(LIB_NAME)

$(FTLIB): $(MODFILES) $(USER_MODULE_OBJS) $(CXX_OBJS) $(LIB_DEPS)
	$(RM)     $(FTLIB)
	@ARCHIVE@ $(FTLIB) $(OBJS)

clean:
	$(RM) $(OBJS) $(FTLIB) $(MODFILES)
	(if test -d SunWS_cache ; then \
           $(RM) -rf SunWS_cache ; \
         fi )

install:
	@INSTALL@ $(FTLIB) @ct_libdir@
	@INSTALL@ $(MODFILES) @ct_incdir@

win-install:
	@INSTALL@ ../../../lib/fct.lib @ct_libdir@

%.d: %.cpp
	g++ -MM $(CXX_INCLUDES) $*.cpp > $*.d

depends: $(DEPENDS)
	cat *.d > .depends
	$(RM) $(DEPENDS) 

cantera_thermo.o: fct.mod cantera_xml.mod cantera_thermo.f90
fct.mod: fct_interface.f90
fctxml.mod: fctxml_interface.f90

ifeq ($(wildcard .depends), .depends)
include .depends
endif
