# This file, makefile.unix, is part of CWEB (Version 3.3 [p11]).
# It is distributed WITHOUT ANY WARRANTY, express or implied.

# Modified for the CC compiler under HP-UX on a HP Apollo 400 at Bayreuth
# University by Andreas Scherer (scherer@genesis.informatik.rwth-aachen.de)
# August 12, 1994.  Other UNIX compilers like c89 or gcc can work with this
# file as well.  Last updated by Andreas Scherer, December 3, 1994.

# Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
# Copyright (C) 1994 Andreas Scherer

# Permission is granted to make and distribute verbatim copies of this
# document provided that the copyright notice and this permission notice
# are preserved on all copies.

# Permission is granted to copy and distribute modified versions of this
# document under the conditions for verbatim copying, provided that the
# entire resulting derived work is given a different name and distributed
# under the terms of a permission notice identical to this one.

# 
# Read the README file, then edit this file to reflect local conditions
#

# directory for TeX inputs (cwebmac.tex and (X|d|i)cwebmac.tex go here)
MACROSDIR= /usr/local/lib/tex/inputs

# directory for CWEB inputs in @i files
CWEBINPUTS=/usr/local/lib/cweb

# extension for manual pages ("l" distinguishes local from system stuff)
MANEXT= l
#MANEXT= 1

# directory for manual pages (cweb.1 goes here)
MANDIR= /usr/man/man$(MANEXT)

# destination directory for executables; must end in /
DESTDIR= /usr/local/bin/

# directory for GNU EMACS Lisp code (cweb.el goes here)
EMACSDIR= /usr/local/emacs/lisp

# directory for the language header file "cweb.h"
CATINCLUDE=./bin/catalogs/

# Set DESTPREF to null if you want to call the executables "tangle" and "weave"
# (probably NOT a good idea; we recommend leaving DESTPREF=c)
DESTPREF=c

# Set CCHANGES to comm-foo.ch if you need changes to common.w
CCHANGES=common.ch

# Set TCHANGES to ctang-foo.ch if you need changes to ctangle.w
TCHANGES=ctangle.ch

# Set WCHANGES to cweav-foo.ch if you need changes to cweave.w
WCHANGES=cweave.ch

# Set MCHANGES to wmerge-foo.ch if you need changes to wmerge.w
MCHANGES=wmerge.ch

# Set EXTENSION to either `c' if you want to treat CWEB as a system
# of ordinary ANSI-C programs, or to `cc', `cxx', `cpp' or similar
# if you want to treat CWEB as a system of C++ programs.  Your
# compiler should be able to distinguish between the two forms
# according to the source file extension.  Even with ANSI-C programs
# it is strongly recommended to use C++ compilers, because of the
# much stricter checking of type conversions and module interfaces.
# For highest portability, all of the extra features of C++ are
# avoided in the CWEB system.
EXTENSION=cc

# We keep debugging info around, for fun, but most users don't need it.
# These lists of arguments are specific for CC.  Change, add or delete
# things here to suit your personal conditions.
# The following set of options work for CC 8.00 on HP-UX 8.00.
# The script cpp.sh is a local workaround for HP-UX 8.00 to unprotorize
# the patched source code, i.e., to remove all ANSI-prototypes.
# If you encounter any problems with the prototypes, look for it at
#    ftp.th-darmstadt.de:/pub/programming/languages/c/unproto-1.2.tar.Z
# If your version of HP-UX 8.00 acknowledges the `-Aa' option, delete
# the reference to cpp.sh.
#CFLAGS = -g -tp,/usr/local/bin/cpp.sh -I$(CATINCLUDE) \
#	-DCWEBINPUTS=\"$(CWEBINPUTS)\"

# The following set of options work for CC 9.30 on HP-UX 9.01.
#CFLAGS = -g -Aa -I$(CATINCLUDE) -DCWEBINPUTS=\"$(CWEBINPUTS)\"

# The following set of options work for CC and GCC on SunOS 4 and SGI's
# IRIX 4.0.5 and DEC's Ultrix 4.2.
# They are standard for many other UNIX-C compilers.
CFLAGS = -O2 -I$(CATINCLUDE) -DCWEBINPUTS=\"$(CWEBINPUTS)\"

# All linkers tested worked fine with this option.
#LINKFLAGS = -g
LINKFLAGS = -s # for smaller (stripped) executables on many UNIX systems

# The `f' flag is turned off to save paper
# The `lX' flag includes Xcwebmac.tex
# The `s' flag displays some statistics
WFLAGS=-f +lX +s
TFLAGS=+s

# What C compiler are you using?
CC = gcc # cc
MAKE = make

# RM and CP are used below in case rm and cp are aliased
RM= /bin/rm
CP= /bin/cp

##########  You shouldn't have to change anything after this point #######

CWEAVE = ./cweave
CTANGLE = ./ctangle
WMERGE=./wmerge
SOURCES = cweave.w common.w ctangle.w
ALMOSTALL = common.w ctangle.w wmerge.w makefile readme common.h \
	common.$(EXTENSION) ctangle.$(EXTENSION) wmerge.$(EXTENSION) \
	cwebman.tex cwebmana.ch cweb.1 cweb.man cweb.el prod.w \
	$(CCHANGES) $(CHCHANGES) $(TCHANGES) $(WCHANGES) $(PCHANGES) \
	comm-vms.ch ctang-vms.ch cweav-vms.ch \
	comm-man.ch ctang-man.ch cweav-man.ch \
	makefile.amiga makefile.pc makefile.unix \
	$(MACROSDIR)cwebmac.tex $(MACROSDIR)Xcwebmac.tex \
	$(MACROSDIR)dcwebmac.tex $(MACROSDIR)icwebmac.tex \
	$(CATINCLUDE)cweb.h $(CATINCLUDE)dcweb.h $(CATINCLUDE)icweb.h \
	examples
ALL =  $(ALMOSTALL) cweave.w

.SUFFIXES: .dvi .tex .w

.w.tex:
	$(CWEAVE) $(WFLAGS) $* $*

.tex.dvi:	
	tex $<

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

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

.w.o:
	$(MAKE) $*.$(EXTENSION)
	$(MAKE) $*.o

# When you say `make' without any arguments, `make' will jump to this item
default: ctangle cweave

# The complete set of files contains the two programs `ctangle' and
# `cweave' plus the program `wmerge', the manuals `cwebman' and `cwebmana'
# and the source documentations.
all: progs docs

# The objects of desire
progs: ctangle cweave wmerge

cautiously: ctangle
	$(CP) common.$(EXTENSION) SAVEcommon.$(EXTENSION)
	$(CTANGLE) $(TFLAGS) common $(CCHANGES) common.$(EXTENSION)
	diff common.$(EXTENSION) SAVEcommon.$(EXTENSION)
	$(RM) SAVEcommon.$(EXTENSION)
	$(CP) ctangle.$(EXTENSION) SAVEctangle.$(EXTENSION)
	$(CTANGLE) $(TFLAGS) ctangle $(TCHANGES) ctangle.$(EXTENSION)
	diff ctangle.$(EXTENSION) SAVEctangle.$(EXTENSION)
	$(RM) SAVEctangle.$(EXTENSION)

SAVEctangle.$(EXTENSION):
	$(CP) ctangle.$(EXTENSION) SAVEctangle.$(EXTENSION)

SAVEcommon.$(EXTENSION):
	$(CP) common.$(EXTENSION) SAVEcommon.$(EXTENSION)

common.$(EXTENSION): common.w $(CCHANGES)
	$(CTANGLE) $(TFLAGS) common $(CCHANGES) common.$(EXTENSION)

common.o: common.$(EXTENSION) $(CATINCLUDE)cweb.h

ctangle: ctangle.o common.o
	$(CC) $(LINKFLAGS) -o ctangle ctangle.o common.o 

ctangle.$(EXTENSION): ctangle.w $(TCHANGES) common.h
	$(CTANGLE) $(TFLAGS) ctangle $(TCHANGES) ctangle.$(EXTENSION)

ctangle.o: ctangle.$(EXTENSION) $(CATINCLUDE)cweb.h common.h

cweave: cweave.o common.o
	$(CC) $(LINKFLAGS) -o cweave cweave.o common.o

cweave.$(EXTENSION): cweave.w $(WCHANGES) common.h
	$(CTANGLE) $(TFLAGS) cweave $(WCHANGES) cweave.$(EXTENSION)

cweave.o: cweave.$(EXTENSION) $(CATINCLUDE)cweb.h common.h

wmerge: wmerge.$(EXTENSION)
	$(CC) $(CFLAGS) -o wmerge wmerge.$(EXTENSION) $(LINKFLAGS)

wmerge.$(EXTENSION): wmerge.w $(MCHANGES)
	$(CTANGLE) $(TFLAGS) wmerge $(MCHANGES) wmerge.$(EXTENSION)

# Take a good lecture for bedtime reading
doc: $(SOURCES:.w=.dvi)

docs: cwebman.dvi cwebmana.dvi common.dvi ctangle.dvi cweave.dvi wmerge.dvi

cwebman.dvi: cwebman.tex
cwebmana.dvi: cwebmana.tex
common.dvi: common.tex
ctangle.dvi: ctangle.tex
cweave.dvi: cweave.tex
wmerge.dvi: wmerge.tex

usermanual: cwebmana.dvi

fullmanual: usermanual $(SOURCES) comm-man.ch ctang-man.ch cweav-man.ch
	$(MAKE) cweave
	$(CWEAVE) common.w comm-man.ch
	$(MAKE) common.dvi
	$(CWEAVE) ctangle.w ctang-man.ch
	$(MAKE) ctangle.dvi
	$(CWEAVE) cweave.w cweav-man.ch
	$(MAKE) cweave.dvi

cwebmana.tex: cwebman.tex cwebmana.ch
	$(WMERGE) cwebman.tex cwebmana.ch cwebmana.tex

# for making the documentation we will have to include the change files
ctangle.tex: ctangle.w common.h $(TCHANGES)
	$(CWEAVE) $(WFLAGS) ctangle $(TCHANGES)

cweave.tex: cweave.w common.h $(WCHANGES)
	$(CWEAVE) $(WFLAGS) cweave $(WCHANGES)

common.tex: common.w $(CCHANGES)
	$(CWEAVE) $(WFLAGS) common $(CCHANGES)

wmerge.tex: wmerge.w $(MCHANGES)
	$(CWEAVE) $(WFLAGS) wmerge $(MCHANGES)

# be sure to leave ctangle.$(EXTENSION) and common.$(EXTENSION)
# and common.h for bootstrapping
clean:
	$(RM) -f -r *~ *.o common.tex cweave.tex cweave.$(EXTENSION) \
	ctangle.tex *.log *.dvi *.toc *.idx *.scn core cweave.w.[12] \
	cweave ctangle cwebmana.tex wmerge.tex wmerge

# Install the new program versions where they can be found
install: all
	$(CP) cweave $(DESTDIR)$(DESTPREF)weave
	chmod 755 $(DESTDIR)$(DESTPREF)weave
	$(CP) ctangle $(DESTDIR)$(DESTPREF)tangle
	chmod 755 $(DESTDIR)$(DESTPREF)tangle
	$(CP) cweb.1 $(MANDIR)/cweb.$(MANEXT)
	chmod 644 $(MANDIR)/cweb.$(MANEXT)
	$(CP) cwebmac.tex $(MACROSDIR)
	chmod 644 $(MACROSDIR)/cwebmac.tex
	$(CP) cweb.el $(EMACSDIR)
	chmod 644 $(EMACSDIR)/cweb.el

bundle: $(ALL)
	sed -n '1,2200 p' cweave.w > cweave.w.1
	sed -n '2201,$$ p' cweave.w > cweave.w.2
	/usr/local/bin/shar -m100000 -c -v -f cweb $(ALMOSTALL) cweave.w.[12]

tags: $(ALL)
	etags -z $(ALL)

cweb.tar: $(ALL)
	tar cvhf cweb.tar $(ALL)

floppy: $(ALL)
	bar cvhf /dev/rfd0 $(ALL)
	bar tvf /dev/rfd0
	eject
