
CC=emcc

all: js/cc65.js js/ca65.js js/ld65.js

js/%.js: bin/%.bc
	emcc -O2 --memory-init-file 0 \
		-s ASM_JS=1 \
		-s MODULARIZE=1 \
		-s EXPORT_NAME=\"'$*'\" \
		-s 'EXTRA_EXPORTED_RUNTIME_METHODS=["FS"]' \
		-s FORCE_FILESYSTEM=1 \
		bin/$*.bc -o $@ $(ARGS_$*)

bin/%.bc:
	mkdir -p bin js
	emmake make $* CC=emcc
	cp bin/$*.exe bin/$*.bc

FILE_PACKAGER=python $(EMSCRIPTEN)/tools/file_packager.py 

fs65-all.js:
	python $(EMSCRIPTEN)/tools/file_packager.py fs65.data \
	--preload include asminc cfg lib target \
	neslib/nes.cfg@cfg/neslib.cfg \
	neslib/neslib.lib@lib/neslib.lib \
	neslib/neslib.h@include/neslib.h \
	--separate-metadata --js-output=fs65.js

fs65-nes.js:
	$(FILE_PACKAGER) fs65-nes.data --separate-metadata --js-output=$@ \
	--preload include asminc cfg/nes* lib/nes* target/nes* \
	neslib/nes.cfg@cfg/neslib.cfg \
	neslib/neslib.lib@lib/neslib.lib \
	neslib/neslib.h@include/neslib.h \

fs65-atari8.js:
	$(FILE_PACKAGER) fs65-atari8.data --separate-metadata --js-output=$@ \
	--preload include asminc cfg/atari* lib/atari* target/atari*

fs65-%.js:
	$(FILE_PACKAGER) fs65-$*.data --separate-metadata --js-output=$@ \
	--preload include asminc cfg/$** lib/$** target/$**

filesystems: fs65-nes.js fs65-apple2.js fs65-c64.js fs65-atari8.js
