#
#   Makefile for dvips.  Edit this first part of the file.
#
#   Watcom C/386 9.0 for MSDOS, 21 Dec 1993, rcpt@urc.tue.nl. 
#   Compilation takes about 3 minutes on my 486/8MB clone.
#
#   [ If you don't have MTPK,
#     - remove mtpk.c   from SRC
#     - remove mtpk.obj from OBJ
#     rjl 23 Dec 1993 ]
#
#   This makefile use the UNIX compatible rm.exe and sed.exe tools. 
#   They are available on good fileservers. And because of MSDOS 
#   limitations in handling command lines you have to add manually an 
#   include line to dvips.c and mtpk.c:
#       #include "dvips.wat" (the one needed in dvips.c)
#       #include "paths.wat" (the one needed in mtpk.c)
#
#   First, the things that absolutely must be edited for your system.
#   Please, don't forget to install MTPK with the same settings
#
#   Run with: `wmake -f pc\makefile.wat' from dvips source directory.

# Define default resolution
DEFRES = 300

# Define name of MTPK
MTPK = mtpk

# where TeX is `rooted'.  Sometimes d:\emtex
# TEXDIR = c:\emtex
TEXDIR = c:\emtex

# another place pk, tfm, and vf files might be found.
# LOCALDIR = c:\texfonts
LOCALDIR = 

# the default path to search for TFM files 
# (this usually is identical to TeX's defaultfontpath, which omits `.')
# (private fonts are given an explicit directory, which overrides the path)
#   overridden by the environment variable TEXFONTS
# TFMPATH = .;$(TEXDIR)\tfm
TFMPATH = .;$(TEXDIR)\tfm

# the default path to search for PK files
# Don't forget to add the directory that MTPK puts the files!  
# (In this case %ddpi\%f.pk)
#   overridden by the environment variable TEXPKS or TEXPACKED or PKFONTS
# PKPATH = %ddpi\%f.pk;$(TEXDIR)\texfonts\%m\%ddpi\%f.pk
PKPATH = %ddpi\%f.pk;$(TEXDIR)\texfonts\%m\%ddpi\%f.pk

# Default FLIPATH and FLINAME
FLIPATH = $(TEXDIR)\texfonts
FLINAME = lj_0;lj_h;lj_1;lj_2;lj_3;lj_4;lj_5

# the default path to search for VF files (usually omits `.')
#   overridden by the environment variable VFFONTS
# VFPATH = .;$(TEXDIR)\vf
VFPATH = .;$(TEXDIR)\vf

# additional directories in which to search for subdirectories to find
# both tfm and pk files
FONTSUBDIRPATH = 

# where the config files go
# CONFIGDIR = $(TEXDIR)\ps
CONFIGDIR = $(TEXDIR)\ps

# the default path to search for config files
#   overridden by the environment variable TEXCONFIG
# CONFIGPATH = .;$(CONFIGDIR)
CONFIGPATH = .;$(CONFIGDIR)

# the name of your config file
# CONFIGFILE = config.ps
CONFIGFILE = config.ps

# where the header PS files go
# HEADERDIR = $(TEXDIR)\ps
HEADERDIR = $(TEXDIR)\ps

# the default path to search for header files
# HEADERPATH = .;$(HEADERDIR)
HEADERPATH = .;$(HEADERDIR)

# where epsf.tex and rotate.tex go (usually the TeX macros directory)
# TEXMACRODIR = $(TEXDIR)\texinput
TEXMACROPARENTDIR = $(TEXDIR)\texinput
TEXMACRODIR = $(TEXMACROPARENTDIR)\dvips

# the default path to search for epsf and psfiles
# (usually the same as TeX's defaultinputpath)
# FIGPATH = .;$(TEXDIR)\texinput
FIGPATH = .;$(TEXDIR)\texinput

# the place man pages are located.
MANDIR = $(TEXDIR)\doc

# change -DDEFRES=300 or whatever is required
#    if the default resolution is not 300 dpi,
# add -DDEBUG to turn on debugging capability
# add -DTPIC for tpic support
# add -DFONTLIB to search font libraries
# add -DSEARCH_SUBDIRECTORIES to search the FONTSUBDIRPATH.
# add -DHAVE_GETCWD if you have getcwd (relevant only for subdir searching)
# add -DIBM6000 for compiling on IBM 6000 systems
# add -DCREATIONDATE if your system has a working time() and you want dated files
# (for VM/CMS, see the MKDVIPS.EXEC file in the vmcms subdirectory).
#
#   If you define FONTLIB, make sure to also give definitions to
#   FLIPATH and FLINAME.
#
#   If your compiler doesn't like void*, then add
#      -DVOID=char
#
DEFS= -DTPIC -DDEBUG -DFONTLIB -DHAVE_GETCWD

# either use
# OPT = -dMSDOS -zq -d2 -j
# OPTIMIZE = /oaxe /zp4 /4r
# or
OPTIMIZE = /oaxe /zp4 /4r
OPT = -dMSDOS -zq -d2 -j

# libraries to include (-lm -lc on most systems)
#FLIBS= 
FLIBS= 

# If you are compiling dvips for suid or other privileges, you will
# definitely want to define the following symbol; else don't.
# SECURE = -DSECURE

# If you want EMTEX specials, define the following.
EMTEX = -DEMTEX

# for SYSV (and friends which use <string.h> instead of <strings.h>)
# define the c-compiler flag
# add -D_POSIX_SOURCE if you are POSIX (also define SYSV) (only relevant
# for subdir searching)
# SYS = -DSYSV

# Define this to be whatever you use for installation.  If you don't have
# install, use a script that invokes copy and chmod's the files
# appropriately.
# INSTALL = copy
INSTALL = copy

# where the installed binary goes
# BINDIR = $(TEXDIR)
BINDIR = $(TEXDIR)

# Compiler and linker names (protected mode versions)
CC = wcl386 -p
LD = wlinkp

.EXTENSIONS:
.EXTENSIONS: .exe .obj .c

.BEFORE
	@set INCLUDE=.;$(%watcom)\h
	@set DOS4G=quiet

CFLAGS = $(DEFS) $(OPT) $(EMTEX) $(OPTIMIZE)

SRC = dospecial.c dviinput.c fontdef.c loadfont.c dvips.c tfmload.c &
	download.c prescan.c scanpage.c skippage.c output.c scalewidth.c &
	dosection.c dopage.c resident.c search.c unpack.c drawPS.c &
	header.c mtpk.c repack.c virtualfont.c dpicheck.c finclude.c &
	pprescan.c papersiz.c flib.c color.c bbox.c emspecial.c

OBJ = dospecial.obj dviinput.obj fontdef.obj loadfont.obj dvips.obj &
	tfmload.obj download.obj prescan.obj scanpage.obj skippage.obj &
	output.obj scalewidth.obj dosection.obj dopage.obj resident.obj &
	search.obj unpack.obj drawPS.obj header.obj mtpk.obj repack.obj &
	virtualfont.obj dpicheck.obj finclude.obj pprescan.obj papersiz.obj &
	flib.obj color.obj bbox.obj emspecial.obj

all : afm2tfm.exe dvips.exe tex.pro texps.pro texc.pro special.pro &
      finclude.pro color.pro crop.pro .SYMBOLIC

dvips.exe : $(OBJ) dvips.rsp
	$(LD) @dvips.rsp

dvips.rsp: pc\Makefile.wat
	echo name dvips.exe > dvips.rsp
	echo debug all >> dvips.rsp
	echo option caseexact >> dvips.rsp
	echo option dosseg >> dvips.rsp
	echo system dos4g >> dvips.rsp
	for %f in ($(OBJ)) do echo file %f >> dvips.rsp

dvips.obj: dvips.c dvips.wat
	$(CC) $(CFLAGS) -c dvips.c

mtpk.obj: mtpk.c paths.wat
	$(CC) $(CFLAGS) -c mtpk.c

afm2tfm.exe: afm2tfm.obj
	$(LD) system dos4g name afm2tfm.exe file afm2tfm.obj

squeeze.exe : squeeze.obj
	$(LD) system dos4g file squeeze.obj name squeeze.exe

tex.pro : tex.lpro squeeze.exe
	squeeze <tex.lpro > tex.pro

texc.pro: texc.lpro squeeze.exe
	squeeze <texc.lpro >texc.pro

texc.lpro: texc.script tex.lpro
	@echo ================================================
	@echo Create texc.lpro:
	@echo    1) copy tex.lpro texc.lpro
	@echo    2) edit texc.lpro; delete lines between
        @echo       % begin code for uncompressed fonts only
	@echo       % end code for uncompressed fonts only
	@echo    3) remove comments `% ' for next lines till line
	@echo       % end of code for unpacking compressed fonts
	@echo    4) restart make
	@echo ================================================

texps.pro : texps.lpro squeeze.exe
	squeeze <texps.lpro >texps.pro

special.pro : special.lpro squeeze.exe
	squeeze <special.lpro >special.pro

finclude.pro : finclude.lpro squeeze.exe
	squeeze <finclude.lpro >finclude.pro

color.pro : color.lpro squeeze.exe
	squeeze <color.lpro >color.pro

crop.pro : crop.lpro squeeze.exe
	squeeze <crop.lpro >crop.pro

install : afm2tfm.exe dvips.exe &
	tex.pro texc.pro texps.pro special.pro finclude.pro color.pro &
	crop.pro config.ps psfonts.map epsf.tex epsf.sty rotate.tex &
	rotate.sty colordvi.tex colordvi.sty blackdvi.tex blackdvi.sty &
	dvips.tex dvipsmac.tex .SYMBOLIC
	-md $(BINDIR)
	-md $(CONFIGDIR)
	-md $(HEADERDIR)
	-md $(MANDIR)
	-md $(TEXMACRODIR)
	$(INSTALL) afm2tfm.exe $(BINDIR)\afm2tfm.exe
	$(INSTALL) dvips.exe $(BINDIR)\dvips.exe
	$(INSTALL) tex.pro $(HEADERDIR)
	$(INSTALL) texc.pro $(HEADERDIR)
	$(INSTALL) texps.pro $(HEADERDIR)
	$(INSTALL) special.pro $(HEADERDIR)
	$(INSTALL) finclude.pro $(HEADERDIR)
	$(INSTALL) color.pro $(HEADERDIR)
	$(INSTALL) crop.pro $(HEADERDIR)
	$(INSTALL) config.ps $(CONFIGDIR)\$(CONFIGFILE)
	$(INSTALL) psfonts.map $(CONFIGDIR)
	$(INSTALL) epsf.tex $(TEXMACRODIR)
	$(INSTALL) epsf.sty $(TEXMACRODIR)
	$(INSTALL) rotate.tex $(TEXMACRODIR)
	$(INSTALL) rotate.sty $(TEXMACRODIR)
	$(INSTALL) colordvi.sty $(TEXMACRODIR)
	$(INSTALL) colordvi.tex $(TEXMACRODIR)
	$(INSTALL) blackdvi.sty $(TEXMACRODIR)
	$(INSTALL) blackdvi.tex $(TEXMACRODIR)
	$(INSTALL) dvips.tex $(MANDIR)
	$(INSTALL) dvipsmac.tex $(MANDIR)

veryclean : clean .SYMBOLIC
	-rm -f dvips.exe texc.lpro *.pro

clean
	-rm -f *.obj squeeze.exe afm2tfm.exe *.log *.dvi

dvips.wat: pc\Makefile.wat
	echo $#define TFMPATH "$(TFMPATH)" > dvips.tmp
	echo $#define PKPATH "$(PKPATH)" >> dvips.tmp
	echo $#define VFPATH "$(VFPATH)" >> dvips.tmp
	echo $#define HEADERPATH "$(HEADERPATH)" >> dvips.tmp
	echo $#define CONFIGPATH "$(CONFIGPATH)" >> dvips.tmp
	echo $#define CONFIGFILE "$(CONFIGFILE)" >> dvips.tmp
	echo $#define FONTSUBDIRPATH "$(FONTSUBDIRPATH)" >> dvips.tmp
	echo $#define FIGPATH "$(FIGPATH)" >> dvips.tmp
        echo $#define DEFRES $(DEFRES) >> dvips.tmp
	echo $#define FLIPATH "$(FLIPATH)" >> dvips.tmp
	echo $#define FLINAME "$(FLINAME)" >> dvips.tmp
	sed -e "s,\\,\\\\,g" dvips.tmp > dvips.wat
	-rm dvips.tmp

paths.wat: pc\Makefile.wat
	echo $#define TFMPATH "$(TFMPATH)" > paths.tmp
	echo $#define PKPATH "$(PKPATH)" >> paths.tmp
	echo $#define VFPATH "$(VFPATH)" >> paths.tmp
	echo $#define HEADERPATH "$(HEADERPATH)" >> paths.tmp
	echo $#define CONFIGPATH "$(CONFIGPATH)" >> paths.tmp
	echo $#define CONFIGFILE "$(CONFIGFILE)" >> paths.tmp
	echo $#define MODEDEF $(DEFRES) >> paths.tmp
	echo $#define FLIPATH "$(FLIPATH);$(FLINAME)" >> paths.tmp
	echo $#define MTPK "$(MTPK)" >> paths.tmp
	sed -e "s,\\,\\\\,g" paths.tmp > paths.wat
	-rm paths.tmp

.c.obj:
	$(CC) $(CFLAGS) -c $[*
