#
#  Makefile for popi the graphics editor.
#
#  @(#)Makefile 1.13 89/12/12
#
#  Popi was originally written by Gerard J. Holzmann - AT&T Bell Labs.
#  This version is based on the code in his Prentice Hall book,
#  "Beyond Photography - the digital darkroom," ISBN 0-13-074410-7,
#  which is copyright (c) 1988 by Bell Telephone Laboratories, Inc. 
#
#  Permission is given to distribute these extensions, as long as these
#  introductory messages are not removed, and no monies are exchanged.
#
#  No responsibility is taken for any errors or inaccuracies inherent
#  either to the comments or the code of this program, but if reported
#  (see README file) then an attempt will be made to fix them.
#
#-------------------------------------------------------------------
#  This makefile is extremely ugly, but does work in a multitude
#  of different environments.
#-------------------------------------------------------------------
#
#  There are various small changes needed when compiling popi on
#  different systems. These have been isolated here, and should
#  be uncommented if needed.
#
#  If you are running under BSD unix, uncomment the two lines:
#
SYS		= -DBSD
INSTALL         = install
#
#	Otherwise, define your BSD style install command
#INSTALL        = bsdinstall
#	Or install by hand
#INSTALL	= :
#
#  For System V, uncomment the next line.
#
#SYS		= -DSYSV
#
#  If you not running under a BSD4.[12] 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
#
#  Most existing versions of unix use a pointer to a function
#  returning an integer as the return type of signal(). Newer systems
#  use pointer to function returning void. If this is the case,
#  uncomment the next line.
#
#SIGRET         = -DSIGRET=void
#
#  If you are running X11R2 on a Sun4, then the popi executable
#  needs to be statically linked to work correctly, so the following
#  line should be uncommented.
#
#LDX11FLAGS     = -Bstatic
#
#  The X11 include directory should be specified here if required
#
#X11HOME		= /home/openwin
#X11INCDIR	= -I$(X11HOME)/include
#
#  If you are compiling the MGR version, then the following
#  definitions should be uncommented.
#
#MGRHOME        = /usr/mgr
#MGRPARAM        = -DMGRHOME=\"$(MGRHOME)\"
#MGRINCDIR       = -I$(MGRHOME)/include
#
#  If you are compiling the NeWS version, then you need to uncomment
#  the following line.
#
#NEWSFILE        = -DNEWSGIVEN -DNEWSFILE=\"$(LIBDIR)/popi.ps\"
#
#  If you are compiling the XView version, then the following two lines
#  should be uncommented.
#
#XVIEWINCDIR      = -I$(XVIEWHOME)/include
#XVIEWLIBDIR      = -L$(XVIEWHOME)/lib
#
#  If you are running on a Sun and you have some kind of floating
#  point co-processor, then uncomment this line, and set accordingly.
#
#SUNFLOAT             = -fswitch
#
#  If you are running Dynix (sequent) compatible parallel make,
#  uncomment the following line.
#
#P		= &
#
#  If you are running on a sequent and want to use the
#  parallel programming library, uncomment the following 2 lines.
#
#PLIB		= -lpps
#PFLAGS		= -Y -DSEQPAR
#
#
#  Name of your favourite C compiler
#	Standard unix
CC		= cc
#	Gnu C
#CC		= gcc
#	Borland's Turbo C
#CC		= tcc
#	Microsoft C
#CC		= cl
#	Microsoft Quick C
#CC		= qcl
#	Mix Power C
#CC		= pc
#	Lattice C for Amiga or DOS
#CC		= lc
#
#  Suffix used for object files
#	Normal
O		= o
#	Dos
#O		= obj
#	Mix Power C
#O		= mix
#
#  Suffix (including the `.') for executable files
#	Normal
E		=
#	Dos
#E		= .exe
#
#  Compiler option for specifying exectable name
#	Unix (must have a space after the `-o')
EXE		= -o $(NOTHING)
#	Turbo C (must not have a trailing space)
#EXE		= -e
#
#  Your system remove command
#	Standard unix
RM		= rm -f
#	Dos
#RM		= del
#	Amiga
#RM		= delete
#
#  Your system copy command
#	Standard unix
CP		= cp
#	DOS and Amiga
#CP		= copy
#
#
#  Specify any flags to be used with your C compiler.
#	Standard unix
OCFLAGS		= -g
#	Turbo C (also set BGIPATH to the location of your .bgi files)
#OCFLAGS		= -DBGIPATH=c:\\util\\tc\\bgi -G -O -Z -d -v -w
#	Microsoft Quick C
#OCFLAGS		= -W3 -AS
#	Mix Power C
#OCFLAGS		= -ms
#	Lattice C for Amiga (ansi compliance, winge, fast FP).
#OCFLAGS		= -caf -ff
#
#  Specify any extra flags to be passed to the linker
OLDFLAGS	=
#
#-------------------------------------------------------------------

BINARIES	= apollo_popi atari_popi mgr_popi null_popi ps_popi sv_popi \
		  x11_popi xv_popi
BINDIR          = /usr/local/bin
LIBDIR          = /usr/local/lib
MANDIR          = /usr/man/man$(MANSECT)
MANSECT         = l
CFLAGS		= $(OCFLAGS) $(SYS) $(SELTYPE) $(SIGRET) $(X11INCDIR) \
		    $(NEWSFILE) $(MGRPARAM) $(MGRINCDIR) \
		    $(XVIEWINCDIR) $(PFLAGS)
LDFLAGS         = $(OLDFLAGS) $(LDX11FLAGS)
HDRS		= popi.h graphics.h
IMAGES          = popi.icon
STDOBJS		= expr.$(O) io.$(O) lex.$(O) main.$(O) polar.$(O) run.$(O) \
		  special.$(O)
LIBS		= -lm $(PLIB)
STDSRCS		= expr.c io.c lex.c main.c polar.c run.c special.c
OTHERSRCS1	= amiga.c apollo.c atariterm.c graphics.c kerterm.c mgr.c
OTHERSRCS2	= news.c nulldev.c ibmpc.c sunview.c x11.c xview.c popi.ps

OTHERSRCS       = $(OTHERSRCS1) $(OTHERSRCS2)
TARGET		= popi$(E)

AMIGALIBS	=
AMIGAOBJS	= $(STDOBJS) amiga.o
AMIGASRCS	= $(STDSRCS) amiga.c

APOLLOLIBS	= $(LIBS)
APOLLOOBJS	= $(STDOBJS) apollo.$(O)
APOLLOSRCS	= $(STDSRCS) apollo.c

ATARILIBS       = $(LIBS)
ATARIOBJS       = $(STDOBJS) atariterm.$(O)
ATARISRCS       = $(STDSRCS) atariterm.c

IBMPCLIBS	= $(LIBS)
IBMPCOBJS	= $(STDOBJS) ibmpc.$(O)
IBMPCSRCS	= $(STDSRCS) ibmpc.c

KERLIBS         = $(LIBS)
KEROBJS         = $(STDOBJS) kerterm.$(O)
KERSRCS         = $(STDSRCS) kerterm.c

MGRLIBS         = $(LIBS) $(MGRHOME)/lib/libmgr.a
MGROBJS         = $(STDOBJS) graphics.$(O) mgr.$(O)
MGRSRCS         = $(STDSRCS) graphics.c mgr.c
 
NULLLIBS        = $(LIBS)
NULLOBJS        = $(STDOBJS) nulldev.$(O)
NULLSRCS        = $(STDSRCS) nulldev.c

PSLIBS          = $(LIBS) $$NEWSHOME/lib/libcps.a
PSOBJS          = $(STDOBJS) graphics.$(O) news.$(O)
PSSRCS          = $(STDSRCS) graphics.c news.c
 
SVLIBS          = $(LIBS) -lsuntool -lsunwindow -lpixrect
SVOBJS          = $(STDOBJS) graphics.$(O) sunview.$(O)
SVSRCS          = $(STDSRCS) graphics.c sunview.c
 
X11LIBS         = $(LIBS) $(X11HOME)/lib/libX11.a
X11OBJS         = $(STDOBJS) graphics.$(O) x11.$(O)
X11SRCS         = $(STDSRCS) graphics.c x11.c
 
XVLIBS          = $(LIBS) -lpixrect -lxview -lX11
XVOBJS          = $(STDOBJS) graphics.$(O) xview.$(O)
XVSRCS          = $(STDSRCS) graphics.c xview.c
 
OTHERS          = Makefile README TODO popi.1 patchlevel.h \
		  popi.msc popi.prj powerc.prj
SRCS            = $(STDSRCS) $(OTHERSRCS)
ALL		= $(SRCS) $(IMAGES) $(HDRS) $(OTHERS)

help:   
		@echo
		@echo "You need to specify one of the following options:"
		@echo
		@echo make amiga      - to make the Amiga version.
		@echo make apollo     - to make the Apollo version.
		@echo make atari      - to make the Atari version.
		@echo make ibmpc      - to make the PC version.
		@echo make kermit     - to make the Kermit version.
		@echo make mgr        - to make the MGR version.
		@echo make news       - to make the NeWS version.
		@echo make nulldev    - to make the null device version.
		@echo make sunview    - to make the SunView version.
		@echo make x11        - to make the X11 version.
		@echo make xview      - to make the XView version.
		@echo

all:		$(BINARIES)

amiga:		amiga_popi
		-delete popi
		rename amiga_popi popi

apollo:		apollo_popi$(E)
		$(CP) apollo_popi$(E) $(TARGET)

atari:          atari_popi$(E)
		$(CP) atari_popi$(E) $(TARGET)

ibmpc:		ibmpc_popi$(E)
		$(CP) ibmpc_popi$(E) $(TARGET)

kermit:         ker_popi$(E)
		$(CP) ker_popi$(E) $(TARGET)

mgr:            mgr_popi$(E)
		$(CP) mgr_popi$(E) $(TARGET)

news:           ps_popi$(E)
		$(CP) ps_popi$(E) $(TARGET)

nulldev:        null_popi$(E)
		$(CP) null_popi$(E) $(TARGET)

sunview:        sv_popi$(E)
		$(CP) sv_popi$(E) $(TARGET)

x11:            x11_popi$(E)
		$(CP) x11_popi$(E) $(TARGET)

xview:          xv_popi$(E)
		$(CP) xv_popi$(E) $(TARGET)

amiga_popi:$(P)   $(AMIGAOBJS)
		blink from lib:c.o $(AMIGAOBJS) to amiga_popi lib lib:lcmffp.lib lib:lc.lib lib:amiga.lib sc sd nd

apollo_popi$(E):	$(APOLLOOBJS)
		$(CC) $(EXE)apollo_popi $(LDFLAGS) $(APOLLOOBJS) $(APOLLOLIBS)

atari_popi$(E):$(P)   $(ATARIOBJS)
		$(CC) $(EXE)atari_popi $(LDFLAGS) $(ATARIOBJS) $(ATARILIBS)

ibmpc_popi$(E):	$(IBMPCOBJS)
		$(CC) $(EXE)ibmpc_popi $(LDFLAGS) $(IBMPCOBJS) $(IBMPCLIBS)

ker_popi$(E):$(P)     $(KEROBJS)
		$(CC) $(EXE)ker_popi $(LDFLAGS) $(KEROBJS) $(KERLIBS)

mgr_popi$(E):$(P)     $(MGROBJS)
		$(CC) $(EXE)mgr_popi $(LDFLAGS) $(MGROBJS) $(MGRLIBS)
        
null_popi$(E):$(P)    $(NULLOBJS)
		$(CC) $(EXE)null_popi $(LDFLAGS) $(NULLOBJS) $(NULLLIBS)

ps_popi$(E):$(P)      $(PSOBJS)
		$(CC) $(EXE)ps_popi $(LDFLAGS) $(PSOBJS) $(PSLIBS)
        
sv_popi$(E):      $(SVOBJS)
		$(CC) $(EXE)sv_popi $(LDFLAGS) $(SVOBJS) $(SVLIBS)
        
x11_popi$(E):$(P)     $(X11OBJS)
		$(CC) $(LDX11FLAGS) $(EXE)x11_popi $(LDFLAGS) $(X11OBJS) $(X11LIBS)
 
xv_popi$(E):$(P)      $(XVOBJS)
		$(CC) $(EXE)xv_popi $(LDFLAGS) $(XVIEWLIBDIR) $(XVOBJS) $(XVLIBS)

install:        $(BINARIES)
		$(INSTALL) -s -m 751 popi $(BINDIR)
		$(INSTALL) -c -m 644 popi.ps $(LIBDIR)
		$(INSTALL) -c -m 644 popi.1 $(MANDIR)/popi.$(MANSECT)

backup:
		$(CP) $(ALL) backdir

clean:
		$(RM) *.$(O)
		$(RM) popi$(E)
		$(RM) $(BINARIES) core popi.tar popi.tar.Z

lint:
		lint $(OTHERFLAGS) $(SVSRCS) $(SVLIBS)
		lint $(OTHERFLAGS) $(ATARISRCS) $(ATARILIBS)
		lint $(OTHERFLAGS) $(NULLSRCS) $(NULLLIBS)
		lint $(OTHERFLAGS) $(MGRSRCS)
		lint $(OTHERFLAGS) $(PSSRCS)
		lint $(OTHERFLAGS) $(X11SRCS) $(X11LIBS)
		lint $(OTHERFLAGS) $(XVSRCS)

shar:
		shar.script $(STDSRCS) > archive.1
		shar.script $(OTHERSRCS1) > archive.2
		shar.script $(OTHERSRCS2) > archive.3
		shar.script $(IMAGES) $(HDRS) $(OTHERS) > archive.4

tape:
		tar cvbf 126 /dev/rst0 $(ALL)

download:	popi.arc
		sb -a popi.arc

tar:		popi.tar

popi.tar:	$(ALL)
		tar cvf popi.tar $(ALL)

arc: popi.arc

popi.arc:	$(ALL)
		arc a popi.arc $?

zoo: popi.zoo

popi.zoo:	$(ALL)
		zoo -add popi.zoo $?

create:         SCCS
		-sccs create $(SRCS) $(HDRS) $(IMAGES) $(OTHERS)

SCCS:
		mkdir SCCS
		chmod 755 SCCS

apollo.$(O):	apollo.c $(HDRS)
atariterm.$(O):	atariterm.c $(HDRS)
expr.$(O):	expr.c $(HDRS)
graphics.$(O):	graphics.c $(HDRS)
io.$(O):	io.c $(HDRS)
kerterm.$(O):	kerterm.c $(HDRS)
lex.$(O):	lex.c $(HDRS)
main.$(O):	main.c $(HDRS) patchlevel.h
mgr.$(O):       mgr.c $(HDRS) $(IMAGES)
news.$(O):	news.c $(HDRS) $(IMAGES)
nulldev.$(O):	nulldev.c $(HDRS)
run.$(O):	run.c $(HDRS)
special.$(O):	special.c $(HDRS)
sunview.$(O):	sunview.c $(HDRS) $(IMAGES)
x11.$(O):	x11.c $(HDRS) $(IMAGES)
xview.$(O):	xview.c $(HDRS) $(IMAGES)
