##############################################################################
#           Makefile for use by LiveData developers                          #
##############################################################################

#
#If the location of the Alias libraries and header files are
# different from $ALIAS_LOCATION, set it here.
#
# ALIAS_LOCATION=/usr/aw/alias
SHELL=/bin/sh

# Note: useMidi* is not included in the EXAMPLES since
# the Makefile cannot tell which irix version we have.
EXAMPLES = \
			polyhist.plugin constrainCV.plugin \
			bake.plugin applyFunction.plugin \
			doChannels.plugin sunShine.plugin \
			resetTransforms.plugin setDevice.plugin  \
			frame.plugin tree.plugin \
			surf.plugin printWorld.plugin \
			sphere.plugin tree2.plugin \
			helix.plugin \
			regpoly.plugin ground.plugin \
			clock.plugin \
			deldag.plugin cont.plugin \
			control.plugin nothing.plugin \
			slider.plugin sball.plugin \
			curve2poly.plugin lpen.plugin \
			cylinder.plugin \
			pickcount.plugin distance.plugin \
			xpaint.plugin \
			intersection.plugin \
			jptCenterPivot.plugin  \
			jptDeletePolys.plugin \
			jptDuplicatePolys.plugin \
			jptExportMTL.plugin \
			jptHideOthers.plugin \
			jptInvertVisible.plugin \
			jptNside.plugin \
			jptPolyData.plugin \
			jptSaveCamera.plugin \
			jptTestRender.plugin \
			waitPix


CC = cc
CPLUSPLUS = CC
INCLUDES = -I. -I$(ALIAS_LOCATION)/ODS/Common/include

#
# Some code is conditionally compiled because it produces a lot of output.
# (see AlPrint.c++ for example) Uncomment the following line if you would
# like to see all the output.
#
# COPIOUS_OUTPUT = -DCOPIOUS_OUTPUT

#
# the -prototypes flag causes a warning message to be displayed on 
# IRIX 5.3 machines, but doesn't affect the plugins in any way.
#
# CFLAGS = -g -xansi -signed -prototypes $(INCLUDES) $(COPIOUS_OUTPUT)
CFLAGS = -g -xansi -signed $(INCLUDES) $(COPIOUS_OUTPUT)
CPLUSPLUSFLAGS = $(CFLAGS)

# 
# The 'libLiveData.so' tells the linker to check the DSO for the Alias api
# symbols.  If you do not specify this, you will see all of the references
# to the Alias api symbols.  This is not harmful, since these symbols are
# resolved when the plugin is loaded.
#
PLUGINFLAGS = -shared -all $(ALIAS_LOCATION)/lib/libLiveData.so
LFLAGS=-r

# Utility files
#	We have chosen to store the scm files in a parallel directory to
# 	the library plugins(which in in ./lib).  The plug_util.o file
#	contains a function for finding the scheme file directory.
UTIL_OBJECT = plugin_util.o

#
# Rules for building.
#
.SUFFIXES: .plugin .o .c++ .c

.c++.plugin: $(UTIL_OBJECT)
	$(CPLUSPLUS) -c $(CPLUSPLUSFLAGS) $<
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$*.plugin $*.o $(UTIL_OBJECT)

.o.plugin: $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$*.plugin $< $(UTIL_OBJECT)

.c++.o:
	$(CPLUSPLUS) -c $(CPLUSPLUSFLAGS) $*.c++

.c.o:
	$(CC) -c $(CFLAGS) $*.c

.o:
	$(CPLUSPLUS) $(LFLAGS) -o $@ $? $(CLIBS)

.c.i:
	 $(CC) -E $(CFLAGS) $*.c | sed -e '/^[    ]*$$/d' > $*.i

.c++.i:
	$(CPLUSPLUS) -E $(CPLUSPLUSFLAGS) $*.c++ | sed -e '/^[  ]*$$/d' > $*.i

#
# Build all the examples.
#
default: $(EXAMPLES)

#
# Copy all the source files for the examples, ignoring errors ( - option )
#
copy:
	- cp $(ALIAS_LOCATION)/ODS/OpenAlias/examples/*.[ch]* .
	- mkdir scm  
	- mkdir lib
	- cp $(ALIAS_LOCATION)/ODS/OpenAlias/examples/scm/* scm
	- cp $(ALIAS_LOCATION)/ODS/Common/examples/*.[ch]* .

#
# Clean up.
#
clean:
	rm *.o
	( cd ./lib ; rm $(EXAMPLES) )

#
# Rules for building specific examples.
#
tree.plugin: tree.o AlVector.o $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ tree.o AlVector.o $(UTIL_OBJECT)

surf.plugin: surf.o AlVector.o $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ surf.o AlVector.o $(UTIL_OBJECT)

printWorld.plugin: printWorld.o AlPrint.o AlPrint2.o $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ printWorld.o AlPrint.o AlPrint2.o $(UTIL_OBJECT)

tree2.plugin: tree2.o AlVector.o $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ tree2.o AlVector.o $(UTIL_OBJECT)

bake.plugin: bake.o WalkTree.o $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ bake.o WalkTree.o $(UTIL_OBJECT)

sunShine.plugin: sunShine.o Tsun.o $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ sunShine.o Tsun.o $(UTIL_OBJECT)

resetTransforms.plugin: resetTransforms.o WalkTree.o $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ resetTransforms.o WalkTree.o $(UTIL_OBJECT)

setDevice.plugin: setDevice.o TdeviceHanger.o $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ setDevice.o TdeviceHanger.o $(UTIL_OBJECT)

useMidi5.3.plugin: useMidi5.3.o TdeviceHanger.o AlHelpMe.o TcapturePerformance.o $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -lmd -o ./lib/$@ useMidi5.3.o TdeviceHanger.o AlHelpMe.o TcapturePerformance.o $(UTIL_OBJECT)

useMidi6.2.plugin: useMidi6.2.o TdeviceHanger.o AlHelpMe.o TcapturePerformance.o $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -lmd -o ./lib/$@ useMidi6.2.o TdeviceHanger.o AlHelpMe.o TcapturePerformance.o $(UTIL_OBJECT)

useMidiOut6.2.plugin: useMidiOut6.2.o TdeviceHanger.o AlHelpMe.o TcapturePerformance.o  $(UTIL_OBJECT)
	$(CPLUSPLUS) $(PLUGINFLAGS) -lmd -o ./lib/$@ useMidiOut6.2.o TdeviceHanger.o AlHelpMe.o TcapturePerformance.o $(UTIL_OBJECT)

jptCenterPivot.plugin: jptCenterPivot.o    
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ jptCenterPivot.o

jptDeletePolys.plugin: jptDeletePolys.o
	 $(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ jptDeletePolys.o

jptDuplicatePolys.plugin: jptDuplicatePolys.o
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ jptDuplicatePolys.o

jptExportMTL.plugin: jptExportMTL.o
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ jptExportMTL.o

jptHideOthers.plugin: jptHideOthers.o
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ jptHideOthers.o

jptInvertVisible.plugin: jptInvertVisible.o
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ jptInvertVisible.o

jptNside.plugin: jptNside.o
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ jptNside.o

jptPolyData.plugin: jptPolyData.o 
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ jptPolyData.o

jptSaveCamera.plugin: jptSaveCamera.o
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ jptSaveCamera.o

jptTestRender.plugin: jptTestRender.o waitPix
	$(CPLUSPLUS) $(PLUGINFLAGS) -o ./lib/$@ jptTestRender.o

waitPix: waitPix.o
	$(CPLUSPLUS) -o ./lib/$@ waitPix.o
