# $Id: Makefile,v 2.2 1999/01/19 11:01:18 felix Exp $
#
# Makefile for a pretzel prettyprinter
#


# prefix of format files. Will produce <LANG>pp executable.
LANG	= pascal

# the prettyprinter main() function
PROG	= $(LANG)pp

# name of file to be prettyprinted
LANGEX	= wurzel.pas

# name of the token definition file for the scanner
TOKDEFS	= ptokdefs.h

# where's pretzel-it?
PRETZELIT = ../../pretzel-it/pretzel-it


# which compiler are we using?
CC	= g++

# compiler options:
OPT	= -I../../include -L../.. -lpretzel -g

# suffix of formatted token files (without dot)
FT	= ft

# suffix of formatted grammar files (without dot)
FG	= fg

# sources:
PSRCS	= $(LANG).l $(LANG).y

# corresponding C sources
PCSRCS	= $(LANG).lex.c $(LANG).tab.c

# objects that the prettyprinter needs created:
POBJS	= $(LANG).lex.o $(LANG).tab.o

# global main() object (made in main/ of Pretzel distribution)
MAINOBJ	= ../../plainpp.o

# headers?
HEADERS	= $(TOKDEFS)

#
#
RM	= rm -f
LEX	= flex
YACC	= bison
XDVI	= dvix11

.SUFFIXES:      .nw .spc .ps .tex .dvi .w .c .o .h .$(FT) .$(FG)


.ft.l:
	pretzel -t $*

.fg.y:
	pretzel -g $*

.y.c:
	$(YACC) $*.y

.l.c:
	$(LEX) -t $*.l > $*.lex.c

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

.nw.c:
	notangle <$*.nw >$*.c


$(PROG): $(HEADERS) $(POBJS)
	$(CC) $(OPT) -o $(LANG)pp $(POBJS) $(MAINOBJ)

$(POBJS): $(PCSRCS)

$(PCSRCS): $(PSRCS)


$(TOKDEFS): $(LANG).y
	$(YACC) -d $(LANG).y
	mv $(LANG).tab.h $(TOKDEFS)

$(LANG).tab.c: $(LANG).y
	$(YACC) $(LANG).y

$(LANG).lex.c: $(LANG).l
	$(LEX) -t $(LANG).l > $(LANG).lex.c


# test is always a simple test
test: simpletest

# test pretzel using pretzel-it:
simpletest:
	$(PRETZELIT) $(LANG) $(LANG)pp
	$(LANG)pp < $(LANGEX) > pprinted.tex
	latex frame.tex
	$(XDVI) frame.dvi

# test the generated prettyprinter using the makefile:
complextest: $(PROG)
	$(PROG) < $(LANGEX) > pprinted.tex
	latex frame.tex
	$(XDVI) frame.dvi

# can't use pretzel-it here because this is a bootstrapping
# target. Use a special copy of pretzel-it here at bootstrap
# time. (Don't add ../../bin to PATH because this is shell
# specific)
#
# If Pretzel is already installed, the line should look like
# this:
#
# 	$(PRETZEL-IT) $(LANG) $(LANGPP)
#
pretzeledpascalpp:
	./pretzel-it-bootstrap $(LANG) $(LANG)pp 
# 	$(PRETZEL-IT) $(LANG) $(LANGPP)

#

MULTOBJS	= multiple.o $(LANG).lex.o $(LANG).tab.o

multiple: $(MULTOBJS)
	$(CC) $(OPT) -o multiple $(MULTOBJS)

multiple.o: multiple.c


multiple.c: multiple.nw


# remove all intermediate products
clean:
	$(RM) $(HEADERS) $(POBJS) $(PCSRCS) $(PSRCS)

# remove all final products
clobber: clean
	$(RM) $(LANG)pp

# make a neat little bundle
#bundle:
#	tar cf $(LANG).tar $(LANG).$(FT) $(LANG).$(FG)		\
#			plainpp.c Makefile $(LANGEX) frame.tex	\
#			*.pas pprinted.tex README pretzel-latex.sty

# release - 
release: pretzeledpascalpp
	cp $(LANG)pp ../../bin

#
# $Log: Makefile,v $
# Revision 2.2  1999/01/19 11:01:18  felix
# previous change was not portable over shells. Using a bootstrap
# version of pretzel-it (called pretzel-it-bootstrap) to overcome
# this. Now the Makefile is not as ``example like'' as praised in
# the PretzelBook anymore.
#
# Revision 2.1  1999/01/19 10:43:13  felix
# `make pretzeledpascalpp' jerks at bootstrap time because pretzel-it
# hasn't been globally released yet. Add ../../bin temporarily to PATH
# to fix this.
#
# Revision 2.0  1996/12/17 07:52:27  gaertner
# *** empty log message ***
#
# Revision 1.12  1995/09/05  14:58:35  gaertner
# Target `release' doesn't copy $(LANG)pp to .. because
# `make install' says `make release' here before the library
# has been finished.
#
# Revision 1.11  1995/09/05  14:41:40  gaertner
# The generated program is $(LANG)pp now. It always takes the
# main program from plainpp.o.
# There is a target `simpletest' that uses pretzel-it and `complextest'
# that does everything by hand.
# Target `release' copies plainpp.o and $(LANG)pp to `..'
#
# Revision 1.10  1995/08/30  17:52:44  gaertner
# Removed pascan.h from bundle line again.
#
# Revision 1.9  1995/08/30  17:41:18  gaertner
# Instead of always producing plainpp, it produces <LANG>pp
# executable.
# New target `release' will copy the plainpp.o to the project
# directory so that it's available for pretzel-it.
# Added pascan.h to the bundle file list.
#
# Revision 1.8  1995/07/20  09:43:30  gaertner
# Changed minimal main program from t to plainpp
#
# Revision 1.7  1995/04/26  18:29:57  gaertner
# README and all .pas files are bundled up now too.
#
# Revision 1.6  1995/04/26  18:21:55  gaertner
# Compiling uses lpretzel library
# now.
#
# Revision 1.5  1994/10/31  19:11:28  gaertner
# Now we can make bundle too.
#
# Revision 1.4  1994/10/24  18:07:48  gaertner
# Dependencies are okay now. The makefile uses pretzel and creates
# intermediates called *.lex.c and *.tab.c.
#
# Revision 1.3  1994/10/21  09:52:53  gaertner
# The token header is now created correctly and there's a new
# target `clean' that removes intermidiate products.
#
# Revision 1.2  1994/10/20  19:47:42  gaertner
# First revision of granny version.
#
#
