BORINGSSL_DIR=/home/hdc/repos/cloudflare/boringssl
BORINGSSL_LIB=$(BORINGSSL_DIR)/build.64bitRel/

CC 		= clang
SRCDIR 	= src
OBJDIR 	= obj
DBG    ?= 1

ifeq ($(DBG),1)
DEBUG = -DDEBUG -g -O0
else
DEBUG = -O3
endif

CFLAGS = -std=c99
CFLAGS+= $(DEBUG)
CFLAGS+= -I$(BORINGSSL_DIR)/ -I$(BORINGSSL_DIR)/include

LDFLAGS = -L$(BORINGSSL_LIB)/crypto -L$(BORINGSSL_LIB)/ssl
LDFLAGS+= -lssl -lcrypto -lpthread

all: server client

clean:
	rm -rf $(OBJDIR)
	rm -rf client server

client: common
	$(CC) -c $(SRCDIR)/client.c -o $(OBJDIR)/client.o $(CFLAGS)
	$(CC) -o client $(OBJDIR)/client.o $(OBJDIR)/common.o $(LDFLAGS)

server: common
	$(CC) -c $(SRCDIR)/server.c -o $(OBJDIR)/server.o $(CFLAGS)
	$(CC) -o server $(OBJDIR)/server.o $(OBJDIR)/common.o  $(LDFLAGS)

common:
	mkdir -p $(OBJDIR)
	$(CC) -c $(SRCDIR)/common.c -o $(OBJDIR)/common.o $(CFLAGS)
