#			-*-makefile-*- (gpm/doc)
#
# Copyright (C) 1994 Alessandro Rubini <rubini@linux.it>
# Copyright (C) 1998 Ian Zimmerman <itz@rahul.net>
# Copyright (C) 2001 Nico Schottelius <nico@schottelius.org>
#
#
# Do you ever got headache from reading Makefiles ? I will help you and
# me to understand this Makefile: 
# 
# The main file is doc.gpm (which is generated by configure from doc.gpm.in).
#
# doc.gpm is not 'real' texinfo, real texinfo is generated by infofilter
# to gpm.texinfo. 
#
# gpm.texinfo is the source of all other formats. 
#
# info is generated by makeinfo (I make that for you).
#
# man pages are generated with the help of manpager.
#
# dvi is generated from texinfo with a small block in this Makefile.
#
# ps is generated from dvi source.
#

SHELL = /bin/sh
srcdir = /builddir/build/BUILD/gpm-1.20.7/doc
top_builddir = ..

include $(top_builddir)/Makefile.include

MANPAGES = gpm.8 mev.1 gpm-root.1 gpm-types.7 mouse-test.1

all: gpm.info gpm.man

# HTML (texi2html)
%.html: %.texinfo
	if [ $(TEXI2HTML) != "no" ]; then $(TEXI2HTML) -monolithic $< ;fi

# TEXINFO (-)
%.texinfo: doc.% Makefile
	@rm -f $@ # correct here ?
	$(SED) -f $(srcdir)/infofilter $< > $@
	chmod 400 $@

# PS (dvips)
%.ps: %.dvi
	if [ $(DVIPS) != "no" ]; then $(DVIPS) -f $< > $@; fi

# INFO (makeinfo)
%.info: %.texinfo
	if [ "$(MAKEINFO)" != "no" ]; then $(MAKEINFO) --no-split $< -o $@; fi

# TXT (-)
%.txt: %.info
	$(AWK) -f $(srcdir)/mktxt $< > $@

# MAN (-)
$(MANPAGES): gpm.man
gpm.man: doc.gpm $(srcdir)/manpager
	$(AWK) -f $(srcdir)/manpager doc.gpm
	for i in gpm-root.1 gpm-types.7 gpm.8 mev.1 mouse-test.1; do \
		expand $$i | sed s/^'[ ]*'//g > $$i.new; \
		mv $$i.new $$i; \
	done;
	touch gpm.man


# DVI 
# This rule is somewhat a rewrite of texi2dvi. I like make more than sh :-)
%.dvi: %.texinfo

# create a spurious  index file to please silly sh (bash will work anyway)
# is this still needed for someone ?
	touch $*.oo

# get the index list, but only if tex is installed
# check the file list, the file and if needed run TeX again
# 
# can somebody tell me in a very short way what format dvi is and why we
# cannot generate ps directly ?
	
	if [ -n "`ls $*.?? $*.aux 2>/dev/null`" -a "$(TEX)" != "no" -a \
	"$(TEXINDEX)" != "no" ]; then \
		for i in `ls $*.?? $*.aux 2>/dev/null`; do cp $$i $$i~; done; \
		$(TEX) $< \
		old="`ls $*.??~ $*.aux~ 2>/dev/null | $(SED) 's/~//g'`"; \
		new="`ls $*.?? $*.aux 2>/dev/null`"; \
		need="n"; \
		if test "$$old" != "$$new"; then need="y"; \
		else \
		  for i in  `ls $*.?? $*.aux 2>/dev/null`; do \
		    cmp -s $$i $$i~; if test $$? -ne 0; then need="y" break; fi; \
		  done; \
		fi; \
		if test "$$need" = "y"; then \
		  $(TEXINDEX) $*.?? && $(TEX) $<; \
		fi; \
	fi

# Main portion

all: gpm.info $(MANPAGES)

# why gpmdoc.ps and gpm.ps??
# there is no gpm.ps in my tree and no rule to generate gpm.ps.
gpmdoc.ps:	gpm.ps
	-$(CP) $< $@

# install & uninstall

installdirs:	
	$(MKDIR) $(man1dir) $(man7dir) $(man8dir) $(infodir)	

install: installdirs
	$(INSTALL_DATA) -m 644 mev.1          $(man1dir)
	$(INSTALL_DATA) -m 644 mouse-test.1   $(man1dir)
	$(INSTALL_DATA) -m 644 gpm-root.1     $(man1dir)
	$(INSTALL_DATA) -m 644 gpm-types.7    $(man7dir)
	$(INSTALL_DATA) -m 644 gpm.8          $(man8dir)
	$(INSTALL_DATA) -m 644 $(srcdir)/gpm.info       $(infodir)
	# Use install-info if available
	-if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
	  if [ -f $(infodir)/dir ] ; then \
		install-info --dir-file=$(infodir)/dir $(infodir)/gpm.info; \
	  fi; \
	fi
	#itz Sat Dec 26 23:21:05 PST 1998
	#i keep all my infopages compressed and i'm tired to do it by
	#hand, so check if there are any compressed pages and do this
	#one too
	#-ls $(infodir)/*[-.]info.gz >/dev/null 2>&1 \
	#	&& gzip -f $(infodir)/gpm.info
	# Hmm.... shouldn't man pages be compressed too?
   # maybe they should, but at least at my system they are not.

# This potentially leaves around cached manpages,
# e.g. /var/cache/man/cat1/mev.1.gz.  Deleting these is not our job,
# but the job of the man program on the host.
uninstall:	
	cd $(man1dir) && rm -f mev.1 mouse-test.1 gpm-root.1
	rm -f $(man7dir)/gpm-types.7 $(man8dir)/gpm.8 
	rm -f $(infodir)/gpm.info $(infodir)/gpm.info.gz
	-if $(SHELL) -c 'install-info --version' >/dev/null 2>&1; then \
	  if [ -f $(infodir)/dir ] ; then \
		install-info --dir-file=$(infodir)/dir \
			--remove $(infodir)/gpm.info; \
	  fi; \
	fi

# configure & unconfigure

Makefile:	$(top_builddir)/config.status $(srcdir)/Makefile.in
	cd $(top_builddir) && $(SHELL) config.status

## CLEANUP section
# normal cleanup
clean:
	rm -f gpmdoc.ps gpmdoc.txt $(MANPAGES) *~ 
	rm -f gpm.?? gpm.???
	rm -f gpm.texinfo

# for creating distribution
distclean:	clean
	rm -f Makefile doc.gpm

# to even remove things we leave for end-users
allclean:	distclean
	rm -f gpm.info

# Maintainer portion, use at your own risk

# ignore this:
TAGS:

## DIST section
# when we cleaned it, we can securely copy us.
dist: distclean
	# unneeded now: using pax + -s option and create tars in ..
	#$(CP) -r $(srcdir) $(top_builddir)/gpm-$(release)/

.INTERMEDIATE:	gpm.ps
.SECONDARY:	%.ps %.texinfo %.dvi

gs: gpm.ps
	gs -sDEVICE=linux -r640x480x2 $<

gv: gpm.ps
	ghostview gpm.ps -magstep -1 -a4
