program = gsftopk.exe
default all: $(program)

SHELL = sh
MAKE=make
top_srcdir = .
srcdir = .

CC = cl
CFLAGS = -nologo -MD -O2 -DWIN32=1 $(XCFLAGS)
CPPFLAGS =  $(XCPPFLAGS)

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

DEFS = -DHAVE_CONFIG_H -DKPATHSEA=1 $(XDEFS) $(YDEFS)

ALL_CPPFLAGS = $(DEFS) -I. \
-I.. -I../kpathsea $(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) $<

# Creating (symbolic) links.
LN = cp

kpathsea_parent = ..
kpathsea_dir = $(kpathsea_parent)/kpathsea
kpathsea_srcdir_parent = $(top_srcdir)/..
kpathsea_srcdir = $(kpathsea_srcdir_parent)/kpathsea
kpathsea = $(kpathsea_dir)/kpathsealib.lib

LDFLAGS =  $(XLDFLAGS)

LIBS = user32.lib advapi32.lib shell32.lib 
LOADLIBES = $(proglib) $(kpathsea) $(LIBS) $(XLOADLIBES)

CCLD = cl
link_command = $(CCLD) -Fe$@ $(LDFLAGS) 

kpathsea_link = $(link_command)

gsftopkpsheaderdir = $(psheaderdir)/gsftopk

objects = gsftopk.obj

$(program): $(kpathsea) $(objects)
	$(kpathsea_link) $(objects) setargv.obj $(LOADLIBES)

makeargs = $(MFLAGS) CC='$(CC)' CFLAGS='$(CFLAGS)' $(XMAKEARGS)

$(kpathsea): $(kpathsea_srcdir)/*.c $(kpathsea_srcdir)/*.h
	cd $(kpathsea_dir) && $(MAKE) $(makeargs)

gsftopk.1: gsftopk1.sed sedscript
	sed -f sedscript <$(srcdir)/gsftopk1.sed >$@

sedscript: mksedscript Makefile
	$(SHELL) $(srcdir)/mksedscript $(DEFS) >$@

BINS=gsftopk.exe
PSDATA=render.ps
PSDATADIR1=c:/usr/local/txdir/w32tex/share/texmf-dist/dvips/gsftopk
PSDATADIR2=c:/usr/work/edrive/wk/dist/DVIPSK/share/texmf-dist/dvips/gsftopk
install: $(BINS) $(PSDATA)
	cp -p $(BINS) c:/usr/local/txdir/w32tex/bin/
	cp -p $(BINS) c:/usr/work/edrive/wk/dist/DVIPSK/bin/
	cp -p $(PSDATA) $(PSDATADIR1)/
	cp -p $(PSDATA) $(PSDATADIR2)/

clean::
	rm -f *~ *.obj *.exe

gsftopk.obj: gsftopk.c $(kpathsea_srcdir)/config.h c-auto.h version.h \
 $(kpathsea_srcdir)/c-std.h \
 $(kpathsea_srcdir)/c-unistd.h \
 $(kpathsea_srcdir)/systypes.h \
 $(kpathsea_srcdir)/c-memstr.h $(kpathsea_srcdir)/c-errno.h \
 $(kpathsea_srcdir)/c-minmax.h \
 $(kpathsea_srcdir)/c-limits.h \
 $(kpathsea_srcdir)/c-proto.h \
 $(kpathsea_srcdir)/debug.h $(kpathsea_srcdir)/types.h \
 $(kpathsea_srcdir)/lib.h \
 $(kpathsea_srcdir)/progname.h $(kpathsea_srcdir)/c-ctype.h \
 $(kpathsea_srcdir)/c-fopen.h \
 $(kpathsea_srcdir)/c-pathmx.h $(kpathsea_srcdir)/proginit.h \
 $(kpathsea_srcdir)/tex-file.h \
 $(kpathsea_srcdir)/tex-make.h 
