#
#  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.
#
LIBDIR		= \"d\:/contrib/lib/calctool\"
HELPNAME	= -DHELPNAME=\"$(LIBDIR)/calctool.hel\"
#-----------------------------------------------------------------------
#  An attempt is now made at using a portable math library. You should
#  carefully setup the following three definitions.
#
#  One of the things this is not the same on all machines is the
#  floating point format. If your machine does *not* use IEEE floating
#  point format, then the following definition needs to be uncommented.
#
#NOIEEE		= -DIEEE
NOIEEE		=
#-----------------------------------------------------------------------
#  Not all machines have the index() string library function. If you
#  don't have this function then you should uncomment the NOINDEX
#  definition below.
#
#NOINDEX	= -DNOINDEX
NOINDEX 	=
#-----------------------------------------------------------------------
#  If you are compiling the MGR version, then the following three
#  definitions should be uncommented.
#
#MGRHOME	= /usr/mgr
#MGRPARAM	= -DMGRHOME=\"$(MGRHOME)\"
MGRPARAM	=
#MGRINCDIR	 = -I$(MGRHOME)/include
MGRINCDIR	=
#-----------------------------------------------------------------------
#  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	 = -DNEWSFILE=\"$(LIBDIR)/calctool.ps\"
NEWSFILE	=
#-----------------------------------------------------------------------
#  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 	 = -DRCNAME=\".calctoolrc\"
RCNAME 	 = -DRCNAME=\"xcalctoo.res\"
#RCNAME		=
#-----------------------------------------------------------------------
#  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
SELTYPE        =
#-----------------------------------------------------------------------
#  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
#  uncomment the other three definitions below, commented out the initial
#  two.
#
LIBNAME 	= libcalctool.a
CALCLIB 	= $(LIBNAME)
#
# Shared library definitions. Uncomment if required.
#LIBNAME	 = libcalctool.so.1.1
#CALCLIB	 = -L. -lcalctool
#SHLIB		 = -pic
SHLIB		=
#-----------------------------------------------------------------------
#  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
SIGRET	       =
#--------------------------------------------------------------------------
#  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
SUN4_KEYBOARD  =
#-------------------------------------------------------------------------
#  If you are running SunOS v3.x, then pr_ttext doesn't exist, and
#  you must uncomment this definition.
#
#TTEXT		= -DNO_PR_TTEXT
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 = -Id:/djgpp/include/X11
# X11LIBDIR	    = -L/djgpp/lib/X11
# X11LIBDIR = -L/djgpp/lib
X11LIBDIR = -Ld:/djgpp/lib
#-------------------------------------------------------------------------
#  If you are compiling the XView version, then the following two lines
#  should be uncommented.
#
# XVIEWINCDIR	   = -I$(OPENWINHOME)/include
XVIEWINCDIR	 =
# XVIEWLIBDIR	   = -L$(OPENWINHOME)/lib
#
#=========================================================================
#
#  Default locations where calctool files will be installed.
#  You might wish to alter these values.
#
BINDIR		= d:/contrib/bin
LIBDIR		= d:/contrib/lib
MANDIR		= d:/contrib/man/man$(MANSECT)
MANSECT 	= 1
#
#  Compilation flags and standard macro definitions.
#
CFLAGS		= -O6 $(HELPNAME) $(NEWSFILE) $(NOIEEE) $(NOINDEX) $(RCNAME) \
		     $(SELTYPE) $(SHLIB) $(SIGRET) $(SUN4_KEYBOARD) \
		     $(TTEXT) $(MGRPARAM) $(MGRINCDIR) $(X11INCDIR) \
		     $(XVIEWINCDIR) 
#
#=========================================================================

BINARIES	= mgr_calctool ps_calctool sv_calctool \
		  tty_calctool xcalctool xv_calctool

CC		= gcc
XE		= .exe

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

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

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

MGRLIBS 	= $(CALCLIB) $(MGRHOME)/lib/libmgr.a -lm
NEWSLIBS	= $(CALCLIB) $$OPENWINHOME/lib/libcps.a -lm
SVIEWLIBS	= $(CALCLIB) -lsuntool -lsunwindow -lpixrect -lm
TTYLIBS 	= $(CALCLIB) -ltermcap -lm
# X11LIBS	  = $(CALCLIB) -lx -lm
X11LIBS 	= $(CALCLIB) -lxt -lxmu -lxext -lx -lsys -lm
XVIEWLIBS	= $(CALCLIB) -lxview -lolgx -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)
		strip xcalctool
		coff2exe xcalctool
		-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 xcalctool$(XE) $(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:; 	grm -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
		shar.script $(SFILES5) > archive.5

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

calctool.o:	calctool.c patchlevel.h color.h calctool.h
display.o:	display.c calctool.h color.h extern.h
functions.o:	functions.c calctool.h color.h extern.h
get.o:		get.c patchlevel.h calctool.h color.h extern.h
graphics.o:	graphics.c calctool.h color.h extern.h
mathlib.o:	mathlib.c mathlib.h calctool.h
mgr.o:		mgr.c calctool.h color.h extern.h
news.o: 	news.c calctool.h color.h extern.h
sunview.o:	sunview.c calctool.h color.h extern.h
tty.o:		tty.c calctool.h color.h extern.h
x11.o:		x11.c calctool.h color.h extern.h
xview.o:	xview.c calctool.h color.h extern.h help.cursor calctool.icon calctool.color.icon
