#
# Makefile for the documentation directory
#
# Copyright 1994,2000   rubini@gnu.org (Alessandro Rubini)
# 
#################
#
# BE CAREFUL in editing:
#	due to the large number of index files, and my use of a non standard
#	info input file, any file $(TARGET).* is removed by "make clean"
#
#	I chose to use a prefix for the input file ("doc.$(TARGET)"), to ease
#	makeing clean and applying my own rules.
#
###################################################################
#
# Assume makeinfo can do images and --html.
# In any case, MAKEINFO can be specified on the commandline

MAKEINFO = makeinfo

##############################################


TARGET = gunzets
ALL    =  $(TARGET).info $(TARGET).ps $(TARGET)doc.txt $(TARGET).html \
		$(TARGET).pdf 

all: $(ALL) terse

info: $(TARGET).info

mpage: all
	mv $(TARGET).ps $(TARGET)1.ps
	mpage -2A $(TARGET)1.ps > $(TARGET)2.ps && rm $(TARGET)1.ps

terse:
# preserve the pdf copy
	@if [ "$(TARGET).???" != "$(TARGET).pdf" ]; then \
		if [ -f $(TARGET).pdf ]; then mv -f $(TARGET).pdf PDF; fi; \
		rm -f *~ *.dvi *.log *.aux \
		      $(TARGET).*.bak $(TARGET).??? $(TARGET).texinfo && \
		if [ -f PDF ]; then mv PDF $(TARGET).pdf; fi; \
	fi
# preserve the ps copy
	@if [ "$(TARGET).??" != "$(TARGET).ps" ]; then \
		if [ -f $(TARGET).ps ]; then mv $(TARGET).ps PS; fi; \
		rm -f $(TARGET).??; \
		if [ -f PS ]; then mv PS $(TARGET).ps; fi; \
	fi

clean-with-docs: terse

clean: terse
	rm -f $(ALL) $(TARGET)_toc.html


####################################################

# These rules used to be expressed as "%.texinfo: doc.%" etc. However, this
# is gmake-specific, so I turned every % to $(TARGET), thus loosing generality
# but gaining portability. I also had to drop "$^": it worked with gmake
# and not pmake, while "$<" worked with pmake and not gmake.
#    ARub 2000-04-21

$(TARGET).texinfo: doc.$(TARGET)
	@rm -f $@ 2> /dev/null
	sed -f ./infofilter doc.$(TARGET) > $@
	chmod 400 $@


# This rule is somewhat a rewrite of texi2dvi. I like make more than sh :-)
# This had to be rewritten too, as "$*" is different in gmake and pmake

$(TARGET).dvi: $(TARGET).texinfo

# create a spurious  index file to please silly sh (bash will work anyway)
	touch $(TARGET).oo

# get the index list
	if test "x`ls $(TARGET).?? $(TARGET).aux`" != "x"; then \
	  for i in `ls $(TARGET).?? $(TARGET).aux`; do \
	    cp $$i $$i~; \
	  done; \
	fi
	tex $(TARGET).texinfo

#check the file list, the file and if needed run TeX again
	old="`ls $(TARGET).??~ $(TARGET).aux~ | sed 's/~//g'`"; \
	new="`ls $(TARGET).?? $(TARGET).aux`"; \
	need="n"; \
	if test "$$old" != "$$new"; then need="y"; \
	else \
	  for i in  `ls $(TARGET).?? $(TARGET).aux`; do \
	    cmp -s $$i $$i~; if test $$? -ne 0; then need="y" break; fi; \
	  done; \
	fi; \
	if test "$$need" = "y"; then \
	  texindex $(TARGET).?? && tex $(TARGET).texinfo; \
	fi


# The ".dvi" and ".texinfo" intermediate files must not appear in the
# dependent list, or make will regenerate them every time.

$(TARGET).ps: doc.$(TARGET)
	$(MAKE) $(TARGET).dvi
	dvips -f $(TARGET).dvi > $@

$(TARGET).pdf: $(TARGET).ps
	ps2pdf $(TARGET).ps > $@

$(TARGET).lj: doc.$(TARGET)
	$(MAKE) $(TARGET).dvi
	dvilj -e- $(TARGET).dvi > $@

$(TARGET).info: doc.$(TARGET)
	$(MAKE) $(TARGET).texinfo
	$(MAKEINFO) $(TARGET).texinfo -o $@

$(TARGET).html: doc.$(TARGET)
	$(MAKE) $(TARGET).texinfo
	$(MAKEINFO) --html -o $@ $(TARGET).texinfo

#$(TARGET).man: doc.$(TARGET)
#		manpages are created by the toplevel Makefile

$(TARGET)doc.txt: $(TARGET).info
	$(MAKEINFO) --no-headers $(TARGET).texinfo > $@







