#CC=gcc
CC=gcc -lpthread

PUBLIC_TESTS:=$(wildcard public? public??)
SECRET_TESTS:=$(wildcard secret? secret??)
ALL_TESTS   :=$(PUBLIC_TESTS) $(SECRET_TESTS)


CLIENT_SRCS :=$(wildcard client?.c) $(wildcard client??.c)
CLIENT_PROGS:=$(basename $(CLIENT_SRCS))



all: server $(CLIENT_PROGS) chmod

TESTS:=$(ALL_TESTS) $(wildcard *.run)
chmod:
	chmod a+x $(TESTS) check-output


clean:
	rm $(wildcard server *.log tester_2.zip $(CLIENT_PROGS))

ALL_TESTS_OUT:=$(addsuffix .output,$(ALL_TESTS))
ALL_TESTS_RE :=$(addsuffix .re,$(ALL_TESTS))

compile:server $(CLIENT_PROGS) 

%.output: compile %.run 
	./$*.run > $@

%.output: compile
	./public.run $(subst secret,,$(subst public,,$*)) > $@

%.re: %.output
	./regexpr $*.output > $@

tester_2.zip: $(ALL_TESTS_RE) $(ALL_TESTS_OUT) check-output
	cp handpick/* .
	zip -9 $@ check-output test.properties client.h Makefile  $(ALL_TESTS_RE) $(ALL_TESTS_OUT) $(TESTS) $(CLIENT_SRCS)
	rm handpick.readme
	zip -9 server.zip server.c common.h 

