#
# Clinton Jeffery
# Project: uflex
# August 2020
#
# Phase 1:  replace ulex C implementation with ulex .icn implementation. (done)
#       1a: clean up (not done)
# Phase 2:  convert NFA->DFA
#
# Note that there are two implementations in this directory, a C version and
# a unicon version.  They are both presumed buggy.  I am using the writing of
# the BYOPL book to debug them.  A
#
CC=cc
CFLAGS= -c -g
LEX=flex
YACC=bison -y

all: uflex ulpp

# C implementation, not debugged yet
uflex: ulpp y.tab.o main.o lex.yy.o ulexskel.o automata.o tree.o convert.o
	$(CC) -o uflex main.o lex.yy.o y.tab.o ulexskel.o automata.o tree.o convert.o
	echo you might want to copy uflex over any previous uflex on your path

# Unicon implementation, not finished yet
uflex-u: flexgram.u main.u uflex-lex.u ulexskel.u automata.u tree.u convert.u
	unicon -o uflex flexgram.u main.u uflex-lex.u ulexskel.u automata.u tree.u convert.u ulpp.icn
	echo you might want to copy uflex over any previous uflex on your path

main.u: main.icn
	unicon -c main

main.o: main.c
	$(CC) $(CFLAGS) main.c

flexgram.u: flexgram.icn
	unicon -c flexgram

flexgram.icn flexgram_tab.icn: flexgram.y
	iyacc -i -d flexgram.y

uflex-lex.u: uflex-lex.icn
	unicon -c uflex-lex

lex.yy.o: lex.yy.c y.tab.h
	$(CC) $(CFLAGS) lex.yy.c

lex.yy.c: lex.l
	$(LEX) lex.l

ulexskel.u: ulexskel.icn
	unicon -c ulexskel

ulexskel.o: ulexskel.c
	$(CC) $(CFLAGS) ulexskel.c

automata.o: automata.c automata.h
	$(CC) $(CFLAGS) automata.c

automata.u: automata.icn
	unicon -c automata

y.tab.o: y.tab.c
	$(CC) $(CFLAGS) y.tab.c

y.tab.c y.tab.h: lexgram.y automata.h tree.h automata.c
	$(YACC) -d lexgram.y

tree.u: tree.icn
	unicon -c tree

tree.o: tree.c tree.h y.tab.h
	$(CC) $(CFLAGS) tree.c

convert.o: convert.c y.tab.h tree.h automata.h
	$(CC) $(CFLAGS) convert.c

convert.u: convert.icn flexgram_tab.icn
	unicon -c convert

#
# test w/ dummy main() used only for debugging ulex's lexical analyzer.
#
lexlex: lex.yy.c y.tab.h
	$(CC) $(CFLAGS) -DDEBUG -DMAIN lex.yy.c
	$(CC) -o lexlex lex.yy.o
	rm lex.yy.o

ulpp: ulpp.icn
	unicon -DMAIN ulpp
	cp ulpp ../../bin

zip:
	echo "Any changes to the Makefile that should be Makefile.public?"
	mv Makefile Makefile.mine
	cp Makefile.public Makefile
	rm y.tab.c lex.yy.c
	zip uflex.zip Makefile *.c *.h *.l *.y
	mv Makefile.mine Makefile

zipall: zip
	zip uflex.zip automata.icn convert.icn main.icn tree.icn uflex-lex.icn ulexskel.icn ulpp.icn

clean:
	rm lex.yy.c y.tab.c y.tab.h *.o ulpp ulex
