# Makefile for the DVI utility programs.

SHELL = /bin/sh
srcdir = @srcdir@
VPATH = @srcdir@

# This is so kpathsea will get remade automatically if you change
# something in it and recompile from the package directory.
kpathsea_parent = ../..
kpathsea_dir = $(kpathsea_parent)/kpathsea
kpathsea = $(kpathsea_dir)/kpathsea.a

# Routines used everywhere.
commondefines = $(srcdir)/../lib/common.defines
commonh = $(srcdir)/../lib/config.h $(kpathsea_dir)/paths.h
commono = ../lib/lib.a $(kpathsea)

program = dvicopy dvitype

CC = @CC@
CFLAGS =
CPPFLAGS = -I../lib -I$(srcdir)/../lib -I../.. -I$(srcdir)/../..

CCLD = $(CC)
LDFLAGS = $(CFLAGS) $(XLDFLAGS)
LIBS = @LIBS@ $(extralibs)
libs = $(commono) $(LIBS)

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@


.SUFFIXES:
.SUFFIXES: .o .c .p .ch
.p.c:
	$(SHELL) $(srcdir)/../lib/convert $< $*.c $(srcdir)
.ch.p:
	../web/tangle $(srcdir)/$*.web $<
	cp $(srcdir)/$*.p $*.p
	rm -f $(srcdir)/$*.p
.c.o:
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $<


default: all
all: $(program)
triptrap: dvitype


dvicopy: dvicopy.o $(commono)
	$(CCLD) -o dvicopy $(LDFLAGS) dvicopy.o $(libs)
dvicopy.o: dvicopy.c $(commonh)
dvicopy.c: dvicopy.p $(commondefines)
dvicopy.p: dvicopy.web dvicopy.ch


dvitype: dvitype.o $(commono)
	$(CCLD) -o dvitype $(LDFLAGS) dvitype.o $(libs)
dvitype.o: dvitype.c $(commonh)
dvitype.c: dvitype.p $(commondefines)
dvitype.p: dvitype.web dvitype.ch


Makefile: Makefile.in ../config.status
	(cd ..; sh config.status)


c-sources: dvicopy.c dvitype.c
.PHONY: c-sources

install install-exec: all
	for p in $(program); do $(INSTALL_PROGRAM) $$p $(bindir)/$$p; done
install-data:


TAGS: *.c *.h
	etags -t *.c *.h


mostlyclean::
	rm -f *.o $(program) $(lib) $(programs)

clean:: mostlyclean
	rm -f *.dvi *.pool

distclean:: clean
	rm -f Makefile config.status c-auto.h

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

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

configclean:
	rm -f configure c-auto.h.in c-auto.h


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

clean::
	rm -f *.p *.c *.h
