#ifndef XCOMM
#define XCOMM #
#endif

XCOMM Fig2dev : General Fig code translation program
XCOMM Copyright (c) 1991 Micah Beck
XCOMM Parts Copyright (c) 1995-2000 by Brian V. Smith
XCOMM Parts Copyright (c) 1999 by T. Sato

XCOMM THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
XCOMM INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
XCOMM EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
XCOMM CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
XCOMM DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
XCOMM TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
XCOMM PERFORMANCE OF THIS SOFTWARE.
XCOMM
XCOMM Any party obtaining a copy of these files is granted, free of charge, a
XCOMM full and unrestricted irrevocable, world-wide, paid up, royalty-free,
XCOMM nonexclusive right and license to deal in this software and
XCOMM documentation files (the "Software"), including without limitation the
XCOMM rights to use, copy, modify, merge, publish, distribute, sublicense,
XCOMM and/or sell copies of the Software, and to permit persons who receive
XCOMM copies from any such party to do so, with the only requirement being
XCOMM that this copyright notice remain intact.

XCOMM You should point XFIGLIBDIR to the same directory you did when you compiled
XCOMM and installed xfig.  This will be made automatic in the future.

XFIGLIBDIR =	/usr/local/lib/X11/xfig

XCOMM If your system has the strerror() function (doesn't have sys_errlist) then
XCOMM comment out NEED_STRERROR with an XCOMM comment.

NEED_STRERROR = -DNEED_STRERROR

XCOMM uncomment the following line if your compiler supports
XCOMM inline functions. With the "INLINE" keyword, you should notice that
XCOMM the display will be a bit faster in complex figures

XCOMM USEINLINE = -DUSE_INLINE

XCOMM Change RGB if necessary, to point to your rgb.txt color database
XCOMM file (for X11).  This is needed for the -g (background color) option.
XCOMM

RGB = $(LIBDIR)/rgb

XCOMM Unomment the #define for USEXPM if you want to use the XPM
XCOMM (color pixmap) package.
XCOMM You need version 3.4c or newer of the XPM package.
XCOMM
XCOMM Change XPMLIBDIR if necessary to point to the xpm library (libXpm)
XCOMM Change XPMINC if necessary to point to the include file for xpm (xpm.h)
XCOMM

XCOMM #define USEXPM

#ifdef USEXPM
XPMLIBDIR = $(USRLIBDIR)
XPMINC = -I/usr/include/X11
#endif

XCOMM For Linux machines or any machines that have a separate library for
XCOMM the database management routines, uncomment the following line.
XCOMM For the Redhat distributions of Linux you may have to change DBMLIB to -ldb.
XCOMM For other Linux versions you may need -ldbm instead of -lgdbm.
XCOMM Slackware and RedHat Linuxes use -lgdbm.

XCOMM DBMLIB = -lgdbm

XCOMM If your system doesn't have ndbm ("New" database manager) comment the following
USE_NDBM = -DNDBM

XCOMM If don't want to use JPEG, comment out the following line

#define USEJPEG

XCOMM If you don't have the jpeg library in your system library area, comment
XCOMM out the USEINSTALLEDJPEG variable (using XCOMM), change the JPEGLIBDIR
XCOMM variable to the directory where your jpeg library resides. Do not change
XCOMM JPEGINCDIR in this case because it must be defined relative to the
XCOMM fig2dev/dev subdirectory.
XCOMM You must have version 5b or newer of the jpeg library.

#define USEINSTALLEDJPEG

#ifdef USEJPEG
#ifdef USEINSTALLEDJPEG
JPEGLIBDIR = /usr/local/lib
JPEGINCDIR = /usr/include/X11
#else
JPEGLIBDIR = ../jpeg
JPEGINCDIR = $(JPEGLIBDIR)
#endif
#endif /* USEJPEG */

XCOMM uncomment the following to set paper size to A4
XCOMM DDA4 = -DA4

XCOMM uncomment the following to set IBM Graphics Enhancement Cartridge
XCOMM DDIBMGEC = -DIBMGEC

XCOMM comment out the DDNFSS = ... line if you don't want NFSS2 font selection
XCOMM	for LaTeX texts
XCOMM comment out the DDLATEX2E_GRAPHICS = ... line if you don't want to use the
XCOMM	standard graphics package distributed w/ LaTeX2e
XCOMM UNcomment the DDEPSFIG = ... line if you want to use the deprecated epsfig macros
XCOMM	distributed w/ LaTeX2e (DDLATEX2E_GRAPHICS must also be defined)
XCOMM
XCOMM     Hint: Users of LaTeX2e will probably want to include both DDNFSS
XCOMM		and DDLATEX2E_GRAPHICS options; users of LaTeX 2.09 will
XCOMM		probably want to include neither.

DDNFSS = -DNFSS
DDLATEX2E_GRAPHICS = -DLATEX2E_GRAPHICS
XCOMM DDEPSFIG = -DEPSFIG

XCOMM comment out the DDDVIPS to NOT use dvips for the DVI-to-PostScript driver
DDDVIPS = -DDVIPS

XCOMM If your system doesn't have strcasecmp and/or strncasecmp
XCOMM undefine the following two definitions

XCOMM HAVE_NO_STRCASECMP = -DHAVE_NO_STRCASECMP
XCOMM HAVE_NO_STRNCASECMP = -DHAVE_NO_STRNCASECMP

XCOMM Uncomment the next line if you want use Japanese (i18n) on xfig.

XCOMM #define I18N

#ifdef I18N
I18N_DEFS = -DI18N 
FIG2DEV_LIBDIR = /usr/local/lib/fig2dev
I18N_DEV_DEFS = $(I18N_DEFS) -DFIG2DEV_LIBDIR='\"/usr/local/lib/fig2dev\"'

install::
	[ -d $(FIG2DEV_LIBDIR) ] || mkdir $(FIG2DEV_LIBDIR)
	$(INSTALL) -c dev/japanese.ps $(FIG2DEV_LIBDIR)
	( cd $(FIG2DEV_LIBDIR); \
	  rm -f ja.ps ja_JP.ps ja_JP.ujis.ps ja_JP.eucJP.ps ja_JP.EUC.ps; \
	  ln -s japanese.ps ja.ps; ln -s japanese.ps ja_JP.ps; \
	  ln -s japanese.ps ja_JP.ujis.ps; ln -s japanese.ps ja_JP.eucJP.ps; \
	  ln -s japanese.ps ja_JP.EUC.ps )
	$(INSTALL) -c  dev/korean.ps $(FIG2DEV_LIBDIR)
	( cd $(FIG2DEV_LIBDIR); \
	  rm -f ko.ps ko_KR.ps ko_KR.ujis.ps ko_KR.eucKR.ps ko_KR.EUC.ps; \
	  ln -s korean.ps ko.ps; ln -s korean.ps ko_KR.ps; \
	  ln -s korean.ps ko_KR.ujis.ps; ln -s korean.ps ko_KR.eucKR.ps; \
	  ln -s korean.ps ko_KR.EUC.ps )
#endif

DEFINES = $(NEED_STRERROR) $(HAVE_NO_STRCASECMP) $(HAVE_NO_STRNCASECMP) $(USEINLINE) \
	$(I18N_DEFS)

XCOMM If your system doesn't have strstr() then uncomment the following line
XCOMM #define NOSTRSTR

XCOMM **************************************************************
XCOMM *** You shouldn't have to change anything below this point ***
XCOMM **************************************************************

DIR_DEFS=	-DBITMAPDIR=\\\"$(XFIGLIBDIR)/bitmaps\\\"

#ifdef USEXPM
DUSEXPM = -DUSE_XPM
XPMLIBS = -L$(XPMLIBDIR) -lXpm -lX11
#endif

#if defined(NOSTRSTR) 
STRSTRC=	strstr.c
STRSTRO=	strstr.o
#endif

#ifdef USEJPEG

DUSEJPEG = -DUSE_JPEG

#ifdef USEINSTALLEDJPEG
JPEGLIBDIR = /usr/local/lib
JPEGLIB = -L$(JPEGLIBDIR) -ljpeg
#else
XCOMM this is relative to this directory (transfig/fig2dev)
JPEGLIBDIR = ../../jpeg-6a
JPEGCONF = configure
JPEGLIB = $(JPEGLIBDIR)/libjpeg.a
DEPLIBJPEG = $(JPEGLIBDIR)/libjpeg.a
#endif	/* USEINSTALLEDJPEG */

#endif /* USEJPEG */

IMAKE_DEFINES = $(DUSEJPEG) $(DUSEXPM)

DEVDEFINES = $(DUSEJPEG) $(DUSEXPM) $(XPMINC) $(DDNFSS) $(DDA4) \
		$(DDLATEX2E_GRAPHICS) $(DDEPSFIG) $(DDIBMGEC) $(DDDVIPS) $(I18N_DEV_DEFS)

#define IHaveSubdirs
#define PassCDebugFlags 'CDEBUGFLAGS=$(CDEBUGFLAGS)'

DEVDIR = dev

SUBDIRS = $(DEVDIR)

LIBTRANSFIG = $(DEVDIR)/libtransfig.a

INCLUDES = -I..

LOCAL_LIBRARIES = $(LIBTRANSFIG) $(JPEGLIB)
#if defined(NetBSDArchitecture) || defined(FreeBSDArchitecture)
SYS_LIBRARIES = $(XPMLIBS) $(DBMLIB) -lm -lcompat
#else
SYS_LIBRARIES = $(XPMLIBS) $(DBMLIB) -lm
#endif
DEPLIBS = $(LIBTRANSFIG)

#if !(defined(SunOSPlatform) && (OSMajorVersion>=5))
GETOPTC=   getopt.c
GETOPTO=   getopt.o
#endif

SRCS = fig2dev.c psfonts.c iso2tex.c arrow.c bound.c colors.c trans_spline.c \
	free.c read.c read1_3.c latex_line.c $(STRSTRC) $(GETOPTC)
OBJS = fig2dev.o psfonts.o iso2tex.o arrow.o bound.o colors.o trans_spline.o \
	free.o read.o read1_3.o latex_line.o $(STRSTRO) $(GETOPTO)

fig2dev: $(DEPLIBJPEG) $(DEPLIBS)

RGBDBM = $(USE_NDBM)
RGBFILE = -DRGB_FILE=\"$(RGB)\"
SpecialObjectRule(colors.o, , $(RGBFILE) $(RGBDBM))
SpecialObjectRule(fig2dev.o, fig2dev.c ../patchlevel.h, )

XCOMM only compile our jpeg if the use doesn't have one installed

#ifndef USEINSTALLEDJPEG
XCOMM We need the cjpeg prog for smoothing jpeg output (there is no ppmtojpeg),
XCOMM so we do "make install"
$(JPEGLIBDIR)/libjpeg.a: $(JPEGLIBDIR)/jconfig.h
	cd $(JPEGLIBDIR); $(MAKE) install

$(JPEGLIBDIR)/jconfig.h:
	cd $(JPEGLIBDIR) ; ./$(JPEGCONF) CC='$(CC)'
#endif

$(LIBTRANSFIG)::
	cd $(DEVDIR); $(MAKE) JPEGINCDIR=$(JPEGINCDIR) \
		DEFINES="$(DEVDEFINES) $(DIR_DEFS)" libtransfig.a

PROGRAM = fig2dev
AllTarget(fig2dev)
MakeSubdirs($(SUBDIRS))
DependSubdirs($(SUBDIRS))

ComplexProgramTarget(fig2dev)

all:: fig2dev.man fig2ps2tex.man pic2tpic.man

XCOMM Install the tk bitmaps here
install::
	@(cd bitmaps ; \
	if [ -d $(XFIGLIBDIR)/bitmaps ]; then set +x; \
	else (set -x; $(MKDIRHIER) $(XFIGLIBDIR)/bitmaps ); fi ; \
	echo Copying bitmap files for tk to $(XFIGLIBDIR)/bitmaps ; \
	for f in * ; do \
	      $(INSTALL) -c $$f $(XFIGLIBDIR)/bitmaps ; \
	done) ; 

InstallScript(fig2ps2tex,$(BINDIR))
InstallScript(fig2ps2tex.sh,$(BINDIR))
InstallScript(pic2tpic,$(BINDIR))

InstallManPage(fig2ps2tex,$(MANDIR))
InstallManPage(pic2tpic,$(MANDIR))

fig2dev.man:: ../doc/fig2dev.1
	-ln -s ../doc/fig2dev.1 fig2dev.man

fig2ps2tex.man:: ../doc/fig2ps2tex.1
	-ln -s ../doc/fig2ps2tex.1 fig2ps2tex.man

pic2tpic.man:: ../doc/pic2tpic.1
	-ln -s ../doc/pic2tpic.1 pic2tpic.man

