## consts

dir_lib := lib
dir_source := source
dir_temp := /tmp/zeitbild-temp
dir_build := build
dir_tools := tools

cmd_cat := cat
cmd_chmod := chmod
cmd_cp := cp
cmd_log := echo "--"
cmd_mkdir := mkdir -p
cmd_echo := echo
cmd_tsc := ${dir_tools}/typescript/node_modules/.bin/tsc


## rules

.PHONY: default
default: ${dir_build}/zeitbild

${dir_temp}/zeitbild-unlinked.js: \
		${dir_lib}/plankton/plankton.d.ts \
		${dir_source}/helpers.ts \
		${dir_source}/conf.ts \
		${dir_source}/database.ts \
		${dir_source}/types.ts \
		${dir_source}/repositories/resource.ts \
		${dir_source}/repositories/calendar.ts \
		${dir_source}/services/calendar.ts \
		${dir_source}/api/base.ts \
		${dir_source}/api/actions/meta_ping.ts \
		${dir_source}/api/actions/meta_spec.ts \
		${dir_source}/api/actions/session_begin.ts \
		${dir_source}/api/actions/session_end.ts \
		${dir_source}/api/actions/calendar_list.ts \
		${dir_source}/api/actions/events.ts \
		${dir_source}/api/functions.ts \
		${dir_source}/main.ts
	@ ${cmd_log} "compile …"
	@ ${cmd_mkdir} $(dir $@)
	@ ${cmd_tsc} --lib es2020 --strict $^ --outFile $@

${dir_temp}/head.js:
	@ ${cmd_mkdir} $(dir $@)
	@ ${cmd_echo} "#!/usr/bin/env node" > $@

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