# Master makefile for TeX, Metafont, and friends.

# Version number of this release.
texmf_version = 5.851
web2c_version = d
version = $(texmf_version)$(web2c_version)

# These pathnames are used to customize the manual pages with local
# directory names; some of them are used in `make install'.  They should
# match the system directories in the paths.
# 
prefix = /usr/athena
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
datadir = $(prefix)/lib

texdatadir = $(datadir)/tex
texpooldir = $(texdatadir)
texinputdir = $(texdatadir)/macros
texfontdir = $(texdatadir)/fonts
formatdir = $(texdatadir)/formats

mfdatadir = $(datadir)/mf
mfpooldir = $(mfdatadir)
mfinputdir = $(mfdatadir)/macros
basedir = $(mfdatadir)/bases

typesources = $(mfdatadir)/typefaces
cmsources = $(typesources)/cm

# Search paths.
# 
# The default is to search subdirectories of /usr/local/lib/tex/fonts
# for fonts, and of /usr/local/lib/tex/macros for TeX source files.
# (The trailing // means to search the given directory and all
# subdirectories, recursively.)
# 
# If your directory scheme is not organized for subdirectory searching,
# and you compile with these values, there is a chance that TeX will
# start up very, very slowly.  If this happens, change these paths to
# match your directory organization.
# 
# See tex.man for the details on which paths are searched for what files.
#
# These programs do not automatically look in the current directory;
# you must put `.' in the default paths.  If you don't, `tex foo' will
# not find `./foo.tex', and `gftopk foo.300gf' will not find
# `./foo.300gf' (for example).  Thus, users will probably be confused.
# 
# Do not put a leading or trailing colon in these paths, or double a
# colon in the middle.  That might lead to infinite recursion.  */
#
default_bibinputs = .:$(texdatadir)/bib
default_bstinputs = .:$(texinputdir)/bib
default_mfbases = $(basedir)
default_mfinputs = .:$(mfinputdir):$(typesources)//
default_mfpool = $(mfpooldir)
default_texfonts = .:$(texfontdir)//
default_texformats = $(formatdir)
default_texinputs = .:$(texinputdir)//
default_texpool = $(texpooldir)
default_vffonts = $(default_texfonts)
default_gffonts = $(default_texfonts)
default_pkfonts = $(default_texfonts)

# Default extension and directory for the man pages.
# 
manext = 1
mandir = $(prefix)/man/man$(manext)

# These lines define the format and base files that `make formats' and
# `make bases' will try to make, and `make install-formats' and `make
# install-bases' will try to install.  See `README' for a brief
# description of each of these formats.
# 
bases = mf.base cmmf.base
formats = tex.fmt latex.fmt slitex.fmt amstex.fmt amslatex.fmt
# slitex.fmt etex.fmt amslatex.fmt amstex.fmt texinfo.fmt inrstex.fmt
# picplus.fmt

# The name of the file that defines your local devices, for use with
# Metafont.  (Only relevant during `make bases'.)  I urge you to get the
# file `modes.mf', which defines all known modes, plus useful
# definitions for all fonts.  It's available from ftp.cs.umb.edu as
# pub/tex/modes.mf, among other places.
# 
localmodes = athena


# Start of system configuration section.
SHELL = /bin/sh

# Compiling.
CC = @CC@
CFLAGS = @CFLAGS@

# Command to link an executable.
CCLD = $(CC)
LDFLAGS = $(XLDFLAGS)
LIBS = @LIBS@ $(extralibs)

# Make `#include <X11/...>' work.
xincludedir = @xincludedir@

# Make `-lX...' work.
xlibdir = @xlibdir@

# This line should select the libraries that match the window systems
# you want Metafont to support.
wlibs = @wlibs@

LEX = @LEX@
LEXLIB = @LEXLIB@
YACC = @YACC@

RANLIB = @RANLIB@
LN = @LN_S@

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

# Make compilation in a different directory simpler.
srcdir = @srcdir@
VPATH = @srcdir@


# 
# Things below here not changed by configure.

# What to do by default.
default: programs
.PHONY: default

# Where we need to make things.
# 
triptrapdirs = dviutil fontutil
progdirs = $(triptrapdirs) tex mf bibtex web
alldirs = $(progdirs) lib man web2c

# What to pass to subdirectories when making various things.
# 
makeargs=$(MFLAGS) SHELL='$(SHELL)' CC='$(CC)' CFLAGS='$(CFLAGS)'	\
  CCLD='$(CCLD)' LDFLAGS='$(LDFLAGS)' LIBS='$(LIBS)' RANLIB='$(RANLIB)'	\
  LN='$(LN)' srcdir=$(srcdir) wlibs='$(wlibs)'				\
  xincludedir='$(xincludedir)' xlibdir='$(xlibdir)'
web2cmakeargs=$(makeargs) YACC='$(YACC)' LEX='$(LEX)' LEXLIB='$(LEXLIB)'
installargs=$(makeargs) 						\
  INSTALL_DATA='$(INSTALL_DATA)'					\
  INSTALL_PROGRAM='$(INSTALL_PROGRAM)'					\
  bindir='$(DESTDIR)$(bindir)'						\
  texfontdir='$(DESTDIR)$(texfontdir)'					\
  texpooldir='$(DESTDIR)$(texpooldir)'					\
  mfpooldir='$(DESTDIR)$(mfpooldir)'					\
  DESTDIR='$(DESTDIR)'

# The triptrap targets make the test versions of TeX and Metafont.
triptrap: trip trap
.PHONY: triptrap

common-trip: do-tangle
	for name in $(triptrapdirs); do					\
          (cd $${name}; $(MAKE) $(makeargs) triptrap);			\
        done

check run-triptrap: run-trip run-trap
.PHONY: check run-triptrap

clean-triptrap: clean-trip clean-trap
.PHONY: clean-triptrap


run-trip: trip
	cd tex; $(MAKE) $(makeargs) run-trip
.PHONY: run-trip

trip: common-trip
	cd tex; $(MAKE) $(makeargs) triptrap
.PHONY: trip

clean-trip: 
	cd tex; $(MAKE) clean-trip
.PHONY: clean-trip


run-trap: trap
	cd mf; $(MAKE) $(makeargs) run-trap
.PHONY: run-trap

trap: common-trip
	cd mf; $(MAKE) $(makeargs) triptrap
.PHONY: trap

clean-trap:
	cd mf; $(MAKE) clean-trap
.PHONY: clean-trap


# 
# The following targets build production versions.

all: programs manpages bases formats
.PHONY: all

programs: do-tangle
	for d in $(progdirs); do (cd $${d}; $(MAKE) $(makeargs) all); done
.PHONY: programs

TeX:	do-tangle
	cd tex; $(MAKE) $(makeargs) all
.PHONY: TeX

MF:	do-tangle
	cd mf; $(MAKE) $(makeargs) all
.PHONY: MF

BibTeX: do-tangle
	cd bibtex; $(MAKE) $(makeargs) all
.PHONY: BibTeX


# The targets help make the prerequisite parts.

lib/paths.h: $(srcdir)/lib/paths.h.in
	rm -f lib/paths.h
	echo "/* Generated from paths.h.in (`date`).  */" > lib/paths.h
	sed -e "s,replace-with-bibinputs-path,$(default_bibinputs),"	\
	    -e "s,replace-with-bstinputs-path,$(default_bstinputs),"	\
	    -e "s,replace-with-mfbases-path,$(default_mfbases),"	\
	    -e "s,replace-with-mfinputs-path,$(default_mfinputs),"	\
	    -e "s,replace-with-mfpool-path,$(default_mfpool),"		\
	    -e "s,replace-with-texfonts-path,$(default_texfonts),"	\
	    -e "s,replace-with-texformats-path,$(default_texformats),"	\
	    -e "s,replace-with-texinputs-path,$(default_texinputs),"	\
	    -e "s,replace-with-texpool-path,$(default_texpool),"	\
	    -e "s,replace-with-gffonts-path,$(default_gffonts),"	\
	    -e "s,replace-with-pkfonts-path,$(default_pkfonts),"	\
	    -e "s,replace-with-vffonts-path,$(default_vffonts),"	\
          $(srcdir)/lib/paths.h.in >> lib/paths.h

do-tangle: do-web2c
	cd web; $(MAKE) $(makeargs) tangle
.PHONY: do-tangle

do-web2c: do-lib
	cd web2c; $(MAKE) $(web2cmakeargs) all
.PHONY: do-web2c

do-lib: lib/paths.h lib/*.c
	cd lib; $(MAKE) $(makeargs) all
.PHONY: do-lib


c-sources: do-tangle
	for d in $(progdirs); do (cd $$d; $(MAKE) $(makeargs) c-sources); done
.PHONY: c-sources

manpages:
	cd man; $(MAKE) srcdir=$(srcdir)				\
	        bindir=$(bindir) texdatadir=$(texdatadir)		\
		texpooldir=$(texpooldir) formatdir=$(formatdir)		\
		texinputdir=$(texinputdir) texfontdir=$(texfontdir)	\
		mfdatadir=$(mfdatadir) mfpooldir=$(mfpooldir)		\
		basedir=$(basedir) mfinputdir=$(mfinputdir)		\
                cmsources=$(cmsources) localmodes='$(localmodes)'	\
                all
.PHONY: manpages

bases: MF
	cd mf; \
          $(MAKE) $(makeargs) bases="$(bases)" localmodes='$(localmodes)' bases
.PHONY: bases

formats: TeX
	cd tex; $(MAKE) $(makeargs) formats="$(formats)" formats
.PHONY: formats


# 
# Installation targets.

install: install-exec install-data
.PHONY: install
install-data: install-formats install-bases install-manpages
	-mkdir $(DESTDIR)$(prefix) >/dev/null 2>&1
	for name in $(progdirs); do					\
          (cd $${name}; $(MAKE) $(installargs) install-data);		\
        done
.PHONY: install-data

install-exec: programs
	-mkdir $(DESTDIR)$(exec_prefix) $(DESTDIR)$(bindir) >/dev/null 2>&1
	for name in $(progdirs); do					\
          (cd $${name}; $(MAKE) $(installargs) install-exec);		\
        done
	for f in $(formats); do						\
	  rm -f $(DESTDIR)$(bindir)/`basename $$f .fmt`;		\
          $(LN) $(DESTDIR)$(bindir)/virtex $(DESTDIR)$(bindir)/`basename $$f .fmt`;\
	done
	for f in $(bases); do						\
	  rm -f $(DESTDIR)$(bindir)/`basename $$f .base`;		\
	  $(LN) $(DESTDIR)$(bindir)/virmf $(DESTDIR)$(bindir)/`basename $$f .base`;\
	done
.PHONY: install-exec

install-formats: formats
	-mkdir $(DESTDIR)$(prefix) $(DESTDIR)$(texdatadir) $(DESTDIR)$(formatdir) >/dev/null 2>&1
	for f in $(formats); do						\
          $(INSTALL_DATA) tex/$$f $(DESTDIR)$(formatdir)/$$f;		\
	done
	cd $(DESTDIR)$(formatdir); rm -f plain.fmt; $(LN) tex.fmt plain.fmt
.PHONY: install-formats

install-bases: bases
	-mkdir $(DESTDIR)$(prefix) $(DESTDIR)$(mfdatadir) $(DESTDIR)$(basedir) >/dev/null 2>&1
	for f in $(bases); do						\
          $(INSTALL_DATA) mf/$$f $(DESTDIR)$(basedir)/$$f;		\
	done
	cd $(DESTDIR)$(basedir); rm -f plain.base; $(LN) mf.base plain.base
.PHONY: install-bases

install-manpages: manpages
	cd man; $(MAKE) $(installargs)   srcdir=$(srcdir)		\
           mandir=$(DESTDIR)$(mandir) manext=$(manext) install
.PHONY: install-manpages


# 
# Other targets.


# We can't make useful tags files out of the web sources, more's the pity.
TAGS:

configure: configure.in
	cd $(srcdir); autoconf

config.status: configure
	cd $(srcdir); $(SHELL) configure --no-create

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

# Prevent GNU make 3 from overflowing arg limit on system V.
.NOEXPORT:

# Need GNU tar for this.
dist: web2c-dist web-dist

# ChangeLog Makefile.in README handled below.
topfiles = AUTHORS FTP INSTALL MACHINES NEWS PRO* configure
distdir = web2c-$(version)

web2c-dist:
	cd web2c; $(MAKE) lex.yy.c y.tab.c
	cd web; $(MAKE) tangleboot.c
	rm -rf $(distdir)
	find * -type d -exec mkdir -p $(distdir)/'{}' \;
	for f in `find -name $(distdir) -prune				\
                       -o \( -name \*.sed				\
		             -o -name convert				\
		             -o -name ChangeLog				\
		             -o -name README				\
		             -o -name \*.sok				\
		             -o -name \*.man				\
		             -o -name \*.defines			\
		             -o -name \*.map				\
			     -o -name \*.ch 				\
			     -o -name \*.in 				\
			     -o -name \*.yacc 				\
			     -o -name \*.lex 				\
                             -o -name fixcoerce.h			\
                             -o -name tr\*penv				\
                             -o -name .gdbinit				\
                          \) -print`; do				\
          ln $$f $(distdir)/`dirname $$f`;				\
        done
	ln $(topfiles) $(distdir)
	cp -p $(gnu)/lib/aclocal.m4 $(distdir)
	cp -p $(HOME)/gnu/gnuorg/COPYING* $(top_distdir)
	ln lib/*.c lib/*.h $(distdir)/lib
	rm -f $(distdir)/lib/paths.h $(distdir)/lib/c-auto.h
	add-version $(web2c_version) $(distdir)/lib/version.c
	ln mf/MFwindow/*.c $(distdir)/mf/MFwindow
	rm -f mf/MFwindow/x11.c mf/MFwindow/sun.c
	ln mf/MFtrap/trap.* mf/MFtrap/trapin.log mf/MFtrap/trapman.tex \
	  $(distdir)/mf/MFtrap
	ln fontutil/gftodmem.h $(distdir)/fontutil
	ln tex/TeXtrip/trip.* tex/TeXtrip/tripin.log \
           tex/TeXtrip/tripman.tex tex/TeXtrip/tripos.tex \
	  $(distdir)/tex/TeXtrip
	for d in tex mf bibtex; do rm -f $(distdir)/$$d/c$$d.ch; done
	ln web/tangleboot.* $(distdir)/web
	rm -f $(distdir)/web/tangleboot.o
	ln web2c/*.c web2c/*.h $(distdir)/web2c
	(cd $(distdir)/web2c; mv y.tab.c y.tab.c-dist; \
	  mv y.tab.h y.tab.h-dist; \
	  mv lex.yy.c lex.yy.c-dist)
	tar czf web2c-$(version). $(distdir)
	rm -rf $(distdir)

web-dist:
	rm -rf $(distdir)
	mkdir $(distdir)
	cd $(distdir); \
          mkdir `cd ..; find . -name \*.web -exec dirname '{}' \; | uniq`
	for d in `find . -name $(distdir) -prune -o -name \*.web -print` ; do\
          ln $$d $(distdir)/`dirname $$d`;				\
        done
	tar czf web-$(version). $(distdir)
	rm -rf $(distdir)

web/tangleboot.c:
	cd web; $(MAKE) tangleboot.c


mostlyclean clean distclean extraclean realclean::
	for name in $(alldirs); do (cd $${name}; $(MAKE) $@); done

realclean distclean::
	rm -f Makefile config.status

extraclean::
	rm -f *~ *\#* patch* *.orig *.rej *.bak *.ckp
	rm -f *.dvi *.log *.aux *gf *pk *.tfm core a.out

# 
# Local variables:
# page-delimiter: "^# \f"
# mode: makefile
# End:
