#
# Generic class slides and materials makefile

# Name of the class
#CLASS=

# Name of slide source file
SLIDES=$(CLASS).slides

AMBLES=./POSTAMBLE ./INAMBLE ./PREAMBLE

# Pictures that will be manufactured from source (such as PIC instructions)
PICS +=

# Canned pictures that should be included in distribution
EXTRAPICS += 

# Files with program source code (.pl and .pm files, typically)
# You only need to include the ones that will be included in the distribution.
SOURCEFILES +=

# Result printable source code files (typically .ps)
SOURCELISTINGS +=

# Any extra files that should be built and included in the distribution
EXTRAFILES += $(SOURCEFILES) $(SOURCELISTINGS) 

DISTFILES += $(EXTRAFILES)

# RECENT=9
# DISTDIR=/home/mjd/public_html/perl/class/Tricks
# DISTDIR_SHORT=Tricks

.SUFFIXES: .ps .gif .pic .pl .pcl .html .pdf .dvi .pm .tex

# -nt -nk -a
A2PS=  a2ps -l66 -nL -p -nP -1 -Xletter -s
# A2PS=  a2ps -l66 -nL -p -nP -1 -Xa4 -s
# 
# -l66: 66 lines per page
# -nt: no translation of special keywords to symbols
# -nL: no 'login ID' ("Printed by Dominus from plover")
# -nk: No 'pretty' printing (idiotic boldfacing of least important words)
# -a: alternative (letter) paper size
# -p: portrait mode
# -nP: deliver PS to stdout instead of to printer
# -1: one-up format
# -Xletter: Letter-sized paper, not A4.
#
# /home/mjd/src/perl/TALKS/Flags-Double/a2ps/a2ps

MAKE_SLIDES=/home/mjd/bin/make-slides

.pl.ps:
	$(A2PS) $*.pl > $*.ps

.pm.ps:
	$(A2PS) $*.pm > $*.ps

.tex.dvi: 
	latex $*.tex

.dvi.ps:
	dvips -o $*.ps $*.dvi

.html.ps: 
	htmltops $*.html

.ps.pcl:
	pstopcl < $*.ps > $*.pcl

.ps.gif: 
	ps2gif < $*.ps > $*.gif

.pic.ps: 
	pic $*.pic | groff > $*.ps

.ps.pdf:
	ps2pdf $*.ps > $*.pdf

default: sourcelistings $(PICS) $(EXTRAFILES) .Slides.done 

warnings: quickwarnings ps
	@-perl -nle 'if (/^%%Pages:\s+(\d+)/) { print "$$ARGV: $$1 pages" if $$1 > 1;}' slide*.ps

quickwarnings: .Slides.done 
	@-cat .width-errors
	@-checkslideimages $(PICS) $(EXTRAPICS)

.Slides.done: $(SLIDES) $(MAKE_SLIDES) /home/mjd/bin/txt2slide $(AMBLES) Makefile
	$(MAKE_SLIDES) $(MSFLAGS) $(RECENT) < $(CLASS).slides
	touch .Slides.done

# TODO: We really need two kinds of distributions.
# One is the printable distribution that is for the students
# The other is the HTML/image distribution for the instructor to teach from
# This is mostly the former, but this makefile presently
# confuses these two notions and includes SOURCELISTINGS in the
# same distribution with EXTRAPICS.
tgz tar dist: $(CLASS).tgz solutions-dist example-dist

$(AMBLES): 
	touch $@

zip: $(CLASS).zip solutions-zip example-zip

$(CLASS).tgz: default $(DISTFILES)
	tar zchf $(CLASS).tgz TABLE*html $(PICS) $(EXTRAPICS) slide*html  $(DISTFILES)

$(CLASS).zip: default $(DISTFILES)
	zip -r $(CLASS).zip TABLE*html $(PICS) $(EXTRAPICS) slide*html $(DISTFILES)

printable: 1up 2up 4up
1up: $(CLASS).ps $(CLASS).pdf 
2up: $(CLASS)-2up.ps $(CLASS)-2up.pdf
4up: $(CLASS)-4up.ps $(CLASS)-4up.pdf

sourcelistings: .sourcelistings.done

.sourcelistings.done: $(SOURCELISTINGS)
	touch .sourcelistings.done

example-dist: .example-dist.done

.example-dist.done: $(SOURCEFILES)
	tar zchf $(CLASS)-Examples.tgz $(SOURCEFILES)
	touch .example-dist.done	

example-zip: .example-zip.done

.example-zip.done: $(SOURCEFILES)
	zip $(CLASS)-Examples.zip $(SOURCEFILES)
	touch .example-zip.done	

solutions-dist: .solutions-dist.done

.solutions-dist.done: $(LABFILES)
	tar zchf $(CLASS)-Solutions.tgz $(LABFILES)
	touch .solutions-dist.done	

solutions-zip: .solutions-zip.done

.solutions-zip.done: $(LABFILES)
	zip $(CLASS)-Solutions.zip $(LABFILES)
	touch .solutions-zip.done	

ps: .ps.done

.ps.done: .Slides.done
	htmltops `grep '[0-9].txt' .slide_names | sed -e 's/txt/html/'`
	touch .ps.done

pdf: $(CLASS).pdf $(CLASS)-2up.pdf $(CLASS)-4up.pdf

$(CLASS).ps:  .ps.done
#	htmltops slide*[0-9].html
#	mypstrim slide*.ps
	mypsmerge slide*.ps > $(CLASS).ps

$(CLASS)-2up.ps: $(CLASS).ps
	mypsup2 < $(CLASS).ps > $(CLASS)-2up.ps

$(CLASS)-4up.ps: $(CLASS).ps
	mypsup4 < $(CLASS).ps > $(CLASS)-4up.ps

clean:
	rm -f *.tar.gz *.ps *.zip *.tgz *.dvi *.aux *.pcl *.pdf '#'*'#' *~
	rm -f $(PICS) $(SOURCELISTINGS) 

veryclean: clean
	rm -f slide*html TABLE_OF_CONTENTS.html
	rm -fr .bak
