#----------------------------------------------------------------------#
#
# Makefile for PLPLOT on Unix-type systems.
# Maurice LeBrun, IFS, University of Texas, Mar 1, 1991.
#
# The available output devices are controlled by the PLDEVICES variable,
# a list of defines for the C preprocessor (affecting only dispatch.c).
# When installing plplot you may wish to exclude devices not present
# on your system in order to reduce screen clutter.  The default setting
# is to include all supported devices.
# 
# Other notes:
#
# 1. The font locating code looks in the following places for the fonts:
#
#	current directory
#	$(HOME)/lib/
#	$(PLFONTS)
#	PLFONTDEV1	(/usr/local/lib/)
#	PLFONTDEV2	(/usr/local/lib/plplot/)
#	PLFONTDEV3	(/usr/local/plplot/)
#
#    It is recommended that you store the fonts in a local directory during
#    installation.  When you have verified the package works as expected,
#    simply move the fonts to the appropriate system directory and then all
#    users will have access to the fonts (no recompilation necessary).  If
#    none of the three given hardwired locations is satisfactory, you can
#    change it by passing in your desired location on the build line for
#    plfont.c (done separately for this purpose), e.g.
#
#	FONTFLAG= '-DPLFONTDEV1="/usr/lib/plplot/"'
#
#    (quotes and trailing slash required).
#
#----------------------------------------------------------------------#
# Generic macros for make.  If any of these do not fit your particular
# system, add the appropriate defines in a section for your system.

# Directory structure.  Note most of these aren't used at present.
# See right before rule declaration for plot library specifications.

PLLIB_DIR	= ../PLPLOT/lib
PLFNT_DIR	= ../PLPLOT/fonts
PLLIB_PATH	= $(PLLIB_DIR)/
PLFNT_PATH	= $(PLFNT_DIR)/
FONTFLAG	=

SYS_LIBS=

DBL_FLAG_C	=
DBL_FLAG_F      =
PLLIB_MAIN	= $(PLLIB_PATH)libplplotf.a


PLLIB_C		= $(PLLIB_MAIN)
PLLIB_F		= $(PLLIB_MAIN)
PLLIB_LDC	= $(PLLIB_C)

# Compiler/linker macros.
# These are pretty generic to many unix systems and may work as-is.
# The device list represents all system-independent output devices.
# (i.e. not specifically requiring a particular CPU)

CC	= gcc
CFLAGS	= -c -Dunix -DSTUB_LAU $(DBL_FLAG_C)
F77	= f77
FFLAGS	= -c $(DBL_FLAG_F)
LDC	= $(CC)
LDCFLAGS= -lm -lX11
LDF	= $(F77)
LDFFLAGS= -lm -lX11
LN	= ln -s
TO	= -o
STARTUP =

PLDEVICES = -DPLMETA -DXTERM -DXWIN -DTEK -DDG300 -DPS -DXFIG \
	    -DLJII -DHP7470 -DHP7580 -DIMP

#----------------------------------------------------------------------#
# System specific defines.
#
# Define appropriate STUB_ flag to enable proper C<->Fortran linkage
# See plstubs.h, you may have to modify for your system.
# Current choices:
#	STUB_LAU	lower-case, append underscore
#	STUB_L		lower-case
#
# If no choice is made, stubs remain unaltered (upper case).


#----------------------------------------------------------------------#
#		HP-UX definitions
# CC  = c89
# F77 = f77
# CFLAGS    = -c -O -Dunix -DSTUB_L $(DBL_FLAG_C) -DHPUX -D_HPUX_SOURCE
# FFLAGS    = -c $(DBL_FLAG_F)
# XINCLUDE  = -I/usr/include/X11R5
# LDCFLAGS  = -L/usr/lib/X11R5 -lm -lX11 -g
# LDFFLAGS  = /usr/lib/X11R5/libX11.a -lm -g
# PLDEVICES = -DXTERM -DXWIN -DPLMETA -DTEK -DXFIG -DPS

#----------------------------------------------------------------------#
#	SUNOS definitions (also good for Ultrix 4.3)
#
# CC        = gcc
# F77       = f77
# CFLAGS    = -c -ansi -Dunix -DSTUB_LAU -Dsun $(DBL_FLAG_C) 
# FFLAGS    = -c $(DBL_FLAG_F)
# XINCLUDE  = -I/usr/openwin/include
# LDCFLAGS  = -L/usr/openwin/lib -lm -lX11
# LDFFLAGS  = -L/usr/openwin/lib -lm -lX11
# PLDEVICES = -DPLMETA -DXTERM -DXWIN -DTEK -DPS -DXFIG

#----------------------------------------------------------------------#
#	LINUX definitions 
#
CC        = gcc
F77       = f77
CFLAGS    = -c -Dunix -ansi -O2 $(DBL_FLAG_C)
FFLAGS    = -c $(DBL_FLAG_F)
LDCFLAGS  = -ansi -lm -L/usr/X11R6/lib -lX11
LDFFLAGS  = -lm -L/usr/X11R6/lib -lX11
PLDEVICES = -DPLMETA -DXTERM -DXWIN -DTEK -DPS -DXFIG

#----------------------------------------------------------------------#
# Object file macros
# Main sources.

OBJ =	\
	base.o \
	convert.o \
	genlin.o \
	move.o \
	pladv.o \
	plaxes.o \
	plbeg.o \
	plbin.o \
	plbox.o \
	plbox3.o \
	plccal.o \
	plcntr.o \
	plcol.o \
	plcont.o \
	plconf.o \
	pldtik.o \
	plend.o \
	plenv.o \
	plerr.o \
	plexit.o \
	plfill.o \
	plfont.o \
	plform.o \
	plgra.o \
	plgrid3.o \
	plgspa.o \
	plhist.o \
	pljoin.o \
	pllab.o \
	pllclp.o \
	plline.o \
	plarea.o \
	pllsty.o \
	plmesh.o \
	plmtex.o \
	plnxtv.o \
	plot3d.o \
	plpat.o \
	plpsty.o \
	plptex.o \
	plrot.o \
	plsdef.o \
	plside3.o \
	plstar.o \
	plstyl.o \
	plsvpa.o \
	plsym.o \
	plt3zz.o \
	pltick.o \
	plvasp.o \
	plvpas.o \
	plvpor.o \
	plvsta.o \
	plw3d.o \
	plwid.o \
	plwind.o \
	plxybx.o \
	plzbx.o \
	string.o 

# Drivers

DRIVERS_OBJ = \
	dg300.o \
	dispatch.o \
	hp7470.o \
	hp7580.o \
	impress.o \
	ljii.o \
	next.o \
	ps.o \
	tek.o \
	plmeta.o \
	pdfutils.o \
	xfig.o \
	xwin.o \
	xterm.o

# Support files for font generators.

FONT_OBJ = \
	font01.o \
	font02.o \
	font03.o \
	font04.o \
	font05.o \
	font06.o \
	font07.o \
	font08.o \
	font09.o \
	font10.o \
	font11.o

# C language stubs for linking Plplot to Fortran.

CSTUB_OBJ = \
	long2str.o \
	sc3d.o \
	scconf.o \
	scstubs.o

# Fortran language stubs for linking Plplot to Fortran.

FSTUB_OBJ = \
	islen.o \
	sfstubs.o \
	str2int.o

# System-specific files.

# Amiga

AMIGA_OBJ = \
	aegis.o \
	amiwn.o \
	amipr.o \
	iff.o \
	plmenu.o \
	plprefs.o \
	plsupport.o \
	plwindow.o 

#----------------------------------------------------------------------#
# Rules
# Placed here to ensure all macros are defined.

.c.o:
	$(CC) $(CFLAGS) $*.c
.f.o:
	$(F77) $(FFLAGS) $*.f

#----------------------------------------------------------------------#
# Targets
# The default is to make all the object libraries.
# You can make everything (except demos) by typing 'make everything'
# but you must create the links ('make links') beforehand.

default: libs
everything: libs fonts plrender pltek

libs:	$(PLLIB_MAIN)

#----------------------------------------------------------------------#
# Plot libraries.
#
# Note -- don't use link libraries but ar libraries instead.
# Link libraries cause lots of grief on some systems because often (reason
# unknown) a structure that needs to be initialized is not (happens on 
# A/IX, VMS).  Fortunately package is reasonably small, especially if
# you compile with debugging off.


$(PLLIB_MAIN):	$(OBJ) $(DRIVERS_OBJ) $(CSTUB_OBJ) $(FSTUB_OBJ)
	-rm -f $(PLLIB_MAIN)
	ar q $(PLLIB_MAIN) $(OBJ) $(DRIVERS_OBJ) $(CSTUB_OBJ) $(FSTUB_OBJ)
	ranlib $(PLLIB_MAIN)

#----------------------------------------------------------------------#
# Font files.
# Note 6 font files actually created.
# sfont - standard font
# xfont - extended fonts

fonts:	sfont xfont

sfont:	$(PLFNT_DIR)/plstnd.fnt
xfont:	$(PLFNT_DIR)/plxtnd.fnt

$(PLFNT_DIR)/plstnd.fnt: stndfont.o $(FONT_OBJ)
	$(LDC) -o stndfont stndfont.o $(FONT_OBJ) $(LDCFLAGS)
	-./stndfont
	mv *.fnt $(PLFNT_DIR)

$(PLFNT_DIR)/plxtnd.fnt: xtndfont.o $(FONT_OBJ)
	$(LDC) -o xtndfont xtndfont.o $(FONT_OBJ) $(LDCFLAGS)
	-./xtndfont
	mv *.fnt $(PLFNT_DIR)

#----------------------------------------------------------------------#
# Explicit rules
#
# plfont.c may have font flags passed in

plfont.o:	plfont.c
	$(CC) $(CFLAGS) $(FONTFLAG) plfont.c

# dispatch.c and all the drivers need to know $(PLDEVICES).  The guts
# of the driver routine are not compiled if its name is not present in
# the device list.  You may want to leave drivers for specific systems
# (Amiga, MS-DOS, OS/2, etc) out of this list.

dispatch.o:	dispatch.c
	$(CC) $(CFLAGS) $(PLDEVICES) dispatch.c

dg300.o:	dg300.c
	$(CC) $(CFLAGS) $(PLDEVICES) dg300.c

hp7470.o:	hp7470.c
	$(CC) $(CFLAGS) $(PLDEVICES) hp7470.c

hp7580.o:	hp7580.c
	$(CC) $(CFLAGS) $(PLDEVICES) hp7580.c

impress.o:	impress.c
	$(CC) $(CFLAGS) $(PLDEVICES) impress.c

ljii.o:	ljii.c
	$(CC) $(CFLAGS) $(PLDEVICES) ljii.c

next.o:	next.c
	$(CC) $(CFLAGS) $(PLDEVICES) next.c

ps.o:	ps.c
	$(CC) $(CFLAGS) $(PLDEVICES) ps.c

tek.o:	tek.c
	$(CC) $(CFLAGS) $(PLDEVICES) tek.c

plmeta.o:	plmeta.c
	$(CC) $(CFLAGS) $(PLDEVICES) plmeta.c

xfig.o:	xfig.c
	$(CC) $(CFLAGS) $(PLDEVICES) xfig.c

xwin.o:	xwin.c
	$(CC) $(CFLAGS) $(PLDEVICES) $(XINCLUDE) xwin.c

xterm.o:	xterm.c
	$(CC) $(CFLAGS) $(PLDEVICES) xterm.c

#----------------------------------------------------------------------#
# Utility programs.

pltek:	pltek.o
	$(LDC) $(STARTUP) pltek.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

plrender: plrender.o 
	$(LDC) $(STARTUP) plrender.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

#----------------------------------------------------------------------#
# Example programs, in c.

CDEMOS= x01c x02c x03c x04c x05c x06c x07c x08c x09c x10c x11c \
	x12c x13c x14c tutor

cdemos:	$(CDEMOS)

x01c:	x01c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x01c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x02c:	x02c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x02c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x03c:	x03c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x03c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x04c:	x04c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x04c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x05c:	x05c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x05c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x06c:	x06c.o
	$(LDC) $(STARTUP) x06c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x07c:	x07c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x07c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x08c:	x08c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x08c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x09c:	x09c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x09c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x10c:	x10c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x10c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x11c:	x11c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x11c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x12c:	x12c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x12c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x13c:	x13c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x13c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

x14c:	x14c.o $(PLLIB_C)
	$(LDC) $(STARTUP) x14c.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

tutor:	tutor.o $(PLLIB_C)
	$(LDC) $(STARTUP) tutor.o $(PLLIB_LDC) $(TO) $@ $(LDCFLAGS)

#----------------------------------------------------------------------#
# Example programs, in Fortran.

FDEMOS = x01f x02f x03f x04f x05f x06f x07f x08f x09f x10f x11f x12f x13f

fdemos:	$(FDEMOS)

x01f:	x01f.o $(PLLIB_F)
	$(LDF) x01f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x02f:	x02f.o $(PLLIB_F)
	$(LDF) x02f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x03f:	x03f.o $(PLLIB_F)
	$(LDF) x03f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x04f:	x04f.o $(PLLIB_F)
	$(LDF) x04f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x05f:	x05f.o $(PLLIB_F)
	$(LDF) x05f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x06f:	x06f.o $(PLLIB_F)
	$(LDF) x06f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x07f:	x07f.o $(PLLIB_F)
	$(LDF) x07f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x08f:	x08f.o $(PLLIB_F)
	$(LDF) x08f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x09f:	x09f.o $(PLLIB_F)
	$(LDF) x09f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x10f:	x10f.o $(PLLIB_F)
	$(LDF) x10f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x11f:	x11f.o $(PLLIB_F)
	$(LDF) x11f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x12f:	x12f.o $(PLLIB_F)
	$(LDF) x12f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

x13f:	x13f.o $(PLLIB_F)
	$(LDF) x13f.o $(PLLIB_F) $(TO) $@ $(LDFFLAGS)

#----------------------------------------------------------------------#
# First time only, should be executed from $(PLTMP_DIR)


links:
	$(LN) \
		../src/*.c \
		../src/stubc/*.c \
		../src/stubf/*.f \
		../utils/*.c \
		../fonts/*.c \
		../include/*.h \
		../drivers/*.c \
		../examples/C/*.c \
		../examples/f77/*.f \
		.




clean:
	-rm -f *.o
	-rm -f lib/*.a stndfont xtndfont fonts/*.fnt
	-rm -f $(CDEMOS) $(FDEMOS) *.plm* *.tek*

