# OS =
# linux_arm64
# linux_x64
# win32_mingw64

CXX = g++
CXX_FLAGS = -std=c++17 -w
INC = -I./include/
LD_FLAGS =

ifeq ($(OS), win32_mingw64)
LD_LIBS = -L./lib/win32_mingw64/ -lbinom -ltcp -lstdc++fs -lpthread -lssl -lcrypto -lws2_32
else
LD_LIBS = -L./lib/$(OS)/ -lbinom -ltcp -lstdc++fs -lpthread -lssl -lcrypto
endif

ifeq ($(DBG), true)
CXX_FLAGS += -ggdb
endif


SRV_SRC = source/server/application.cpp source/security.cpp source/server/layered_action_routing.cpp source/server/actions.cpp
SRV_OBJ = application.o security.o layered_action_routing.o actions.o

server: $(SRV_OBJ) build_folder
	$(CXX) -o librehubd $(SRV_OBJ) $(LD_LIBS) $(LD_FLAGS)
	mv librehubd build/

security.o: source/security.cpp
	$(CXX) -c source/security.cpp $(INC) $(CXX_FLAGS)

application.o: source/server/application.cpp
	$(CXX) -c source/server/application.cpp $(INC) $(CXX_FLAGS)

layered_action_routing.o: source/server/layered_action_routing.cpp
	$(CXX) -c source/server/layered_action_routing.cpp $(INC) $(CXX_FLAGS)

actions.o: source/server/actions.cpp
	$(CXX) -c source/server/actions.cpp $(INC) $(CXX_FLAGS)

libtcp_update:
	make -C TcpServer libtcp.a
	mv TcpServer/libtcp.a lib/$(OS)/
	make -C TcpServer clean

libbinom_update:
	make -C BinOM libbinom.a
	mv BinOM/libbinom.a lib/$(OS)/
	make -C BinOM clean

tcp_inc_update:
	rm -rf include/tcp/*
	cp TcpServer/tcp/include/* include/tcp/

binom_inc_update:
	rm -rf include/binom/*
	cp BinOM/libbinom/include/* include/binom/ -r

build_folder:
	mkdir build -p

inc_update: tcp_inc_update binom_inc_update

libs_update: libtcp_update libbinom_update

tcp_update: libtcp_update tcp_inc_update

binom_update: libbinom_update binom_inc_update

clean:
	rm -rf ./*.o ./librehubd ./build
