# 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: pass1i pass2i takeoni
	echo All up to date

pass1i: pass1.imp i77.tables.imp imp2021-i
	./imp2021-i pass1.imp
	mv pass1-i pass1i

pass2i: pass2.imp imp2021-i
	./imp2021-i pass2.imp
	mv pass2-i pass2i

takeoni: takeon.imp imp2021-i
	./imp2021-i takeon.imp
	mv takeon-i takeoni

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 takeoni
	./takeoni 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

