#
# Makefile designed for use with ctangle, cweave, gcc, and plain TeX.
#
# Copyright (C) 2003-2006, Fredrik Jonsson <fj@phys.soton.ac.uk>
#
# The CTANGLE program converts a CWEB source document into a C program that
# may be compiled in the usual way. The output file includes #line specifica-
# tions so that debugging can be done in terms of the CWEB source file.
#
# The CWEAVE program converts the same CWEB file into a TeX file that may be
# formatted and printed in the usual way. It takes appropriate care of typo-
# graphic details like page layout and the use of indentation, italics,
# boldface, etc., and it supplies extensive cross-index information that it
# gathers automatically.
#
# CWEB allows you to prepare a single document containing all the information
# that is needed both to produce a compilable C program and to produce a well-
# formatted document describing the program in as much detail as the writer
# may desire.  The user of CWEB ought to be familiar with TeX as well as C.
#
PROJECT  = dvlabel
CTANGLE  = ctangle
CC       = gcc
CCOPTS   = -O2 -Wall -ansi -std=iso9899:1999 -pedantic
LNOPTS   = -lm
CWEAVE   = cweave
TEX      = tex
DVIPS    = dvips
DVIPSOPT = -ta4 -D1200
METAPOST = mp
PS2PDF   = ps2pdf

all: $(PROJECT) fig $(PROJECT).pdf sample

$(PROJECT): $(PROJECT).o # generate the executable file
	$(CC) $(CCOPTS) -o $(PROJECT) $(PROJECT).o $(LNOPTS)

$(PROJECT).o: $(PROJECT).c # generate the object file
	$(CC) $(CCOPTS) -c $(PROJECT).c

$(PROJECT).c: $(PROJECT).w # generate C code from the CWEB source
	$(CTANGLE) $(PROJECT)

$(PROJECT).pdf: $(PROJECT).ps # generate the PDF documentation
	$(PS2PDF) $(PROJECT).ps $(PROJECT).pdf

$(PROJECT).ps: $(PROJECT).dvi # generate the PostScript documentation
	$(DVIPS) $(DVIPSOPT) $(PROJECT).dvi -o $(PROJECT).ps

$(PROJECT).dvi: $(PROJECT).tex # generate the device-independent documentation
	$(TEX) $(PROJECT).tex

$(PROJECT).tex: $(PROJECT).w # generate plain TeX code from the CWEB source
	$(CWEAVE) $(PROJECT)

fig:
	@echo "n" > fig.dvl
	@echo "Table of contents" >> fig.dvl
	@echo "This is line number one" >> fig.dvl
	@echo "This is line number two" >> fig.dvl
	@echo "This is line number three" >> fig.dvl
	@echo "." >> fig.dvl
	@echo "Monday 29/12/2003" >> fig.dvl
	@echo "Beavis and Butthead" >> fig.dvl
	@echo "Fredrik Jonsson" >> fig.dvl
	@echo "Storgatan 77" >> fig.dvl
	@echo "SE-47111 Sunne, Sweden" >> fig.dvl
	@echo "." >> fig.dvl
	@echo "hmv@hotmail.com" >> fig.dvl
	@echo "q" >> fig.dvl
	@./$(PROJECT) -d "-D1200" -c -i fig -o fig -v --eps -H -C

sample:
	make $(PROJECT)
	@echo "n" > sample.dvl
	@echo "DV1: Table of contents" >> sample.dvl
	@echo "DV1: This is line number one" >> sample.dvl
	@echo "DV1: This is line number two" >> sample.dvl
	@echo "DV1: This is line number three" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "DV1: Monday 26/11/2004 [Tape 001 SP]" >> sample.dvl
	@echo "DV1: Beavis and Butthead" >> sample.dvl
	@echo "Fredrik Jonsson" >> sample.dvl
	@echo "Storgatan 77" >> sample.dvl
	@echo "SE-471\\thinspace11 Sunne, Sweden" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "hmv@hotmail.com" >> sample.dvl
	@echo "n" >> sample.dvl
	@echo "DV2: Table of contents" >> sample.dvl
	@echo "DV2: This is line number one" >> sample.dvl
	@echo "DV2: This is line number two" >> sample.dvl
	@echo "DV2: This is line number three" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "DV2: Monday 26/11/2004 [Tape 002 SP]" >> sample.dvl
	@echo "DV2: Beavis and Butthead" >> sample.dvl
	@echo "Fredrik Jonsson" >> sample.dvl
	@echo "Storgatan 77" >> sample.dvl
	@echo "SE-471\\thinspace11 Sunne, Sweden" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "hmv@hotmail.com" >> sample.dvl
	@echo "n" >> sample.dvl
	@echo "DV3: Table of contents" >> sample.dvl
	@echo "DV3: This is line number one" >> sample.dvl
	@echo "DV3: This is line number two" >> sample.dvl
	@echo "DV3: This is line number three" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "DV3: Monday 26/11/2004 [Tape 003 SP]" >> sample.dvl
	@echo "DV3: Beavis and Butthead" >> sample.dvl
	@echo "Fredrik Jonsson" >> sample.dvl
	@echo "Storgatan 77" >> sample.dvl
	@echo "SE-471\\thinspace11 Sunne, Sweden" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "hmv@hotmail.com" >> sample.dvl
	@echo "n" >> sample.dvl
	@echo "DV4: Table of contents" >> sample.dvl
	@echo "DV4: This is line number one" >> sample.dvl
	@echo "DV4: This is line number two" >> sample.dvl
	@echo "DV4: This is line number three" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "DV4: Monday 26/11/2004 [Tape 004 SP]" >> sample.dvl
	@echo "DV4: Beavis and Butthead" >> sample.dvl
	@echo "Fredrik Jonsson" >> sample.dvl
	@echo "Storgatan 77" >> sample.dvl
	@echo "SE-471\\thinspace11 Sunne, Sweden" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "hmv@hotmail.com" >> sample.dvl
	@echo "n" >> sample.dvl
	@echo "DV5: Table of contents" >> sample.dvl
	@echo "DV5: This is line number one" >> sample.dvl
	@echo "DV5: This is line number two" >> sample.dvl
	@echo "DV5: This is line number three" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "DV5: Monday 26/11/2004 [Tape 004 SP]" >> sample.dvl
	@echo "DV5: Beavis and Butthead" >> sample.dvl
	@echo "Fredrik Jonsson" >> sample.dvl
	@echo "Storgatan 77" >> sample.dvl
	@echo "SE-471\\thinspace11 Sunne, Sweden" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "hmv@hotmail.com" >> sample.dvl
	@echo "n" >> sample.dvl
	@echo "DV6: Table of contents" >> sample.dvl
	@echo "DV6: This is line number one" >> sample.dvl
	@echo "DV6: This is line number two" >> sample.dvl
	@echo "DV6: This is line number three" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "DV6: Monday 26/11/2004 [Tape 004 SP]" >> sample.dvl
	@echo "DV6: Beavis and Butthead" >> sample.dvl
	@echo "Fredrik Jonsson" >> sample.dvl
	@echo "Storgatan 77" >> sample.dvl
	@echo "SE-471\\thinspace11 Sunne, Sweden" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "hmv@hotmail.com" >> sample.dvl
	@echo "n" >> sample.dvl
	@echo "DV7: Table of contents" >> sample.dvl
	@echo "DV7: This is line number one" >> sample.dvl
	@echo "DV7: This is line number two" >> sample.dvl
	@echo "DV7: This is line number three" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "DV7: Monday 26/11/2004 [Tape 004 SP]" >> sample.dvl
	@echo "DV7: Beavis and Butthead" >> sample.dvl
	@echo "Fredrik Jonsson" >> sample.dvl
	@echo "Storgatan 77" >> sample.dvl
	@echo "SE-471\\thinspace11 Sunne, Sweden" >> sample.dvl
	@echo "." >> sample.dvl
	@echo "hmv@hotmail.com" >> sample.dvl
	@echo "q" >> sample.dvl
	@./$(PROJECT) -d "-D1200 -ta4" -c -i sample -o sample -v

clean:
	-rm -Rf *~ *.o *.exe *.aux *.log *.toc *.idx $(PROJECT) \
	*.tex *.c *.scn *.dvi *.ps *.eps *.pdf *.dat *.dvl

archive:
	make -ik clean
	tar --gzip --directory=../ -cf ../$(PROJECT).tar.gz $(PROJECT)
