# Makefile for W32
# Makefile for libpdf

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

OPTIMIZE=-O2 -MT
#
# Debugging
#
#OPTIMIZE=-Od -Zi -MT
#
MPLIBDIR=../mplibdir

CC = cl

CFLAGS = -nologo $(OPTIMIZE) -wd4819

CPPFLAGS =  $(XCPPFLAGS)

XDEFS = -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_DEPRECATE \
-DLUA_COMPAT_MODULE=1 -DLUA_COMPAT_LOADSTRING=1 \
-D_CRT_OBSOLETE_NO_DEPRECATE -D_SECURE_SCL=0 -DLUA_BUILD_AS_DLL=1 \
-DNATIVE_TEXLIVE_BUILD=1 -DHAVE_STRUCTTREEROOT_H=1 \
-Denviron=_environ -Dmkdir=_mkdir

#
DEFS = -DHAVE_CONFIG_H -Zm200 -DWIN32=1 -DMSVC=1 -DW32TEX=1 -DpdfTeX \
-DSYNCTEX_ENGINE_H='<synctex-luatex.h>' -DNO_KPSE_DLL=1 $(XDEFS)
#

# 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 = -W3 $(DEFS) -I. -I.. -I$(ZLIBDIR) \
  -I../.. -I../../kpathsea -I../synctexdir -I../lualibs -I$(MPLIBDIR) \
  $(prog_cflags) $(CPPFLAGS)
ALL_CFLAGS = $(ALL_CPPFLAGS) $(CFLAGS) -c
compile = $(CC) $(ALL_CFLAGS) -Fo$@

.SUFFIXES:
.SUFFIXES: .c .obj # in case the suffix list has been cleared, e.g., by web2c
luabin/%.obj: %.c
	$(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 = cp

# 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)/libkpathsea.lib


LDFLAGS =  $(XLDFLAGS)

LIBS = 
LOADLIBES = $(proglib) $(kpathsea) $(LIBS) $(XLOADLIBES)

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

kpathsea_link = $(link_command)

AR = lib
ARFLAGS = -out:
RANLIB = ranlib

kpathsea_srcdir_parent = $(srcdir)/../..
kpathsea_dir_parent = ../..
.SUFFIXES: .cc .obj
luabin/%.obj: %.cc
	$(CXX) $(CXXFLAGS) -c -Fo$@ -Tp$<

CXXFLAGS = -nologo $(OPTIMIZE) -EHsc -wd4819 -DHAVE_CONFIG_H -DWIN32=1 \
 $(XDEFS) -DNO_KPSE_DLL=1 -I. -I.. -I$(kpathsea_dir_parent) \
 -I$(kpathsea_dir_parent)/kpathsea \
 -I$(kpathsea_srcdir_parent) -I$(LIBPOPPLERDIR) \
 -I$(LIBPOPPLERDIR)/fofi -I$(LIBPOPPLERDIR)/goo -I$(LIBPOPPLERDIR)/poppler \
 -I$(LIBPNGDIR) -I$(ZLIBDIR) \
 -I../lualibs  -I../lualibs/lua52

CXX = cl

LIBPNGDIR=../../../libs/libpng
LIBPNGSRCDIR=$(srcdir)/$(LIBPNGDIR)

ZLIBDIR=../../../libs/zlib
ZLIBSRCDIR=$(srcdir)/$(ZLIBDIR)
ZLIBLIB=$(ZLIBDIR)/libz.lib

LIBXPDFDIR=../../../libs/xpdf
LIBXPDFSRCDIR=$(srcdir)/$(LIBXPDFDIR)

LIBPOPPLERDIR=../../../libs/poppler/poppler-0.32.0

LIBMD5DIR=../libmd5
LIBMD5SRCDIR=$(srcdir)/$(LIBMD5DIR)

LUAINC=-I../lualibs/lua52 -I../lualibs

XCPPFLAGS=-I.. -I$(srcdir)/.. -I../.. -I$(srcdir)/../.. \
-I$(LIBPNGDIR) -I$(LIBMD5DIR) -I$(LIBMD5SRCDIR) -I$(LIBPNGSRCDIR) \
-I$(ZLIBDIR) -I$(ZLIBSRCDIR) -I$(LIBPOPPLERDIR) \
-I$(LIBPOPPLERDIR)/goo \
-I$(LIBPOPPLERDIR)/fofi \
-I$(LIBPOPPLERDIR)/poppler $(LUAINC)

OBJS = \
luabin/pdflua.obj \
luabin/dvi/dvigen.obj \
luabin/font/mapfile.obj \
luabin/font/pkin.obj \
luabin/font/subfont.obj \
luabin/font/tounicode.obj \
luabin/font/vfpacket.obj \
luabin/font/writeenc.obj \
luabin/font/writefont.obj \
luabin/font/writet1.obj \
luabin/font/writet3.obj \
luabin/font/writettf.obj \
luabin/font/writetype0.obj \
luabin/font/writetype2.obj \
luabin/font/writecff.obj \
luabin/font/tt_glyf.obj \
luabin/font/tt_table.obj \
luabin/font/sfnt.obj \
luabin/font/texfont.obj \
luabin/font/tfmofm.obj \
luabin/font/vfovf.obj \
luabin/font/luafont.obj \
luabin/font/dofont.obj \
luabin/image/pdftoepdf.obj \
luabin/image/writeimg.obj \
luabin/image/writejbig2.obj \
luabin/image/writejp2.obj \
luabin/image/writejpg.obj \
luabin/image/writepng.obj \
luabin/lang/hnjalloc.obj \
luabin/lang/hyphen.obj \
luabin/lang/texlang.obj \
luabin/lua/lcallbacklib.obj \
luabin/lua/lepdflib.obj \
luabin/lua/lfontlib.obj \
luabin/lua/limglib.obj \
luabin/lua/liolibext.obj \
luabin/lua/llanglib.obj \
luabin/lua/llfslibext.obj \
luabin/lua/llualib.obj \
luabin/lua/lkpselib.obj \
luabin/lua/lnodelib.obj \
luabin/lua/loslibext.obj \
luabin/lua/lpdflib.obj \
luabin/lua/lpdfscannerlib.obj \
luabin/lua/lstrlibext.obj \
luabin/lua/lstatslib.obj \
luabin/lua/ltexiolib.obj \
luabin/lua/ltexlib.obj \
luabin/lua/lnewtokenlib.obj \
luabin/lua/ltokenlib.obj \
luabin/lua/luagen.obj \
luabin/lua/luainit.obj \
luabin/lua/luanode.obj \
luabin/lua/luastuff.obj \
luabin/lua/luatoken.obj \
luabin/lua/texluac.obj \
luabin/pdf/pdfaction.obj \
luabin/pdf/pdfannot.obj \
luabin/pdf/pdfcolorstack.obj \
luabin/pdf/pdfdest.obj \
luabin/pdf/pdffont.obj \
luabin/pdf/pdfgen.obj \
luabin/pdf/pdfglyph.obj \
luabin/pdf/pdfimage.obj \
luabin/pdf/pdflink.obj \
luabin/pdf/pdflistout.obj \
luabin/pdf/pdfliteral.obj \
luabin/pdf/pdfluaapi.obj \
luabin/pdf/pdfobj.obj \
luabin/pdf/pdfoutline.obj \
luabin/pdf/pdfpage.obj \
luabin/pdf/pdfpagetree.obj \
luabin/pdf/pdfrule.obj \
luabin/pdf/pdfsaverestore.obj \
luabin/pdf/pdfsetmatrix.obj \
luabin/pdf/pdfshipout.obj \
luabin/pdf/pdftables.obj \
luabin/pdf/pdfthread.obj \
luabin/pdf/pdfxform.obj \
luabin/tex/align.obj \
luabin/tex/arithmetic.obj \
luabin/tex/buildpage.obj \
luabin/tex/commands.obj \
luabin/tex/conditional.obj \
luabin/tex/directions.obj \
luabin/tex/dumpdata.obj \
luabin/tex/equivalents.obj \
luabin/tex/errors.obj \
luabin/tex/expand.obj \
luabin/tex/extensions.obj \
luabin/tex/filename.obj \
luabin/tex/inputstack.obj \
luabin/tex/linebreak.obj \
luabin/tex/mainbody.obj \
luabin/tex/maincontrol.obj \
luabin/tex/mathcodes.obj \
luabin/tex/memoryword.obj \
luabin/tex/mlist.obj \
luabin/tex/nesting.obj \
luabin/tex/packaging.obj \
luabin/tex/postlinebreak.obj \
luabin/tex/primitive.obj \
luabin/tex/printing.obj \
luabin/tex/scanning.obj \
luabin/tex/stringpool.obj \
luabin/tex/texdeffont.obj \
luabin/tex/texfileio.obj \
luabin/tex/texmath.obj \
luabin/tex/texnodes.obj \
luabin/tex/textcodes.obj \
luabin/tex/textoken.obj \
luabin/utils/avl.obj \
luabin/utils/avlstuff.obj \
luabin/utils/managed-sa.obj \
luabin/utils/tmpfile.obj \
luabin/utils/unistring.obj \
luabin/utils/utils.obj \
luabin/synctex.obj \
../libmd5/md5.obj

all: libluatex.lib

libluatex.lib: $(OBJS)
	$(AR) $(ARFLAGS)$@  $(OBJS)

../libmd5/md5.obj: ../libmd5/md5.c
	$(CC) $(ALL_CFLAGS) -Fo$@ ../libmd5/md5.c

luabin/synctex.obj: synctex.c
synctex.c: ../synctexdir/synctex.c
	cp ../synctexdir/synctex.c $@
luabin/pdflua.obj: pdflua.c

#pdflua.c: luascripts/pdflua.lua txt2zlib.exe
#	./txt2zlib.exe luascripts/pdflua.lua $@

pdflua.c: luascripts/pdflua.c
	cp luascripts/pdflua.c $@

txt2zlib.exe: luascripts/txt2zlib.obj $(ZLIBLIB)
	$(CC) -Fe$@ luascripts/txt2zlib.obj $(ZLIBLIB)
luascripts/txt2zlib.obj: luascripts/txt2zlib.c
	$(CC) $(CFLAGS) -I$(ZLIBDIR) $(XDEFS) -c -Fo$@ luascripts/txt2zlib.c
luascripts/txt2zlib.c: luascripts/txt2zlib.w
	../ctangle luascripts/txt2zlib.w - luascripts/txt2zlib.c
dvi/dvigen.c: dvi/dvigen.w
	../ctangle dvi/dvigen.w - dvi/dvigen.c
tex/equivalents.c: tex/equivalents.w
	../ctangle tex/equivalents.w - tex/equivalents.c
tex/textoken.c: tex/textoken.w
	../ctangle tex/textoken.w - tex/textoken.c
tex/commands.c: tex/commands.w
	../ctangle tex/commands.w - tex/commands.c
tex/textcodes.c: tex/textcodes.w
	../ctangle tex/textcodes.w - tex/textcodes.c
tex/postlinebreak.c: tex/postlinebreak.w
	../ctangle tex/postlinebreak.w - tex/postlinebreak.c
tex/conditional.c: tex/conditional.w
	../ctangle tex/conditional.w - tex/conditional.c
tex/memoryword.c: tex/memoryword.w
	../ctangle tex/memoryword.w - tex/memoryword.c
tex/primitive.c: tex/primitive.w
	../ctangle tex/primitive.w - tex/primitive.c
tex/errors.c: tex/errors.w
	../ctangle tex/errors.w - tex/errors.c
tex/inputstack.c: tex/inputstack.w
	../ctangle tex/inputstack.w - tex/inputstack.c
tex/maincontrol.c: tex/maincontrol.w
	../ctangle tex/maincontrol.w - tex/maincontrol.c
tex/printing.c: tex/printing.w
	../ctangle tex/printing.w - tex/printing.c
tex/extensions.c: tex/extensions.w
	../ctangle tex/extensions.w - tex/extensions.c
tex/stringpool.c: tex/stringpool.w
	../ctangle tex/stringpool.w - tex/stringpool.c
tex/scanning.c: tex/scanning.w
	../ctangle tex/scanning.w - tex/scanning.c
tex/mainbody.c: tex/mainbody.w
	../ctangle tex/mainbody.w - tex/mainbody.c
tex/texdeffont.c: tex/texdeffont.w
	../ctangle tex/texdeffont.w - tex/texdeffont.c
tex/mathcodes.c: tex/mathcodes.w
	../ctangle tex/mathcodes.w - tex/mathcodes.c
tex/texnodes.c: tex/texnodes.w
	../ctangle tex/texnodes.w - tex/texnodes.c
tex/align.c: tex/align.w
	../ctangle tex/align.w - tex/align.c
tex/dumpdata.c: tex/dumpdata.w
	../ctangle tex/dumpdata.w - tex/dumpdata.c
tex/directions.c: tex/directions.w
	../ctangle tex/directions.w - tex/directions.c
tex/texmath.c: tex/texmath.w
	../ctangle tex/texmath.w - tex/texmath.c
tex/packaging.c: tex/packaging.w
	../ctangle tex/packaging.w - tex/packaging.c
tex/texfileio.c: tex/texfileio.w
	../ctangle tex/texfileio.w - tex/texfileio.c
tex/mlist.c: tex/mlist.w
	../ctangle tex/mlist.w - tex/mlist.c
tex/linebreak.c: tex/linebreak.w
	../ctangle tex/linebreak.w - tex/linebreak.c
tex/nesting.c: tex/nesting.w
	../ctangle tex/nesting.w - tex/nesting.c
tex/expand.c: tex/expand.w
	../ctangle tex/expand.w - tex/expand.c
tex/filename.c: tex/filename.w
	../ctangle tex/filename.w - tex/filename.c
tex/arithmetic.c: tex/arithmetic.w
	../ctangle tex/arithmetic.w - tex/arithmetic.c
tex/buildpage.c: tex/buildpage.w
	../ctangle tex/buildpage.w - tex/buildpage.c
lang/texlang.c: lang/texlang.w
	../ctangle lang/texlang.w - lang/texlang.c
lang/hnjalloc.c: lang/hnjalloc.w
	../ctangle lang/hnjalloc.w - lang/hnjalloc.c
lang/hyphen.c: lang/hyphen.w
	../ctangle lang/hyphen.w - lang/hyphen.c
ocp/ocp.c: ocp/ocp.w
	../ctangle ocp/ocp.w - ocp/ocp.c
ocp/runocp.c: ocp/runocp.w
	../ctangle ocp/runocp.w - ocp/runocp.c
ocp/ocplist.c: ocp/ocplist.w
	../ctangle ocp/ocplist.w - ocp/ocplist.c
ocp/readocp.c: ocp/readocp.w
	../ctangle ocp/readocp.w - ocp/readocp.c
font/tt_table.c: font/tt_table.w
	../ctangle font/tt_table.w - font/tt_table.c
font/writet1.c: font/writet1.w
	../ctangle font/writet1.w - font/writet1.c
font/pkin.c: font/pkin.w
	../ctangle font/pkin.w - font/pkin.c
font/writet3.c: font/writet3.w
	../ctangle font/writet3.w - font/writet3.c
font/vfpacket.c: font/vfpacket.w
	../ctangle font/vfpacket.w - font/vfpacket.c
font/tt_glyf.c: font/tt_glyf.w
	../ctangle font/tt_glyf.w - font/tt_glyf.c
font/luafont.c: font/luafont.w
	../ctangle font/luafont.w - font/luafont.c
font/writettf.c: font/writettf.w
	../ctangle font/writettf.w - font/writettf.c
font/writecff.c: font/writecff.w
	../ctangle font/writecff.w - font/writecff.c
font/sfnt.c: font/sfnt.w
	../ctangle font/sfnt.w - font/sfnt.c
font/writetype0.c: font/writetype0.w
	../ctangle font/writetype0.w - font/writetype0.c
font/mapfile.c: font/mapfile.w
	../ctangle font/mapfile.w - font/mapfile.c
font/writetype2.c: font/writetype2.w
	../ctangle font/writetype2.w - font/writetype2.c
font/subfont.c: font/subfont.w
	../ctangle font/subfont.w - font/subfont.c
font/writeenc.c: font/writeenc.w
	../ctangle font/writeenc.w - font/writeenc.c
font/writefont.c: font/writefont.w
	../ctangle font/writefont.w - font/writefont.c
font/vfovf.c: font/vfovf.w
	../ctangle font/vfovf.w - font/vfovf.c
font/texfont.c: font/texfont.w
	../ctangle font/texfont.w - font/texfont.c
font/tfmofm.c: font/tfmofm.w
	../ctangle font/tfmofm.w - font/tfmofm.c
font/tounicode.c: font/tounicode.w
	../ctangle font/tounicode.w - font/tounicode.c
font/dofont.c: font/dofont.w
	../ctangle font/dofont.w - font/dofont.c
lua/luainit.c: lua/luainit.w
	../ctangle lua/luainit.w - lua/luainit.c
lua/texluac.c: lua/texluac.w
	../ctangle lua/texluac.w - lua/texluac.c
lua/luagen.c: lua/luagen.w
	../ctangle lua/luagen.w - lua/luagen.c
lua/luatoken.c: lua/luatoken.w
	../ctangle lua/luatoken.w - lua/luatoken.c
lua/luanode.c: lua/luanode.w
	../ctangle lua/luanode.w - lua/luanode.c
lua/luastuff.c: lua/luastuff.w
	../ctangle lua/luastuff.w - lua/luastuff.c
image/writepng.c: image/writepng.w
	../ctangle image/writepng.w - image/writepng.c
image/pdftoepdf.cc: image/pdftoepdf.w
	../ctangle image/pdftoepdf.w - image/pdftoepdf.cc
image/writeimg.c: image/writeimg.w
	../ctangle image/writeimg.w - image/writeimg.c
image/writejbig2.c: image/writejbig2.w
	../ctangle image/writejbig2.w - image/writejbig2.c
image/writejp2.c: image/writejp2.w
	../ctangle image/writejp2.w - image/writejp2.c
image/writejpg.c: image/writejpg.w
	../ctangle image/writejpg.w - image/writejpg.c
utils/unistring.c: utils/unistring.w
	../ctangle utils/unistring.w - utils/unistring.c
utils/utils.c: utils/utils.w
	../ctangle utils/utils.w - utils/utils.c
utils/avlstuff.c: utils/avlstuff.w
	../ctangle utils/avlstuff.w - utils/avlstuff.c
utils/managed-sa.c: utils/managed-sa.w
	../ctangle utils/managed-sa.w - utils/managed-sa.c
pdf/pdfcolorstack.c: pdf/pdfcolorstack.w
	../ctangle pdf/pdfcolorstack.w - pdf/pdfcolorstack.c
pdf/pdffont.c: pdf/pdffont.w
	../ctangle pdf/pdffont.w - pdf/pdffont.c
pdf/pdfrule.c: pdf/pdfrule.w
	../ctangle pdf/pdfrule.w - pdf/pdfrule.c
pdf/pdfobj.c: pdf/pdfobj.w
	../ctangle pdf/pdfobj.w - pdf/pdfobj.c
pdf/pdfpage.c: pdf/pdfpage.w
	../ctangle pdf/pdfpage.w - pdf/pdfpage.c
pdf/pdfaction.c: pdf/pdfaction.w
	../ctangle pdf/pdfaction.w - pdf/pdfaction.c
pdf/pdfannot.c: pdf/pdfannot.w
	../ctangle pdf/pdfannot.w - pdf/pdfannot.c
pdf/pdfsetmatrix.c: pdf/pdfsetmatrix.w
	../ctangle pdf/pdfsetmatrix.w - pdf/pdfsetmatrix.c
pdf/pdfimage.c: pdf/pdfimage.w
	../ctangle pdf/pdfimage.w - pdf/pdfimage.c
pdf/pdfliteral.c: pdf/pdfliteral.w
	../ctangle pdf/pdfliteral.w - pdf/pdfliteral.c
pdf/pdfdest.c: pdf/pdfdest.w
	../ctangle pdf/pdfdest.w - pdf/pdfdest.c
pdf/pdfpagetree.c: pdf/pdfpagetree.w
	../ctangle pdf/pdfpagetree.w - pdf/pdfpagetree.c
pdf/pdfsaverestore.c: pdf/pdfsaverestore.w
	../ctangle pdf/pdfsaverestore.w - pdf/pdfsaverestore.c
pdf/pdflistout.c: pdf/pdflistout.w
	../ctangle pdf/pdflistout.w - pdf/pdflistout.c
pdf/pdfluaapi.c: pdf/pdfluaapi.w
	../ctangle pdf/pdfluaapi.w - pdf/pdfluaapi.c
pdf/pdfthread.c: pdf/pdfthread.w
	../ctangle pdf/pdfthread.w - pdf/pdfthread.c
pdf/pdfgen.c: pdf/pdfgen.w
	../ctangle pdf/pdfgen.w - pdf/pdfgen.c
pdf/pdftables.c: pdf/pdftables.w
	../ctangle pdf/pdftables.w - pdf/pdftables.c
pdf/pdfoutline.c: pdf/pdfoutline.w
	../ctangle pdf/pdfoutline.w - pdf/pdfoutline.c
pdf/pdfglyph.c: pdf/pdfglyph.w
	../ctangle pdf/pdfglyph.w - pdf/pdfglyph.c
pdf/pdfshipout.c: pdf/pdfshipout.w
	../ctangle pdf/pdfshipout.w - pdf/pdfshipout.c
pdf/pdfxform.c: pdf/pdfxform.w
	../ctangle pdf/pdfxform.w - pdf/pdfxform.c
pdf/pdflink.c: pdf/pdflink.w
	../ctangle pdf/pdflink.w - pdf/pdflink.c


clean:
	rm -f *.obj libluatex.lib *.exe *~
	rm -f luabin/dvi/*.obj luabin/font/*.obj luabin/image/*.obj
	rm -f luabin/lang/*.obj luabin/lua/*.obj luabin/*.obj
	rm -f luabin/pdf/*.obj luabin/tex/*.obj luabin/utils/*.obj
	rm -f dvi/*~ font/*~ image/*~
	rm -f lang/*~ lua/*~
	rm -f pdf/*~ tex/*~ utils/*~

distclean maintainer-clean extraclean: clean
	rm -f config.log config.status

depend: depend.mk

depend.mk: mkdep.sh
	./mkdep.sh

include depend.mk
