# 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

## 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}/structure.html
	@ ${cmd_log} "structure …"
	@ ${cmd_dir_make} ${dir_build}
	@ ${cmd_copy} $^ $@

${dir_temp}/logic-unlinked.js: ${dir_source}/logic.js
	@ ${cmd_log} "logic:compiling …"
	@ ${cmd_dir_make} ${dir_temp}
	@ ${cmd_concatenate} $^ > $@

${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.css
	@ ${cmd_log} "style …"
	@ ${cmd_concatenate} $^ > $@