#Troy Rosin

CC				=gcc
CFLAGS		=-g
CPPFLAGS	=-c -g -Wall -pedantic -Wextra
LDFLAGS		=-lSDL2 -lm -lSDL2main -lSDL2_image
LDFLAGS 	+=-L/usr/local/lib -lSDL2_ttf
INCFLAGS	= -I. -Iinclude 


INC				=include/
BIN				=build/bin/
LIB				=build/lib/
OBJ				=build/obj/
DIRS			=$(BIN) $(LIB) $(OBJ)

debug			?=on
ifeq ($(debug),on)
CPPFLAGS += -Ddebug
endif

BINARIES	= game client_test server_test

all : $(BINARIES)

clean :
	rm -rf build/ $(BINARIES)

$(DIRS) :
	mkdir -p $@

## --- OBJECT FILES ---
#$(OBJ) : | $(OBJ) 
#	$(CC) $(CPPFLAGS) -o $@ $< $(INCFLAGS)

$(OBJ)client_test.o : client_test.c | $(OBJ) 
	$(CC) $(CPPFLAGS) -o $@ $< $(INCFLAGS)

$(OBJ)server_test.o : server_test.c | $(OBJ) 
	$(CC) $(CPPFLAGS) -o $@ $< $(INCFLAGS)

$(OBJ)main.o : main.c $(INC)input.h $(INC)game.h | $(OBJ) 
	$(CC) $(CPPFLAGS) -o $@ $< $(INCFLAGS)

$(OBJ)battle.o : battle.c $(INC)game.h $(INC)deck.h | $(OBJ) 
	$(CC) $(CPPFLAGS) -o $@ $< $(INCFLAGS)

$(OBJ)input.o : input.c $(INC)input.h | $(OBJ) 
	$(CC) $(CPPFLAGS) -o $@ $< $(INCFLAGS)

$(OBJ)host.o : host.c $(INC)host.h | $(OBJ) 
	$(CC) $(CPPFLAGS) -o $@ $< $(INCFLAGS)

$(OBJ)join.o : join.c | $(OBJ) 
	$(CC) $(CPPFLAGS) -o $@ $< $(INCFLAGS)

$(OBJ)options.o : options.c | $(OBJ) 
	$(CC) $(CPPFLAGS) -o $@ $< $(INCFLAGS)

$(OBJ)game.o : game.c $(INC)game.h | $(OBJ) 
	$(CC) $(CPPFLAGS) -o $@ $< $(INCFLAGS)

$(OBJ)overworld.o : overworld.c $(INC)overworld.h | $(OBJ) 
	$(CC) $(CPPFLAGS) -o $@ $< $(INCFLAGS)



## --- LIBRARY FILES ---
#$(LIB) :  | $(LIB)
#	ar rcs $@ $^ 

## --- EXECUTABLE FILES ---
#$(BIN) : $(OBJ) | $(BIN)
#	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

$(BIN)client_test : $(OBJ)client_test.o | $(BIN)
	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

$(BIN)server_test: $(OBJ)server_test.o | $(BIN)
	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) 
  
$(BIN)game : $(OBJ)main.o $(OBJ)input.o $(OBJ)battle.o $(OBJ)game.o\
	 $(OBJ)options.o $(OBJ)host.o $(OBJ)join.o $(OBJ)overworld.o | $(BIN)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

$(BINARIES) : % : $(BIN)%
	ln -sf $< $@ 
