#
#  Makefile for calctool, a calculator program.
#
#  @(#)Makefile 1.16 89/12/21
#
#  Copyright (c) Rich Burridge.
#                Sun Microsystems, Australia - All rights reserved.
#
#  Permission is given to distribute these sources, as long as the
#  copyright messages are not removed, and no monies are exchanged.
#
#  No responsibility is taken for any errors inherent either in the comments
#  or the code of this program, but if reported to me then an attempt will
#  be made to fix them.
#
#======================================================================
#
#  There are various small changes needed when compiling calctool on
#  different systems. These have been isolated here, and should
#  be uncommented if needed.
#
#======================================================================
#
#  Calctool uses an helpfile to supply online help for each key.
#  By default this file is called "calctool.help", and is looked
#  for in every directory on the users search path. You can also
#  override it's location and name at runtime with the -h option.
#  It can also be specified here by uncommenting the following
#  macro definition and setting appropriately.
#
#HELPNAME        = -DHELPGIVEN -DHELPNAME=\"$(LIBDIR)/calctool.help\"
#
#  If you are compiling the MGR version, then the following three
#  definitions should be uncommented.
#
#MGRHOME         = /usr/mgr
#MGRPARAM        = -DMGRHOME=\"$(MGRHOME)\"
#MGRINCDIR       = -I$(MGRHOME)/include
#
#  If you are compiling the NeWS version, then the following definition
#  should be uncommented and set to the default location for the calctool
#  PostScript file, which is downloaded to the NeWS server.
#
#NEWSFILE        = -DNEWSGIVEN -DNEWSFILE=\"$(LIBDIR)/calctool.ps\"
#
#  Calctool loads a run control file when it starts. By default
#  this file is called ".calctoolrc", and is taken from the users
#  home directory. If there is a similar file in the current directory,
#  then these values override the default ones. Its name and location
#  can also be specified here by uncommenting the following macro
#  definition and setting appropriately.
#
#RCNAME          = -DRCGIVEN   -DRCNAME=\".calctoolrc\"
#
#  If you not running under a BSD4.3 derived system, the parameters
#  to the select call are different, and this definition should be
#  uncommented. You need to uncomment this for SunOS v3.x.
#
#SELTYPE        = -DNO_4.3SELECT
#
#  Note that with SunOS v4.x it is possible to create a shared library
#  for the calctool routines. If you wish to do this, then you should
#  change LIBNAME below to libcalctool.so.1.1, and uncomment the SHLIB
#  line.
#
LIBNAME         = libcalctool.a
#
#LIBNAME         = libcalctool.so.1.1
#SHLIB           = -pic
#
#  If you are not running under a BSD4.3 derived system, then the
#  second parameter to a select call is a pointer to an integer function,
#  and this definition needs to be uncommented. You need to uncomment this
#  for SunOS v3.x.
#
#SIGRET         = -DNO_4.3SIGNAL
#
#  Calctool endevours to provide a numeric keypad using the right function
#  keypad. The Sun3 keyboard has a different pad setup to the Sun4 keyboard.
#  If you wish to use these function keys with a Sun4 keyboard, then you
#  need to uncomment the following definition.
#
#SUN4_KEYBOARD  = -DSUN4_KEYBOARD
#
#  If you are running SunOS v3.x, then pr_ttext doesn't exist, and
#  you must uncomment this definition.
#
#TTEXT          = -DNO_PR_TTEXT
#
#  If you are compiling the X11 version and the X11 include and
#  library files are not in a standard place, then the following
#  two lines should be uncommented, and set appropriately.
#
#X11INCDIR         = -I$(XNEWSHOME)/include
#X11LIBDIR         = -L$(XNEWSHOME)/lib
#
#  If you are compiling the XView version, then the following two lines
#  should be uncommented.
#
#XVIEWINCDIR      = -I$(XNEWSHOME)/include
#XVIEWLIBDIR      = -L$(XNEWSHOME)/lib
#
#=========================================================================
#
#  Default locations where calctool files will be installed.
#  You might wish to alter these values.
#
BINDIR          = /usr/local/bin
LIBDIR          = /usr/local/lib
MANDIR          = /usr/man/man$(MANSECT)
MANSECT         = l
#
#  Compilation flags and standard macro definitions.
#
CFLAGS		= -g $(HELPNAME) $(NEWSFILE) $(RCNAME) $(SELTYPE) $(SHLIB) \
		     $(SIGRET) $(SUN4_KEYBOARD) $(TTEXT) \
		     $(MGRPARAM) $(MGRINCDIR) $(X11INCDIR) $(XVIEWINCDIR)
#
#=========================================================================

BINARIES        = mgr_calctool ps_calctool sv_calctool \
		  tty_calctool xcalctool xv_calctool

LIBSRCS         = graphics.c display.c functions.c get.c
LIBOBJS         = graphics.o display.o functions.o get.o
STDSRCS         = calctool.c
STDOBJS         = calctool.o
OBJS            = $(STDOBJS) $(LIBNAME)

GSRCS           = mgr.c news.c sunview.c tty.c x11.c xview.c
HDRS            = calctool.h color.h extern.h
IMAGES          = calctool.icon calctool.color.icon help.cursor
OTHERS          = Makefile README TODO calctool.help calctool.1 \
		  calctool.ps patchlevel.h .calctoolrc

SFILES1         = $(LIBSRCS) $(STDSRCS)
SFILES2         = $(GSRCS)
SFILES3         = $(HDRS) $(IMAGES)
SFILES4         = $(OTHERS)

CALCLIB         = -L. -lcalctool
MGRLIBS         = $(CALCLIB) $(MGRHOME)/lib/libmgr.a -lm
NEWSLIBS        = $(CALCLIB) $$NEWSHOME/lib/libcps.a -lm
SVIEWLIBS       = $(CALCLIB) -lsuntool -lsunwindow -lpixrect -lm
TTYLIBS         = $(CALCLIB) -ltermcap -lm
X11LIBS         = $(CALCLIB) -lX11 -lm
XVIEWLIBS       = $(CALCLIB) -lxview -lX11 -lm

.PRECIOUS:      $(LIBNAME)

help:
		@echo
		@echo "You need to specify one of the following options:"
		@echo
		@echo "  make mgr        - to make the MGR version."
		@echo "  make news       - to make the NeWS version."
		@echo "  make sunview    - to make the SunView version."
		@echo "  make tty        - to make the dumb tty version."
		@echo "  make x11        - to make the X11 version."
		@echo "  make xview      - to make the XView version."
		@echo
		@echo "This should be followed by:"
		@echo
		@echo "  make install"
		@echo "  make clean"
		@echo

all:            $(BINARIES)

mgr:            $(OBJS) mgr.o
		cc -o mgr_calctool $(CFLAGS) $(STDOBJS) mgr.o $(MGRLIBS)
		-cp mgr_calctool calctool

news:           $(OBJS) news.o
		cc -o ps_calctool $(CFLAGS) $(STDOBJS) news.o $(NEWSLIBS)
		-cp ps_calctool calctool

sunview:        $(OBJS) sunview.o
		cc -o sv_calctool $(CFLAGS) $(STDOBJS) sunview.o $(SVIEWLIBS)
		-cp sv_calctool calctool

tty:            $(OBJS) tty.o
		cc -o tty_calctool $(CFLAGS) $(STDOBJS) tty.o $(TTYLIBS)
		-cp tty_calctool calctool

x11:            $(OBJS) x11.o
		cc -o xcalctool $(X11LIBDIR) $(CFLAGS) $(STDOBJS) x11.o \
				$(X11LIBS)
		-cp xcalctool calctool

xview:          $(OBJS) xview.o
		cc -o xv_calctool $(XVIEWLIBDIR) $(CFLAGS) $(STDOBJS) xview.o \
				  $(XVIEWLIBS)
		-cp xv_calctool calctool

libcalctool.a:  $(LIBOBJS)
		ar rv $@ $?
		ranlib $@
                 
#  These are the library creation rules for making the shared calctool
#  library (available with SunOS v4.x).
 
libcalctool.so.1.1:     $(LIBOBJS)
			ld -o libcalctool.so.1.1 -assert pure-text $?

install:
		install -c -m 644 $(LIBNAME) $(LIBDIR)
		install -s -m 751 calctool $(BINDIR)
		install -c -m 644 calctool.help $(LIBDIR)
		install -c -m 644 calctool.ps $(LIBDIR)
		install -c -m 644 calctool.1 $(MANDIR)/calctool.$(MANSECT)

clean:;         rm -f *.o archive.* *~ *.a $(BINARIES) core

lint:;		lint $(CFLAGS) $(STDSRCS) $(LIBSRCS) tty.c $(TTYLIBS)
		lint $(CFLAGS) $(STDSRCS) $(LIBSRCS) sunview.c $(SVIEWLIBS)
		lint $(CFLAGS) $(STDSRCS) $(LIBSRCS) xview.c $(XVIEWLIBS)
		lint $(CFLAGS) $(STDSRCS) $(LIBSRCS) x11.c $(X11LIBS)
		lint $(CFLAGS) $(STDSRCS) $(LIBSRCS) news.c $(NEWSLIBS)
		lint $(CFLAGS) $(STDSRCS) $(LIBSRCS) mgr.c $(MGRLIBS)

shar:;          shar.script $(SFILES1) > archive.1
		shar.script $(SFILES2) > archive.2
		shar.script $(SFILES3) > archive.3
		shar.script $(SFILES4) > archive.4

create:		SCCS
		-sccs create $(STDSRCS) $(GSRCS) $(HDRS) $(IMAGES) $(OTHERS)
SCCS:
		-mkdir SCCS
		chmod 755 SCCS
