#
# Uncomment following line for Sys V machines (but not AIX version 3).
#LIB1	= -lPW -lc_s
YTAB	= y.tab
O	= o

#
# Use the following for a standard development system
CC	= gcc
DEBUG	= -O2
YACC	= bison -y
LIBEXT	= a

#
# Use the following for OS/2 & DOS. (You need the GNU bison).
#CC	= cc -W3 -AL
#DEBUG	= -Zi
#YACC	= bison =y
#YTAB	= y_tab
#O	= obj
#LIBEXT	= lib
#LIB1	= -F 8000 -link /NOE
#########################
YFLAGS = -d
SRC	= Makefile *.h *.y *.c crunch.cr
INCDIR=..
CFLAGS =  $(DEBUG) -I$(INCDIR)/llist -I$(INCDIR)/foxlib
LIBDIR	= $(INCDIR)/lib
LIB	= $(LIBDIR)/llist.$(LIBEXT) $(LIBDIR)/splay.$(LIBEXT) $(LIBDIR)/foxlib.$(LIBEXT)
OBJ	= cry.$(O) crasc.$(O) crbin.$(O) crlex.$(O) crmain.$(O) crsubs.$(O) \
	  cr_gen.$(O)  debug.$(O) symtab.$(O) \
	  ../obj/common.$(O) ../obj/cm_keywd.$(O) ../obj/refstr.$(O) ../obj/word.$(O)
H2	= gen.h $(YTAB).h
H	= crunch.h $(H2)

crunch:	$(OBJ) $(LIB)
	$(CC)  $(DEBUG) -o crunch $(OBJ) $(LIB) $(LIB1)
cru:	$(OBJ)
	$(CC) -F 8000 $(DEBUG) -o cru *.o 
raw:
	$(MAKE) YACC=yacc CC=cc
	
gen.h:	cry.$(O)

cry.$(O):	cry.y crunch.h
	@echo "Expect 2 shift/reduce and 1 reduce/reduce conflicts."
	$(YACC) $(YFLAGS) cry.y
	grep '^# *define' y.tab.h > gen.h
	$(CC) $(CFLAGS) -c $(YTAB).c
	mv $(YTAB).$(O) cry.$(O)
#	rm -f $(YTAB).c
$(YTAB).h:	cry.$(O)

crasc.$(O): crasc.c $(H)
	$(CC) $(CFLAGS) -c crasc.c
crbin.$(O): crbin.c $(H)
	$(CC) $(CFLAGS) -c crbin.c
crlex.$(O): crlex.c $(H)
	$(CC) $(CFLAGS) -c crlex.c
debug.$(O): debug.c $(H)
	$(CC) $(CFLAGS) -c debug.c
crmain.$(O):	crmain.c $(H)
	$(CC) $(CFLAGS) -c crmain.c
crsubs.$(O): crsubs.c $(H)
	$(CC) $(CFLAGS) -c crsubs.c
cr_gen.$(O): cr_gen.c $(H)
	$(CC) $(CFLAGS) -c cr_gen.c
symtab.$(O): symtab.c $(H)
	$(CC) $(CFLAGS) -c symtab.c

gl.$(O):	gl.lex crunch.h
	lex gl.lex
	$(CC) -c -o gl.$(O) lex.yy.c
	rm -f lex.yy.c
clean:
	-rm -f crunch
	-rm -f *.$(O) 
	-rm -f *.cm
	-rm -f y.output y.tab.c y.tab.h y_tab.c y_tab.h gen.h
	-rm -f yacc*
gnu:
	$(MAKE) CC=gcc DEBUG="-pipe -pedantic -O -g -ansi -W -Wall" \
		LIBEXT=a \
		YACC="bison -y"
dos:
	$(MAKE) CFLAGS= CC="cl -I../llist -I../foxlib -W3 -AL -Gs" YTAB=y_tab O=obj LIBEXT=lib LIB1="-F 8000 -link /NOE" crunch
	link @..\os2utils\crunch.lnk

all:
	rm -f y.tab.h
	rm -f *.o
	make YACC=yacc
lint:
	lint -I../foxlib -I../llist *.c
