# main.icn -- mainline and reading of specification input file
# grammar.icn -- recursive descent parser of specification file
# output.icn -- routines to output ASCII & PostScript reps of decision
#	trees
# tree.icn -- routines for converting patterns into DNF and for 
# 	heuristically generating decision trees 	

CC=gcc
CFLAGS=
NOWEAVE=noweave -x

%.tex: %.nw
	$NOWEAVE -l $prereq > $target

%.dvi: %.tex
	latex $prereq

%.icn:	%.nw
	notangle -L'#line %-1L "%F"%N' $prereq > $target

%.sml: %.nw
	notangle $prereq > $target

%.ps:	%.dag 
	dag -Tps <$stem.dag | 
	sed 's/) show/) dup stringwidth pop neg 0 rmoveto show/' >$stem.ps
	
%.dag:	%Asm.nw pattern
	notangle -L ${stem}Asm.nw | pattern -dag $stem.dag

%Asm.c:	%Asm.nw pattern
	notangle -L ${stem}Asm.nw | pattern -map -case ${stem}Asm.c -spec $stem.spec


%.u1:	%.icn
	icont -c $prereq

D%: dis.o %Asm.o printloc.o
	$CC $CFLAGS -o $target $prereq

#  printloc.c: proctable dis.o SparcAsm.o
#  	$prereq > $target

PATTERNU=assembly.u1 patterns.u1 grammar.u1 tree.u1 dag.u1 aparse.u1 \
	main.u1 output.u1 gencode.u1 C.u1 m3.u1 lex.u1 equations.u1 \
	disassembly.u1 solve.u1 idump.u1 Ceqn.u1 fieldinfo.u1 \
	patterns.u1 grammar.u1 tree.u1 dag.u1 aparse.u1 \
	pushtrace.u1 commafy.u1 openfile.u1


all:V: pattern
install:V: all
	[ -d $M3BIN ] && cp pattern $M3BIN

pattern: $PATTERNU
	icont -o $target $prereq

#pattern: `cat pattern.icn.sm`
#	odin pattern

Mips.dis: pattern MipsInstructions.nw mips.nw
	notangle -L MipsInstructions.nw mips.nw | pattern -dis $target >$target.log

Mips.asm: pattern MipsInstructions.nw mips.nw
	notangle -L MipsInstructions.nw mips.nw | pattern -asm $target >$target.log

mslib.h: mslib.nw
	notangle -R$target $prereq | cpif $target

reloc.h: reloc.nw
	notangle -R'C declarations' $prereq | cpif $target

md.c:	pattern MipsInstructions.nw Mips.dis MD.nw
	notangle -L MipsInstructions.nw Mips.dis MD.nw | pattern -case $target

ma.h:	Mips.asm
	(echo 'extern void (*fail)(char *fmt, ...);
	#define sign_extend(x, n) (x & (1 << (n-1)) ? x | (~0 << n) : x)' ; notangle -Rheader $prereq) > $target
ma.c:	Mips.asm
	(for i in mslib reloc ma; do echo "#include \"$i.h\""; done; notangle $prereq) > $target

ma.o:	ma.h mslib.h reloc.h

doc.tex: patterns.nw grammar.nw tree.nw dag.nw aparse.nw gencode.nw output.nw main.nw
	noweave -l $prereq > $target

proctable: proctable.icn
	icont $target

clean:V:
	rm -f *.icn *.u? *.o *.[ch] *.aux *.dvi *.ps *.log *~ ./#*#
veryclean:V: clean
	rm -f pattern


# COUNT=5664  # sparc
COUNT=500

%.my.dump: D%
	$prereq $COUNT > $target

%.dbx.dump: D%
	dbxdump $prereq $COUNT > $target

%.compare:V: %.my.dump %.dbx.dump
	diff -b $prereq | sed 's/[ 	][ 	]*/ /g' | disdiffs

%.ty:	%.sml
	echo "use \"$prereq\";" | sml > $target
sem:V: semantics.ty
	cat $prereq
