# 
# Makefile for the Linux System Administrators' Guide
#
# Lars Wirzenius
# "@(#)sag:$Id$"
#

# The file for each chapter and the files it includes (e.g., pictures)
sty = linuxdoc.sty chapterbib.sty
frontmatter = frontmatter.tex linux-logo.ps
intro = intro.tex rhyme.tex convntns.tex blurb.tex copyright.tex
disks = disks.tex hd-schematic.ps hd-layout.ps  \
	hd-mount-separate.tex hd-mount-mounted.tex
mem = mem.tex
walkabout = walkabout.tex
backups = backups.tex backup-timeline.tex
logins = logins.tex logins-via-terminals.ps
time = time.tex
overview = overview.tex overview-kernel.ps
up-n-down = up-n-down.tex
ext2fs = ext2fs/paper.tex ext2fs/dir.ps ext2fs/inode.ps ext2fs/vfs.ps \
	ext2fs/remy.sty ext2fs/biblio.bib
devicelist = device-list.tex
measure-holes = measure-holes/measure-holes.tex
bib = bibliography.tex sag.bib


# All the chapters that are currently included
chapters = $(sty) $(frontmatter) $(intro) $(disks) $(mem) $(backups) \
	$(ext2fs) $(measure-holes) $(bib) $(walkabout) $(logins) \
	$(overview) $(devicelist) $(time) $(up-n-down)

# Implicit rules
.fig.tex:
	fig2dev -L latex $< > $@
.fig.ps:
	fig2dev -L ps $< > $@
.SUFFIXES: $(SUFFIXES) .fig .tex .ps

# Other rules

all: ps

ps: sag.ps
dvi: sag.dvi
txt: sag.txt

sag.ps: sag.dvi
	dvips -f sag.dvi > sag.ps

sag.dvi: sag.tex $(chapters)
	latex sag
	if [ -f ext2fs/paper.aux ]; then bibtex ext2fs/paper; fi
	bibtex bibliography
	latex sag
	latex sag

sag.txt: $(chapters)
	for i in $(chapters); do case $$i in *.tex) \
		sed 's/\\linux/Linux/g;\
		     s/\\UNIX/UNIX/g;\
		     s/\\meta/META: /g;\
		     s/\\man//g;\
		     s/\\man//g;\
		     s/\\fn//g' $$i | delatex \
		;; esac; done | \
	awk '{if (!p || NF>0) print; p=(NF==0)}' > sag.txt

backup-timeline.tex: backup-timeline.fig 

hd-mount-separate.tex: hd-mount-separate.fig 
hd-mount-mounted.tex: hd-mount-mounted.fig 
hd-schematic.ps: hd-schematic.fig 
	fig2dev -L ps -m 0.5 $< > $@
hd-layout.ps: hd-layout.fig 
	fig2dev -L ps -m 0.75 $< > $@

ext2fs/dir.ps: ext2fs/dir.fig
ext2fs/inode.ps: ext2fs/inode.fig
ext2fs/vfs.ps: ext2fs/vfs.fig

clean:
	rm -f sag.log sag.aux sag.dvi sag.ps sag.toc sag.txt
	rm -f hd-schematic.ps hd-layout.ps
	rm -f hd-mount-separate.tex hd-mount-mounted.tex
	rm -f ext2fs/dir.ps ext2fs/vfs.ps ext2fs/inode.ps
	rm -f extfs/paper.blg ext2fs/paper.bbl ext2fs/paper.aux
	rm -f backup-timeline.tex logins-via-terminals.ps
	rm -f bibliography.aux bibliography.blg bibliography.bbl
	rm -f overview-kernel.ps
