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

< /$objtype/mkfile

CFLAGS = 
LDFLAGS = 

BIN = /$objtype/bin

# Be sure that CWEB version 3.0 or greater is installed before proceeding!
# In fact, CWEB 3.61 is recommended for making hardcopy or PDF documentation.
CTANGLE = ctangle
CWEAVE = cweave

CWEBMAC = /sys/lib/texmf/tex/generic/cweb/cwebmac.tex

# changes for MMIXware under Plan 9
MMIXALCH = mmixal-plan9.ch
SIMCH = sim-plan9.ch
MMMIXCH = mmmix-plan9.ch
ARITHCH = arith-plan9.ch
MEMCH = mem-plan9.ch
PIPECH = pipe-plan9.ch
IOCH = io-plan9.ch
CONFIGCH = config-plan9.ch
MMOTYPECH = mmotype-plan9.ch
ABSTIMECH = abstime-plan9.ch

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

%.tex: %.w
	$CWEAVE  $stem

%.dvi: %.tex
	tex $stem 

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

%.mmo: %.mms
	mmixal -x -b 250 -l $stem.mml $prereq

%.mmo: %.mmb
	mmix -D$target $prereq

##########  You shouldn't have to change anything after this point #######
basic:V:  mmixal mmix

all:V:    mmixal mmix mmmix mmotype

mmix-arith.c: mmix-arith.w $ARITHCH
	$CTANGLE $prereq

mmix-config.c: mmix-config.w $CONFIGCH
	$CTANGLE $prereq

mmix-io.c: mmix-io.w $IOCH
	$CTANGLE $prereq

mmix-mem.c: mmix-mem.w $MEMCH
	$CTANGLE $prereq

mmix-pipe.c: mmix-pipe.w $PIPECH
	$CTANGLE $prereq

mmix-sim.c: mmix-sim.w $SIMCH
	$CTANGLE $prereq

mmixal.c: mmixal.w $MMIXALCH
	$CTANGLE $prereq

mmmix.c: mmmix.w $MMMIXCH
	$CTANGLE $prereq

mmotype.c: mmotype.w $MMOTYPECH
	$CTANGLE $prereq

abstime.c: abstime.w $ABSTIMECH
	$CTANGLE $prereq

mmix-pipe.$O: mmix-pipe.c abstime
	./abstime > abstime.h
	$CC $CFLAGS mmix-pipe.c
	rm abstime.h

mmix-config.$O: mmix-config.c mmix-pipe.$O
	$CC $CFLAGS mmix-config.c

mmix-sim.$O: mmix-sim.c abstime
	./abstime > abstime.h
	$CC $CFLAGS mmix-sim.c
	rm abstime.h

mmmix: mmix-arith.$O mmix-pipe.$O mmix-mem.$O mmix-io.$O mmix-config.$O mmmix.$O
	$LD $LDFLAGS -o $target $prereq

mmixal: mmix-arith.$O mmixal.$O
	$LD $LDFLAGS -o $target $prereq

mmix: mmix-arith.$O mmix-io.$O mmix-sim.$O
	$LD $LDFLAGS -o $target $prereq

mmotype: mmotype.$O
	$LD $LDFLAGS -o $target $prereq

abstime: abstime.$O
	$LD $LDFLAGS -o $target $prereq

cwebmac.tex:
	cp $CWEBMAC .

# You need TeX for Plan 9
doc:V: cwebmac.tex mmix-doc.ps mmixal.dvi mmix-sim.dvi
	dvips -n13 mmixal.dvi -o mmixal-intro.ps
	dvips -n8 mmix-sim.dvi -o mmix-sim-intro.ps
	rm cwebmac.tex

clean:V:
	rm -f *.$O *.c *.h mmixal mmix mmmix mmotype abstime \
		*.tex *.log *.dvi *.toc *.idx *.scn *.ps *.mmo *.mmb cwebmac.tex

install:V: all
	for(p in mmixal mmix mmmix mmotype){
		cp $p $BIN/
		chmod 755 $BIN/$p
	}

