# Makefile for dvipsk -- kb@mail.tug.org. Public domain.
version = 5.98

# Add -DDEFRES=dpi to DEFS to change the default resolution from 600.
# Add -DSECURE if you will install dvips with special privileges.
# Add -DNO_DEBUG to omit debugging support.
# Add -DNO_EMTEX to omit EMTEX specials.
# Add -DNO_HPS to omit hypertex support.
# Add -DNO_TPIC to omit tpic support.
# 
# For VM/CMS or (perhaps) VMS or DOS compilation, need the corresponding
# subdirectory from the original dvips distribution.  (Maybe dvipsk
# won't work at all on such systems; if you have info one way or the
# other, please let kb@cs.umb.edu know.)

# paths.mk -- installation directories.
#
# The compile-time paths are defined in kpathsea/paths.h, which is built
# from kpathsea/texmf.in and these definitions.  See kpathsea/INSTALL
# for how the various path-related files are used and created.

# Do not change prefix and exec_prefix in Makefile.in!
# configure doesn't propagate the change to the other Makefiles.
# Instead, give the -prefix/-exec-prefix options to configure.
# (See kpathsea/INSTALL for more details.) This is arguably
# a bug, but it's not likely to change soon.
prefix = c:/usr/local
exec_prefix = ${prefix}

# Architecture-dependent executables.
bindir = ${exec_prefix}/bin

# Architecture-independent executables.
scriptdir = $(bindir)

# Architecture-dependent files, such as lib*.a files.
libdir = ${exec_prefix}/lib

# Architecture-independent files.
datadir = ${prefix}/share

# Header files.
includedir = ${prefix}/include

# GNU .info* files.
infodir = ${prefix}/info

# Unix man pages.
manext = 1
mandir = ${prefix}/man/man$(manext)

# TeX system-specific directories. Not all of the following are relevant
# for all programs, but it seems cleaner to collect everything in one place.

# The default paths are now in kpathsea/texmf.in. Passing all the
# paths to sub-makes can make the arg list too long on system V.
# Note that if you make changes below, you will have to make the
# corresponding changes to texmf.in or texmf.cnf yourself.

# The root of the main tree.
texmf = c:/usr/local/share/texmf

# The directory used by varfonts.
vartexfonts = c:/var/tex/fonts

# Regular input files.
texinputdir = $(texmf)/tex
mfinputdir = $(texmf)/metafont
mpinputdir = $(texmf)/metapost
mftinputdir = $(texmf)/mft

# dvips's epsf.tex, rotate.tex, etc. get installed here;
# ditto for dvilj's fonts support.
dvips_plain_macrodir = $(texinputdir)/plain/dvips
dvilj_latex2e_macrodir = $(texinputdir)/latex/dvilj

# mktex.cnf, texmf.cnf, etc.
web2cdir = $(texmf)/web2c

# The top-level font directory.
fontdir = $(texmf)/fonts

# Memory dumps (.fmt/.base/.mem).
fmtdir = $(web2cdir)
basedir = $(fmtdir)
memdir = $(fmtdir)

# Pool files.
texpooldir = $(web2cdir)
mfpooldir = $(texpooldir)
mppooldir = $(texpooldir)

# Where the .map files from fontname are installed.
fontnamedir = $(texmf)/fontname

# For dvips configuration files, psfonts.map, etc.
dvipsdir = $(texmf)/dvips

# For dvips .pro files, gsftopk's render.ps, etc.
psheaderdir = $(dvipsdir)

# If a font can't be found close enough to its stated size, we look for
# each of these sizes in the order given.  This colon-separated list is
# overridden by the envvar TEXSIZES, and by a program-specific variable
# (e.g., XDVISIZES), and perhaps by a config file (e.g., in dvips).
# This list must be sorted in ascending order.
default_texsizes = 300:600

# End of paths.mk.
# common.mk -- used by all Makefiles.
SHELL = sh
MAKE=make
top_srcdir = .
srcdir = .

CC = cl
#
#XDEFS = -DPRINT_CFG_MAP
#
CFLAGS = -nologo -wd4305 -W3 -favor:blend -O2 -MD -DWIN32=1 \
  -DDOWNLOAD_USING_PDFTEX=1 $(XCFLAGS)
LKDEBUG =

#CFLAGS = -nologo -Od -Zi -MD -QI0f -QIfdiv- -DWIN32=1 \
#  -DDOWNLOAD_USING_PDFTEX=1 $(XCFLAGS)
#LKDEBUG = /DEBUG:FULL

YDEFS = -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_DEPRECATE \
-D_CRT_OBSOLETE_NO_DEPRECATE -D_SECURE_SCL=0

CPPFLAGS =  $(XCPPFLAGS)
DEFS = -DHAVE_CONFIG_H $(XDEFS) $(YDEFS)

# Kpathsea needs this for compiling, programs need it for linking.
LIBTOOL = $(kpathsea_srcdir_parent)/klibtool

# You can change [X]CPPFLAGS, [X]CFLAGS, or [X]DEFS, but
# please don't change ALL_CPPFLAGS or ALL_CFLAGS.
# prog_cflags is set by subdirectories of web2c.
ALL_CPPFLAGS = $(DEFS) -I. -I$(srcdir) \
-I$(kpathsea_parent) -I$(kpathsea_srcdir_parent) \
$(prog_cflags) $(CPPFLAGS)
ALL_CFLAGS = $(ALL_CPPFLAGS) $(CFLAGS) -c
compile = $(CC) $(ALL_CFLAGS)

.SUFFIXES:
.SUFFIXES: .c .obj # in case the suffix list has been cleared, e.g., by web2c
.c.obj:
	$(compile) $<

# Installation.
INSTALL = cp
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = $(INSTALL_PROGRAM)
INSTALL_DATA = ${INSTALL}
INSTALL_LIBTOOL_LIBS = INSTALL_DATA='$(INSTALL_DATA)' $(LIBTOOL) install-lib
INSTALL_LIBTOOL_PROG = INSTALL_PROGRAM='$(INSTALL_PROGRAM)' $(LIBTOOL) install-prog

# Creating (symbolic) links.
LN = ln

# We use these for many things.
kpathsea_parent = ..
kpathsea_dir = $(kpathsea_parent)/kpathsea
kpathsea_srcdir_parent = $(top_srcdir)/..
kpathsea_srcdir = $(kpathsea_srcdir_parent)/kpathsea
kpathsea = $(kpathsea_dir)/kpathsealibw64.lib

#M#ifeq ($(CC), gcc)
#M#XDEFS = -Wpointer-arith $(warn_more)
#M#CFLAGS = -pipe -g $(XCFLAGS)
#M#endif
# End of common.mk.
# programs.mk -- used by Makefiles for executables only.

# Don't include $(CFLAGS), since ld -g under Linux forces
# static libraries, e.g., libc.a and libX*.a.
LDFLAGS =  $(XLDFLAGS)

# proglib is for web2c; 
# XLOADLIBES is for the installer.
LIBS =
LOADLIBES = $(proglib) $(kpathsea) $(LIBS) $(XLOADLIBES)

# May as well separate linking from compiling, just in case.
CCLD = $(CC)
link_command = $(CCLD) -Fe$@ $(LDFLAGS)

# When we link with Kpathsea, have to take account that it might be a
# shared library, etc.
kpathsea_link = $(link_command)
# End of programs.mk.
# texi.mk -- making .dvi and .info from .texi.
#M#MAKEINFO = makeinfo
#M#MAKEINFO_FLAGS = --paragraph-indent=2 -I$(srcdir)

#M#TEXI2DVI = texi2dvi
#M## To make sure that generation of the dvi files succeeds on the
#M## maintainer's system.
#M#TEXI2DVI = TEXMFCNF=$(web2cdir) texi2dvi

#M#TEXI2HTML = texi2html
#M#TEXI2HTML_FLAGS = -expandinfo -number -menu -split_chapter
# If you prefer one big .html file instead of several, remove
# -split-node or replace it by -split_chapter.

# For making normal text files out of Texinfo source.
#M#one_info = --no-headers --no-split --no-validate

#M#.SUFFIXES: .info .dvi .html .texi
#M#.texi.info:
#M#	$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@
#M#.texi.dvi:
#M#	$(TEXI2DVI) $(TEXI2DVI_FLAGS) $<
#M#.texi.html:
#M#	$(TEXI2HTML) $(TEXI2HTML_FLAGS) $< 
# End of texi.mk.
prog_cflags = -DKPATHSEA=1 -DNeedFunctionPrototypes=1 -DSHIFTLOWCHARS=1

# The `t[mp]-' business is so that we don't create an empty .pro file,
# if running squeeze fails for some reason.  A dependency on squeeze
# fails here, so we include it below.
.SUFFIXES: .pro .lpro
.lpro.pro:
	./squeeze/squeeze <$< >t-$@
	mv t-$@ $@
prologues = tex.pro texps.pro texc.pro special.pro finclude.pro \
            color.pro crop.pro hps.pro

objects = bitmapenc.obj dospecial.obj dviinput.obj emspecial.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 repack.obj virtualfont.obj dpicheck.obj \
           finclude.obj writet1.obj pprescan.obj papersiz.obj \
           color.obj bbox.obj hps.obj # isnt.obj

program = dvips.exe
programs = afm2tfm.exe $(program)


# default all: $(programs) $(prologues) dvips.info
default all: $(programs) $(prologues)

$(program): $(kpathsea) $(objects)
	$(kpathsea_link) $(objects) setargv.obj $(LOADLIBES) -link $(LKDEBUG)
afm2tfm.exe: $(kpathsea) afm2tfm.obj
	$(kpathsea_link) afm2tfm.obj setargv.obj $(LOADLIBES)
# Omit LOADLIBES since no need to dynamically link with kpathsea.
squeeze/squeeze.exe: squeeze/squeeze.obj
	$(link_command) squeeze/squeeze.obj

$(prologues): squeeze/squeeze.exe
texc.lpro: texc.script tex.lpro
	$(SHELL) $(srcdir)/texc.script $(srcdir)/tex.lpro $@

# tkpathsea.mk -- target for remaking kpathsea.
makeargs = $(MFLAGS) CC='$(CC)' CFLAGS='$(CFLAGS)' $(XMAKEARGS)

# This is wrong: the library doesn't depend on kpsewhich.c or
# acconfig.h.  But what to do?
#$(kpathsea): $(kpathsea_srcdir)/*.c $(kpathsea_srcdir)/*.h
#	cd $(kpathsea_dir) && $(MAKE) $(makeargs)
# End of tkpathsea.mk.

check: all
	rm -f mtest.ps
	-(TFMFONTS=$(srcdir)/testdata: VFFONTS=$(srcdir)/testdata: \
	TEXPSHEADERS=$(srcdir)/testdata TEXCONFIG=$(srcdir)/testdata \
	  ./dvips -D 300 $(srcdir)/testdata/dvipstst.xdv -o dvipstst.ps)
	mv dvipstst.ps mtest.ps
	-(TFMFONTS=$(srcdir)/testdata: VFFONTS=$(srcdir)/testdata: \
	TEXPSHEADERS=$(srcdir)/testdata: TEXCONFIG=$(srcdir)/testdata: \
	  ./dvips -D 300 $(srcdir)/testdata/dvipstst.xdv -o)
	-diff $(srcdir)/testdata/dvipstst.xps dvipstst.ps

BINS=afm2tfm.exe dvips.exe
ZZ=c:/usr/local/txdir/w32tex/bin64/

install: $(BINS)
	cp -p $(BINS) c:/usr/work/edrive/wk/w64dist/DVIPSK/bin64/
	cp -p $(BINS) $(ZZ)

#	@echo "Create $(psheaderdir)/base/config.ps if necessary (see ./INSTALL)."
uninstall: uninstall-exec uninstall-data

install-exec: all
	$(SHELL) $(top_srcdir)/../mkinstalldirs $(bindir) $(scriptdir) $(fontdir)
	for p in $(programs); do $(INSTALL_LIBTOOL_PROG) $(bindir) $$p; done
uninstall-exec:
	for p in $(programs); do rm -f $(bindir)/$$p; done

install-data: $(program).info
	$(SHELL) $(top_srcdir)/../mkinstalldirs $(mandir) $(infodir) $(psheaderdir)/base
# PostScript prologues and encodings.
	for h in $(prologues); do $(INSTALL_DATA) $$h $(psheaderdir)/base/$$h; done
#	cd $(srcdir)/reencode && \
#	  for e in *.enc; do $(INSTALL_DATA) $$e $(psheaderdir)/base/$$e; done
# config.ps. Any one config.ps will be wrong for most people, so don't
# install anything by default.
#	if test ! -r $(psheaderdir)/base/config.ps				\
#	   || grep 'original config.ps --' $(psheaderdir)/base/config.ps	\
#	      >nul; then	\
#          $(INSTALL_DATA) $(srcdir)/config.ps $(psheaderdir)/base/config.ps;	\
#        else true; fi
# psfonts.map.
#	if test ! -r $(psheaderdir)/base/psfonts.map 			\
#	   || grep 'original psfonts.map --' $(psheaderdir)/base/psfonts.map \
#	      >nul; then	\
#	  $(INSTALL_DATA) $(srcdir)/psfonts.map $(psheaderdir)/base/psfonts.map; \
#        else true; fi
# Info files.
	cd $(srcdir) && for i in $(program).i*; do \
	  $(INSTALL_DATA) $$i $(infodir)/$$i; done
# Man pages.
	$(INSTALL_DATA) $(srcdir)/dvips.1 $(mandir)/dvips.$(manext)
	$(INSTALL_DATA) $(srcdir)/afm2tfm.1 $(mandir)/afm2tfm.$(manext)
# TeX macros.
#	cd $(srcdir)/tex && for m in *.tex; do \
#	  $(INSTALL_DATA) $$m $(dvips_plain_macrodir)/$$m; done
	$(POSTINSTALL)
	if $(SHELL) -c 'install-info --version' >nul 2>&1; then \
	  install-info --info-dir=$(infodir) $(infodir)/$(program).info; \
	else true; fi

uninstall-data:
	rm -f $(infodir)/dvips.i*
#	for h in $(prologues); do rm -f $(psheaderdir)/base/$$h; done
#	cd $(srcdir)/reencode && for e in *.enc; do rm -f $(psheaderdir)/base/$$e; \
#	  done
#	if grep 'original config.ps --' $(psheaderdir)/base/config.ps	\
#             >nul 2>&1; then rm -f $(psheaderdir)/base/config.ps;	\
#        else true; fi
#	if grep 'original psfonts.map --' $(psheaderdir)/base/psfonts.map	\
#              >nul 2>&1; then rm -f $(psheaderdir)/base/psfonts.map;	\
#        else true; fi
	rm -f $(mandir)/dvips.$(manext) $(mandir)/afm2tfm.$(manext)

distname = dvipsk
program_files = *.texi *.info* *.lpro psfonts.map *.1 texc.script \
  dvips.help $(program).aux $(program).cps dvipstst.dvi
version_files = dvips.h afm2tfm.c dvips.c

pre-dist-$(distname): INSTALL $(program).info $(program).dvi
post-dist-$(distname):
	ln -s `pwd`/contrib `pwd`/tex $(distdir)
	mkdir $(distdir)/reencode; ln -s $(fontname)/*.enc $(distdir)/reencode
	ln -s `pwd`/README.reencode $(distdir)/reencode/README
	rm -f $(distdir)/texc.lpro

info: $(program).info
dvi: $(program).dvi

#M#INSTALL: $(program).texi
#M#	$(MAKEINFO) -D INSTALLONLY --no-headers --no-split --no-validate \
#M#	  $(MAKEINFO_FLAGS) $< -o $@
#M#	add-info-toc $@
#M#$(program).info: dvips.help
#M#dvips.help: dvips.c
#M#	./dvips --help | sed s/@/@@/g >$@
#M#doc: info INSTALL

# clean.mk -- cleaning.
clean:
	rm -f *.exe *.dvi *.lj *.obj *~

distclean:: extraclean clean
	rm -f Makefile
	rm -f config.status config.log config.cache c-auto.h
	rm -f stamp-auto stamp-tangle stamp-otangle

# Although we can remake configure and c-auto.in, we don't remove
# them, since many people may lack Autoconf.  Use configclean for that.
maintainer-clean:: distclean
	rm -f *.info*

extraclean::
	rm -f *.aux *.bak *.bbl *.blg *.dvi *.log *.pl *.tfm *.vf *.vpl
	rm -f *.*pk *.*gf *.mpx *.i *.s *~ *.orig  *.rej *\#*
	rm -f CONTENTS.tex a.out core mfput.* texput.* mpout.*

configclean:
	rm -f configure c-auto.in c-auto.h stamp-*
# End of clean.mk.

distclean::
	rm -f *.pro texc.lpro

# Let's stick a rule for TAGS here, just in case someone wants them.
# (We don't put them in the distributions, to keep them smaller.)
TAGS: *.c *.h
	pwd | grep kpathsea >nul && append=../kpathsea/TAGS; \
	  etags $$append *.[ch]

# Prevent GNU make 3.[59,63) from overflowing arg limit on system V.
.NOEXPORT:

squeeze/squeeze.obj: squeeze/squeeze.c
	$(compile) -Fo$@ $<

include depend.mk
