# mkfile for CWEB under Plan 9
# by Lee Duhem, lee.duhem@gmail.com, February 2007

< /$objtype/mkfile

# directory for TeX inputs (cwebmac.tex goes here)
MACROSDIR= /sys/lib/texmf/tex/generic/cweb

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

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

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

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

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

CFLAGS = 
LDFLAGS = 

BIN = /$objtype/bin

# meta-rules
%.$O: %.c
	$CC $CFLAGS $prereq

%.dvi: %.tex
	tex $stem 

%.ps: %.dvi
	dvips $stem -o $target

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

SOURCES = common.w ctangle.w cweave.w

all:V: ctangle cweave

cautiously:V: 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

common.c: common.w $CCHANGES
	./ctangle common $CCHANGES

ctangle.c: ctangle.w $TCHANGES
	./ctangle ctangle $TCHANGES

ctangle: ctangle.$O common.$O
	$LD $LDFLAGS -o $target $prereq

cweave.c: cweave.w $WCHANGES
	mk ctangle
	./ctangle cweave $WCHANGES

cweave: cweave.$O common.$O
	$LD $LDFLAGS -o $target $prereq

# You need TeX for Plan 9 for these targets about document.

doc:V: usermanual

usermanual:V: cwebman.tex cwebmac.tex
	tex cwebman
	dvips cwebman -o cwebman.ps

fullmanual:V: usermanual ${SOURCES:%.w=%.ps}
	mk cweave
	mk $prereq

common.tex: common.w comm-man.ch
	./cweave $prereq

ctangle.tex: ctangle.w ctang-man.ch
	./cweave $prereq

cweave.tex: cweave.w cweav-man.ch
	./cweave $prereq

install:V: all
	cp ctangle $BIN/ctangle
	chmod 755 $BIN/ctangle
	cp cweave $BIN/cweave
	chmod 755 $BIN/cweave
	cp cweb.1 $MANDIR/cweb
	chmod 644 $MANDIR/cweb
	mkdir -p $MACROSDIR
	cp cwebmac.tex $MACROSDIR
	chmod 644 $MACROSDIR/cwebmac.tex
	mkdir -p $CWEBINPUTS
	cp c++lib.w $CWEBINPUTS
	chmod 644 $CWEBINPUTS/c++lib.w

# be sure to leave ctangle.c and common.c for bootstrapping
clean:V:
	rm -f common.tex cweave.tex cweave.c ctangle.tex \
	  *.log *.dvi *.toc *.idx *.scn *.ps *.$O core cweave ctangle


