##########################################################################
#
# Top level Makefile for the YODL program.
#
# Edit the following to configure:

# A `lib' directory under which ...../yodl will be attached, as the
# system-wide include directory for macros of the yodl program?
LIBDIR=/usr/local/lib

# To what directory are the yodl program and all shell scripts installed?
BINDIR = /usr/local/bin

# Where do your man pages go? MANPREFIX is where the subdirs man1, man2 etc.
# are located, CATPREFIX is where subdirs cat1, cat2 etc. are, that's
# where formatted pages go.
MANPREFIX=/usr/man
CATPREFIX=/var/man

# What's your LaTeX command? The shellscript "yodl2dvi" will run "yodl2tex" and
# your LaTeX-er for you, creating the .dvi file. LaTeX is also used in
# "make dvidoc" and "make psdoc".
LATEX = mlatex

# What's your command to process a manpage into a format that's suitable
# for viewing? Command should take one file argument and send the output
# to stdout.
MANTOASCII = groff -t -Tascii -man

# Similar, but when Yodl converts to ms format. What's the right
# command? I have the GNU version, so for me it's "groff" and "mgs".
MSTOASCII = groff -t -Tascii -mgs

# Similar, but a conversion via ms to PostScript. Output is assumed to go
# to stdout, the appropriate shellscript will redirect.
MSTOPS = groff -t -Tps -mgs

# What's your pager, a-la "less"? Will be used in the "yodl2manless"
# and "yodl2msless" scripts that show groff output in ASCII via a pager.
LESS = less

# The C compiler?
CC = cc

# Compiler flags?
CFLAGS = -g -c -Wall

# Installation program? If you don't have install, make sure that you state
# something that also strips executables.
INSTALL = install -s

# Install what shell scripts? The first part of the name is always "yodl2",
# the second part is the output format: tex for LaTeX, html for HTML, etc..
# The names are used to make links from yodl2whatever to each of the SCRIPTS
# names. This setting doesn't need to mention the "second stage" scripts, as
# "yodl2dvi" etc..
SCRIPTS = yodl2tex yodl2html yodl2sgml yodl2txt yodl2man yodl2ms

# The recognized formats, must match the SCRIPTS specification.
FORMATS = tex html sgml txt man ms

# Your dvips command, if you want to "make psdoc". Command must send
# output to a file "yodl.ps". Only used in the making of the Yodl package
# to make the .ps version.
DVIPS = dvips -oyodl.ps

# The misc/ directory holds a program striproff, to strip ASCII control
# characters off nroff output -- so that you keep just plain ascii. If you
# want striproff installed to $(BINDIR), uncomment the following line:
SROFF = $(BINDIR)/striproff

# If you also want the manpage under $(MANPREFIX)/man1, uncomment:
# SROFFMAN = $(MANPREFIX)/man1/striproff.1

# Additionally, if you want the preformatted manpage under $(CATPREFIX)/cat1,
# uncomment:
SROFFCAT = $(CATPREFIX)/cat1/striproff.1.gz

# Lots of scripts in the installation and in the preprocessors or
# postprocessors use the Borne-Again Shell (bash). Maybe another full-POSIX
# shell will do too, but I suggest that you get bash if you don't have it
# yet. I have it installed as /bin/sh, lucky me.
# Define the path of your bash below:
BASH = /bin/sh

# Some systems seem to lack the function strerror() (I've heard of SunOS 4.1.4
# with GCC 2.6). If that's the case, uncomment the following:
# NEEDSTRERROR = -DNEEDSTRERROR

# Same for systems that don't have optind, optarg etc. Undefine the following:
# NEEDOPT = -DNEEDOPT

# What's your system wide temp directory? Used to create temporary files.
# The following should be generally correct.
TMPDIR = /tmp

#
# That's all, the rest should need no tweaking. Now do a "make". The Makefile
# will inform you what arguments you can specifify to make what.
#
############################################################################

# Version number
VER = 1.22
YEARS = 1996-1997

# Current maintainer.
MAINT = Frank B. Brokken <frank@icce.rug.nl>

# Total include directory name
STD_INCLUDE = $(LIBDIR)/yodl

# Tag names for the postprocessor
TAGSTART=.YODLTAGSTART.
TAGEND=.YODLTAGEND.
TOCCOMMAND=.YODLTOCCOMMAND.

foobar::
	@echo 'Make what? Choose one of:'
	@echo ''
	@echo '	   make install: install the whole thing, this is probably'
	@echo '		what you want'
	@echo ''
	@echo '	   make progs: make programs under src/'
	@echo '	   make installprogs: make progs and install'
	@echo '	   make installmacros: install macro package to $(STD_INCLUDE)'
	@echo '	   make manpages: make install and recreate manpages/*.man'
	@echo '	   make installman: install manpages under $(MANPREFIX)'
	@echo '	   make installcat: install formatted manpages under $(CATPREFIX)'
	@echo '	   make installmanual: install YODL manual as $(MANPREFIX)/man5/yodl.man'
	@echo '	   make installcatual: install YODL manual as $(CATPREFIX)/cat5/yodl.5.gz'
	@echo '	   make clean: clean up stale files'
	@echo ''
	@echo '	   make latexdoc: make install, make YODL docs in LaTeX format'
	@echo '	   make dvidoc: same as latexdoc, but LaTeX-es it too'
	@echo '	   make psdoc: same as dvidoc, but dvips-es it too'
	@echo '	   make htmldoc: make install, recreate YODL docs in HTML format'
	@echo '	   make txtdoc: make install, make YODL docs in ASCII format'
	@echo '	   make mandoc: make install, make YODL docs in "man" format'
	@echo '	   make msdoc: make install, make YODL docs in "ms" format'
	@echo '	   make lessdoc: make install, make msdoc, and pipe into $(LESS)'
	@echo ''
	@echo '	   make debug: debug YODL program,  only for me (Frank)'
	@echo '	   make prof: profile YOLD program, only for me (Frank)'
	@echo ''
	exit 1

progs::
	(cd src; make STD_INCLUDE=$(STD_INCLUDE) CC=$(CC) \
	    CFLAGS="$(CFLAGS)" VER=$(VER) YEARS=$(YEARS) \
	    TAGSTART=$(TAGSTART) TAGEND=$(TAGEND) NEEDOPT=$(NEEDOPT) \
	    TMPDIR=$(TMPDIR) MAINT="$(MAINT)" \
	    NEEDSTRERROR=$(NEEDSTRERROR) TOCCOMMAND=$(TOCCOMMAND) all)
	@echo 'Program construction complete.'

debug: progs installmacros
	(cd src/yodl; make BASH=$(BASH) debug)
	@echo 'Debugging session finished.'

prof: progs installmacros
	(cd src/yodl; make prof)
	@echo 'Profiling finished.'

.cleanup: .cleanup.in Makefile
	sed 's:__BASH__:$(BASH):' < .cleanup.in > .cleanup
	chmod +x .cleanup

clean: .cleanup
	(cd src; make clean)
	./.cleanup
	rm -f lib/.instpackage lib/yodl/.makemacrodoc .cleanup \
	    manpages/Makefile manpages/*.man scripts/.makelinks
	@echo 'During make clean: HTMLs not removed.'
	@echo 'YODL sourcetree cleaned up.'

install: installprogs installmacros
	@echo 'YODL installation complete.'

installprogs: progs
	(cd src; make INSTALL="$(INSTALL)" BINDIR=$(BINDIR) \
	    VER=$(VER) YEARS="$(YEARS)" \
	    TAGSTART=$(TAGSTART) TAGEND=$(TAGEND) \
	    TOCCOMMAND=$(TOCCOMMAND) \
	    STD_INCLUDE=$(STD_INCLUDE) install)
	(cd scripts; make BINDIR=$(BINDIR) SCRIPTS="$(SCRIPTS)" \
	    INSTALL="$(INSTALL)" VER=$(VER) YEARS=$(YEARS) \
	    FORMATS="$(FORMATS)" LATEX="$(LATEX)" \
	    MANTOASCII="$(MANTOASCII)" MSTOASCII="$(MSTOASCII)"\
	    MSTOPS="$(MSTOPS)"\
	    LESS="$(LESS)" BASH=$(BASH) \
	    STD_INCLUDE=$(STD_INCLUDE) install)
	@echo 'YODL program installation complete.'

lib/.instpackage: lib/.instpackage.in Makefile
	sed 's:__BASH__:$(BASH):' < lib/.instpackage.in > lib/.instpackage
	chmod +x lib/.instpackage

lib/yodl/.makemacrodoc: lib/yodl/.makemacrodoc.in Makefile
	sed 's:__BASH__:$(BASH):' < lib/yodl/.makemacrodoc.in > \
	    lib/yodl/.makemacrodoc
	chmod +x lib/yodl/.makemacrodoc

installmacros: lib/.instpackage lib/yodl/.makemacrodoc
	-mkdir -p $(STD_INCLUDE)
	(cd lib; ./.instpackage $(STD_INCLUDE) $(VER) $(YEARS) $(TAGSTART) \
	 $(TAGEND) $(TOCCOMMAND))
	@echo 'YODL macrofiles installation complete.'

lib/yodl/macrodoc.yo: lib/yodl/shared.yo.in
	lib/yodl/.makemacrodoc lib/yodl/shared.yo.in lib/yodl/macrodoc.yo

manpages/Makefile: manpages/Makefile.in
	sed 's:__BASH__:$(BASH):' < manpages/Makefile.in > manpages/Makefile

manpages: install lib/yodl/macrodoc.yo manpages/Makefile
	(cd manpages; make manpages)

installman: manpages
	(cd manpages; make MANPREFIX=$(MANPREFIX) \
	    CATPREFIX=$(CATPREFIX) installman)
	@echo 'YODL manpages installed.'

installcat: manpages
	(cd manpages; make MANPREFIX=$(MANPREFIX) \
	    CATPREFIX=$(CATPREFIX) \
	    MANTOASCII="$(MANTOASCII)" installcat)
	@echo 'YODL manpages, preformatted version, installed.'

installmanual: mandoc
	cp doc/yodl.man $(MANPREFIX)/man5/yodl.5

installcatual: mandoc
	$(MANTOASCII) doc/yodl.man | gzip -c > $(CATPREFIX)/cat5/yodl.5.gz

latexdoc: install lib/yodl/macrodoc.yo
	(cd doc; yodl2tex -P'SUBST(XXVERSIONXX)($(VER))' yodl)
	@echo 'Docs in LaTeX format now in doc/yodl.tex!'

dvidoc: latexdoc lib/yodl/macrodoc.yo
	(cd doc; ($(LATEX) yodl.tex && $(LATEX) yodl.tex))

psdoc: dvidoc lib/yodl/macrodoc.yo
	(cd doc; $(DVIPS) yodl.dvi)

htmldoc: install lib/yodl/macrodoc.yo
	(cd doc; yodl2html -P'SUBST(XXVERSIONXX)($(VER))' yodl)
	@echo 'Docs in HTML format now in doc/yodl.html!'

txtdoc: install lib/yodl/macrodoc.yo
	(cd doc; yodl2txt -P'SUBST(XXVERSIONXX)($(VER))' yodl)
	@echo 'Docs in ASCII format now in doc/yodl.txt!'

msdoc: install lib/yodl/macrodoc.yo
	(cd doc; yodl2ms -P'SUBST(XXVERSIONXX)($(VER))' yodl)
	@echo 'Docs in ms format now in doc/yodl.ms!'

doc/yodl.man: install lib/yodl/macrodoc.yo
	(cd doc; yodl2man -P'SUBST(XXVERSIONXX)($(VER))' yodl)
	@echo 'Docs in man format now in doc/yodl.man!'

mandoc: doc/yodl.man

lessdoc: install lib/yodl/macrodoc.yo
	(cd doc; yodl2msless -P'SUBST(XXVERSIONXX)($(VER))' yodl)
	@echo 'Docs in man format also in doc/yodl.ms!'

dist: installcat manpages installcatual
	cp /usr/man/cat5/yodl.5.gz doc/yodl.txt.gz
	sh .makedist $(VER)
	makeyodl4linux
	@echo 'YODL distribution made and completed. Local ICCE distribution'
	@echo 'in the queue for unpacking. Uploaded to www and ftp'

# How to make stuff related to striproff: the program, manpage, catpage.
$(SROFF): misc/striproff.c
	$(CC) -o $(SROFF) misc/striproff.c

$(SROFFMAN):
	(cd manpages; make $(SROFFMAN))

$(SROFFCAT):
	(cd manpages; make $(SROFFCAT))

