############################################################# 
# Makefile for the Linux Network Administrators' Guide
# Copyright (C) Olaf Kirch, 1992, 1993, 1994.
#
# Ampliaciones/Revisiones (C) Juan Jose Amor 1996-1999.
#
#############################################################
VERSION=1.0

#############################################################
# set this to a4 or legal, depending on the paper size your
# printer understands. Currently, the only effect of this is
# that dvips will be forced to output the appropiate size.
# The paper size is _not_ given to latex.
#############################################################
PAPER=a4
# PAPER=letter

#############################################################
# Get the filesets for the various format distributions
#############################################################
include FILESETS

#############################################################
# Commands
# Note that for making the distribution, you must have
# GNU tar (or any other tar that supports the -T option)
#############################################################
TEXIFY	  = texify
MAKEINFO  = makeinfo
TEXI2ROFF = texi2roff
TAR	  = tar
SHELL	  = /bin/sh

CRUFT	  = *.aux *.toc *.lof *.log

#############################################################
# Rules section
#############################################################
.SUFFIXES: .fig .eepic .epsf .idx .ind

# all: ps pdf	# por defecto generamos pdf, ps y dvi
all: ps		# por defecto generamos ps y dvi
# all:	dvi	# default target

clean: cleantex cleanps cleaninfo cleanroff cleanpdf
	rm -f aux/*/* nag.dvi nagps.dvi index/*

emacsclean:
	find . -name \*~ -exec rm -f {} \; -print

mrproper: clean emacsclean
	rm -f nag.out *.aux *.toc *.idx *.log *.lof .recurse

#############################################################
# Targets relating to TeX/DVI/PS
#############################################################
dvi:	nag.dvi
pdf:	nag.pdf
html:	nag.html
psdvi:	nagps.dvi
#ps:	nagps.dvi
#	dvips -t $(PAPER) nagps.dvi -o nag.ps
ps:	nag.dvi
	dvips -t $(PAPER) nag.dvi -o nag.ps

nag.html:$(TEXDEP)
	TEXINPUTS=styles/latex:aux/dvi:.//:$$TEXINPUTS:	\
	latex2html toplevel/nag.tex

nag.pdf:$(TEXDEP)
	@if [ ! -f aux/dvi/nag.aux -a ! -f .recurse ]; then\
		echo;\
		echo "Veo que ests construyendo $@ por primera vez.";\
		echo "Por tanto ejecutar LaTeX tres veces...";\
		echo "(No es un buen momento para tomar un caf?)";\
		echo;\
		sleep 1;\
		touch .recurse;\
		make $@; touch $(TEXDEP); \
		make $@; touch $(TEXDEP); \
		rm -f .recurse; \
	fi
	TEXINPUTS=styles/latex:aux/dvi:.//:$$TEXINPUTS:	\
	pdflatex nag.tex;
	-mv $(CRUFT) aux/dvi
	@if [ -f nag.idx ]; then \
		mv nag.idx index && make index/nag.ind; \
	fi

nag.dvi:$(TEXDEP)
	@if [ ! -f aux/dvi/nag.aux -a ! -f .recurse ]; then\
		echo;\
		echo "Veo que ests construyendo $@ por primera vez.";\
		echo "Por tanto ejecutar LaTeX tres veces...";\
		echo "(No es un buen momento para tomar un caf?)";\
		echo;\
		sleep 1;\
		touch .recurse;\
		make $@; touch $(TEXDEP); \
		make $@; touch $(TEXDEP); \
		rm -f .recurse; \
	fi
	TEXINPUTS=styles/latex:aux/dvi:.//:$$TEXINPUTS:	\
	latex nag.tex;
	-mv $(CRUFT) aux/dvi
	@if [ -f nag.idx ]; then \
		mv nag.idx index && make index/nag.ind; \
	fi

nagps.dvi: $(PSDEP)
	@if [ ! -f aux/dvips/nagps.aux -a ! -f .recurse ]; then\
		echo;\
		echo "Veo que ests construyendo $@ por primera vez.";\
		echo "Por tanto ejecutar LaTeX tres veces...";\
		echo "(No es un buen momento para tomar un caf?)";\
		echo;\
		sleep 1;\
		touch .recurse;\
		make $@; touch $(PSDEP); \
		make $@; touch $(PSDEP); \
		rm -f .recurse; \
	fi
	TEXINPUTS=styles/latex:aux/dvips/:.//:$$TEXINPUTS: \
	latex nagps.tex;
	-mv $(CRUFT) aux/dvips
	@if [ -f nagps.idx ]; then \
		mv nagps.idx index && make index/nagps.ind; \
	fi

spollchuck:
	echo "Checking for misspellings (not a big win, tho)"
	../bin/makewords $(TEXALL)

cleantex:
	rm -f nag.dvi index/nag.* aux/dvi/*

cleanps:
	rm -f nagps.dvi nag.ps index/nagps.* aux/dvips/*

cleanpdf:
	rm -f nag.pdf

#############################################################
# Targets relating to TeXinfo/Info
#############################################################
texi:	net.texi

info: 	netguide

netguide:$(TEXI)
	$(MAKEINFO) nag.texi

net.texi:$(TEXIDEP)
	$(TEXIFY) net.tex
	$(TEXIFY) net.tex

cleaninfo:
	rm -f netguide netguide-[0-9] netguide-[0-9][0-9] \
		net.texi net.auxi net.ff net.menu aux/info/*

#############################################################
# Targets relating to groff/ASCII. These targets require
# that you have LoTeX-0.9
#############################################################
roff:	$(ROFF)
ascii:	nag.ascii

nag.mm:$(ROFFDEP)
	@echo "Preparando versin roff GNU... esto puede tardar"
	@echo "unos pocos minutos (o ms)."
	LOTEXINCLUDES=aux/mm:.//: LOTEXSTYLES=styles/lotex lotex nagmm
	mv nagmm.mm nag.mm
	mv *.auxl aux/mm

nag.ascii:$(ROFF)
	rm -f *.qrf
	@$(MAKE) rungroff
	makeroffidx net.idxl
	@$(MAKE) rungroff

rungroff:
	(groff -t -Tascii -mgm nag.mm | colcrt - > nag.ascii) 2>&1 | \
		tee nagasc.log

cleanroff:
	rm -f nag.mm nag.ascii aux/mm/* index/nagmm.*

#############################################################
# Targets relating to fig picture conversion
#############################################################
.fig.eepic:
	fig2dev -Leepic $< > $@
.fig.epsf:
	fig2dev -Lps $< > $@

#############################################################
# Targets relating to index generation
#############################################################
.idx.ind:
	@echo Generating index for $?.dvi
	makeindex $<

#############################################################
# Make distribution files
#############################################################
dist:	src-dist dvi-dist ps-dist roff-dist

src-dist:
	@ls $(SRCDIST)

dvi-dist:dvi
	@ls $(DVIDIST)  | sed "s/^/.\/netguide\//" > MANIFEST
	-cd ..; $(TAR) -cvf - -T netguide/MANIFEST |\
		gzip > nagdvi-$(VERSION).tgz

ps-dist: ps
	@ls $(PSDIST)   | sed "s/^/.\/netguide\//" > MANIFEST
	-cd ..; $(TAR) -cvf - -T netguide/MANIFEST |\
		gzip > nagps-$(VERSION).tgz

texi-dist:texi
	@ls $(TEXIDIST) | sed "s/^/.\/netguide\//" > MANIFEST
	-cd ..; $(TAR) -cvf - -T netguide/MANIFEST |\
		gzip > nagtexi-$(VERSION).tgz

roff-dist:roff
	@ls $(ROFFDIST) | sed "s/^/.\/netguide\//" > MANIFEST
	-cd ..; $(TAR) -cvf - -T netguide/MANIFEST |\
		gzip > nagroff-$(VERSION).tgz

