#  ***********************************************************************
#                 MAKEFILE FOR GPLOT, GTEX and DRAWCGM
#  ***********************************************************************
#                   
#	To build one of the following utilities, type make followed by
#       the utility name. You will need to edit the top half of this 
#       makefile to include the appropriate drivers before building it.

#         gplot     utility for viewing CGM files on different devices
#         gplotdw   Decwindows interface      (Point & Click version) 
#         gplotaw   Athena Widgets interface  (         "           )
#         gplotm    Motif interface           (         "           )
#         gplottool Sunview interface         (         "           )
#                 
#  ***********************************************************************
#
#       PLEASE READ THE INSTRUCTIONS BEFORE ADDING OR DELETING ANYTHING
#  
#  ***********************************************************************
     
#	To add controllers and device drivers, include the following 
#       -D qualifiers on the CTR_FLAGS (controller) and DRV_FLAGS 
#       (driver) lines below:
#
#		inctty		tty controller (always include this!)
#		incxws		X window system driver
#		incps		postscript driver
#		inctek		tektronix terminal driver
#		incsun		Sun CGI driver
#		incigl		Silicon Graphics Iris GL
#		inccgmc     	clear text CGM driver
#		inccgmb     	binary CGM driver
#               incsv           SunView driver
#               incxl           Xlib driver
#               inclvr          sony laser video disk recorder controller
#               incdq           diaquest controller

#	To include specific drivers, add the necessary files to the 
#       DRV_OBJ lines below:
#
#		ps.o		postscript driver
#		tek.o		tektronix terminal driver
#		cgmc.o      	clear text CGM driver
#		cgmb.o      	binary CGM driver
#		igl.o		Silicon Graphics Iris driver
#               sv.o            SunView driver
#		sundriv.o	Sun CGI driver
#               xl.o            Xlib driver
#		$(XWS_OBJ)	X window system driver

#	To include specific controllers, add the necessary files 
#       to the CTR_OBJ lines below:
#
#		tty.o		tty controller (always include this!)
#               lvr.o lvr_io.o  sony laser video disk recorder controller
#               dq.o            diaquest controller          

DRV_FLAGS = -Dincps -Dinctek -Dinccgmc -Dinccgmb 

CTR_FLAGS = -O -Dinctty
CTR_OBJ = tty.o

XWS_OBJ = xws_cla.o xws_color.o xws_delim.o xws_marker.o xws_polygon.o \
	xws_polyline.o xws_setup.o xws_text.o drvcla.o
DRV_OBJ = ps.o tek.o cgmc.o cgmb.o 
#
# These lines should not be modified.
DCGM_PATH = drawcgm/
MACHINE_DEFS = $(DCGM_PATH)unix_defs.h
F_LINK = f77
AR = ar -ru
RANLIB =  echo 'fake-ranlib'


# To include the XWS, XLib drivers, or GPLOTAW (athena widget) interface, 
# uncomment the next line.
#XLIBS = -lXaw -lXmu -lXt -lX11 

# To include the Decwindows interface, uncomment the next line.
#DLIBS = -ldwt -lXt -lX11

# To include the MOTIF driver, uncomment the next line. 
# Note:  The Xt and X11 libraries might be in a different directory on 
#        your system, so check with your system administrator, and make 
#        the appropriate changes.
#MLIBS = -lXm -lXt -lX11

# To build this software on a Sun workstation, uncomment the next lines.
#AR = ar ru
#F_LINK = f77
#RANLIB = ranlib
# To include the Sunview driver and gplottool interface, uncomment SVLIBS.
# To include the Sun CGI B&W driver, uncomment SLIBS.
# NOTE: Uncomment only one of the following two lines.
#SVLIBS = -lsuntool -lsunwindow -lpixrect
#SLIBS = -lcgi -lsunwindow -lpixrect

# To build this software on a Silicon Graphics Iris, uncomment the next lines
#MACHINE_OBJ = ardent.o
#AR = ar rus
#F_LINK = f77
#ILIBS = -lgl -lX11

# To build this software on a IBM RISC System/6000, uncomment the next lines.
#F_LINK = xlf
#RANLIB = ranlib
# To include the IRIS driver (igl) on the IBM RS6000, uncomment the next line.
#ILIBS = -lgl     

# To build this software on an Ardent Titan, uncomment the next lines
#MACHINE_OBJ = ardent.o
#AR = ar rus
#F_LINK = fc

# To build this software on an Ultrix Vaxstation, uncomment the next lines
#AR = ar ru
#F_LINK = f77
#RANLIB = ranlib

# To build this software on an Ultrix Decstation, uncomment the next lines
#AR = ar ru
#F_LINK = f77 -static
#RANLIB = ranlib

# To build this software on a Cray under Unicos, uncomment the next lines
#MACHINE_DEFS = $(DCGM_PATH)unicos_defs.h /usr/include/fortran.h
#MACHINE_OBJ = ardent.o
#F_LINK = segldr
#AR = bld r
#.f.o: ; cf77 -c $*.f
#MACHINE_LIBS = $(XLIBS) -lsc -lnet     

# To build this software on a Cray, delete the entry $(XLIBS) from the
# next line.
LIBS =	$(XLIBS) $(DLIBS) $(MLIBS) $(SLIBS) $(SVLIBS) $(ILIBS) \
	$(MACHINE_LIBS) -lm 

FONTS = hload.o

# To add debugging information, uncomment the next line.
#CFLAGS = -g
# To build Gplot on the IRIS, uncomment the next line.
#CFLAGS = -cckr
CFLAGS =

#  ******************************************************************
#
#   You do not need to modify the rest of the Makefile if you are 
#   using the xl driver for gplotdw, gplotaw and gplotm. 
#   You need to make some changes below to compile gplotaw on the Cray.
#
#  ******************************************************************

GPT_OBJ = gplot.o cgm.o ccgm.o utils.o io.o carray.o devices.o \
	$(FONTS) emul.o

GTEX_OBJ = gtex.o cgm.o utils.o io.o carray.o devices.o \
        $(FONTS) pkras.o emul.o cache.o ccgm.o 

DCGM_OBJ = $(DCGM_PATH)drawcgm.o $(DCGM_PATH)cgmgen.o \
	$(DCGM_PATH)cgm_clip.o $(DCGM_PATH)cgm_textem.o \
	utils.o carray.o io.o $(FONTS) devices.o emul.o

gplot: $(GPT_OBJ) $(CTR_OBJ) $(DRV_OBJ) $(MACHINE_OBJ)
	cc  -o $@ $(GPT_OBJ) $(CTR_OBJ) $(DRV_OBJ) $(MACHINE_OBJ) $(LIBS)

gtex: $(GTEX_OBJ) ps.o tek.o qms.o cgmb.o cgmc.o tty.o
	cc -o $@ $(GTEX_OBJ) ps.o tek.o qms.o cgmb.o cgmc.o tty.o -lm 

gplottool: gplot_suntool.o wint.o ccgm.o cgm.o utils.o io.o carray.o \
	hload.o emul.o sv.o
	cc -o $@ gplot_suntool.o wint.o cgm.o utils.o io.o carray.o ccgm.o \
	hload.o emul.o sv.o $(LIBS)

# To use the xws driver for gplotdw, include $(XWS_OBJ) instead of xl.o
gplotdw: gplotdw.o wint.o cgm.o utils.o io.o carray.o ccgm.o emul.o \
	hload.o xl.o
	cc -o $@ gplotdw.o wint.o cgm.o utils.o io.o carray.o ccgm.o emul.o \
	hload.o xl.o $(LIBS)

# To use the xws driver for gplotaw, include $(XWS_OBJ) instead of xl.o
gplotaw: gplotaw.o wint.o cgm.o ccgm.o utils.o io.o carray.o \
	hload.o emul.o xl.o $(MACHINE_OBJ)
	cc -o $@ gplotaw.o wint.o cgm.o ccgm.o utils.o io.o carray.o \
	hload.o emul.o xl.o $(MACHINE_OBJ) $(LIBS)

# To use the xws driver for gplotm, include $(XWS_OBJ) instead of xl.o
gplotm: gplotm.o wint.o cgm.o utils.o io.o carray.o ccgm.o emul.o \
	hload.o xl.o $(MACHINE_OBJ)
	cc -o $@ gplotm.o wint.o cgm.o utils.o io.o carray.o ccgm.o emul.o \
	hload.o xl.o $(MACHINE_OBJ) $(LIBS)

drawcgm: $(DCGM_PATH)drawcgm.a

tests: $(DCGM_PATH)drawcgm_test $(DCGM_PATH)drawcgm_tst2 \
	$(DCGM_PATH)cgmgen_test $(DCGM_PATH)clip_test 

tar:
	tar -cvhf gplot.tar *.c *.h Makefile README.GPLOT \
          README.DRAWCGM cc.opt *.doc *.com testicon testcursor \
          descrip.mms gplot.hlp gplot.man gplot.txt gpt_commands.cld \
          hfonts.bin *.tex *.cgmb drawcgm/*.c drawcgm/COLORS.DAT \
          drawcgm/Makefile drawcgm/*.h drawcgm/*.f drawcgm/*.doc \
		drawcgm/*.jbl 

clean: 
	rm *.o ; rm drawcgm/*.o

$(DCGM_PATH)drawcgm_test: $(DCGM_PATH)drawcgm_test.o $(DCGM_PATH)drawcgm.a
	$(F_LINK) -o $@ $(DCGM_PATH)drawcgm_test.o $(DCGM_PATH)drawcgm.a \
		$(LIBS)

$(DCGM_PATH)drawcgm_tst2: $(DCGM_PATH)drawcgm_tst2.o $(DCGM_PATH)drawcgm.a
	$(F_LINK) -o $@ $(DCGM_PATH)drawcgm_tst2.o $(DCGM_PATH)drawcgm.a \
		$(LIBS)

$(DCGM_PATH)cgmgen_test: $(DCGM_PATH)cgmgen_test.o $(DCGM_PATH)cgmgen_test2.o \
		$(DCGM_PATH)drawcgm.a
	$(F_LINK) -o $@ $(DCGM_PATH)cgmgen_test.o $(DCGM_PATH)cgmgen_test2.o \
		$(DCGM_PATH)drawcgm.a $(LIBS)

$(DCGM_PATH)clip_test: $(DCGM_PATH)clip_test.o $(DCGM_PATH)drawcgm.a
	$(F_LINK) -o $@ $(DCGM_PATH)clip_test.o $(DCGM_PATH)drawcgm.a \
	$(LIBS)

# drawcgm library
$(DCGM_PATH)drawcgm.a: $(DCGM_OBJ) $(CTR_OBJ) $(DRV_OBJ) $(MACHINE_OBJ)
	$(AR) $@ $(DCGM_OBJ) $(CTR_OBJ) $(DRV_OBJ) $(MACHINE_OBJ)
	$(RANLIB) $@

# controlling GPLOT program
gplot.o: gplot.c defs.h
	cc -c $(CFLAGS) gplot.c

# controlling GPLOT program for the SUNview driver
gplot_suntool.o: gplot_suntool.c defs.h
	cc -c $(CFLAGS) gplot_suntool.c

# controlling GPLOTAW program for Athena Widgets
gplotaw.o: gplotaw.c
# To make gplotaw (xl) compile on the Cray, uncomment the next line
#       cc -c -DR3_INTRINSICS gplotaw.c
# To make gplotaw (xws) compile on the Cray, uncomment the next line
#       cc -c -DR3_INTRINSICS -Dincxws gplotaw.c
# To use the xws driver for gplotaw, uncomment the next line
#	cc -c $(CFLAGS) -Dincxws gplotaw.c

# controlling GPLOTDW program for Decwindows 
gplotdw.o: gplotdw.c defs.h
# To use the xws driver for gplotdw, uncomment the next line
#	cc -c $(CFLAGS) -Dincxws gplotdw.c

# controlling GPLOTM program for Motif 
gplotm.o: gplotm.c defs.h
# To use the xws driver for gplotm, uncomment the next line
#	cc -c $(CFLAGS) -Dincxws gplotm.c

# window interface module
wint.o: wint.c defs.h
	cc -c $(CFLAGS) wint.c

# controlling GTEX program
gtex.o: gtex.c defs.h
	cc -c $(CFLAGS) -Dincps -Dincqms gtex.c

# all of the cgm specific stuff
cgm.o: cgm.c defs.h
	cc -c $(CFLAGS) cgm.c

# all of the clear text cgm specific stuff
ccgm.o: ccgm.c defs.h ccdefs.h
	cc -c $(CFLAGS) ccgm.c 

# utility functions
utils.o: utils.c defs.h
	cc -c $(CFLAGS) -Dinchershey utils.c
# if we wanted PK fonts also, it would be
#       cc -c $(CFLAGS) -Dinchershey -Dincpkras utils.c

# I/O routines
io.o: io.c defs.h
	cc -c $(CFLAGS) $(CTR_FLAGS) io.c   
# To get a gplot usage log file on Unix, uncomment the next line
#	cc -c $(CTR_FLAGS) -DUSAGE_NAME=\"gplot_usage.log\" io.c 

# devices interface
devices.o: devices.c defs.h
	cc -c $(CFLAGS) $(CTR_FLAGS) $(DRV_FLAGS) devices.c

# Cell Array libraries
carray.o: carray.c defs.h
	cc -c $(CFLAGS) carray.c

drvcla.o: drvcla.c defs.h
	cc -c $(CFLAGS) drvcla.c

# Emulation package
emul.o: emul.c defs.h
	cc -c $(CFLAGS) emul.c

# Hershey font support
hload.o: hload.c hload.h defs.h
	cc -c $(CFLAGS) hload.c

# decoding for the PK format files
# if fonts are available we must say here where they are
# in this case they are pk format fonts (only type supported) in
# /usr/staff/andrews/pk/mag/*.pk where mag is the integer magnification
# (1000 implies 10 point fonts at 300 pt/in), e.g.,
# /usr/staff/andrews/pk/1000/cmr10.pk
pkras.o: pkras.c defs.h
	cc -c -DUNIXFONTS=\"/usr/staff/andrews/pk\" pkras.c

#TTY controller
tty.o: tty.c defs.h
	cc -c $(CFLAGS) tty.c

# LVR controller
lvr.o: lvr.c lvr_defines.h defs.h
	cc -c $(CFLAGS) lvr.c
#       to change audit file name, lvr port
#       cc -c -DAUDIT_FILE="lvr.dat" -DDEFAULT_PORT="ttyd2" lvr.c

dq.o: dq.c defs.h
	cc -c $(CFLAGS) dq.c

lvr_io.o: lvr_io.c lvr_defines.h
	cc -c $(CFLAGS) lvr_io.c
#       to turn on debug I/O printout
#       cc -c -DDEBUG_IO lvr_io.c

# Postscript device
ps.o: ps.c defs.h
	cc -c $(CFLAGS) ps.c

# Tektronix devices
tek.o: tek.c defs.h
	cc -c $(CFLAGS) tek.c

# Clear text CGM driver
cgmc.o: cgmc.c defs.h
	cc -c $(CFLAGS) cgmc.c

# Binary CGM driver
cgmb.o: cgmb.c defs.h
	cc -c $(CFLAGS) cgmb.c

# Sun CGI driver
sundriv.o: sundriv.c defs.h
	cc -c $(CFLAGS) sundriv.c

# Silicon Graphics GI driver
igl.o:	igl.c defs.h
	cc -c $(CFLAGS) igl.c

# the sunview driver
sv.o:	sv.c defs.h
	cc -c $(CFLAGS) sv.c

# the Xlib driver
xl.o:	xl.c defs.h
	cc -c $(CFLAGS) xl.c


#-------------- X Window System driver (xws) --------------------------

xws_setup.o:	/usr/include/stdio.h \
		/usr/include/strings.h \
		/usr/include/X11/Intrinsic.h \
		/usr/include/X11/StringDefs.h \
		/usr/include/X11/Xutil.h \
		/usr/include/X11/cursorfont.h \
		defs.h xws_defs.h

xws_delim.o:    /usr/include/stdio.h \
		/usr/include/strings.h \
		/usr/include/X11/Intrinsic.h \
		/usr/include/X11/Xutil.h \
		defs.h xws_defs.h

xws_color.o:	/usr/include/stdio.h \
		/usr/include/math.h \
		/usr/include/X11/Intrinsic.h \
		/usr/include/X11/Xutil.h \
		/usr/include/X11/Xatom.h \
		defs.h xws_defs.h xws_color.h

xws_polyline.o:/usr/include/X11/Intrinsic.h \
		defs.h xws_defs.h

xws_polygon.o:	/usr/include/stdio.h \
		/usr/include/X11/Intrinsic.h \
		defs.h xws_defs.h xws_fill.h

xws_marker.o:	/usr/include/X11/Intrinsic.h \
		defs.h xws_defs.h

xws_text.o:	/usr/include/strings.h \
		/usr/include/X11/Intrinsic.h \
		/usr/include/X11/Xatom.h \
		defs.h xws_defs.h

xws_cla.o:      /usr/include/stdio.h \
		/usr/include/math.h \
		/usr/include/X11/Intrinsic.h \
		defs.h xws_defs.h xws_color.h
#-----------------------------------------------------------------------------
# DrawCGM and CGMGen, and test routines
$(DCGM_PATH)cgmgen.o:	/usr/include/stdio.h \
		/usr/include/string.h \
		$(DCGM_PATH)cgm_clip.h \
		$(DCGM_PATH)cgm_textem.h \
		$(DCGM_PATH)defs.h $(MACHINE_DEFS)
	cd $(DCGM_PATH) ; make cgmgen.o

$(DCGM_PATH)cgm_clip.o: /usr/include/stdio.h \
		$(DCGM_PATH)cgm_clip.h
	cd $(DCGM_PATH) ; make cgm_clip.o

$(DCGM_PATH)cgm_textem.o: /usr/include/stdio.h /usr/include/string.h \
		$(DCGM_PATH)defs.h $(DCGM_PATH)cgm_textem.h
	cd $(DCGM_PATH) ; make cgm_textem.o

$(DCGM_PATH)drawcgm.o:
	cd $(DCGM_PATH) ; make drawcgm.o

$(DCGM_PATH)drawcgm_test.o:
	cd $(DCGM_PATH) ; make drawcgm_test.o

$(DCGM_PATH)drawcgm_tst2.o:
	cd $(DCGM_PATH) ; make drawcgm_tst2.o

$(DCGM_PATH)cgmgen_test.o:
	cd $(DCGM_PATH) ; make cgmgen_test.o

$(DCGM_PATH)clip_test.o: $(MACHINE_DEFS)
	cd $(DCGM_PATH) ; make clip_test.o 

$(DCGM_PATH)cgmgen_test2.o: \
		/usr/include/stdio.h /usr/include/string.h \
		$(DCGM_PATH)defs.h $(MACHINE_DEFS)
	cd $(DCGM_PATH) ; make cgmgen_test2.o

#-----------------------------------------------------------------------------
# Machine-specific modules

ardent.o:	/usr/include/math.h
