exe = pl

base_files = pcmain.c pebblisp.c tokens.c object.c env.c hash.c
func_files = plfunc/web.c plfunc/general.c plfunc/threads.c plfunc/plstring.c plfunc/pc.c
files:= $(base_files) $(func_files)

libs = -lreadline -lmicrohttpd -lpthread

file_libs := $(files) $(libs)

BINPREFIX ?= /usr/bin
SCRIPTDIR ?= /usr/local/share/pebblisp
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))

GCC_ARGS ?= -g -Wall -o $(exe) -D WEBSERVER -D STANDALONE -DSCRIPTDIR=\"$(SCRIPTDIR)\"
GCC_COM ?= gcc -O0 $(GCC_ARGS)

all: notest
	echo && ./tests.sh

notest:
	$(GCC_COM) $(file_libs)

val: notest
	./tests.sh -val

release_notest:
	gcc -O3 $(GCC_ARGS) -D RELEASE $(file_libs) && strip ./$(exe)

release: release_notest
	echo && ./tests.sh

debug:
	$(GCC_COM) -D DEBUG $(file_libs)

run:
	./$(exe)

install:
	cp -pf ./$(exe) $(BINPREFIX)
	mkdir -p $(SCRIPTDIR)
	cp -r ./examples/* $(SCRIPTDIR)

uninstall:
	rm $(BINPREFIX)/$(exe)
	rm -r $(SCRIPTDIR)