#
#   vnet makefile
#   
#

########################################
# compiler & linker
#
CXX = g++
LN = g++

########################################
# source/build directories
#
S = source
B = build

########################################
# build options
#
CXX_FLAGS =-g -Wall -Isource -D_THREAD_SAFE 
LN_FLAGS =
LN_LIBS = -lpthread

########################################
# rules
#

all : ${B}/all
dirty: ${B}/dirty
	

${B}/cSocket.o : ${S}/cSocket.cpp ${S}/cSocket.h ${S}/cRandom.h
	${CXX} ${CXX_FLAGS} -c ${S}/cSocket.cpp -o ${B}/cSocket.o

## tun driver that doesn't work on windows; might still compile
${B}/cTun.o : ${S}/cTun.cpp ${S}/cTun.h
	${CXX} ${CXX_FLAGS} -c ${S}/cTun.cpp -o ${B}/cTun.o
	
${B}/cRandom.o : ${S}/cRandom.cpp ${S}/cRandom.h
	${CXX} ${CXX_FLAGS} -c ${S}/cRandom.cpp -o ${B}/cRandom.o
	
${B}/cSettings.o : ${S}/cSettings.cpp ${S}/cSettings.h
	${CXX} ${CXX_FLAGS} -c ${S}/cSettings.cpp -o ${B}/cSettings.o
	
${B}/cMutex.o : ${S}/cMutex.cpp ${S}/cMutex.h
	${CXX} ${CXX_FLAGS} -c ${S}/cMutex.cpp -o ${B}/cMutex.o
	
${B}/cThread.o : ${S}/cThread.cpp ${S}/cThread.h
	${CXX} ${CXX_FLAGS} -c ${S}/cThread.cpp -o ${B}/cThread.o

${B}/cClients.o : ${S}/cClients.cpp ${S}/cClients.h 
	${CXX} ${CXX_FLAGS} -c ${S}/cClients.cpp -o ${B}/cClients.o

${B}/cClient.o : ${S}/cClient.cpp ${S}/cClient.h ${S}/cThread.h ${S}/cSettings.h ${S}/cSocket.h ${S}/cTun.h
	${CXX} ${CXX_FLAGS} -c ${S}/cClient.cpp -o ${B}/cClient.o
	
${B}/cServer.o : ${S}/cServer.cpp ${S}/cServer.h ${S}/cThread.h ${S}/cMutex.h ${S}/cSettings.h ${S}/cSocket.h ${S}/cQueue.h
	${CXX} ${CXX_FLAGS} -c ${S}/cServer.cpp -o ${B}/cServer.o
	
## evil minilzo library... damned GPL, also damned C...
${B}/minilzo.o : ${S}/minilzo/minilzo.c ${S}/minilzo/minilzo.h
	${CXX} ${CXX_FLAGS} -c ${S}/minilzo/minilzo.c -o ${B}/minilzo.o
## end evil

${B}/main.o : ${S}/cServer.h ${S}/cClient.h ${S}/cThread.h ${S}/cSettings.h ${S}/main.cpp
	${CXX} ${CXX_FLAGS} -c ${S}/main.cpp -o ${B}/main.o

${B}/client_main.o : ${S}/cClient.h ${S}/cSettings.h ${S}/client_main.cpp
	${CXX} ${CXX_FLAGS} -c ${S}/client_main.cpp -o ${B}/client_main.o
	
${B}/server_main.o : ${S}/cServer.h ${S}/cSettings.h ${S}/server_main.cpp
	${CXX} ${CXX_FLAGS} -c ${S}/server_main.cpp -o ${B}/server_main.o

## main.exec
${B}/main.exec : 	${B}/main.o ${B}/cSocket.o  ${B}/cRandom.o ${B}/cSettings.o ${B}/cTun.o ${B}/cThread.o \
					${B}/cMutex.o ${B}/minilzo.o ${B}/cClient.o ${B}/cClients.o ${B}/cServer.o
	${LN} ${LN_FLAGS} ${LN_LIBS} ${B}/main.o ${B}/cClient.o ${B}/cClients.o ${B}/cServer.o ${B}/cSocket.o ${B}/cRandom.o ${B}/cSettings.o ${B}/cTun.o ${B}/cMutex.o ${B}/cThread.o ${B}/minilzo.o -o ${B}/main.exec

${B}/client.exec : 	${B}/client_main.o ${B}/cSocket.o  ${B}/cRandom.o ${B}/cSettings.o ${B}/cTun.o ${B}/cThread.o \
					${B}/cMutex.o ${B}/minilzo.o ${B}/cClient.o ${B}/cClients.o ${B}/cServer.o
	${LN} ${LN_FLAGS} ${LN_LIBS} ${B}/client_main.o ${B}/cClient.o ${B}/cClients.o ${B}/cServer.o ${B}/cSocket.o ${B}/cRandom.o ${B}/cSettings.o ${B}/cTun.o ${B}/cMutex.o ${B}/cThread.o ${B}/minilzo.o -o ${B}/client.exec

${B}/server.exec : 	${B}/server_main.o ${B}/cSocket.o  ${B}/cRandom.o ${B}/cSettings.o ${B}/cTun.o ${B}/cThread.o \
					${B}/cMutex.o ${B}/minilzo.o ${B}/cClient.o ${B}/cClients.o ${B}/cServer.o
	${LN} ${LN_FLAGS} ${LN_LIBS} ${B}/server_main.o ${B}/cClient.o ${B}/cClients.o ${B}/cServer.o ${B}/cSocket.o ${B}/cRandom.o ${B}/cSettings.o ${B}/cTun.o ${B}/cMutex.o ${B}/cThread.o ${B}/minilzo.o -o ${B}/server.exec



# all
${B}/all : ${B}/main.exec ${B}/client.exec ${B}/server.exec
	@touch ${B}/all
 
#dirty
${B}/dirty : ${B}/all
	@touch ${B}/dirty
	@echo "<make> Fuzzy handcuffs or tight black leather?"
	
	
#######
.PHONY : clean
clean :
	@if [ -e ${B}/dirty ]; then echo "<make> Awwh, but we were having so much fun! Cleaning the (dirty) build directory."; else echo "Cleaning Build directory."; fi
	@touch ${B}/rm
	@rm -f ${B}/*
	@touch ${B}/.keep















