# Buildtemplate for C preprocessor

VPATH = ../mi

SPECINCLUDES = -I../mi

PCCDIR = /usr/stanford/bin

#ifdef UNIX
OPTS = -Dunix=1 -DFLEXNAMES
#else
OPTS = -Dunix=1 -Dmc68000=1 -DFLEXNAMES
#         ^ Yes, we really do need "unix" in lower case - see #if's in cpp.c
#	    Don't know how much good "mc68000" does us.  It's used to determine
#	    whether characters are signed or unsigned, and to define the symbol
#	    "mc68000" (what else?).  Hope no-one relies on "mc68000", since it
#	    probably isn't defined if you use cc68 on VAX Unix (probably don't
#	    even get our version of cpp).
#endif

all: cpp.$(MACHINE)

cpp.$(MACHINE):	rodata.$(OBJSUFFIX) cpp.$(OBJSUFFIX) cpy.$(OBJSUFFIX)
	$(CC) $(MIFLAGS) $< -o $@ $(MDFLAGS) $(LIBRARIES)

.c.$(OBJSUFFIX):
	$(CC) $(OPTS) $(MIFLAGS) $(SPECINCLUDES) $(INCLUDES) -c $*.c

# Whichever Unix wizard wrote the original makefile for the Unix version of cpp
#   went to some trouble to extract read-only data from y.tab.c, put it in
#   rodata.c, and compile the latter with -R.  This made the data read-only and
#   shareable.  I can only assume that this was meant to increase the amount
#   of sharing if two or more processes were using cpp, though there's only
#   about 120 bytes of data involved.
# Because I don't see why we need it and because it's a pain to write the
#   buildfiles that way, we no longer compile rodata.c with -R (only works for
#   cc, not cc68, anyway), but I can't be bothered taking out the stuff that
#   generates and uses rodata.c.  As far as I know I haven't broken anything.
# Was there a real reason that I've missed?  TMM

cpy.c rodata.c: cpy.y
	yacc cpy.y
	$(PCCDIR)/pcc/:yyfix yyexca yyact yypact yypgo yyr1 yyr2 yychk yydef
	mv y.tab.c cpy.c
# ^ Have I got it anything like right?  TMM

install : cpp.$(MACHINE)
#ifdef UNIX
	rcp $< $(UNIXDESTDIR)/cpp
#			       ^ Is this the right name?  Conflicts with VAX
#				 Unix cpp.
#else
	$(NETINSTALL) -p $< $(VSYS)/bin
#endif

clean :
	rm -f *.s *.$(OBJSUFFIX) cpy.c rodata.c cpp.$(MACHINE)

relink:
	rm -f cpp.$(MACHINE)
