# $Id: Makefile,v 1.13 1996/09/12 18:43:27 gaertner Exp gaertner $
# ----------------------------------------------------------------------

#
# Makefile for formatted grammar file scanner and parser
#

# ----------------------------------------------------------------------
# Here are the things that determine the configuration:
# ----------------------------------------------------------------------

# what compiler do we use?
CC 	= g++

# de-comment this if you want a debug version:
#DBVERSION = -D XXX

# compiler flags:
CFLAGS	= -g -I../include -L.. -lpretzel

# prefix for globals of scanner and parser (`yy' by default)
GLOBALSPREFIX = Pretzel_fg

# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# You probably don't need to change anything from here:
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------

# Groups of files:

# all noweb sources
NOWEBS	= fgscan.nw fgparse.nw fgrammar.nw

# root chunk name of headers
HEADERCHUNK     = header

# root chunk name of C implementation
IMPLEMENTATIONCHUNK     = implementation

# root chunk name of flex implementation
FLEXIMPLCHUNK   = flex-implementation

# root chunk name of bison implementation
BISONIMPLCHUNK  = bison-implementation

# all `WEB' sources (old)
#WEBS	= fgscan.spc fgscan.l fgparse.spc fgparse.y fgrammar.w

# all other program WEB sources (old)
#ETCWEBS	= pparse.spc

# all TeX documents
TEXDOCS	=

# all other files for the distribution
DISTFILES = Makefile pascal.fg test.output.correct README

# name of the distribution package
DISTNAME =

# Which program to make by default:
PROG	= fgrammar

# objects of this program:
OBJS 	= fgscan.o fgparse.o fgrammar.o

# objects to be released:
RELOBJS	= fgparse.o fgscan.o

# C sources of this program:
CSRCES	= fgscan.c fgparse.c fgrammar.c

# intermediate products from which C sources are made
INTERMEDIATES = fgscan.l fgparse.y

# crap to be removed when making clean:
OTHERCRAP = fgparse.aux fgparse.dvi fgparse.idx fgparse.log 	\
		fgparse.scn fgparse.tex fgparse.toc		\
		fgscan.aux fgscan.dvi fgscan.idx fgscan.log	\
		fgscan.scn fgscan.tex fgscan.toc		\
		fgscan.l fgparse.y				\
		pparse.dvi pparse.idx pparse.log pparse.scn	\
		pparse.tex pparse.toc				\
		Pparse.h Ppparse.h				\
		fgrammar.aux fgrammar.dvi fgrammar.idx fgrammar.log	\
		fgrammar.scn fgrammar.tex test.output



# ----------------------------------------------------------------------
# these are all the headers for the compiler
HEADERS = fgscan.h fgparse.h fgramdefs.h Pparse.h Ppparse.h

# these are all the objects for the compiler
OBJECTS = $(OBJS)

# these are all the C sources to make the objects
CSOURCES = $(CSRCES)

# These are all of the flags for the compiler:
CCFLAGS = $(CFLAGS) $(DBVERSION)

# these are all C sources that might possibly crop up
ALLCSRCS = $(CSOURCES)

# these are all object files that may appear
ALLOBJS = $(OBJECTS)

# these are all header files produced from WEBs that may appear
ALLHEADERS = $(HEADERS)

# these are all the executables that could be produced
ALLPROGS = $(PROG)

# ----------------------------------------------------------------------

CWEAVE 	= cweave
CTANGLE	= ctangle
NOTANGLE= notangle
NOWEAVE = noweave
TEX 	= tex
DVIPS 	= dvips
REMOVE	= rm -f
MAKE	= make
LEX	= flex
#LEX	= lex
YACC	= bison
#YACC	= yacc
TEX	= tex
LATEX	= tex-it latex
CPIF	= cpif

# ----------------------------------------------------------------------

BISONOPTIONS 	= -p$(GLOBALSPREFIX)
FLEXOPTIONS 	= -L -P$(GLOBALSPREFIX)

# ----------------------------------------------------------------------

.SUFFIXES:	.nw .spc .ps .tex .dvi .w .c .o .h

# overall rules:

.nw.tex:
	$(NOWEAVE) -delay $*.nw > $*.tex


.w.tex:
	$(CWEAVE) $*

.tex.dvi:
	$(LATEX) $<

.w.dvi:
	$(MAKE) $*.tex
	$(MAKE) $*.dvi

.dvi.ps:
	$(DVIPS) $< -o $*.ps

.nw.h:
	$(NOTANGLE) -L -R$(HEADERCHUNK) $*.nw | $(CPIF) $*.h

.nw.c:
	$(NOTANGLE) -L -R$(IMPLEMENTATIONCHUNK) $*.nw | $(CPIF) $*.c

.nw.l:
	$(NOTANGLE) -R$(FLEXIMPLCHUNK) $*.nw | $(CPIF) $*.l

.nw.y:
	$(NOTANGLE) -R$(BISONIMPLCHUNK) $*.nw | $(CPIF) $*.y

.w.c:
	$(CTANGLE) $*

.spc.h:
	$(CTANGLE) $*.spc - $*.h

#.w.o:
#	$(MAKE) $*.c
#	$(MAKE) $*.o

.c.o:
	$(CC) -c $*.c $(CCFLAGS)

.y.c:
	$(YACC) $(BISONOPTIONS) $*.y
	mv $*.tab.c $*.c

.l.c:
	$(LEX) $(FLEXOPTIONS) $*.l
	mv lex.$(GLOBALSPREFIX).c $*.c

# ----------------------------------------------------------------------

# regenerate whole system:


system: $(PROG)


$(PROG): $(OBJECTS)
	$(CC) -o $@ $(OBJECTS) $(CCFLAGS)

$(OBJS): $(HEADERS) $(CSRCES)

$(CSRCES): $(INTERMEDIATES)

# make the common token header file
fgramdefs.h: fgparse.y
	$(YACC) -d fgparse.y
	mv fgparse.tab.h fgramdefs.h

Ppparse.h: fgparse.nw
	$(NOTANGLE) -R"header file for prettyprinting parser" fgparse.nw >Ppparse.h

Pparse.h: fgparse.nw
	$(NOTANGLE) -R"header file for abstract base class of [[Pparse]]" fgparse.nw >Pparse.h


# list all source code:

print:


# apply lint to all C sources:

lint:

# regression:
regression: $(PROG)
	./fgrammar <pascal.fg > test.output
	if  diff test.output test.output.correct;		\
		then echo "Regression test is fine."; 		\
		else echo "Regression test failed.";		\
		fi

# remove all intermediate products but not executables or sources!

clean:
	$(REMOVE) $(ALLOBJS) $(ALLCSRCS) $(ALLHEADERS) $(OTHERCRAP)


# remove everything that doesn't belong to original source:

clobber: clean
	$(REMOVE) $(ALLPROGS)


# bundle source files together into an archive:

#bundle:
#	tar cf $(DISTNAME).tar 			\
#		$(WEBS) $(ETCWEBS) $(TEXDOCS) $(DISTFILES)


# copy executables into PATH directories, et al.

install:


# release a new version:

release: $(HEADERS) $(RELOBJS)
	cp $(HEADERS) ../include
	ar vrus ../libpretzel.a $(RELOBJS)



# ======================================================================
#
# $Log: Makefile,v $
# Revision 1.13  1996/09/12  18:43:27  gaertner
# Changed to g++ and noweb
#
# Revision 1.12  1996/03/21  08:14:06  gaertner
# Changed to make it work with the new noweb versions of the files.
#
# Revision 1.11  1995/08/15  17:21:54  gaertner
# Moved CC options to the end of the command line for portability.
#
# Revision 1.10  1995/08/15  16:52:53  gaertner
# Catered for multiple scanners: Added variables GLOBALSPREFIX
# and BISONOPTIONS/FLEXOPTIONS that instruct Bison and flex
# to prefix all globals with `yyfgrammar'.
#
# Revision 1.9  1995/04/26  17:56:11  gaertner
# Now README is recognized and bundled too.
#
# Revision 1.8  1995/04/26  17:50:13  gaertner
# Compiling/releasing uses lpretzel library now.
# You can make a regression test now.
# Making dvi's uses LaTeX now.
#
# Revision 1.7  1994/10/31  19:04:32  gaertner
# Now make bundle creates fgrammar.tar
#
# Revision 1.6  1994/10/24  16:51:50  gaertner
# Now fgrammar.o isn't released anymore.
#
# Revision 1.5  1994/10/24  16:29:32  gaertner
# Changed pscan.spc to pparse.spc (was a mistake).
#
# Revision 1.4  1994/10/24  16:19:41  gaertner
# Added pscan.h as header. It is released too.
#
# Revision 1.3  1994/10/19  18:40:47  gaertner
# Added dependency of fgramdefs.h file.
#
# Revision 1.2  1994/10/18  18:53:51  gaertner
# First revision using the Makefile template.
#
#




