# This file is part of CWEB.
# It is distributed WITHOUT ANY WARRANTY, express or implied.
# Last updated by Don Knuth, October 1992

# Copyright (C) 1987,1990,1992 Silvio Levy and Donald E. Knuth

# 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 file, then edit this file to reflect local conditions
#

# directory for TeX inputs (cwebmac.tex goes here)
MACROSDIR= /usr/local/lib/tex/inputs

# directory for CWEB inputs in @i files
INCLUDEDIR= /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= /u/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

# 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 common-foo.ch if you need changes to common.w
CCHANGES=

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

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

# We keep debugging info around, for fun, but most users don't need it
CFLAGS = -g -DDEBUG -DSTAT
#CFLAGS = -O

# What C compiler are you using?
CC = gcc
# You need this under EMX
EMXBIND = emxbind

# 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.exe
CTANGLE = .\ctangle.exe
SOURCES = cweave.w common.w ctangle.w
ALMOSTALL =  common.w ctangle.w Makefile README common.c common.h ctangle.c \
	cwebman.tex cwebmac.tex examples common-vms.ch ctangle-vms.ch \
	cweave-vms.ch common-man.ch ctangle-man.ch cweave-man.ch \
	cweb.1 cweb.el prod.w
ALL =  $(ALMOSTALL) cweave.w

.SUFFIXES: .tex .dvi .w

.w.tex:
	$(CWEAVE) $*

.tex.dvi:	
	tex $<

.w.dvi:
	make $*.tex
	make $*.dvi

.w.c:
	$(CTANGLE) $*

.w.o:
	make $*.c
	make $*.o

all: ctangle.exe cweave.exe

cautiously: ctangle.exe
	$(CP) common.c SAVEcommon.c
	.\ctangle.exe common $(CCHANGES)
	diff common.c SAVEcommon.c
	$(RM) SAVEcommon.c
	$(CP) ctangle.c SAVEctangle.c
	.\ctangle.exe 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) -DINCLUDEDIR="$(INCLUDEDIR)/" -c common.c

ctangle.exe: ctangle.o common.o
	$(CC) $(CFLAGS) -o ctangle ctangle.o common.o
	$(EMXBIND) ctangle

ctangle.c: ctangle.w $(TCHANGES)
	$(CTANGLE) ctangle $(TCHANGES)

cweave.exe: cweave.o common.o
	$(CC) $(CFLAGS) -o cweave cweave.o common.o
	$(EMXBIND) cweave

cweave.c: cweave.w $(WCHANGES)
	$(CTANGLE) cweave $(WCHANGES)

doc: $(SOURCES:.w=.dvi)

usermanual: cwebman.tex cwebmac.tex
	tex cwebman

fullmanual: usermanual $(SOURCES) common-man.ch ctangle-man.ch cweave-man.ch
	make cweave
	.\cweave.exe common.w common-man.ch
	tex common.tex
	.\cweave.exe ctangle.w ctangle-man.ch
	tex ctangle.tex
	.\cweave.exe cweave.w cweave-man.ch
	tex cweave.tex

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

install: all
	$(CP) cweave.exe $(DESTDIR)$(DESTPREF)weave
	chmod 755 $(DESTDIR)$(DESTPREF)weave
	$(CP) ctangle.exe $(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,1500 p' cweave.w > cweave.w.1
	sed -n '1501,$$ p' cweave.w > cweave.w.2
	/usr/local/bin/shar -m100000 -c -v -f cweb $(ALMOSTALL) cweave.w.[12]

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

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