## directories

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


## commands

cmd_log := echo "--"
cmd_copy := cp --recursive --update --verbose
cmd_concatenate := cat
cmd_dir_make := mkdir --parents
cmd_tsc := tsc --lib dom,es2016 --target ES6
cmd_sassc := sassc


## rules

all: ${dir_build}/index.html ${dir_build}/logic.js ${dir_build}/style.css
.PHONY: all

${dir_temp}/plankton.d.ts:
	@ ${cmd_log} "fetching plankton declaration"
	@ ${cmd_dir_make} ${dir_temp}
	@ schwamm --include=${dir_lib}/plankton/plankton.swm.json --output=dump:logic-decl > ${dir_temp}/plankton.d.ts

${dir_temp}/plankton.js:
	@ ${cmd_log} "fetching plankton implementation"
	@ ${cmd_dir_make} ${dir_temp}
	@ schwamm --include=${dir_lib}/plankton/plankton.swm.json --output=dump:logic-impl > ${dir_temp}/plankton.js

${dir_build}/index.html: ${dir_source}/main.html
	@ ${cmd_log} "structure …"
	@ ${cmd_dir_make} ${dir_build}
	@ ${cmd_copy} $^ $@

${dir_temp}/logic-unlinked.js: \
	${dir_temp}/plankton.d.ts \
	${dir_source}/conf.ts \
	${dir_source}/widgets/widget.ts \
	${dir_source}/widgets/languagechooser/logic.ts \
	${dir_source}/widgets/correlation/logic.ts \
	${dir_source}/widgets/translate/logic.ts \
	${dir_source}/pages/page.ts \
	${dir_source}/pages/portal/logic.ts \
	${dir_source}/services/service.ts \
	${dir_source}/main.ts
	@ ${cmd_log} "logic:compiling …"
	@ ${cmd_dir_make} ${dir_temp}
	@ ${cmd_tsc} $^ --outFile $@

${dir_build}/logic.js: ${dir_temp}/plankton.js ${dir_temp}/logic-unlinked.js
	@ ${cmd_log} "logic:linking …"
	@ ${cmd_dir_make} ${dir_build}
	@ ${cmd_concatenate} $^ > $@

${dir_build}/style.css: ${dir_source}/style.sass
	@ ${cmd_log} "style …"
	@ ${cmd_concatenate} $^ | ${cmd_sassc} --stdin > $@