cmd_md := mkdir -p
cmd_rm := rm -rf
cmd_echo := echo # -e
cmd_cp := cp -r -u -v
cmd_cat := cat
cmd_ln := ln --symbolic
cmd_tsc := tsc --target ES5 --allowUnreachableCode
cmd_sass := sassc

dir_source := source
dir_build := build

all: \
	${dir_build}/vtm.html \
	${dir_build}/vtm.css \
	${dir_build}/vtm.dat.js \
	${dir_build}/vtm.js \
	music \
	${dir_build}/index.html
.PHONY: all

clear:
	@ ${cmd_echo} "-- clearing …"
	@ ${cmd_rm} ${dir_build}
.PHONY: clear

${dir_build}/vtm.html: \
	${dir_source}/main.html
	@ ${cmd_echo} "-- structure …"
	@ ${cmd_md} ${dir_build}
	@ ${cmd_cp} $^ $@

${dir_build}/vtm.css: \
	${dir_source}/manifestation/web/game.scss \
	${dir_source}/main.scss
	@ ${cmd_echo} "-- style …"
	@ ${cmd_md} ${dir_build}
	@ ${cmd_cat} $^ | ${cmd_sass} --stdin > $@

${dir_build}/vtm.dat.js: \
	${dir_source}/data/strings/de.dat.js \
	${dir_source}/data/strings/en.dat.js \
	${dir_source}/data/strings/eo.dat.js \
	${dir_source}/data/tasks.dat.js
	@ ${cmd_echo} "-- data …"
	@ ${cmd_md} ${dir_build}
	@ ${cmd_cat} $^ > $@

${dir_build}/vtm.js: \
	${dir_source}/helpers/types.ts \
	${dir_source}/helpers/call.ts \
	${dir_source}/helpers/trait.ts \
	${dir_source}/helpers/errormonade.ts \
	${dir_source}/helpers/string.ts \
	${dir_source}/helpers/xml.ts \
	${dir_source}/helpers/list.ts \
	${dir_source}/helpers/math.ts \
	${dir_source}/helpers/vector.ts \
	${dir_source}/helpers/hashmap.ts \
	${dir_source}/helpers/translate.ts \
	${dir_source}/helpers/svg.ts \
	${dir_source}/data/_data.ts \
	${dir_source}/model/direction.ts \
	${dir_source}/model/symbol.ts \
	${dir_source}/model/spot.ts \
	${dir_source}/model/state.ts \
	${dir_source}/model/token.ts \
	${dir_source}/model/actuators/_actuator.ts \
	${dir_source}/model/actuators/rejector.ts \
	${dir_source}/model/actuators/acceptor.ts \
	${dir_source}/model/actuators/generator.ts \
	${dir_source}/model/actuators/conveyer.ts \
	${dir_source}/model/actuators/writer.ts \
	${dir_source}/model/actuators/reader.ts \
	${dir_source}/model/world.ts \
	${dir_source}/model/tasks/acceptortest.ts \
	${dir_source}/model/tasks/transducertest.ts \
	${dir_source}/model/tasks/test.ts \
	${dir_source}/model/tasks/acceptortask.ts \
	${dir_source}/model/tasks/transducertask.ts \
	${dir_source}/model/tasks/task.ts \
	${dir_source}/model/mode.ts \
	${dir_source}/model/game.ts \
	${dir_source}/manifestation/manifestation.ts \
	${dir_source}/manifestation/position.ts \
	${dir_source}/manifestation/svg/token.ts \
	${dir_source}/manifestation/svg/actuators/_actuator.ts \
	${dir_source}/manifestation/svg/actuators/rejector.ts \
	${dir_source}/manifestation/svg/actuators/acceptor.ts \
	${dir_source}/manifestation/svg/actuators/generator.ts \
	${dir_source}/manifestation/svg/actuators/conveyer.ts \
	${dir_source}/manifestation/svg/actuators/writer.ts \
	${dir_source}/manifestation/svg/actuators/reader.ts \
	${dir_source}/manifestation/svg/game.ts \
	${dir_source}/manifestation/web/game.ts \
	${dir_source}/manifestation/store/game.ts \
	${dir_source}/main.ts 
	@ ${cmd_echo} "-- logic …"
	@ ${cmd_md} ${dir_build}
	@ ${cmd_tsc} $^ --outFile $@

music:
	@ ${cmd_md} ${dir_build}/music
	@ ${cmd_cp} ${dir_source}/music/* ${dir_build}/music/
.PHONY: music

${dir_build}/index.html:
	@ ${cmd_ln} vtm.html ${dir_build}/index.html
	
