# we make binaries that are compiled from the imp sources by the c binaries
# this is an intermediate state between c compiled by c and imp compiled by imp

all: pass1 pass2 takeon
	echo All up to date

pass1: pass1.imp i77.tables.imp imp2021
	./imp2021 pass1.imp

pass2: pass2.imp imp2021
	./imp2021 pass2.imp

takeon: takeon.imp imp2021
	./imp2021 takeon.imp

pass1.imp:
	./getfile https://raw.githubusercontent.com/siliconsam/imp2021/main/source/imp/compiler/pass1.imp
	./remove-cr pass1.imp
	./ecce pass1.imp -command "(r0v-/%c/s//ji/ /,m)0;%c"
	# some temporary edits until the github code is updated
	./ecce pass1.imp -command "f/%ownbyteintegerarray char(0:133) = ;  !input line/s/%ownbyteintegerarray char(0:133) = { input line }/;%c"
	./ecce pass1.imp -command "f/!         err,1764, 247, err(4), -rtp, -fnp, -mapp, -predp, err, 214,/s/{         err,1764, 247, err(4), -rtp, -fnp, -mapp, -predp, err, 214, }/;%c"
	./ecce pass1.imp -command "f/class = escdec;  g = glink(g)              ! escape/s/class = escdec;  g = glink(g) ! escape/;%c"

pass2.imp:
	./getfile https://raw.githubusercontent.com/siliconsam/imp2021/main/source/imp/compiler/pass2.imp
	./remove-cr pass1.imp
	./ecce pass2.imp -command "(r0v-/%c/s//ji/ /,m)0;%c"

takeon.imp:
	./getfile https://raw.githubusercontent.com/siliconsam/imp2021/main/source/imp/compiler/takeon.imp
	./remove-cr pass1.imp

imp2021-i:
	make -f Makefile
	mv pass1-c pass1c
	mv pass2-c pass2c
	mv takeon-c takeonc

i77.tables.imp: i77.grammar takeon
	./takeon i77.grammar=i77.tables.imp,i77.par.debug,i77.lex.debug

i77.grammar:
	./getfile https://raw.githubusercontent.com/siliconsam/imp2021/main/source/imp/compiler/i77.grammar
	./remove-cr i77.grammar

clean:
	@rm -f pass1.imp  pass2.imp  takeon.imp  i77.tables.imp i77.grammar

