## consts

dir_lib := lib
dir_source := source
dir_temp := temp
dir_build := build

cmd_log := echo "--"
cmd_cat := cat
cmd_chmod := chmod
cmd_mkdir := mkdir -p
cmd_cp := cp


## rules

.PHONY: default
default: node_modules ${dir_build}/espe


.PHONY: node_modules
node_modules:
	@ ${cmd_mkdir} ${dir_build}/node_modules
	@ ${cmd_log} "node modules …"
	@ ${cmd_cp} -r -u ${dir_lib}/node/node_modules/* ${dir_build}/node_modules/

${dir_temp}/espe-unlinked.js: \
	${dir_lib}/plankton/plankton.d.ts \
	${dir_source}/helpers.ts \
	${dir_source}/database.ts \
	${dir_source}/service-member.ts \
	${dir_source}/service-admin.ts \
	${dir_source}/api/base.ts \
	${dir_source}/api/actions/session_begin.ts \
	${dir_source}/api/actions/session_end.ts \
	${dir_source}/api/actions/email.ts \
	${dir_source}/api/actions/verification_get.ts \
	${dir_source}/api/actions/verification_check.ts \
	${dir_source}/api/actions/member_list.ts \
	${dir_source}/api/actions/member_read.ts \
	${dir_source}/api/actions/member_create.ts \
	${dir_source}/api/actions/member_update.ts \
	${dir_source}/api/actions/member_delete.ts \
	${dir_source}/api/actions/member_urge_for_registration.ts \
	${dir_source}/api/actions/member_register.ts \
	${dir_source}/api/functions.ts \
	${dir_source}/conf.ts \
	${dir_source}/main.ts
	@ ${cmd_log} "compile …"
	@ ${cmd_mkdir} $(dir $@)
	@ tsc --lib es2020 $^ --outFile $@

${dir_build}/espe: ${dir_source}/head.js ${dir_lib}/plankton/plankton.js ${dir_temp}/espe-unlinked.js
	@ ${cmd_log} "link …"
	@ ${cmd_mkdir} $(dir $@)
	@ ${cmd_cat} $^ > $@
	@ ${cmd_chmod} +x $@
