# Makefile for Unix version of CRUDETYPE.
#
# {{ Originally written by P.King, much altered by RMD}}

#
# COPYRIGHT ( C ) P. King, Heriot-Watt University, 1988.
#
# Permission is given to any person to make and distribute copies of this
# software, subject to the following conditions:
#
# 1. All copies of the software must carry an exact copy of this notice.
#
# 2. This software is distributed free of charge, "AS IS" with absolutely no
# guarantee of performance. Any persons receiving or using this software must do
# so entirely at their own risk. Neither the authors nor their institutions
# accept any liability for any defects of this software, or for any consequential
# loss or damage however caused.
#
# 3. Any person who changes this software must clearly mark it as modified and
# add a note describing the changes made.
#
#
# They depend on the Berkeley implementation of Pascal, and have only been tried
# on BSD4.2 UNIX.
#
#
#
#
#
# Makefile:
# --------------------------------
#
#   Adapted from:
#   Makefile for TeX82 distribution, subdirectory `=TeXware'
#   version for 4.2 bsd
#
#   This file makes CRUDETYPE from its WEB source.
#
#   Note: The -J option on the 'pc' commands below is the only way to
#         'pc' to use the -J option to the assembler (which makes it
#         do the sensible thing with branches).  This flag is not
#         documented, which is correct, since 'pc' should really be
#         using it all of the time...  (Grrr..)
#
#   Note: several parts of this Makefile are unsatisfactory; I could
#   not get them to work.
#
#
#  Before using this makefile, change these macros to conform to
#  local practice:

################################################################
# Which image(s) do you want to build? See README for some names
################################################################

all:	$(IMAGES)

POSSIBLE_IMAGES= crudetype crude-p noscheme-p noscheme-c  hpgf

IMAGES =

################################################################
# Where does the S-ware live? In TEX version3 there are files:
# site.h  and defaults.h in the top level directory of TEX that
# describe your machine. 
################################################################

SITEDIR= /tex/ver3
SITE_H=$(SITEDIR)/site.h
DEFT_H=$(SITEDIR)/defaults.h

# I had to rewrite common.defines

COMMONDIR= .
COMM_DEFS=$(COMMONDIR)/w2c.defines	

# Where to install things

BINDIR=/tex
MANDIR=/usr/man/manl

################################################################
# Compiler options
################################################################

OPT= -O
CFLAGS=$(OPT) -I$(SITEDIR)
PFLAGS= -J -g -C
LDFLAGS= $(OPT)
INSTALL = cp -m 555

################################################################
# Names of compilers etc
################################################################

CC = cc
PC = pc
TANGLE=-tangle
RM=/bin/rm
YACC=yacc	# You can substitute "bison -y" for "yacc" if you like
LEX=lex		# Note: If you're going to use flex, compile web2cl.c with "-DFLEX"


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

.p.o:
		$(PC) $(PFLAGS) -c $*.p


################################################################
# This is what I regard as the 'normal' version of Crudetype, using
# my modified web2c.
################################################################

CRUDE_C_OBJS= crude-c.o w2c-ext.o w2c-main.o

crudetype:	$(CRUDE_C_OBJS)
		cc $(LDFLAGS) -o $@ $(CRUDE_C_OBJS)

$(CRUDE_C_OBJS):	$(SITE_H) $(DEFT_H)

crude-c.c:	crude-c.p w2c $(COMM_DEFS)
		w2c -d$(COMM_DEFS) <crude-c.p >crude-c.c

crude-c.p:	crudetype.web unix-c.ch
		$(TANGLE) crudetype unix-c
		mv crudetype.p crude-c.p


################################################################
#Compile w2c itself
################################################################

WC_OBJS= w2cy.o w2cl.o w2c.o


w2c:		$(WC_OBJS)
		$(CC)  $(LDFLAGS) -o  w2c $(WC_OBJS)  -ll

$(WC_OBJS):	w2c-symtab.h  w2cy.h w2c.h

w2cl.c:		w2c.lex $(SITE_H) $(DEFT_H)
		$(LEX) w2c.lex
		mv -f lex.yy.c w2cl.c

w2cy.c:		w2c.yacc $(SITE_H) $(DEFT_H)
		$(YACC) -d w2c.yacc
		mv -f y.tab.c w2cy.c
		-cmp y.tab.h w2cy.h || cp y.tab.h w2cy.h

################################################################
# Version using pc is called crude-p
################################################################


crude-p: 	crude-p.o unixext.o
		$(PC) $(PFLAGS) -o $@  crude-p.o unixext.o $(PCLIB)

crude-p.p:	crudetype.web unix-pas.ch
		$(TANGLE) crudetype unix-pas
		mv crudetype.p crude-p.p


################################################################
# YEUCHY mess for no coding schemes
################################################################

noscheme-p:	noscheme-p.o unixext.o
		$(PC) $(PFLAGS) -o $@  noscheme-p.o unixext.o $(PCLIB)

noscheme-p.p: 	noscheme.web unix-pas.ch
		$(TANGLE) noscheme unix-pas
		mv noscheme.p noscheme-p.p

noscheme.web: 	crudetype.web noscheme.add
		cat crudetype.web noscheme.add > $@

################################################################
# More mess. Noscheme compiled with W2C
#
################################################################

NOSC_OBJS= noscheme-c.o w2c-ext.o w2c-main.o

noscheme-c:	$(NOSC_OBJS)
		cc $(LDFLAGS) -o $@ $(NOSC_OBJS)

$(NOSC_OBJS):	$(SITE_H) $(DEFT_H)

noscheme-c.c:	noscheme-c.p w2c $(COMM_DEFS)
		w2c -d$(COMM_DEFS) <noscheme-c.p >noscheme-c.c

noscheme-c.p:	noscheme.web unix-c.ch
		$(TANGLE) noscheme unix-c
		mv noscheme.p noscheme-c.p


################################################################
# Typical example of a printer changefile
################################################################


hpgf: hpgf.o unixext.o
		$(PC) $(PFLAGS) -o hpgf hpgf.o unixext.o $(PCLIB)

hpgf.p: crudetype.web  unixhp.ch
		$(TANGLE) crudetype unixhp
		mv crudetype.p hpgf.p
	
unixhp.ch: unix-pas.ch hpgf.ch
		cat unix-pas.ch hpgf.ch > $@


################################################################
# Install etc. You probably want to alter the installed names.
################################################################

install: $(IMAGES)
	for i in $(POSSIBLE_IMAGES) ; do\
		if -i $$i \
			$(INSTALL) $$i  $(BINDIR); \
		fi \
	done
	$(INSTALL) unixcru.man $(MANDIR)crudetype.l


veryclean:	clean
		$(RM) -f  crude-c.c noscheme-c.c

clean:
		$(RM) -f *.p *.o $(POSSIBLE_IMAGES) \
			y.* lex.* w2c w2cy.c w2cy.h w2cl.c coerce.h \
			noscheme.web unixhp.ch \
			answers.tex index.tex  \
			*.dvi *.lpr *.log *~ *#