#-------------------------------------------------------------------#
#-- Makefile for "perfly" the basic demonstration program         --#
#-------------------------------------------------------------------#
#-- RCS version information                                       --#
#--   $Revision: 1.22 $                                           --#
#--   $Date: 94/03/19 20:36:08 $                                --#
#-------------------------------------------------------------------#

#-------------------------------------------------------------------#
#-- The default make target makes the optimized executable.       --#
#-- The other targets are:                                        --#
#--    build debugging version: dbg (or debug)                    --#
#--    build optimized version: opt (or optimize)                 --#
#--    build dynamic shared object version: dso                   --#
#--    remove all unneeded files after a build: clean             --#
#--    remove all machine generated files: clobber                --#
#-- Common files are in the "../common" directory                 --#
#-- Debug objects are kept in the "DBG" directory.                --#
#-- Optimized objects are kept in the "OPT" directory.            --#
#-- All libraries are kept in this directory.                     --#
#-- The DSO library is made from the optimized objects.           --#
#-------------------------------------------------------------------#

#--
#--	definitions
#--

#-- force Make to use a known shell
SHELL	= /bin/sh

#-- provide a list of alternate locations for file searches
UNIQUE	= .

#-- alternate locatins for included files
INCLUDE	= \
	-I${UNIQUE}

#-- some libraries lack .so versions; so use optimized .a's instead
LACKDSO	= ${LIB:.so=.a}

PERFORMER = \
	-L/usr/lib \
	-lm -lgl_s

#-- IRIX 4.x uses shared gl {gl_s} library {System-V Make lacks #if tests}
LIBGL1	= -lgl.${MAJOR}
LIBGL2	= ${LIBGL1:.4=_s}
LIBGL	= ${LIBGL2:.5=}

#		.ptu (Performer Terrain Utility)
# This loader requires linking with the ImageVision Libraries(IL)!
# Shoud you want to use the Performer Terrain Utility loader (.ptu)
# then install the image library and un-comment the following two
# definitions of LIBIL and LIBCIL.
#LIBIL   = -lil
#LIBCIL  = -lcil

SYSTEM = \
	-lgl \
	-lm

LIBRARIES = \
	${SYSTEM}

#-- select c-compiler options
CFLAGS	= -xansi -D__STDC__ ${INCLUDE} ${COPT}

#-- base name of program
TARGET	= swirly

#-- dummy assignment in case pmake is used
EXT=
LIB=
MAJOR=

#-- object files from which target built {some are in the common directory}
OBJECTS	= \
	swirly.o 

#-- the debug version is in DBG and both opt and dso are in OPT
DIRS = DBG OPT

#--
#--	generic targets
#--

#-- make optimized non-dso version of program by default
default: dbg

#-- synonym targets
debug: dbg

optimize: opt

#-- make dbg and opt versions of program
all: dbg opt

#-- clean up directories {remove junk}
clean:
	rm -f ${OBJECTS}

#-- remove all machine-built files
clobber: clean
	rm -f ${TARGET} ${TARGET}.OPT ${TARGET}.DSO ${TARGET}.DBG 

#--
#--	library targets
#--

#-- make a debugging version of the program
dbg:
	@ echo "\nmaking DBG version of ${TARGET}"
	@ ${MAKE} -f Makefile COPT=-g EXT=DBG LIB=-g.a \
	    MAJOR=`grep "RELEASE=" /usr/include/make/releasedefs | \
	      sed "s/.*=\(.\).*/\1/"` \
	    ${TARGET}.DBG
	rm -f ${TARGET}
	ln -s ${TARGET}.DBG ${TARGET}

#-- make an optimized version of the program
opt:
	@ echo "making OPT version of ${TARGET}"
	@ ${MAKE} -f Makefile COPT=-O2 EXT=OPT LIB=.a \
	    MAJOR=`grep "RELEASE=" /usr/include/make/releasedefs | \
	      sed "s/.*=\(.\).*/\1/"` \
	      ${TARGET}.OPT
	rm -f ${TARGET}
	ln -s ${TARGET}.OPT ${TARGET}

#-- make an optimized version of the program that uses DSOs
dso:	opt
	@ echo "making DSO version of ${TARGET}"
	@ ${MAKE} -f ../Makefile COPT=-O EXT=DSO LIB=.so \
	    MAJOR=`grep "RELEASE=" /usr/include/make/releasedefs | \
	      sed "s/.*=\(.\).*/\1/"` \
	    ${TARGET}.DSO
	rm -f ${TARGET}
	ln -s ${TARGET}.DSO ${TARGET}

#--
#--	internal targets
#--

${TARGET}.${EXT}: ${OBJECTS}
	${CC} ${CFLAGS} -o $@ ${OBJECTS} ${LIBRARIES}

#-- objects are built from either unique or common files
swirly.o:	${UNIQUE}/swirly.c	; ${CC} ${CFLAGS} -c swirly.c

