# This file is part of CWEB.
# This program by Silvio Levy is based on a program by D. E. Knuth.
# It is distributed WITHOUT ANY WARRANTY, express or implied.
#
# Modified for the SAS/C 6.0 compiler under AmigaOS 2.XX on a AMIGA 2000 by
# Andreas Scherer (sorry, no e-mail; Abt-Wolf-Straße 17, 96215 Lichtenfels,
# Federal Republic of Germany), March 1993.
# Last updated by Andreas Scherer, March 15th 1993

# Copyright (C) 1987,1990 Silvio Levy and Donald E. Knuth
# Copyright (C) 1993 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 distributed under the terms of a
# permission notice identical to this one.

# 
# Read the readme.amiga file, then edit this file to reflect local conditions
#

# directory for TeX inputs (cwebmac.tex goes here)
MACROSDIR= cweb:macros

# directory for CWEB inputs in @i files
INCLUDEDIR= cweb:

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

# directory for manual pages (cweb.1 goes here)
MANDIR= cweb:

# destination directory for executables; must end in /
DESTDIR= cweb:bin/

# directory for GNU EMACS Lips code (cweb.el goes here)
EMACSDIR= s:

# Set DESTPREF to null if you want to call the executables "tangle" and "weave"
# (probably not a good idea)
DESTPREF=c

# Set CHCHANGES to common-foo.hch if you need changes to common.h
CHCHANGES=common-p.hch

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

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

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

# Set PCHANGES to prod-foo.ch if you need changes to prod.w
PCHANGES=prod-p.ch

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

# We keep debugging info around, for fun, but most users don't need it
CFLAGS = data=FAR define=DEBUG define=STAT NOWVRET NOSTKCHK NODEBUG
# Annotation:  There had been the `OPTIMIZE' option included.  But:
# This resulted in a faulty version of `cweave' (`ctangle' worked fine).
# The `TeX' code produced by this version had a lot of extra `$' characters
# in various combinations with `cwebmac' macros, which made it impossible
# for \TeX\ to compile the results correctly.  Hopefully the version 6.1
# of the SAS/C optimizer will do a better job.
LFLAGS = STRIPDEBUG VERBOSE

# On default my version of cweave includes the option for Amiga keywords
# and the use of German macros. So you have to switch these off for all
# the CWEB documentation.
WFLAGS = -fag

# Set WMERGE such that the wmerge processor can be found.
# It will be needed if you made additional changes to 
# common-p.hch, prod-w.ch, ccwebmac.ch or ccwebmacg.ch.
# If you installed a copy, e.g. in /usr/local/bin, and this is in
# you PATH, just call wmerge; but if it is not installed, you may
# have to call it from the subdirectory
WMERGE=examples/wmerge

# RM and CP are used below in case rm and cp are aliased
RM= delete
CP= copy
#INSTALL= install
INSTALL= XCopy  # use this if `install' isn't available

# For bootstrapping type `smake cautiously'.
# If your compiler complains about too much code in one module when
# compiling `CWeave.c', you should delete `define=DEBUG' in `CFLAGS'.
# To get the documentation files, type `smake docs'.
# To clean your directory up, type `smake clean'.

CC = SC
LINK = SLink
MAKE = SMake

OBJS = LIB:c.o+common.o
LIBS = LIB:scnb.lib+LIB:amiga.lib

CWEAVE = cweave
CTANGLE = ctangle
SOURCES = cweave.w common.w ctangle.w
ALMOSTALL = common.w ctangle.w makefile.org readme.org common.c common.h \
	ctangle.c cwebman.tex cwebmang.tex cwebmac.tex examples cweb.1 \
	cweb.el prod.w $(CCHANGES) $(CHCHANGES) $(TCHANGES) $(WCHANGES) \
	$(PCHANGES) readme.c89 ccwebmac.ch ccwebmacg.ch cweb.man readme.pc \
	makefile.pc
ALL =  $(ALMOSTALL) cweave.w

.SUFFIXES: .tex .dvi .w

.w.tex:
	$(CWEAVE) $(WFLAGS) $*.w $*.ch
.tex.dvi:	
	tex $*.tex
.w.dvi:
	$(MAKE) $*.tex
	$(MAKE) $*.dvi
.w.c:
	$(CTANGLE) $*
.w.o:
	$(MAKE) $*.c
	$(MAKE) $*.o
.c.o:
	$(CC) $(CFLAGS) $*.c

# When you say `smake' without any arguments, `smake' will jump to this item.
default: all

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

# The objects of desire.
programs: ctangle cweave examples/wmerge

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

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

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

common.c: common.w $(CCHANGES)
	$(CTANGLE) common $(CCHANGES)

common.o: common.c
	$(CC) $(CFLAGS) define=INCLUDEDIR common.c

ctangle: ctangle.o common.o
	$(LINK) $(LFLAGS) FROM $(OBJS)+ctangle.o TO ctangle LIB $(LIBS)

ctangle.c: ctangle.w $(TCHANGES) common-p.h
	$(CTANGLE) ctangle $(TCHANGES)

ctangle.o: ctangle.c

cweave: cweave.o common.o
	$(LINK) $(LFLAGS) FROM $(OBJS)+cweave.o TO cweave LIB $(LIBS)

cweave.c: cweave.w $(WCHANGES) common-p.h prod-p.w
	$(CTANGLE) cweave $(WCHANGES)

cweave.o: cweave.c
	$(CC) $(CFLAGS) code=FAR cweave.c

# additional rules to `wmerge' the remaining files
#
examples/wmerge: examples/wmerge.c
	$(CC) $(CFLAGS) link examples/wmerge.c TO examples/wmerge

examples/wmerge.c: examples/wmerge.w examples/$(MCHANGES)
	$(CTANGLE) examples/wmerge examples/$(MCHANGES) examples/wmerge.c

common-p.h: common.h $(CHCHANGES)
	$(WMERGE) common.h $(CHCHANGES) > common-p.h

prod-p.w: prod.w $(PCHANGES)
	$(WMERGE) prod.w $(PCHANGES) > prod-p.w

ccwebmac.tex: cwebmac.tex ccwebmac.ch
	$(WMERGE) cwebmac.tex ccwebmac.ch > ccwebmac.tex

ccwebmacg.tex: cwebmac.tex ccwebmacg.ch
	$(WMERGE) cwebmac.tex ccwebmacg.ch > ccwebmacg.tex

# Take a good lecture.
docs: cwebman.dvi cwebmang.dvi common.dvi ctangle.dvi cweave.dvi examples/wmerge.dvi
cwebman.dvi: cwebman.tex
cwebmang.dvi: cwebmang.tex
common.dvi: common.tex
ctangle.dvi: ctangle.tex
cweave.dvi: cweave.tex

cwebmang.tex: cwebman.tex cwebmang.ch
	$(WMERGE) cwebman.tex cwebmang.ch > cwebmang.tex

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

cweave.tex: cweave.w $(WCHANGES)
	$(CWEAVE) cweave $(WCHANGES)

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

examples/wmerge.tex: examples/wmerge.w examples/$(MYCHANGES)
	$(CWEAVE) examples/wmerge.w examples/$(MCHANGES) examples/wmerge.tex

# be sure to leave ctangle.c and common.c for bootstrapping
clean:
	$(RM) \#?.o \#?.bak common.tex cweave.tex cweave.c ctangle.tex \
	  \#?.log \#?.dvi \#?.toc cweave ctangle \
	  examples/wmerge.tex examples/wmerge examples/\#?.o \
	  examples/\#?.bak examples/\#?.log examples/\#?.dvi \
	  examples/\#?.toc

# Install the new program versions where they can be found.
install: cweb:bin/ctangle cweb:bin/cweave cweb:bin/wmerge \
	cweb:macros/ccwebmac.tex cweb:macros/ccwebmacg.tex
	$(INSTALL) cweave $(DESTDIR)$(DESTPREF)weave
	$(INSTALL) examples/wmerge $(DESTDIR)wmerge
	$(INSTALL) ctangle $(DESTDIR)$(DESTPREF)tangle
	$(INSTALL) ccwebmac.tex $(MACROSDIR)
	$(INSTALL) ccwebmacg.tex $(MACROSDIR)
	$(INSTALL) cweb.1 $(MANDIR)/cweb.$(MANEXT)
	$(INSTALL) cweb.el $(EMACSDIR)
