LIBOBJ = ad4cache.o cache.o non_cache.o conf_independent.o coords.o grid.o szv_grid.o model.o monte_carlo.o mutate.o parallel_mc.o parse_pdbqt.o quasi_newton.o quaternion.o random.o utils.o vina.o
MAINOBJ = main.o
SPLITOBJ = split.o

INCFLAGS = -I $(BOOST_INCLUDE)

GIT_VERSION := $(shell git describe --abbrev=7 --dirty --always --tags | sed 's/dirty/mod/g')
ifeq (,$(GIT_VERSION))
GIT_VERSION := v1.2.7
endif
C_OPTIONS+=-DVERSION=\"$(GIT_VERSION)\"

# -pedantic fails on Mac with Boost 1.41 (syntax problems in their headers)
#CC = ${GPP} ${C_PLATFORM} -ansi -pedantic -Wno-long-long ${C_OPTIONS} $(INCFLAGS)
CC = ${GPP} ${C_PLATFORM} -ansi -Wno-long-long ${C_OPTIONS} $(INCFLAGS)

LDFLAGS = -L$(BASE)/lib -L.

# test if boost_thread-mt exists, this is
# necessary as some versions of boost only
# install libboost_thread-mt, but not
# libboost_thread (e.g. macOS)
$(shell echo "int main(){ return 0; }" > linktest.cpp)
ifeq ($(BOOST_STATIC), y)
$(shell $(CC) $(LDFLAGS) ${BASE}/lib/libboost_thread-mt${BOOST_LIB_VERSION}.a linktest.cpp -o linktest >/dev/null 2>&1)
else
$(shell $(CC) $(LDFLAGS) -l boost_thread-mt${BOOST_LIB_VERSION} linktest.cpp -o linktest >/dev/null 2>&1)
endif
threadmt:=$(shell if [ -f ./linktest ]; then echo "-mt"; rm ./linktest; fi;)
$(shell rm ./linktest.cpp)

ifeq ($(BOOST_STATIC), y)
LIBS = ${BASE}/lib/libboost_system${BOOST_LIB_VERSION}.a ${BASE}/lib/libboost_thread${threadmt}${BOOST_LIB_VERSION}.a ${BASE}/lib/libboost_serialization${BOOST_LIB_VERSION}.a ${BASE}/lib/libboost_filesystem${BOOST_LIB_VERSION}.a ${BASE}/lib/libboost_program_options${BOOST_LIB_VERSION}.a
else
LIBS = -l boost_system${BOOST_LIB_VERSION} -l boost_thread${threadmt}${BOOST_LIB_VERSION} -l boost_serialization${BOOST_LIB_VERSION} -l boost_filesystem${BOOST_LIB_VERSION} -l boost_program_options${BOOST_LIB_VERSION}#-l pthread
endif

.SUFFIXES: .cpp .o

%.o : ../../../src/lib/%.cpp 
	$(CC) $(CFLAGS) -o $@ -c $< 

%.o : ../../../src/design/%.cpp 
	$(CC) $(CFLAGS) -I ../../../src/lib -o $@ -c $< 
	
%.o : ../../../src/main/%.cpp 
	$(CC) $(CFLAGS) -I ../../../src/lib -o $@ -c $< 

%.o : ../../../src/split/%.cpp 
	$(CC) $(CFLAGS) -I ../../../src/lib -o $@ -c $< 

all: vina vina_split

include dependencies

vina: $(MAINOBJ) $(LIBOBJ)
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

vina_split: $(SPLITOBJ)
	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)

clean:
	rm -f *.o

depend:
	ln -sf `${GPP} -print-file-name=libstdc++.a`
	rm -f dependencies_tmp dependencies_tmp.bak
	touch dependencies_tmp
	makedepend -f dependencies_tmp -Y -I ../../../src/lib ../../../src/lib/*.cpp ../../../src/tests/*.cpp ../../../src/design/*.cpp ../../../src/main/*.cpp ../../../src/split/*.cpp  ../../../src/tune/*.cpp
	sed -e "s/^\.\.\/\.\.\/\.\.\/src\/[a-z]*\//.\//" dependencies_tmp > dependencies
	rm -f dependencies_tmp dependencies_tmp.bak
