########################################################################
#                             Makefile                                 #
#                                                                      #
#              Michael Hughes, Discreet Logic,  (c) 1994               #
#                                                                      #
#                                                                      #
# This Makefile is designed to compile and link Spark code in order to #
# load sparks into the FLINT/FLAME environment. Read the comments      #
# carefully and it should be very clear how to compile and use         #
# Sparks.                                                              #
#                                                                      #
########################################################################

SHELL = /bin/sh

#
# The symbol SPARKSOURCE indicates where the source code for the Sparks 
# resides. It is currently set to the local directory in which this
# Makefile resides. Should you decide to usr source code to a different
# directory, update this symbol accordingly.
#
SPARKSOURCE = .

#
# The symbol SPARKDESTINATION indicates the directory where the linked 
# (i.e. loadable) sparks will be output. This directory should match
# the directory associated to the 'Spark' token in your configuration
# file so that FLAME/FLINT can locate the Sparks. It is assumed for the
# moment that this Makefile resides in the correct directory (hence the .)
#
# *** NOTE ***
# You must also create a 'setups' directory within the SPARKDESTINATION
# directory. This is where FLINT/FLAME will write Spark setup files that
# can be loaded for future use.
#
SPARKDESTINATION = .

#
# The SPARK_CFILES list indicates which Sparks are to be compiled. Any
# new Sparks that are developed should be added to this list. Please
# note that there must be a 'Tab' character as the first character on
# each line.
#
SPARK_CFILES = \
	sparkAverage1.c \
	sparkAverage2.c \
	sparkBlend.c \
	sparkComposite.c \
	sparkImage.c \
	sparkInvert.c \
	sparkKey.c \
	sparkReverse.c \
	sparkWipe.c \
	$(END_OF_LIST)

#
# Please don't touch these two lines
#
OFILES = $(SPARK_CFILES:.c=.o)
SFILES = $(SPARK_CFILES:.c=.spark)

#
# Standard Silicon Graphics Libraries
# Should you require any SGI supplied libraries that are not already in
# this list, add them here, but be careful as the ordering is significant.
# For more information on SGI supplied libraries, please consult the
# documentation (online 'man' or hard copy manuals) that came with your
# system.
#
SGI_STD_LIBS = \
            -ldl \
            -lXm \
            -lXt \
            -lXext \
            -lX11 \
            -lds \
            -lsphere \
            -lfm \
            -lgl \
            -lfastm \
            -lm \
            -lmpc \
            -lmalloc \
            -lC

#
# The LDFLAGS provides a mechanism for you to link your spark with
# libraries that you develop yourself. Add any library names you require,
# but make sure to include a full path name.
#
LDFLAGS =   -s \
            -shared \
	    -check_registry /usr/lib/so_locations \
            $(SGI_STD_LIBS)

#
# CFLAGS lets you specify compiling options for your sparks.
#
CFLAGS = -O2

#
# The following script determines whether or not Sparks can be compiled
# under the operating system that your system is currently running. If
# you do not have IRIX 5.2 (or greater for future releases), then you must
# upgrade your system before Sparks can be used within your FLAME/FLINT
# environment.
#
default all:
	@set -a *; \
	if (test $(OBJFORMAT) = ELF) then { \
		make sparks_target; \
	} \
	else { \
		echo ""; \
		echo "ERROR --> This Operating System does not support Sparks"; \
		echo ""; \
		make no_sparks_target; \
	} fi

sparks_target:    $(SFILES)

no_sparks_target: 

#
# These script lines perform the actual compilation and linking of the
# Sparks themselves. The creation of a Spark is actually twofold. The
# first step is to compile the '.c' sources into '.o' object code. The
# object code is then linked '-shared' to produce a '.spark' file that
# is the object that FLAME/FLINT loads. The loadable '.spark' file is
# what SGI terms a DSO (dynamic shared object). Please consult your SGI
# documentation for more info regarding shared objects (use 'man dso').
#
$(SFILES) : $(OFILES)
$(OFILES) :
	@echo ""
	@echo "MAKING SPARK ..."
	cc $(CFLAGS) -c $(SPARKSOURCE)/$*.c -o $(SPARKSOURCE)/$*.o
	ld $(LDFLAGS) $(SPARKSOURCE)/$*.o -o $(SPARKDESTINATION)/$*.spark

# DO NOT DELETE THIS LINE

#
# Dependencies - The following lines provide you a simple way of indicating
#                the conditions under which the individual Sparks are
#                recompiled and relinked. The dependency line indicates that
#                the spark is remade if the second file on the line is more
#                recent.
#
sparkAverage1.o: 	sparkAverage1.c
sparkAverage1.o: 	spark.h
sparkAverage2.o: 	sparkAverage2.c
sparkAverage2.o: 	spark.h
sparkBlend.o: 		sparkBlend.c
sparkBlend.o: 		spark.h
sparkComposite.o:	sparkComposite.c
sparkComposite.o:	spark.h
sparkImage.o:		sparkImage.c
sparkImage.o:		spark.h
sparkInvert.o:		sparkInvert.c
sparkInvert.o:		spark.h
sparkKey.o:		sparkKey.c
sparkKey.o:		spark.h
sparkReverse.o:		sparkReverse.c
sparkReverse.o:		spark.h
sparkWipe.o:            sparkWipe.c
sparkWipe.o:            spark.h
