
srcdir = @srcdir@
VPATH  = @srcdir@

-include ../config.mk

OBJS	= dvi.o dvidraw.o x11.o
SOURCES = dvi.c dvidraw.c x11.c
HEADERS = x11.h
OTHERFILES = Makefile.in

INCLUDES = -I$(srcdir) -I.. -I$(srcdir)/../include
LOCAL_CFLAGS = $(INCLUDES) $(KPSE_CFLAGS) $(X_CFLAGS)
ALL_CFLAGS = $(CFLAGS) $(ADDCFLAGS) $(CPPFLAGS) $(LOCAL_CFLAGS)

ALL_LIBS = $(KPSE_LIBS) $(T1LIB_LIBS) $(FREETYPE_LIBS) \
	$(X_LIBS) $(ADDLIBS) $(LIBS)

DEPSOURCES = $(SOURCES)
DEPCFLAGS = $(ALL_CFLAGS)
DISTFILES = $(SOURCES) $(HEADERS) $(OTHERFILES)

CLEANABLE += $(OBJS) $(PROGRAMS) core
DISTCLEANABLE += Makefile

MDVILIB  = ../lib/mdvi.a
PROGRAM = mdvi

.PHONY: all
all: $(PROGRAM)

mdvi: $(MDVILIB) $(OBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(MDVILIB) $(ALL_LIBS)

.PHONY: install
install:
	$(MKINSTALLDIRS) $(bindir)
	$(INSTALL) -m 755 $(PROGRAM) $(bindir)/$(PROGRAM)

.PHONY: uninstall
uninstall:
	$(RM) $(bindir)/$(PROGRAM)

.PHONY: $(MDVILIB)
$(MDVILIB):
	$(MAKE) -C ../lib

../config.mk:
	@echo "*** Error: Run \`configure' in the top source directory."
	@exit 1

.c.o:
	$(CC) $(ALL_CFLAGS) -c $<

dvi.o: dvi.c
	$(CC) $(ALL_CFLAGS) $(T1LIB_CFLAGS) $(FREETYPE_CFLAGS) -DLOCALEDIR=\"$(localedir)\" -c $<

include $(FRAGDIR)/dist.mk
include $(FRAGDIR)/targets.mk
include $(FRAGDIR)/depend.mk
