# make file for "flex" tool

# modified for Amiga and Aztec C. uses bison instead of yacc

# the first time around use "make first_flex"

SKEL_FILE = ":lib/flex.skel"
F_SKEL_FILE = ":lib/flex.fastskel"
SKEL = -DDEFAULT_SKELETON_FILE=$(SKEL_FILE) -DFAST_SKELETON_FILE=$(F_SKEL_FILE)
CC = cc
LD = ln
CFLAGS = -b -n -dAMIGA
LDFLAGS = -g
LIBS = -lgnu -lc

FLEX_FLAGS = -ist
FLEX = :c/flex

FLEXOBJS = \
	ccl.o \
	dfa.o \
	ecs.o \
	main.o \
	misc.o \
	nfa.o \
	parse.o \
	scan.o \
	sym.o \
	tblcmp.o \
	yylex.o

FLEX_C_SOURCES = \
	ccl.c \
	dfa.c \
	ecs.c \
	main.c \
	misc.c \
	nfa.c \
	parse.c \
	scan.c \
	sym.c \
	tblcmp.c \
	yylex.c

flex : $(FLEXOBJS)
	$(LD) -o ram:flex $(LDFLAGS) $(FLEXOBJS) $(LIBS)
	cp ram:flex* .
	delete ram:flex*

first_flex:
	cp scan.c.dist scan.c
	make $(MFLAGS) flex

parse.h parse.c : parse.y
	- delete parse.c parse.h
	:c/bison -d parse.y
	rename parse.tab.c parse.c
	rename parse.tab.h parse.h

# comment-out the next two lines after a successful "make test" and
# comment-in the following two lines.

scan.c : scan.l
	$(FLEX) >scan.c $(FLEX_FLAGS) scan.l

scan.o : scan.c parse.h flexskeldef.h flexdef.h
	cc $(CFLAGS) -Y150 -o scan.o scan.c

#scan.o : scan.c.dist parse.h flexskeldef.h flexdef.h
#	cc $(CFLAGS) -Y150 -o scan.o scan.c.dist

main.o : main.c flexdef.h
	cc $(CFLAGS) $(SKEL) main.c

parse.o : parse.c flexdef.h

tblcmp.o : tblcmp.c flexdef.h
	cc $(CFLAGS) -E160 tblcmp.c

ccl.o : ccl.c flexdef.h

dfa.o : dfa.c flexdef.h

ecs.o : ecs.c flexdef.h

misc.o : misc.c flexdef.h

nfa.o : nfa.c flexdef.h

scan.o : scan.c flexskeldef.h flexdef.h parse.h flexskelcom.h

sym.o : sym.c flexdef.h

yylex.o : yylex.c flexdef.h parse.h

flex.lint : $(FLEX_C_SOURCES)
	@echo "Expect a \"may be used before set\" and 2 \"unused\"'s
	lint $(FLEX_C_SOURCES) > flex.lint

clean :
	rm -f core errs flex *.o parse.c *.lint parse.h

test :
	$(FLEX) $(FLEX_FLAGS) scan.l | diff scan.c -
