XPICLIBDIR=$(LIBDIR)/xpic
# The documents go in $(DOCDIR)/xpic - see the install target. 
# At CSRI, we use a logical link to the source, so we don't 
# install this. You must still keep this accurate, because 
# it's put into the man page. Change the install target appropriately.
#DOCDIR=/nfs/church/csri5/doc/local
DOCDIR=/ai/doc/X11
# the directory in which xpic saves the current buffer 
# in case it dies on a signal
DUMPDIR=/tmp
#############################################################
# -DXPIC is used by the filename completion code.
# -DMAGIC will include code that puts a '#! $(BINDIR)/xpic'
# header on the saved xpic files, and make them executable, so
# you can just execute the saved xpic file and it starts up
# xpic.
# -DDEBUG turns on debugging output - do you really want that?!
# -DDRAWBBOX is also for debugging - it draws the bounding box
# of all gels.
# -DGRAB should be defined if XtAddGrab and XtRemoveGrab can be 
# made to work in Minibuf.c and input.c - I can't seem to get them
# to work.
# -DTYPEOUT includes the typeout code - this is still not used by
# xpic - not much point defining it.
#DEFINES = -DXPIC -DMAGIC -DDEBUG
DEFINES = -DXPIC -DMAGIC
#############################################################
CDEBUGFLAGS = -g
#CDEBUGFLAGS = -O
INCLUDES =  -I$(TOOLKITSRC) -I$(TOP) -Ibitmaps
CFLAGS = $(CDEBUGFLAGS) $(INCLUDES) $(STD_DEFINES) $(DEFINES)
LINTFLAGS = $(LINTOPTS) $(INCLUDES) $(STD_DEFINES) $(DEFINES) -DLINT
#############################################################
VPATH = bitmaps
#############################################################
# Note - You need the HP widgets (Xw) for the X11 Toolkit
# These should be defined in an Imake.tmpl - except that the 
# normal Imake.tmpl insists on these being compiled in the 
# X directory tree.
XWLIB=$(USRLIBDIR)/libXw.a
XTOOLLIB=$(USRLIBDIR)/libXt.a
XLIB=$(USRLIBDIR)/libX11.a
# Sigh - we use sin(), cos(), atan2() for arrow. 
MATHLIB=-lm
#############################################################
# /usr/lib/debug/malloc.o is Sun's debugging malloc() - it
# provides the malloc_debug() and malloc_verify() calls.
# malloc.o is a first-fit malloc with debugging ASSERTs. Finds
# heap corruption fast. Not defining this will use libc.
#MALLOC = /usr/lib/debug/malloc.o
#MALLOC = malloc.o
MALLOC = 
#############################################################
MYXTSTUFF = Form.o PButton.o
#############################################################
OBJS1 = main.o windows.o xpic.o handlers.o input.o  \
		event.o grid.o error.o spline.o arrow.o newfonts.o \
		util.o gels.o null.o obj_line.o obj_spline.o obj_text.o \
		obj_box.o obj_circ.o obj_ell.o obj_block.o obj_elem.o \
		updown.o text.o isqrt.o ask.o xtypeout.o Minibuf.o Window.o
#############################################################
SRCS1 = main.c windows.c xpic.c handlers.c input.c  \
		event.c grid.c error.c spline.c arrow.c newfonts.c \
		util.c gels.c null.c obj_line.c obj_spline.c obj_text.c \
		obj_box.c obj_circ.c obj_ell.c obj_block.c obj_elem.c \
		updown.c text.c isqrt.c ask.c xtypeout.c Minibuf.c Window.c
#############################################################
OBJS2 = x2pic.o hash.o
SRCS2 = x2pic.c hash.c
#############################################################
OBJS3 = x2ps.o hash.o
SRCS3 = x2ps.c hash.c
#############################################################
PROGRAMS = xpic x2ps x2pic

.SUFFIXES: .manX .man

.manX.man:
	sed -e 's?DOCDIR?$(DOCDIR)/xpic?g'\
	    -e 's?XPICLIBDIR?$(XPICLIBDIR)?g' $*.manX > $*.man

ComplexProgramTarget_1(xpic,$(MYXTSTUFF) $(MALLOC) $(XWLIB) $(XTOOLLIB) $(XLIB),$(MATHLIB))

SingleProgramTarget(x2pic,$(OBJS2) $(MALLOC),,)
InstallProgram(x2ps, $(BINDIR))
InstallManPage(x2ps, $(MANDIR))

SingleProgramTarget(x2ps,$(OBJS3) $(MALLOC),,$(MATHLIB))
InstallProgram(x2pic, $(BINDIR))
InstallManPage(x2pic, $(MANDIR))

lint:
	lint -abz $(SRCS1) $(LDFLAGS) -lXw -lXt -lX11 -lm $(LINTFLAGS)
	lint -abz $(SRCS2) $(LDFLAGS) $(LINTFLAGS)
	lint -abz $(SRCS3) $(LDFLAGS) -lm $(LINTFLAGS)


clean::
	$(RM) tune.h.new xpic.man x2ps.man x2pic.man
#	cd fontstuff/vfontscale; make clean

id: tags
	mkid *.[ch]

install::
	-mkdir $(XPICLIBDIR)
	$(INSTALL) $(INSTAPPFLAGS) x2ps.pro $(XPICLIBDIR)
	$(INSTALL) $(INSTAPPFLAGS) x2ps.tra $(XPICLIBDIR)
	-mkdir $(XPICLIBDIR)/fontdesc
	$(INSTALL) $(INSTAPPFLAGS) fontdesc/xpic $(XPICLIBDIR)/fontdesc
	$(INSTALL) $(INSTAPPFLAGS) fontdesc/x2pic $(XPICLIBDIR)/fontdesc
	$(INSTALL) $(INSTAPPFLAGS) fontdesc/x2ps $(XPICLIBDIR)/fontdesc

install::
#	rm -r $(DOCDIR)/xpic
#	cp -r doc $(DOCDIR)/xpic
#	-mkdir $(FONTDIR)
#	cp -r fontstuff/sunfonts.* $(FONTDIR)
	
tar:
	cd ..; tar cvfX - xpic/ExcludeFiles xpic | compress > xpic.tar.Z

tune.h: Makefile
	echo \#define LIBDIR \"$(XPICLIBDIR)\" > tune.h.new
	echo \#define PROGRAMNAME \"$(BINDIR)/xpic\" >> tune.h.new
	echo \#define DUMPDIR \"$(DUMPDIR)\" >> tune.h.new
	-cmp -s tune.h.new tune.h || cp tune.h.new tune.h
