/*
 * Imakefile for dvi previewer.  Edit the file according to the enclosed
 * instructions before running ``xmkmf.''
 *
 * Some of these instructions refer to ``uncommenting'' a line.  To do this,
 * delete the word ``XCOMM'' and the space immediately following it.
 */

/* We need this first.  (Do not change this.)  */

#ifndef XCOMM
#define XCOMM #
#endif

/*
 * By default, xdvi is compiled with the Athena widgets (Xaw).
 * If you want to compile xdvi with a different widget set or without
 * the X toolkit, you may uncomment one of the following lines.
 *
 * Most likely you will not want to change anything here.
 */

XCOMM #define NOTOOL	/* This selects compilation without a toolkit.  */
XCOMM #define MOTIF	/* This selects compilation with the Motif toolkit.  */

/*
 * If you have additional X include files and libraries in another location
 * (for example, if the toolkit is not contained in the X source tree)
 * then the top directory can be set here.  To do so, uncomment the line
 * and put the path in the quotes.
 *
 * EXAMPLE:
 *   #define AUX_TOP "/usr/dt"
 */

XCOMM #define AUX_TOP "PUT THE TOP DIRECTORY HERE"

/*
 * To enable support for GF-format pixel files, uncomment the following line.
 */

XCOMM #define USE_GF

/*
 * PostScript options:
 *
 * xdvi supports PostScript specials by several mechanisms.  You may select
 * more than one of the following; it will choose the best one available at
 * run-time.
 *
 * To enable PostScript support via Display PostScript, uncomment the following
 * line:
 */

XCOMM #define PS_DPS

/*
 * To enable PostScript support via NeWS (SunOS 4 only), uncomment the
 * following line:
 */

XCOMM #define PS_NEWS

/*
 * To enable PostScript support via ghostscript, uncomment the following line:
 */

XCOMM #define PS_GS

/*
 * If you have selected PS_GS and wish to have the path to Ghostscript
 * compiled into the xdvi binary, uncomment and change the following line
 * to contain the full path.  This is optional.
 *
 * EXAMPLE:
 *   #define GSPATH "/usr/local/bin/gs"
 */

XCOMM #define GSPATH "PUT THE PATH TO GS HERE"

/*
 * Other options to the configure script can be put here.  These may be
 * chosen from the following list; see the INSTALL file for details.
 *
 *	--disable-grey
 *	--disable-buttons
 *	--disable-make-pk
 *	--enable-make-pk=PATH
 *	--enable-old-make-pk
 *	--enable-old-make-pk=PATH
 *	--enable-config-file=PATHLIST
 *	--enable-self-auto
 *	--enable-self-auto=PATHLIST
 *	--enable-config-to-res
 *	--enable-config-to-res=PATHLIST
 *	--enable-dosnames
 *	--enable-a4
 *	--enable-texxet
 *	--with-mfmode=MODE:DPI
 *	--without-mfmode
 *
 * EXAMPLE:
 *   #define CONFIG_ARGS --aux-top=/usr/dt --disable-buttons
 */

#define CONFIG_ARGS

/*
 * If any options need to be set via the CPPFLAGS variable (as mentioned in
 * the INSTALL file), they can be set here.
 *
 * EXAMPLE:
 *   DEFS = -DALTFONT="\"ptmr8r\""
 *
 * Note the handling of quotes.  This is because the Imakefile is processed
 * by cpp, which may choke on \".
 */

DEFS =

/*----------------------------------------------------*\
 *
 * End of user edited part.
 * No changes beyond this point should be necessary.
 *
\*----------------------------------------------------*/

#ifndef NOTOOL
#ifdef MOTIF
  /* I'm just guessing about how to handle Motif within an Imakefile.  */
  LOCAL_LIBRARIES=$(DPS_LIBS) $(NEWS_LIBS) XmClientLibs
  DEPLIBS=XmClientDepLibs
  LINTLIBS=$(LINTXM) $(LINTXMU) $(LINTXTOOL) \
    $(LINTEXTENSIONLIB) $(LINTXLIB) $(MATHLIB)
  WITH_TOOLKIT = --with-x-toolkit=motif
#else /* Xaw */
  LOCAL_LIBRARIES=$(DPS_LIBS) $(NEWS_LIBS) XawClientLibs
  DEPLIBS=XawClientDepLibs
  LINTLIBS=$(LINTXAW) $(LINTXMU) $(LINTXTOOL) \
    $(LINTEXTENSIONLIB) $(LINTXLIB) $(MATHLIB)
  WITH_TOOLKIT =
#endif /* Xaw */
#else /* NOTOOL */
  LOCAL_LIBRARIES=$(DPS_LIBS) $(NEWS_LIBS) $(XLIB)
  DEPLIBS=$(DEPXLIB)
  LINTLIBS=$(LINTXLIB) $(MATHLIB)
  WITH_TOOLKIT = --without-x-toolkit
#endif

#ifdef AUX_TOP
  AUXTOP = AUX_TOP
  INCLUDES = -I$(AUXTOP)/include
  LOCAL_LDFLAGS = -L$(AUXTOP)/lib
  LD_RUN_PATH = $(AUXTOP)/lib
#endif

#ifdef USE_GF
  GF_C = gf.c
  GF_O = gf.o
  ENABLE_GF = --enable-gf
#else
  GF_C =
  GF_O =
  ENABLE_GF =
#endif

#ifdef PS_DPS
  PSDPS_C = psdps.c
  PSDPS_O = psdps.o
  ENABLE_PS_DPS = --enable-ps-dps
  DPS_LIBS = -ldps
#else
  PSDPS_C =
  PSDPS_O =
  ENABLE_PS_DPS =
  DPS_LIBS =
#endif

#if defined(PS_DPS) && defined(SunArchitecture) && OSMajorVersion == 5
  OPENWIN_DPS_INCLUDE_HACK = -I/usr/openwin/include/X11
#else
  OPENWIN_DPS_INCLUDE_HACK =
#endif

#ifdef PS_NEWS
  PSNEWS_C = psnews.c
  PSNEWS_O = psnews.o
  ENABLE_PS_NEWS = --enable-ps-news
  NEWS_LIBS = -u _xv_psview_pkg -lxvps -lxview -lcps -lolgx
#else
  PSNEWS_C =
  PSNEWS_O =
  ENABLE_PS_NEWS =
  NEWS_LIBS =
#endif

#ifdef PS_GS
  PSGS_C = psgs.c
  PSGS_O = psgs.o
#ifdef GSPATH
  ENABLE_PS_GS = --enable-ps-gs=GSPATH
#else
  ENABLE_PS_GS = --enable-ps-gs
#endif
#else
  PSGS_C =
  PSGS_O =
  ENABLE_PS_GS =
#endif

#if defined(PS_DPS) || defined(PS_NEWS) || defined(PS_GS)
  PSHEADER_C = psheader.c
  PSHEADER_O = psheader.o
#else
  PSHEADER_C =
  PSHEADER_O =
#endif

OPT_SRCS = $(GF_C) $(PSHEADER_C) $(PSDPS_C) $(PSNEWS_C) $(PSGS_C)
OPT_OBJS = $(GF_O) $(PSHEADER_O) $(PSDPS_O) $(PSNEWS_O) $(PSGS_O)

SRCS=xdvi.c events.c dvi-init.c dvi-draw.c special.c font-open.c filefind.c \
  pk.c vf.c util.c $(OPT_SRCS)
OBJS=xdvi.o events.o dvi-init.o dvi-draw.o special.o font-open.o filefind.o \
  pk.o vf.o util.o $(OPT_OBJS)

MATHLIB = -lm
SYS_LIBRARIES = $(MATHLIB)
DEFINES = $(DEFS) $(OPENWIN_DPS_INCLUDE_HACK)

all::xdvi.man

depend::config.h $(PSHEADER_C)

config.h: Imakefile configure
	echo $(DEFS) > conftest; \
	CPPFLAGS="`cat conftest`" ./configure --imake --x-top=$(PROJECTROOT) \
	$(WITH_TOOLKIT) $(ENABLE_GF) $(ENABLE_PS_DPS) $(ENABLE_PS_NEWS) \
	$(ENABLE_PS_GS) CONFIG_ARGS

ComplexProgramTarget(xdvi)

psheader.c:	psheader.txt squeeze
	./squeeze psheader.txt psheader.c

squeeze:	squeeze.c
	$(CC) $(CFLAGS) -o squeeze squeeze.c

xdvi.man: xdvi-man.sed mksedscript Makefile config.h xdvi-paths.h
	./mksedscript . $(DEFS) > sedscript
	sed -f sedscript < xdvi-man.sed > xdvi.man

check:

uninstall:
	-$(RM) $(DESTDIR)$(BINDIR)/xdvi $(DESTDIR)$(MANDIR)/xdvi.$(MANSUFFIX)

mostlyclean:
	-$(RM) *.o xdvi xdvi.man core sedscript *~

archclean:
	-$(RM) *.o xdvi Makefile config.h config.cache config.status config.log

clean::
	-$(RM) xdvi.man sedscript psheader.c squeeze

distclean: clean
	-$(RM) Makefile config.h config.cache config.status config.log

veryclean: distclean

realclean: distclean

maintainer-clean: veryclean
	@echo "This command is intended for maintainers to use;"
	@echo "it deletes files that may require special tools to rebuild."
	rm -f config.hin configure

.PHONY: all uninstall mostlyclean archclean distclean veryclean realclean \
maintainer-clean
