#
# Makefile for the Jargon File project
#
# Note: The files jarghist.html and jargbook.html may need substantive
# changes.  The file version.tex *will* need substantive changes.
VERSION = 4.3.1
VERS    = 431
#
# How to prepare a release:
#
#  1. Check to make sure the date on the latest history entry in version.tex
#     is current.
#  2. Do `make clean'.
#  3. Do `make pcheck' to check syntax
#  4. If the preceding steps reveal problems, fix and return to step 5.
#  5. Describe the new release in jarghist.html.
#  6. Do `make'.  This will recreate all distributed formats
#     and a tarball.  Watch for cross-reference errors turned up by HTML
#     generation.
#  7. RCS-commit all the masters.
#  8. Upload (by running `upload').
#
# After each release:
#
# 1. Bump the version number here.
# 2. Add the new version number to the version list in mkchange.
# 3. Add a new version paragraph to version.tex and move @comment LATEST
#    to precede it.
#

AWK = gawk	# This should be either gawk or nawk

HTMLFILES = INSTALL-HTML index.html jarghist.html download.html \
		jargbook.html alternates.html search.html jargon-search \
		jargtxt.html awards.html quoting.html mirroring.html \
		mirrorlist.html submissions.html related.html jargoogle.html
DERIVED  = jargon-upd.lst jargon-README

LEXIFILES = lexicon1.tex ascii.tex lexicon2.tex lexicon3.tex lexicon4.tex
TXTFILES  = jargon.tex $(LEXIFILES) online.tex version.tex
BOOKFILES = jargon.tex $(LEXIFILES) jargonbook.tex version.tex
OLDFILES  = oldversions/jargon-2.1.1.txt oldversions/jargon-81.txt oldversions/jargon-82.txt 
TEX       = macros.tex contents.tex $(BOOKFILES) \
		jargon-new.lst jargon-chg.lst jargon-del.lst
PATCHERS = patch.contents patch.names patch.size fixjargon.pl splitnode.pl
ELISP    = jargon-mode.el
ALL      = READ.ME Makefile $(TEX) online.tex names.tex $(PATCHERS) ascii.bash nbreak.c dlgen.sh $(OLDFILES)

# Distribution files
FILES = $(HTMLFILES) $(DERIVED) jargon.html html graphics jarg$(VERS).gz

all: txtdist htmldist dvi 

# Plug in generated version and date variables
variables.tex: $(TXTFILES)
	echo "@set VERSION $(VERSION)" >variables.tex
	set `date`; echo "@set DATE $$3 "`echo $$2 | tr '[a-z]' '[A-Z]'`" $$6" >>variables.tex
	sh dlgen.sh $(VERSION)

#
# HTML: Make an HTML-only distribution tarball
#

htmldist: jargon-$(VERSION).tar.gz

jargon-$(VERSION).tar.gz: Introduction.html $(HTMLFILES) $(OLDFILES) $(DERIVED) jarg$(VERS).gz 
	@echo $(FILES) | tr ' ' "\012" | sed s:^:jargon-$(VERSION)/: >MANIFEST
	@(cd ..; ln -s jargon jargon-$(VERSION))
	(cd ..;tar -czf jargon/jargon-$(VERSION).tar.gz `cat jargon/MANIFEST`)
	@(cd ..; rm jargon-$(VERSION))
	ls -l jargon-$(VERSION).tar.gz

jargon.html: online.tex macros.tex variables.tex jargon.tex version.tex $(LEXIFILES)
	makeinfo --html jargon.tex

Introduction.html: jargon.html splitnode.pl
	splitnode.pl --title="The Jargon File" --framenode="The Jargon Lexicon" --version=$(VERSION) --graphdir="graphics" jargon.html

#
# TeX: Make a source distribution for publishers and other hackers
#
jargsrc.tar: $(ALL) $(ELISP)
	tar -cvf jargsrc.tar $(ALL) $(ELISP)
jargsrc.tar.gz: jargsrc.tar
	gzip -f jargsrc.tar

# Generate credits list
names.tex: nbreak $(BOOKFILES)
	patch.names

# Make the illustration pointers file
illos.tex: jargon.il
	sed <jargon.il >illos.tex '/\\entry *{\([^}]*\)}{\([0-9]*\)}{.*}/s//@set ILLO-\1 \2/'

# Make a corrected contents page
contents.tex: jargon.toc
	patch.contents

# Make the book version.
dvi: variables.tex $(BOOKFILES)
	make jargon.dvi		# to set up jargon.toc and jargon.il properly
	make illos.tex		# patch in `next' pointers in illo captions
	make contents.tex	# generate up-to-date contents page
	make jargon.dvi		# formatting with proper illo page numbers

FRONT = jargonbook.tex new.tex changed.tex # contents.tex
MS = variables.tex macros.tex $(FRONT) jargon.tex $(LEXIFILES) # names.tex

# Grind a DVI for previewing from the current collection of TeX files
jargon.dvi jargon.il jargon.toc: $(MS) names.tex
	rm -f jargon.aux	# This shouldn't be necessary
	tex '\newif\ifdvi \dvitrue \input jargon \batchmode'

# Now view it
preview: jargon.dvi
	xdvi -paper 6x9 -s 5 jargon.dvi

new.tex changed.tex: jargon-new.lst jargon-chg.lst
	$(AWK) -F"\t" <jargon-new.lst '{print $$1 "; "}' | sort -u >new.lst
	$(AWK) -F"\t" <jargon-chg.lst '{print $$1 "; "}' | sort -u >changed.lst
	sed <new.lst '$$s/; /./' >new.tex	
	comm -13 new.lst changed.lst | sed '$$s/; /./' >changed.tex

#
# Generate the info version (no longer distributed). We used to do this with:
# 	emacs -batch -l jargon-mode.el -e "jargon-make-info";rm -f jargon.info~
# but we use makeinfo now, which has the unfortunate effect that paragraphs
# get filled in behind us.
# 
txtdist: jarg$(VERS).gz

jarg$(VERS).gz: variables.tex $(TXTFILES)
	make jargon.txt
	mv jargon.txt jarg$(VERS)
	gzip -f jarg$(VERS)

# This is the plain-ASCII version
jargon.txt: variables.tex $(TXTFILES)
	makeinfo --no-split jargon.tex --output=/tmp/jargon$$.info
	ascii.bash </tmp/jargon$$.info >/tmp/jargon$$.txt
	sh patch.size /tmp/jargon$$.txt
	makeinfo --no-split jargon.tex --output=/tmp/jargon$$.info
	ascii.bash </tmp/jargon$$.info | fixjargon.pl >jargon.txt
	rm -f /tmp/jargon$$.info /tmp/jargon$$.txt

#
# Log and documentation files
#

# Generate a change report
jargon-upd.lst: 
	mkchange >changes.tex
	makeinfo --force --no-split --no-headers --output jargon-upd.lst changes.tex
	rm changes.tex
jargon-upd.lst.gz: jargon-upd.lst
	gzip jargon-upd.lst

# Generate the jargon-README file by dumping various HTML docs
jargon-README: jargbook.html jarghist.html
	echo "This file is dumped from two HTML documents." >jargon-README
	echo "You can view them using a WWW browser on the URL given below." >>jargon-README
	echo "" >>jargon-README
	lynx -dump jarghist.html >>jargon-README
	lynx -dump jargbook.html >>jargon-README

#
# Utility productions
#

spellcheck: jargon.txt
	spell +jargonwords jargon.txt 

pcheck: 
	grep -n "^@hd" lexicon[1234].tex | grep -v "@p{"

htmlclean:
	rm -fr html/*

clean: htmlclean
	rm -f *.cp *.aux *.fn *.log *.pg *.il changes.tex jargon-upd.lst
	rm -f *.toc *.tp *.vr *.ky *.dvi *.info *.info-* jsplit.?? *~ \#*
	rm -f jargon.html download.html
	rm -f new.tex changed.tex variables.tex jargon-README jargon.cut
	rm -f jargon$(VERSION).tar.gz

clobber: clean
	rm -f nbreak jarg2html
