#/bin/sh

LIBDIR = @buildlib@
INCDIR = -I@ctroot@/Cantera/src
BINDIR = @buildbin@
build_ck = @BUILD_CK@

LCXX_FLAGS = -L$(LIBDIR)  @LOCAL_LIB_DIRS@ @CXXFLAGS@
LOCAL_LIBS = -lcantera -ltpx -lctcxx 
#LOCAL_LIBS = -lcantera @math_libs@ @BLAS_LAPACK_LIBS@ -lctcxx 

LCXX_END_LIBS = @LCXX_END_LIBS@ @EXTRA_LINK@

OBJS = ck2cti.o cti2ctml.o fixtext.o

DEPENDS = $(OBJS:.o=.d)

CONVLIB_DEP = @buildlib@/libconverters.a
CANTERALIB_DEP = @buildlib@/libcantera.a \
	         @buildlib@/libctcxx.a

progs = $(BINDIR)/cti2ctml $(BINDIR)/fixtext
ifeq ($(build_ck),1) 
exes =  $(progs) $(BINDIR)/ck2cti
else
exes = $(progs)
endif

.cpp.o:
	@CXX@ -c $< @DEFS@  $(INCDIR) @CXXFLAGS@ $(CXX_FLAGS) 

all: $(exes)

ck: $(BINDIR)/ck2cti

$(BINDIR)/ck2cti: ck2cti.o $(CONVLIB_DEP) $(CANTERALIB_DEP)
	$(RM) $(BINDIR)/ck2cti
	@CXX@ -o $(BINDIR)/ck2cti ck2cti.o $(LCXX_FLAGS) \
               -lconverters -lcantera -ltpx -lctcxx $(LCXX_END_LIBS)

$(BINDIR)/cti2ctml: cti2ctml.o $(CANTERALIB_DEP)
	$(RM) $(BINDIR)/cti2ctml
	@CXX@ -o $(BINDIR)/cti2ctml cti2ctml.o $(LCXX_FLAGS) $(LOCAL_LIBS) \
               $(LCXX_END_LIBS)

$(BINDIR)/fixtext: fixtext.o 
	$(RM) $(BINDIR)/fixtext
	@CXX@ -o $(BINDIR)/fixtext fixtext.o $(LCXX_FLAGS) \
               $(LCXX_END_LIBS)

$(CONVLIB_DEP):
	cd ../../Cantera/src/converters; @MAKE@

clean:
	$(RM) *.o *.*~ $(BINDIR)/cti2ctml $(BINDIR)/ck2cti
	(if test -d SunWS_cache ; then \
           $(RM) -rf SunWS_cache ; \
        fi )

%.d:
	@CXX@ -MM $(INCDIR) @CXXFLAGS@ $(CXX_FLAGS) $*.cpp > $*.d

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

ifeq ((test -e .depends),0)
include .depends
endif
