MAKEFLAGS += -r
export TWEEGO_PATH=devTools/tweeGo/storyFormats
HASH := $(shell git rev-list -n 1 --abbrev-commit HEAD)
COMMIT := $(shell git rev-parse --short HEAD)
TWEEGO := $(shell command -v tweego 2>/dev/null)
ifndef TWEEGO
	uname := $(shell uname -s)
	arch := $(shell uname -m)
	arch := $(shell if test $(arch) = x86_64 -o $(arch) = amd64; then echo 64; else echo 32; fi)
	ifeq ($(uname),Linux)
		ifeq ($(arch),64)
			TWEEGO := devTools/tweeGo/tweego_nix64
		else
			TWEEGO := devTools/tweeGo/tweego_nix86
		endif
	else ifeq ($(uname),Darwin)
		ifeq ($(arch),64)
			TWEEGO := devTools/tweeGo/tweego_osx64
		else
			TWEEGO := devTools/tweeGo/tweego_osx86
		endif
	endif
endif

all: bin/FC_pregmod.html bin/resources

git: bin/FC_pregmod_$(HASH).html bin/resources

bin/resources: resources
	test -L "$@" || ln -s "../$<" bin/

bin/%.html: bin/tmp
	git checkout -- src/gui/mainMenu/AlphaDisclaimer.tw
	mv $< $@

bin/fc.js: bin/
	devTools/concatFiles.sh js/ '*.js' $@

bin/tmp: bin/fc.js injectGitCommitHash
	$(TWEEGO) --module=bin/fc.js --head devTools/head.html src/ > $@
	rm -f bin/fc.js

injectGitCommitHash:
	sed -Ei "s/build: .releaseID/\0, commit $(COMMIT)/" src/gui/mainMenu/AlphaDisclaimer.tw

bin/:
	mkdir -p $@

sanity:
	./sanityCheck.sh

sugarcube:
	(cd submodules/sugarcube-2/ && node build.js -6 -b 2)
	cp submodules/sugarcube-2/build/twine2/sugarcube-2/format.js devTools/tweeGo/storyFormats/sugarcube-2/format.js

.PHONY: all sanity git sugarcube

Makefile