# Imakefile for AthenaTools plotter widget set, V5.
#
# $Id: Imakefile,v 1.1 91/08/22 16:37:35 gnb Exp $
# $Source: /export/data/sources/x/At/Plotter/RCS/Imakefile,v $
#
# $Log:	Imakefile,v $
# Revision 1.1  91/08/22  16:37:35  gnb
# Initial revision
# 
#
# Destination directories for the library, include files, and man
# pages.  These should be changed to the directories where you
# want to install the plotter widget library, include files, and man
# pages. 
# The headers will be in $(ATINCDIR)/At.
# The man pages will have the name $(ATMANDIR)/AtPlot.$(ATMANSUFFIX)

#if defined(MipsArchitecture)
MACHINE = decmips
CDEBUGFLAGS = -g
PROTO = -D_NO_PROTO
#endif

ATLIBDIR =	/mit/atdev/$(MACHINE)/lib
ATINCDIR =	/mit/atdev/include
ATMANDIR =	/mit/atdev/man/man3
ATMANSUFFIX =	3X

# Define one of these to force use of either ansi of traditional compilers.
# Defining neither will use the default compiler.
# The library compiles without warnings with either cc or gcc -Wall (1.40)
# Full prototypes on the library are used if __STDC__ is available, and 
# XTFUNCPROTOS are used if USE_GCC is defined.
# USE_GCC is probably incompatable with shared libraries unless you have
# hacked your Imake.rules to use LIB_CC instead of CC wherever -pic is used.
#define  USE_GCC
#undef  USE_CC
CDEBUGFLAGS = -g

# Define this to allow shared libraries to be built; undef it to forbid them.
#undef SHARED_LIB_VERSION 4.0

# Define this if you don't have strcasecmp and strncasecmp in your C library.
# This is required for SunOs < 4.1.
#define NEED_STRCASECMP

# Cpp define for the font metrics path.  This should be changed to the
# path to the Postscript font metrics files on your system.  Don't get
# rid of the quoted "s -- they're very important!

AFMPATH =	\"/usr/athena/lib/ps\"

# Cpp defines.
#
# DEBUG enables checking of widget classes passed to member functions etc
#	This should probably be left defined
# TRACE gives verbose output of the decision making to stderr
#	And I mean verbose.  Don't define it!
# _AtDevelopment_ looks in . for include files, not /usr/include/At
# X11R4_INTRINSICS required if Xt is R4 or greater 
#	(actually, it probably no longer compiles under R3)

DEFINES = -DDEBUG -D_AtDevelopment_ -DX11R4_INTRINSICS -DATHENA

# The command used to preformat the man pages.  Must be functionally
# equivalent to the Unix command 'tbl'.  If your man(1) command supports the
# convention for specifying preprocessors in  the first line source file, ie
#	'\" t
# to run tbl, then cat will be fine.  
# SunOS certainly supports this from 4.0 onwards.

#TBL	= tbl
TBL	= cat

# For making PostScript versions of th man page (so they're easy to print 
# out!)  define this command that takes an input file called "$*.man" and
# runs tbl, troff and your troff to ps converter then sticks the ps on STDOUT.
MAN2PS	= tbl $*.man | troff -t -man | thack 
# You could use this to create lpr-able text versions (if you don't mind the
# confusion arising from the dual use of the .ps suffix!)
# MAN2PS = tbl $*.man | nroff -man 

# If you use Wcl and want to build the Wcl-based test program and include 
# the wcl registration function, define the following macros.  Things like 
#
# #define WclCFlags -I/usr/local/include
# #define WclLibs -lWc -lXp
#
# may be appropriate.  If Wcl is installed in /usr/include & /usr/lib, 
# just define WclCFlags to be the comment /**/

#define WclCFlags -I/mit/motifdev/Wcl/src
#define WclLibs -L/mit/motif/$(MACHINE)lib -lWc -lXp

# Some imake setups have MAKEDIRHIER badly defined in the template file...
MKDIRHIER = mkdirhier.sh

#################################################################
#
#  You shouldn't need to edit from here on
#
#################################################################

# The default build target
all::

# Should be including Library.tmpl but that isn't exported
# A BBY local hack in Imake.rules has $(LIB_CC) instead of $(CC) on every
# line that has -pic in it.  This allows us to use gcc on the non-shared
# library, and cc on the shared library.
LIB_CC = LibraryCcCmd

# Need this so gcc will find its own header files instead of standard ones!
TOP_INCLUDES=
#ifdef WclCFlags
# Need this so that make depend will work on the WcRegister function 
DEPEND = makedepend -- WclCFlags --
#endif

#ifdef USE_GCC
# GCC has prototypes, so enable them for better error checking
CC = gcc -fpcc-struct-return -Wall -DXTFUNCPROTO

#endif

#ifdef USE_CC
CC = cc
#endif


# Header files for the library.

HEADERS = \
	AxisCore.h\
	AxisCoreP.h\
	FrameAxis.h\
	FrameAxisP.h\
	Axis.h\
	AxisP.h\
	LabelAxis.h\
	LabelAxisP.h\
	Plot.h\
	PlotP.h\
	SPlot.h\
	SPlotP.h\
	LinePlot.h\
	LinePlotP.h\
	BarPlot.h\
	BarPlotP.h\
	TextPlot.h\
	TextPlotP.h\
	Plotter.h\
	PlotterP.h\
	Scale.h\
	Shading.h\
	FontFamily.h\
	FontFamilyP.h\
	Text.h\
	AtConverters.h

#ifdef NEED_STRCASECMP
STRCASECMP = strcasecmp.c
STRCASECMP_O = strcasecmp.o
#else
CASECMP_C = strcasecmp.c
#endif	
#ifdef WclCFlags
WCLREGISTER = WclRegister.c
WCLREGISTER_O = WclRegister.o
#else
REGISTER_C = WclRegister.c
#endif

SRCS = \
	AtConverters.c\
	AxisCore.c\
	FrameAxis.c\
	Axis.c\
	LabelAxis.c\
	Plot.c\
	SPlot.c\
	LinePlot.c\
	BarPlot.c\
	TextPlot.c\
	Plotter.c\
	Scale.c\
	Shading.c\
	FontFamily.c\
	Text.c\
	PlotterPS.c\
	TextPS.c\
	FontFamilyPS.c\
	$(WCLREGISTER) $(STRCASECMP)

OBJS = \
	AtConverters.o\
	AxisCore.o\
	FrameAxis.o\
	Axis.o\
	LabelAxis.o\
	Plot.o\
	SPlot.o\
	LinePlot.o\
	BarPlot.o\
	TextPlot.o\
	Plotter.o\
	Scale.o\
	Shading.o\
	FontFamily.o\
	Text.o\
	PlotterPS.o\
	TextPS.o\
	FontFamilyPS.o\
	$(WCLREGISTER_O) $(STRCASECMP_O)

# Man pages for the library.
# The MAN_SRC files have tbl contructs in them and need to be de-tbl-ified 
# before being installed on many systems.  If this is required, the command
# to do it is $(TBL).  MANS is the list of files as they will be installed.
# MAN_PS is the postscript versions of the same; the command to do that is 
# MAN2PS, and quite site-specific

MAN_SRC = AtPlotter.man AtPlot.man \
	AtAxisCore.man AtAxis.man AtLabelAxis.man AtFrameAxis.man \
	AtSPlot.man AtLinePlot.man AtBarPlot.man \
	AtText.man AtTextPlot.man AtFontFamily.man AtShading.man

MANS = AtPlotter.$(ATMANSUFFIX) AtPlot.$(ATMANSUFFIX) \
	AtAxisCore.$(ATMANSUFFIX) AtAxis.$(ATMANSUFFIX) \
	AtLabelAxis.$(ATMANSUFFIX) AtFrameAxis.$(ATMANSUFFIX) \
	AtSPlot.$(ATMANSUFFIX) AtLinePlot.$(ATMANSUFFIX) \
	AtBarPlot.$(ATMANSUFFIX) AtText.$(ATMANSUFFIX) \
	AtTextPlot.$(ATMANSUFFIX) AtFontFamily.$(ATMANSUFFIX) \
	AtShading.$(ATMANSUFFIX)

MAN_PS = AtPlotter.ps AtPlot.ps \
	AtAxisCore.ps AtAxis.ps AtLabelAxis.ps AtFrameAxis.ps \
	AtSPlot.ps AtLinePlot.ps AtBarPlot.ps \
	AtText.ps AtTextPlot.ps AtFontFamily.ps AtShading.ps

# The various stuff included in the Using document.  The INCLUDE_FILES are 
# the actual .tex files the Using.tex file includes.  The INCLUDE_SRC files
# are the (non-xfig) files these are generated from.  The FIGS are xfig source 
# files that transfig converts into postscript + tex files for inclusion.
# The fig files are treated special as they have ^A characters in them!
# FIGS_TEX are the stub includes that transfig generates from fig files.
# FIGS_PS are files that have to be included in the shar/tar archive.  They are
# generated at the same time as the FIG_TEX files but they cannot be made
# dependencies of anything else loops result.
# sample_prog.tex is a latex-ified version of sample_prog.c.

FIGS = classes.fig layout.fig bars.fig 
FIGS_UU = classes.uu layout.uu bars.uu 
FIGS_PS = classes.ps layout.ps bars.ps
FIGS_TEX = classes.tex layout.tex bars.tex

DOC_INCLUDE_SRC = Sample.PS
DOC_INCLUDE_FILES = Sample.tex $(FIGS_TEX) sample_prog.tex


# Stuff to include in the tar.Z/shar archives
DOC_PS = Using.ps
DOC_SRC = Using.tex $(DOC_INCLUDE_SRC) $(DOC_INCLUDE_FILES) tgrind.sty
	

# Extra files to include in the tar.z/shar archive
# REGISTER_C and CASECMP_C are only defined if those files aren't in $(SRCS)
EXTRAFILES = README CHANGED-V4 redraw-protocol Imakefile ToDo ispell-words \
	$(REGISTER_C) $(CASECMP_C) \
	Makefile.std Test.ad test.c sample_prog.c $(DOC_SRC)


# Necessary libraries for the demo program.

DEMOLIBS = -lXaw -lXmu -lXt -lXext -lX11 -lm

################
# Rules for library build.
################

#ifdef SHARED_LIB_VERSION

SharedLibraryObjectRule()

#ifdef WclCFlags
SpecialSharedObjectRule($(WCLREGISTER_O), $(WCLREGISTER), WclCFlags)
#endif

SpecialSharedObjectRule(FontFamilyPS.o, FontFamilyPS.c, -DAFMPATH=$(AFMPATH))

NormalSharedLibraryTarget(At,SHARED_LIB_VERSION, $(OBJS))

MakeDirectories(install, $(ATLIBDIR))
InstallSharedLibrary(At,SHARED_LIB_VERSION, $(ATLIBDIR))

#else /* No Shared Libraries */

NormalLibraryObjectRule()

#ifdef WclCFlags
SpecialObjectRule($(WCLREGISTER_O), $(WCLREGISTER), WclCFlags)
#endif

SpecialObjectRule(FontFamilyPS.o, FontFamilyPS.c, -DAFMPATH=$(AFMPATH))

#endif /* Shared Libraries */

NormalLibraryTarget(At,$(OBJS))

MakeDirectories(install, $(ATLIBDIR))
InstallLibrary(At, $(ATLIBDIR))

MakeDirectories(install.man, $(ATMANDIR))
InstallMultipleMan($(MANS), $(ATMANDIR))

MakeDirectories(install,$(ATINCDIR)/At)
InstallMultiple($(HEADERS),$(ATINCDIR)/At)

################
# Rule for the test and sample program build.
################

#ifdef SHARED_LIB_VERSION
#define deplib libAt.so.SHARED_LIB_VERSION
#define thislib -L. -lAt
#else
#define deplib libAt.a
#define thislib libAt.a
#endif

#ifdef WclCFlags
SpecialObjectRule(test.o, test.c $(HEADERS), WclCFlags)
NormalProgramTarget(test, test.o, deplib, thislib, WclLibs $(DEMOLIBS))
#endif

# demo program described in the Using document
SpecialObjectRule(sample_prog.o, sample_prog.c,)
NormalProgramTarget(sample_prog, sample_prog.o, deplib, thislib, $(DEMOLIBS))

################
# Rules to build documents
################

doc: $(DOC_PS)
doc-clean::
	$(RM) $(DOC_INCLUDE_FILES) *.dvi *.aux *.lof *.log *.dlog

clean:: doc-clean

Using.ps: Using.tex $(DOC_INCLUDE_FILES)

Sample.tex: Sample.PS
	cp Sample.PS Sample.ps
	fig2ps2tex Sample.ps > Sample.tex

.SUFFIXES: .tex .fig .ps .uu

.tex.ps:
	@echo "latex \"\batchmode\input $*\""
	@latex "\batchmode\input $*" || \
	  (echo "(Latex Failed.  Look in $*.log for error messages)" 1>&2 && \
		exit 1)
	@while grep 'Label(s) may have changed' $*.log > /dev/null ; do \
		echo ; echo "Xrefs changed, rerunning latex..." ; echo ; \
		latex  "\batchmode\input $*"; \
	done
	dvi2ps -r -q $* > $*.ps

# How to make a .tex from a .fig.  Also makes a .ps as a side effect.
.fig.tex:
	fig2dev -L ps $*.fig > $*.ps
	fig2ps2tex $*.ps > $*.tex

# Encode it up so we can shar it.
.fig.uu:
	uuencode < $*.fig $*.fig > $*.uu

# If we got this via a shar file, the .figs are uuencoded.
# If a .fig exists, this is ignored.
.fig:
	uudecode $*.uu

# how to make a .tex from a .c
.c.tex:
	tgrind -f $*.c | sed -e '1d' -e '$$d' > $*.tex

doc-clean::
	$(RM) *.ps $(FIGS_UU)

#########
# Format and print the man pages
#########
.SUFFIXES: .man .$(ATMANSUFFIX)

.man.$(ATMANSUFFIX):
	$(TBL) $*.man > $*.$(ATMANSUFFIX)

clean::
	$(RM) $(MANS) $(MAN_PS)

man-ps: $(MAN_PS)

.man.ps:
	$(MAN2PS) > $*.ps


################
# Rule for makedepend
################
DependTarget()

################
# For shipping stuff
################

### NB: Need to change the manifest file if we add or delete files in the list
### of things to ship.
shar: $(EXTRAFILES) $(SRCS) $(HEADERS) $(MAN_SRC) $(FIGS_UU)
	makekit -m -s60k 

# $(EXTRAFILES) $(SRCS) $(HEADERS) $(MAN_SRC) $(FIGS_UU) $(FIGS_PS) 

tar: $(EXTRAFILES) $(SRCS) $(HEADERS) $(MAN_SRC) $(FIG) $(DOC_PS)
	tar cf - $(EXTRAFILES) $(SRCS) $(HEADERS) $(MAN_SRC) \
			$(FIG) $(FIGS_PS) $(DOC_PS) | \
		compress -v > plotter.tar.Z

tgrind.sty:
	cp /usr/local/lib/tex/inputs/tgrind.sty .

clean::
	$(RM) Part?? plotter.tar.Z tgrind.sty
