# Generated automatically from Makefile.in by configure.
#
# on SUN under SunOS 4.1.3
#
## and manually adapted to OS/2 & EMX0.8h by Gregor Buehler (6 Oct 94).
## Sorry, a lot of defs and rules were thrown out,
## because they were not useful in my environment.
## Use following targets with make <target>:
##	'all' 		- default - does all within 'srcdir'
##	'install' 	- installs within EMX dirs (if required alter below)
##      'uninstall'	- uninstalls off EMX dirs
##	'clean'		- cleans produced files afer install
## Rules for producing a standalone version were added.
## This can be run under DOS or OS/2 without having EMX.
# make file for "flex" tool
# Porting considerations:
#
#    For System V Unix machines, add -DUSG to CFLAGS (if it's not
#         automatically defined)
#    For Vax/VMS, add "-DVMS -DUSG" to CFLAGS.
#    For MS-DOS, add "-DMS_DOS -DUSG" to CFLAGS.  Create \tmp if not present.
#	  See MSDOS.notes for more info.
#    For Amiga, add "-DAMIGA -DUSG" to CFLAGS.
#    For SCO Unix, add "-DSCO_UNIX" to CFLAGS.
#
#    For C compilers which don't know about "void", add -Dvoid=int to CFLAGS.
#
#    If your C compiler is ANSI standard but does not include the <stdlib.h>
#    header file (some installations of gcc have this problem), then add
#    -DDONT_HAVE_STDLIB_H to CFLAGS.
#
# By default, flex will be configured to generate 8-bit scanners only
# if the -8 flag is given.  If you want it to always generate 8-bit
# scanners, add "-DDEFAULT_CSIZE=256" to CFLAGS.  Note that doing
# so will double the size of all uncompressed scanners.
# 
# If on your system you have trouble building flex due to 8-bit
# character problems, remove the -8 from FLEX_FLAGS and the
# "#define FLEX_8_BIT_CHARS" from the beginning of flexdef.h.


# the first time around use "make first_flex"



# the path defs are mostly twofold
# due to GNU/UNIX Style '/' and
# OS/2 '\'

srcdir = \flex
srcdir_gnu = /flex


prefix=\emx
prefix_gnu=/emx

# where the installed emx binary goes
bindir = $(prefix)\bin
bindir_gnu = $(prefix_gnu)/bin

# where the installed emx standalone binary goes
bindir_sta = $(srcdir)\st_alone.bin
bindir_sta_gnu = $(srcdir_gnu)/st_alone.bin

# where the parsers skeletons go
libdir = $(prefix)\lib
libdir_gnu = $(prefix_gnu)/lib

# where the headers go
incdir = $(prefix)\include 
incdir_gnu = $(prefix_gnu)/include

# where the info files go
infodir = $(prefix)\info

# where manual pages go and what their extensions should be
# someone should add a rule and program to compile the manual
# to OS/2 INF format
mandir = $(prefix)\book

#### End of system configuration section. ####



# files of binary OS/2 & EMX distribution

BINDISTFILES = $(srcdir_gnu)/flex.exe $(srcdir_gnu)/flexsta.exe $(srcdir_gnu)/flexskel.cc \
               $(srcdir_gnu)/flexskel.h \
               $(srcdir_gnu)/makefile $(srcdir_gnu)/flexppm.txt $(srcdir_gnu)/00readme.emx\
	 $(srcdir_gnu)/install.bat $(srcdir_gnu)/install.cmd $(srcdir_gnu)/patch.emx



SKELETON_FILE = $(libdir_gnu)/flexskel.cc
HEADERSKELETON_FILE = $(incdir_gnu)/flexskel.h
SKELFLAGS = -DDEFAULT_SKELETON_FILE=\"$(SKELETON_FILE)\" \
            -DDEFAULT_SKELETONHEADER_FILE=\"$(HEADERSKELETON_FILE)\"


# defs for standalone version of flex++

SKELETON_FILE_STA = $(srcdir_gnu)/flexskel.cc
HEADERSKELETON_FILE_STA = $(srcdir_gnu)/flexskel.h
SKELFLAGS_STA = -DDEFAULT_SKELETON_FILE=\"$(SKELETON_FILE_STA)\" \
            -DDEFAULT_SKELETONHEADER_FILE=\"$(HEADERSKELETON_FILE_STA)\"


CFLAGS = -O2  -DDEFAULT_CSIZE=256
LDFLAGS = -O2 -s

FLEX_FLAGS = -ist8

# which "flex" to use to generate scan.c from scan.l
FLEX = flex

YACC= bison -y
CC = gcc

AR = ar
RANLIB = ar -s

FLEXOBJS_COMMON = \
	ccl.o \
	dfa.o \
	ecs.o \
	gen.o \
	misc.o \
	nfa.o \
	parse.o \
	scan.o \
	sym.o \
	tblcmp.o \
	yylex.o

FLEXOBJS = $(FLEXOBJS_COMMON) main.o

FLEXOBJS_STA = $(FLEXOBJS_COMMON) mainsta.o


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

FLEX_LIB_OBJS = \
	libmain.o

FLEXLIB = flexlib.a


all : flex.exe flexsta.exe $(FLEXLIB) flex.info flexpp.zip


# EMX version of flex++

flex.exe : $(FLEXOBJS)
	$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(FLEXOBJS)


# standalone version of flex++ for machines without EMX or RSX

flexsta.exe : $(FLEXOBJS_STA)
	$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(FLEXOBJS_STA)
	emxbind -xq flexsta.exe a.out
	emxbind $(EMXBIND_FLAGS) -q $(bindir)\emx.exe a.out flexsta.exe
	del a.out



first_flex:
	copy initscan.c scan.c
	dmake flex.exe

parse.h parse.c : parse.y 
	$(YACC) -d parse.y 
	sed '/extern char.*malloc/d' <y.tab.c >parse.c 
	del y.tab.c
	rename y.tab.h parse.h

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

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


# production of main for EMX with default EMX directories

main.o : main.c flexdef.h
	$(CC) $(CFLAGS) -c $(SKELFLAGS) main.c

# production of main for standalone version

mainsta.o : main.c flexdef.h
	$(CC) $(CFLAGS) -c $(SKELFLAGS_STA) -o $@ main.c


ccl.o : ccl.c flexdef.h
dfa.o : dfa.c flexdef.h
ecs.o : ecs.c flexdef.h
gen.o : gen.c flexdef.h
misc.o : misc.c flexdef.h
nfa.o : nfa.c flexdef.h
parse.o : parse.c flexdef.h
sym.o : sym.c flexdef.h
tblcmp.o : tblcmp.c flexdef.h
yylex.o : yylex.c flexdef.h


$(FLEXLIB) : $(FLEX_LIB_OBJS)
	$(AR) cru $(FLEXLIB) $(FLEX_LIB_OBJS)

	
# make a distribution file of the binaries, skeletons, makefile, and manual

flexpp.zip: $(BINDISTFILES)
	zip -k flexpp.zip $(BINDISTFILES)

clean:
	del *.o flex.exe flexsta.exe flex.i*
	del flexpp.zip

install: all $(BINDISTFILES)
	xcopy $(srcdir)\flex.exe $(bindir) /O
	xcopy $(srcdir)\flexskel.cc $(libdir) /O
	xcopy $(srcdir)\flexskel.h $(incdir) /O
	xcopy $(srcdir)\flexppm.txt $(mandir) /O
	xcopy $(srcdir)\flex.info $(infodir) /O
	xcopy $(srcdir)\flex.i* $(infodir) /O
	xcopy $(srcdir)\$(FLEXLIB) $(libdir) /O
	if exist $(libdir)\libfl.a del $(libdir)\libfl.a
	rename $(libdir)\$(FLEXLIB) libfl.a
	$(RANLIB) $(libdir_gnu)/libfl.a

uninstall:
	del $(bindir)\flex.exe
	del $(libdir)\$(SKELETON_FILE) $(libdir)\$(SKELETONHEADER_FILE)
	del $(mandir)\flexppm.txt
	del $(infodir)\flex.i*
	del $(libdir)\libfl.a


# make the info files for GNU info browser

flex.info: flex.texinfo
	makeinfo flex.texinfo


test : flex
	echo "diff should only be on #line directive"
	flex $(FLEX_FLAGS) -S./flexskel.cc -H./flexskel.h $(COMPRESSION) scan.l | diff scan.c -
bigtest :
	echo "diff should only be on #line directive"
	del scan.c ; dmake COMPRESSION="-C" test
	echo "diff should only be on #line directive"
	del scan.c ; dmake COMPRESSION="-Ce" test
	echo "diff should only be on #line directive"
	del scan.c ; dmake COMPRESSION="-Cm" test
	echo this should fail because there is trailing context in the grammar
	del scan.c ; dmake COMPRESSION="-Cfe" test
	echo this should fail because there is trailing context in the grammar
	del scan.c ; dmake COMPRESSION="-CFe" test
	echo this should fail because there is trailing context in the grammar
	del scan.c ; dmake COMPRESSION="-Cf" test
	echo this should fail because there is trailing context in the grammar
	del scan.c ; dmake COMPRESSION="-CF" test
	echo "diff should only be on #line directive"
	del scan.c ; dmake



