# @(#) $Id: Makefile.noweb,v 1.1 1993/04/29 15:56:54 leavens Exp leavens $
# Makefile for noweb (.nw) files

### Some program names and options
LATEX = latex
BIBTEX = bibtex
DVI2PS = dvitps
NOWEAVE = noweave
NOTANGLE = notangle

C = .C    # this works for both g++ and AT&T C++, but you can also use .cc
CXX = g++  # CC
CXXFLAGS = -Wall -I/usr/unsup/include -O
CXXLDFLAGS = -L/usr/unsup/lib -lL  # find LEDA libraries


# Tell make about our suffixes: (required to define rules)
.SUFFIXES: .tex .dvi .ps .nw .lc .lsl .C .cc .lcc # $(SUFFIXES)
.nw.tex:
	# the sed below can be used to change the document style
	# put stuff that goes before \begin{document} in beforebegin.tex
	#$(NOWEAVE) -l $< | sed -e '1s/\]/]/;1s/$$/\\input{beforebegin}/' > $@
	$(NOWEAVE) -l $< | sed -e '1s/\]/]/' > $@

.nw.lcc:
	$(NOTANGLE) -R"$@" $< > $@

.nw.lsl:
	$(NOTANGLE) -R"$@" $< > $@

.nw$(C):
	$(NOTANGLE) -R"$@" $< > $@

.nw.h:
	$(NOTANGLE) -R"$@" $< > $@

.tex.dvi:
	$(LATEX) $<

.dvi.ps:
	$(DVI2PS) $< > $@

$(C).o:
	$(CXX) $(CXXFLAGS) -c $<

### defs for this program
SOURCES = main$(C) World$(C) StdWorld$(C) WorldMaker$(C) Decision$(C)
OBJECTS = main.o World.o StdWorld.o WorldMaker.o Decision.o
HEADERS = Decision.h Prisoner.h StdWorld.h World.h PrisonerTypes.h
PROGRAM = prisoners-dilemma

# make targets for the program and its parts
all: $(PROGRAM).dvi $(PROGRAM)

main.o: $(HEADERS)

$(PROGRAM).dvi : $(PROGRAM).tex

$(PROGRAM): $(OBJECTS)
	$(CXX) $(OBJECTS) -o $(PROGRAM) $(CXXLDFLAGS)

# extraction from noweb dependencies that aren't obvious
main$(C): $(PROGRAM).nw $(HEADERS)
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@

Decision$(C): $(PROGRAM).nw Decision.h
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@

World$(C): World.h Prisoner.h $(PROGRAM).nw
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@

StdWorld$(C): $(PROGRAM).nw StdWorld.h World.h Prisoner.h
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@

WorldMaker$(C): World.h Prisoner.h StdWorld.h PrisonerTypes.h \
		$(PROGRAM).nw \
		AllC.h AllD.h
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@

Prisoner.h: $(PROGRAM).nw Decision.h
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@
PrisonerTypes.h: $(PROGRAM).nw
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@
StdWorld.h: $(PROGRAM).nw
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@
World.h: $(PROGRAM).nw
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@
Decision.h: $(PROGRAM).nw
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@
AllC.h: $(PROGRAM).nw
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@
AllD.h: $(PROGRAM).nw
	$(NOTANGLE) -R"$@" $(PROGRAM).nw > $@


# note that clean removes the files generated by noweb
clean: cleangened cleanbinary

cleangened:
	rm -f *$(C) *.h *.tex makefile

cleanbinary:
	texclean -fd
	rm -f *.o core

cleanall: clean
	rm -f a.out $(PROGRAM)
