##================================================================
## Makefile rules for building EQUINOX-3D plugins
##
## AUTHOR:  Gabor Nagy
## DATE:    2026-Aug-10 17:54:58
##
## Copyright (C) 1996-2026 By Gabor Nagy. All rights reserved.
##================================================================

# Create image with alpha from RGBA image + shadow image (result = imageRGB * A + backgroundRGB * (1.0-A)):
#setenv IMAGE  a.sgi;setenv SHADOW a-shadow.sgi;rm t/*
# Old kind: (for simple alpha-blending)
#ispl -v -i $IMAGE -oiA t/.sgi
#icm -v -M -i $SHADOW -i t/$IMAGE  -io -o t/.sgi
#icm -v -iRGB $IMAGE -iA t/$SHADOW -o t/.sgi

# New kind: alpha is light visibility (result = imageRGB + backgroundRGB * A)
# this is more correct and it preserves colors better in the background.
#ispl -v -i $IMAGE -oA t/.sgi
#icm -v  -M  -i $IMAGE   -i t/$IMAGE  -o t/RGB.sgi
#icm -v  -S  -i $SHADOW  -i t/$IMAGE  -o t/A.sgi
#icm -v  -iRGB t/RGB.sgi  -iA t/A.sgi  -o t/A.sgi

SSHELL = sh

EICONH_GAIN = 1.4

CC += $(ARCH_FLAG)

ICON_TMP_DIR = $(ICON_DIR)/tmp

Plugins all:	$(ICON_DIR) $(ICON_TMP_DIR)\
		$(OBJ_DIRS)\
		$(DSO_DIRS)\
		$(TARGETS)
		$(LC) $(SRC_FILES)



$(DSO_DIR)/Plugins.list:	Plugins.list
				cp -p Plugins.list $@


PTX_DIR = ptx

GPURT_OptiX6_OBJ += $(OBJ_DIR)/Rendering/GPURT-OptiX6.o $(OBJ_DIR)/Rendering/GPURTCode.o $(OBJ_DIR)/Rendering/RayTracerGUI.o $(OBJ_DIR)/Rendering/BloomGUI.o
GPURT_OptiX6_OBJ += $(OBJ_DIR)/Rendering/Constant_core.cuo
GPURT_OptiX6_OBJ += $(OBJ_DIR)/Rendering/Lambert_core.cuo $(ICON_DIR)/RT.o

GPURT_PTX_OBJS += $(OBJ_DIR)/Rendering/GPURT/ptx/Cameras/Perspective.o
GPURT_PTX_OBJS += $(OBJ_DIR)/Rendering/GPURT/ptx/Geometry/GeometryTriangles.o
GPURT_PTX_OBJS += $(OBJ_DIR)/Rendering/GPURT/ptx/Geometry/TriangleMesh.o
GPURT_PTX_OBJS += $(OBJ_DIR)/Rendering/GPURT/ptx/Shaders/Constant.o
GPURT_PTX_OBJS += $(OBJ_DIR)/Rendering/GPURT/ptx/Shaders/Lambert.o
GPURT_PTX_OBJS += $(OBJ_DIR)/Rendering/GPURT/ptx/Shaders/Phong.o
GPURT_PTX_OBJS += $(OBJ_DIR)/Rendering/GPURT/ptx/Shaders/Blinn.o
GPURT_PTX_OBJS += $(OBJ_DIR)/Rendering/GPURT/ptx/Shaders/Metal.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/cuda/include/vector_types.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/cuda/include/vector_functions.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optix.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optix_device.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optix_math.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optix_sizet.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/internal/optix_datatypes.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/internal/optix_declarations.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/internal/optix_defines.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/internal/optix_internal.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optixu/optixu_math.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optixu/optixu_math_namespace.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optixu/optixu_vector_functions.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optixu/optixu_vector_types.h.o
GPURT_HEADER_OBJS += $(OBJ_DIR)/Rendering/GPURT/src/include/GPURTTypes.h.o

GPURT_OptiX6_DEP += $(GPURT_OptiX6_OBJ)
GPURT_OptiX6_DEP += $(GPURT_PTX_OBJS)
GPURT_OptiX6_DEP += $(PTX_DIR)/Shaders
GPURT_OptiX6_DEP += $(PTX_DIR)/Shaders/Constant.ptx
GPURT_OptiX6_DEP += $(PTX_DIR)/Shaders/Lambert.ptx
GPURT_OptiX6_DEP += $(PTX_DIR)/Shaders/Phong.ptx
GPURT_OptiX6_DEP += $(PTX_DIR)/Shaders/Blinn.ptx
GPURT_OptiX6_DEP += $(PTX_DIR)/Shaders/Metal.ptx
GPURT_OptiX6_DEP += $(OBJ_DIR)/Rendering/GPURT/cuda/include
GPURT_OptiX6_DEP += $(OBJ_DIR)/Rendering/GPURT/OptiX/include
GPURT_OptiX6_DEP += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/internal
GPURT_OptiX6_DEP += $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optixu
GPURT_OptiX6_DEP += $(OBJ_DIR)/Rendering/GPURT/src/include
GPURT_OptiX6_DEP += $(GPURT_HEADER_OBJS)

GPURT_OptiX8_OBJ += $(OBJ_DIR)/Rendering/GPURT-OptiX8.o $(OBJ_DIR)/Rendering/GPURTCode.o $(OBJ_DIR)/Rendering/RayTracerGUI.o $(OBJ_DIR)/Rendering/BloomGUI.o

OBJ_FILES += $(GPURT_OptiX6_OBJ)
OBJ_FILES += $(GPURT_OptiX8_OBJ)


clean:
		rm -rf so_locations $(TARGETS) core $(OBJ_FILES)

TAG_FILES =	$(PWD)/*.[ch] $(PWD)/*/*.[ch] $(PWD)/*/*/*.[ch]
tags:		$(TAG_FILES)
		ctags -f tags $(TAG_FILES)



## Rules to create the necessary directories if they don't exist yet
##
$(OBJ_DIRS) $(ICON_DIR) $(ICON_TMP_DIR) $(ICON_TMP_DIR)/IMon $(DSO_DIRS):
				mkdir -p $@


##================================================
## General
##================================================
$(OBJ_DIR)/%.o:			%.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@


## Build rules for the individual plugins
##
$(DSO_DIR)/AppLink$(DSO_SUFFIX):		$(OBJ_DIR)/AppLink.o
				$(DSO_LD) $(OBJ_DIR)/AppLink.o $(PLFLAGS) -o $@


##
## Boolean
##
$(DSO_DIR)/Boolean$(DSO_SUFFIX):		$(OBJ_DIR)/Boolean.o
				$(DSO_LD) $(OBJ_DIR)/Boolean.o $(PLFLAGS) -o $@


##
## Edit
##

$(DSO_DIR)/Edit$(DSO_SUFFIX):		$(OBJ_DIR)/Edit.o $(OBJ_DIR)/EditObject.o $(OBJ_DIR)/EditMesh.o $(OBJ_DIR)/VertexOps.o
				$(DSO_LD) $(OBJ_DIR)/Edit.o $(OBJ_DIR)/EditObject.o $(OBJ_DIR)/EditMesh.o $(OBJ_DIR)/VertexOps.o $(PLFLAGS) -o $@


##
## Camera
##
$(DSO_DIR)/Camera$(DSO_SUFFIX):		$(OBJ_DIR)/Camera.o
				$(DSO_LD) $(OBJ_DIR)/Camera.o $(PLFLAGS) -o $@

##
## Clone
##
$(DSO_DIR)/Clone$(DSO_SUFFIX):		$(OBJ_DIR)/Duplicate.o $(OBJ_DIR)/DuplicateWithRepeat.o $(ICON_DIR)/Duplicate.o
				$(DSO_LD) $(OBJ_DIR)/Duplicate.o $(OBJ_DIR)/DuplicateWithRepeat.o $(ICON_DIR)/Duplicate.o $(PLFLAGS) -o $@

$(OBJ_DIR)/DuplicateWithRepeat.o:       DuplicateWithRepeat.c $< $(INCLUDES) ControlSpline.h PathNormalGUI.ci PathNormalGUI.h
	$(CC) $(CFLAGS) $< -o $@


## Rules to build the icons
##
$(ICON_DIR)/Duplicate.o:	Icons/images/Duplicate.sgi $(IconRules.make)
				$(iS) -s $(EICONBIG_SIZEX) $(EICONBIG_SIZEY) Icons/images/Duplicate.sgi $(ICON_TMP_DIR)/DuplicateBig.c
				$(CC) -c $(ICON_TMP_DIR)/DuplicateBig.c -o $@;rm -f $(ICON_TMP_DIR)/DuplicateBig.c



##
## Layers
##
$(DSO_DIR)/Layers$(DSO_SUFFIX):		$(OBJ_DIR)/Layers.o
				$(DSO_LD) $(OBJ_DIR)/Layers.o $(PLFLAGS) -o $@


##
## Mirror
##
$(DSO_DIR)/Mirror$(DSO_SUFFIX):		$(OBJ_DIR)/Mirror.o\
				$(ICON_DIR)/Mirror.o
				$(DSO_LD) $(OBJ_DIR)/Mirror.o $(ICON_DIR)/Mirror.o $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/Mirror.o:		Icons/images/Mirror.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
				$(SSHELL) scripts/iconproc1-3auto.sh Mirror "$(CC)" $@ $(ICON_TMP_DIR)


$(OBJ_DIR)/Cleanup.o:	Cleanup.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Cleanup$(DSO_SUFFIX):		$(OBJ_DIR)/Cleanup.o
				$(DSO_LD) $(OBJ_DIR)/Cleanup.o $(PLFLAGS) -o $@

#touch Icons/images/IMon/orig/IMon.sgi
$(ICON_DIR)/IMon.o:  $(ICON_TMP_DIR)/IMon Icons/images/IMon/*.sgi Icons/images/IMon/orig/IMon*.sgi
				icr $(EITHREADS) -v -T -c -3 -711 0 0  Icons/images/IMon/orig/IMon.sgi $(ICON_TMP_DIR)/IMon/IMon_Mouse.sgi
				icr $(EITHREADS) -v -T -c -3 -711 0 0  Icons/images/IMon/orig/IMon_Mouse*.sgi $(ICON_TMP_DIR)/IMon/.sgi
				icr $(EITHREADS) -v -T -c -165 -538 0 0  Icons/images/IMon/orig/IMon.sgi $(ICON_TMP_DIR)/IMon/IMon_Shift.sgi
				icr $(EITHREADS) -v -T -c -165 -538 0 0  Icons/images/IMon/orig/IMonActive.sgi $(ICON_TMP_DIR)/IMon/IMon_ShiftPressed.sgi
				icr $(EITHREADS) -v -T -c -339 -396 0 0  Icons/images/IMon/orig/IMon.sgi $(ICON_TMP_DIR)/IMon/IMon_Ctrl.sgi
				icr $(EITHREADS) -v -T -c -339 -396 0 0  Icons/images/IMon/orig/IMonActive.sgi $(ICON_TMP_DIR)/IMon/IMon_CtrlPressed.sgi
				icr $(EITHREADS) -v -T -c -481 -255 0 0  Icons/images/IMon/orig/IMon.sgi $(ICON_TMP_DIR)/IMon/IMon_Alt.sgi
				icr $(EITHREADS) -v -T -c -481 -255 0 0  Icons/images/IMon/orig/IMonActive.sgi $(ICON_TMP_DIR)/IMon/IMon_AltPressed.sgi
				icr $(EITHREADS) -v -T -c -622 -113 0 0  Icons/images/IMon/orig/IMon.sgi $(ICON_TMP_DIR)/IMon/IMon_Command.sgi
				icr $(EITHREADS) -v -T -c -622 -113 0 0  Icons/images/IMon/orig/IMonActive.sgi $(ICON_TMP_DIR)/IMon/IMon_CommandPressed.sgi
				icr $(EITHREADS) -v -T -c -764   -6 0 0  Icons/images/IMon/orig/IMon.sgi $(ICON_TMP_DIR)/IMon/IMon_Key.sgi
				icr $(EITHREADS) -v -T -c -764   -6 0 0  Icons/images/IMon/orig/IMonActive.sgi $(ICON_TMP_DIR)/IMon/IMon_KeyPressed.sgi
				is $(EITHREADS) -v -T -s 0 30 Icons/images/IMon/IMon*.sgi $(ICON_TMP_DIR)/IMon/IMon*.sgi $(ICON_TMP_DIR)/IMon/.c
				ic $(EITHREADS) -v -T Icons/images/IMon/K*.sgi $(ICON_TMP_DIR)/IMon/.c
				cat $(ICON_TMP_DIR)/IMon/*.c > $(ICON_TMP_DIR)/IMon.c
				$(CC) -c $(ICON_TMP_DIR)/IMon.c -o $@

IMonIcons = $(ICON_DIR)/IMon.o


$(OBJ_DIR)/IMon.o:	IMon.c IMon.ci
				$(CC) $(CFLAGS) -I$(FREETYPE_DIR)/include IMon.c -o $@

$(DSO_DIR)/IMon$(DSO_SUFFIX):		$(OBJ_DIR)/IMon.o $(IMonIcons)
				$(DSO_LD) $(OBJ_DIR)/IMon.o $(IMonIcons) $(PLFLAGS) -o $@



$(OBJ_DIR)/Debug.o:	Debug.c
				$(CC) $(CFLAGS) -I$(FREETYPE_DIR)/include Debug.c -o $@

$(DSO_DIR)/Debug$(DSO_SUFFIX):		$(OBJ_DIR)/Debug.o
				$(DSO_LD) $(OBJ_DIR)/Debug.o $(PLFLAGS) -o $@


$(DSO_DIR)/Display$(DSO_SUFFIX):		$(OBJ_DIR)/Display.o
				$(DSO_LD) $(OBJ_DIR)/Display.o $(PLFLAGS) -o $@


$(DSO_DIR)/Files$(DSO_SUFFIX):		$(OBJ_DIR)/Files.o
				$(DSO_LD) $(OBJ_DIR)/Files.o $(PLFLAGS) -o $@


$(DSO_DIR)/Info$(DSO_SUFFIX):		$(OBJ_DIR)/Info.o
				$(DSO_LD) $(OBJ_DIR)/Info.o $(PLFLAGS) -o $@


$(OBJ_DIR)/Merge.o:	Merge.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Merge$(DSO_SUFFIX):		$(OBJ_DIR)/Merge.o $(ICON_DIR)/Merge.o
				$(DSO_LD) $(OBJ_DIR)/Merge.o $(ICON_DIR)/Merge.o $(PLFLAGS) -o $@


$(ICON_DIR)/Merge.o:		Icons/images/Merge.sgi Icons/images/Merge-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Merge $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Merge-all.c -o $@;rm -f $(ICON_TMP_DIR)/Merge-all.c


$(DSO_DIR)/BevelFillet$(DSO_SUFFIX):		$(OBJ_DIR)/BevelFillet.o $(ICON_DIR)/BevelFillet.o
				$(DSO_LD) $(OBJ_DIR)/BevelFillet.o $(ICON_DIR)/BevelFillet.o $(PLFLAGS) -o $@

$(ICON_DIR)/BevelFillet.o:		Icons/images/BevelFillet.sgi Icons/images/BevelFillet-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh BevelFillet $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/BevelFillet-all.c -o $@


$(DSO_DIR)/Polhemus$(DSO_SUFFIX):		$(OBJ_DIR)/Polhemus.o
				$(DSO_LD) $(OBJ_DIR)/Polhemus.o $(PLFLAGS) -o $@


$(OBJ_DIR)/Geometries.o:         Geometries.c $< $(INCLUDES) $(EINC_DIR)/E3D/PickInput.ci
	$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Geometries$(DSO_SUFFIX):	$(OBJ_DIR)/Geometries.o
				$(DSO_LD) $(OBJ_DIR)/Geometries.o $(PLFLAGS) -o $@


$(DSO_DIR)/PolyGroups$(DSO_SUFFIX):	$(OBJ_DIR)/PolyGroups.o
				$(DSO_LD) $(OBJ_DIR)/PolyGroups.o $(PLFLAGS) -o $@


##----------------------------------------
## Hierarchy editing
##----------------------------------------
HrcIcons=			$(ICON_DIR)/Connect.o\
				$(ICON_DIR)/Disconnect.o\
				$(ICON_DIR)/Reparent.o

$(DSO_DIR)/Hierarchies$(DSO_SUFFIX):	$(OBJ_DIR)/Hierarchies.o $(HrcIcons)
				$(DSO_LD) $(OBJ_DIR)/Hierarchies.o  $(HrcIcons) $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/Connect.o:		Icons/images/Connect.sgi Icons/images/Connect-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Connect $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Connect-all.c -o $@


$(ICON_DIR)/Disconnect.o:	Icons/images/Disconnect.sgi Icons/images/Disconnect-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Disconnect $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Disconnect-all.c -o $@

$(ICON_DIR)/Reparent.o:	Icons/images/Reparent.sgi Icons/images/Reparent-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Reparent $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Reparent-all.c -o $@


##----------------------------------------
## Lights
##----------------------------------------
$(DSO_DIR)/Lights/Lights$(DSO_SUFFIX):		$(OBJ_DIR)/Lights/Lights.o $(ICON_DIR)/PointLight.o
				$(DSO_LD) $(OBJ_DIR)/Lights/Lights.o $(ICON_DIR)/PointLight.o $(PLFLAGS) -o $@


## Rules to build the icons
##
$(ICON_DIR)/PointLight.o:	Icons/images/PointLight.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
				$(SSHELL) scripts/iconproc1-3auto.sh PointLight "$(CC)" $@ $(ICON_TMP_DIR)


$(OBJ_DIR)/Lights/%.o:		Lights/%.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@

$(OBJ_DIR)/Lights/Area.o:		Lights/Area.c $< $(INCLUDES) Lights/LightProbe.h
				$(CC) $(CFLAGS) $< -o $@

Lights_Area_OBJS = $(OBJ_DIR)/Lights/Area.o $(ICON_DIR)/ALightRectangle.o $(ICON_DIR)/ALightSphereEnv.o $(ICON_DIR)/ALightSun.o
ifeq ($(OSNAME),MacOSX)
#CFLAGS += -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
endif

$(DSO_DIR)/Lights/Area$(DSO_SUFFIX):	$(Lights_Area_OBJS)
#				$(DSO_LD) $(Lights_Area_OBJS) $(PLFLAGS) -o $@
				$(DSO_LD_CPP) $(Lights_Area_OBJS) $(CPP_LIB) $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/ALightRectangle.o:	Icons/images/ALightRectangle.sgi Icons/images/ALightRectangle-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh ALightRectangle $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/ALightRectangle-all.c -o $@

$(ICON_DIR)/ALightSphereEnv.o:	Icons/images/ALightSphereEnv.sgi Icons/images/ALightSphereEnv-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh ALightSphereEnv $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/ALightSphereEnv-all.c -o $@

$(ICON_DIR)/ALightSun.o:	Icons/images/ALightSun.sgi Icons/images/ALightSun-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh ALightSun $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/ALightSun-all.c -o $@


Lights_LightProbe_OBJS = $(OBJ_DIR)/Lights/LightProbe.o $(OBJ_DIR)/SH.o
Lights_LightProbe_OBJS += $(OBJ_DIR)/Lights/SGLight.o

$(OBJ_DIR)/Lights/LightProbe.o:		Lights/LightProbe.c $< $(INCLUDES) Lights/LightProbe.h
				$(CC) $(CFLAGS) $< -o $@

$(OBJ_DIR)/Lights/SGLight.o:		Lights/SGLight.cpp $< $(INCLUDES) Lights/LightProbe.h Lights/NNLS.h
				$(CPP) $(CFLAGS) -I$(EINC_DIR)/External $(CPP_LIB) $< -o $@

$(DSO_DIR)/Lights/LightProbe$(DSO_SUFFIX):	$(Lights_LightProbe_OBJS)
#				$(DSO_LD) $(Lights_LightProbe_OBJS) $(PLFLAGS) -o $@
				$(DSO_LD_CPP) $(Lights_LightProbe_OBJS) $(CPP_LIB) $(PLFLAGS) -o $@



##----------------------------------------
## Material editor
##----------------------------------------
MaterialIcons	=		$(ICON_DIR)/Arrow.o\
				$(ICON_DIR)/Cube.o\
				$(ICON_DIR)/Cylinder.o\
				$(ICON_DIR)/Sphere.o

## Textures in the material sample scene
MaterialIcons +=		$(ICON_DIR)/MtlTextures.o

Materials_OBJS = $(OBJ_DIR)/Materials.o $(OBJ_DIR)/Textures.o $(MaterialIcons)
$(DSO_DIR)/Materials$(DSO_SUFFIX):	$(Materials_OBJS)
				$(DSO_LD) $(Materials_OBJS) $(PLFLAGS) -lm -o $@

$(OBJ_DIR)/Materials.o:		Materials.c Materials.h
				$(CC) $(CFLAGS) Materials.c -o $@

$(OBJ_DIR)/Textures.o:		Textures.c Materials.h
				$(CC) $(CFLAGS) Textures.c -o $@


MtlTextures =			lmaps/MtlFloor.png


$(ICON_DIR)/MtlTextures.o:	$(MtlTextures)
				$(iC) $(EITHREADS) -v lmaps/MtlFloor.png lmaps/MtlFloor.c
				$(iC) $(EITHREADS) -v lmaps/MtlLWall.png lmaps/MtlLWall.c
				$(iC) $(EITHREADS) -v lmaps/MtlBWall.png lmaps/MtlBWall.c
				$(iC) $(EITHREADS) -v lmaps/MtlRWall.png lmaps/MtlRWall.c
				cat lmaps/Mtl*.c > $(ICON_TMP_DIR)/MtlTextures.c
				$(CC) -c $(ICON_TMP_DIR)/MtlTextures.c -o $@

## Rules to build the icons
##
include		$(ESRC_DIR)/libsrc/E3D/Panel/IconRules.make

$(ICON_DIR)/Cube.o:		Icons/images/Cube.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
				$(SSHELL) scripts/iconproc1-3auto.sh Cube "$(CC)" $@ $(ICON_TMP_DIR)


#$(ICON_DIR)/Arrow.o:		Icons/handmade/Arrow.c
#				$(CC) -c Icons/handmade/Arrow.c -o $@

$(ICON_DIR)/Arrow.o:		Icons/images/Arrow.sgi $<
				ic -ma $< $(ICON_TMP_DIR)/.c
				$(CC) -c $(ICON_TMP_DIR)/Arrow.c -o $@



$(DSO_DIR)/Select$(DSO_SUFFIX):		$(OBJ_DIR)/Select.o
				$(DSO_LD) $(OBJ_DIR)/Select.o  $(PLFLAGS) -o $@

$(DSO_DIR)/SoftSelect$(DSO_SUFFIX):		$(OBJ_DIR)/SoftSelect.o
				$(DSO_LD) $(OBJ_DIR)/SoftSelect.o  $(PLFLAGS) -o $@


$(DSO_DIR)/Deformers/BlendShape$(DSO_SUFFIX):  $(OBJ_DIR)/Deformers/BlendShape.o
				$(DSO_LD) $(OBJ_DIR)/Deformers/BlendShape.o $(PLFLAGS) -o $@


$(DSO_DIR)/Deformers/SkinMesh$(DSO_SUFFIX):  $(OBJ_DIR)/Deformers/SkinMesh.o
				$(DSO_LD) $(OBJ_DIR)/Deformers/SkinMesh.o $(PLFLAGS) -o $@


##
## Spline editing
##
SplinesIcons	=		$(ICON_DIR)/SplSegmentLin.o\
				$(ICON_DIR)/SplSegmentCrv.o\
				$(ICON_DIR)/SplSegmentArc.o\
				$(ICON_DIR)/TgC0.o\
				$(ICON_DIR)/TgC1.o\
				$(ICON_DIR)/TgG1.o

$(DSO_DIR)/Splines$(DSO_SUFFIX):		$(OBJ_DIR)/Splines.o $(SplinesIcons)
				$(DSO_LD) $(OBJ_DIR)/Splines.o $(SplinesIcons) $(PLFLAGS) -o $@

SplIconSizeX = 42
SplIconSizeY = 42

## Rules to build the icons
##
$(ICON_DIR)/SplSegmentLin.o:	Icons/images/SplSegmentLin.sgi $(IconRules.make) ../../libsrc/E3D/Panel/scripts/iconproc3auto3.sh make.rules
				$(SSHELL) ../../libsrc/E3D/Panel/scripts/iconproc3auto3.sh SplSegmentLin $(SplIconSizeX) $(SplIconSizeY) "$(CC)" $@ $(ICON_TMP_DIR)

$(ICON_DIR)/SplSegmentCrv.o:	Icons/images/SplSegmentCrv.sgi $(IconRules.make) ../../libsrc/E3D/Panel/scripts/iconproc3auto3.sh make.rules
				$(SSHELL) ../../libsrc/E3D/Panel/scripts/iconproc3auto3.sh SplSegmentCrv $(SplIconSizeX) $(SplIconSizeY) "$(CC)" $@ $(ICON_TMP_DIR)

$(ICON_DIR)/SplSegmentArc.o:	Icons/images/SplSegmentArc.sgi $(IconRules.make) ../../libsrc/E3D/Panel/scripts/iconproc3auto3.sh make.rules
				$(SSHELL) ../../libsrc/E3D/Panel/scripts/iconproc3auto3.sh SplSegmentArc $(SplIconSizeX) $(SplIconSizeY) "$(CC)" $@ $(ICON_TMP_DIR)



$(ICON_DIR)/TgC0.o:		Icons/images/TgC0.sgi $(IconRules.make) scripts/iconproc2-3auto.sh make.rules
				$(SSHELL) scripts/iconproc2-3auto.sh TgC0 $(SplIconSizeX) $(SplIconSizeY) $EICONH_GAIN $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/TgC0-all.c -o $@


$(ICON_DIR)/TgC1.o:		Icons/images/TgC1.sgi $(IconRules.make) scripts/iconproc2-3auto.sh make.rules
				$(SSHELL) scripts/iconproc2-3auto.sh TgC1 $(SplIconSizeX) $(SplIconSizeY) $EICONH_GAIN $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/TgC1-all.c -o $@


$(ICON_DIR)/TgG1.o:		Icons/images/TgG1.sgi $(IconRules.make) scripts/iconproc2-3auto.sh make.rules
				$(SSHELL) scripts/iconproc2-3auto.sh TgG1 $(SplIconSizeX) $(SplIconSizeY) $EICONH_GAIN $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/TgG1-all.c -o $@




##
## SplineLinearize
##
$(DSO_DIR)/SplineLinearize$(DSO_SUFFIX):		$(OBJ_DIR)/SplineLinearize.o\
				$(ICON_DIR)/SplineLinearize.o
				$(DSO_LD) $(OBJ_DIR)/SplineLinearize.o $(ICON_DIR)/SplineLinearize.o $(PLFLAGS) -o $@


$(OBJ_DIR)/SplineLinearize.o:	SplineLinearize.c $< $(INCLUDES) SplineOps.h
				$(CC) $(CFLAGS) $< -o $@

## Rules to build the icons
##
$(ICON_DIR)/SplineLinearize.o:		Icons/images/SplineLinearize.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
				$(SSHELL) scripts/iconproc1-3auto.sh SplineLinearize "$(CC)" $@ $(ICON_TMP_DIR)




##
## SplineOffset
##
$(DSO_DIR)/SplineOffset$(DSO_SUFFIX):		$(OBJ_DIR)/SplineOffset.o $(ICON_DIR)/SplineOffset.o
				$(DSO_LD) $(OBJ_DIR)/SplineOffset.o $(ICON_DIR)/SplineOffset.o $(PLFLAGS) -o $@


$(OBJ_DIR)/SplineOffset.o:	SplineOffset.c $< $(INCLUDES) SplineOps.h
				$(CC) $(CFLAGS) $< -o $@

## Rules to build the icons
##
$(ICON_DIR)/SplineOffset.o:		Icons/images/SplineOffset.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
				$(SSHELL) scripts/iconproc1-3auto.sh SplineOffset "$(CC)" $@ $(ICON_TMP_DIR)






$(DSO_DIR)/Faces$(DSO_SUFFIX):		$(OBJ_DIR)/Faces.o
				$(DSO_LD) $(OBJ_DIR)/Faces.o $(PLFLAGS) -o $@



##----------------------------------------
## Stripify
##----------------------------------------
$(DSO_DIR)/Stripify$(DSO_SUFFIX):		$(OBJ_DIR)/Stripify.o\
				$(ICON_DIR)/Stripify.o
				$(DSO_LD) $(OBJ_DIR)/Stripify.o $(ICON_DIR)/Stripify.o $(PLFLAGS) -o $@


$(DSO_DIR)/Simplify$(DSO_SUFFIX):		$(OBJ_DIR)/Simplify.o\
				$(ICON_DIR)/Simplify.o
				$(DSO_LD) $(OBJ_DIR)/Simplify.o $(ICON_DIR)/Simplify.o $(PLFLAGS) -o $@

$(ICON_DIR)/Simplify.o:		Icons/images/Simplify.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
				$(SSHELL) scripts/iconproc1-3auto.sh Simplify "$(CC)" $@ $(ICON_TMP_DIR)

## Rules to build the icons
##
$(ICON_DIR)/Stripify.o:		Icons/images/Stripify.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
				$(SSHELL) scripts/iconproc1-3auto.sh Stripify "$(CC)" $@ $(ICON_TMP_DIR)


##----------------------------------------
## Tesselate / triangulate
##----------------------------------------
$(DSO_DIR)/Tesselate$(DSO_SUFFIX):	$(OBJ_DIR)/Tesselate.o\
				$(ICON_DIR)/Triangulate.o
				$(DSO_LD) $(OBJ_DIR)/Tesselate.o $(ICON_DIR)/Triangulate.o $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/Triangulate.o:	Icons/images/Triangulate.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
				$(SSHELL) scripts/iconproc1-3auto.sh Triangulate "$(CC)" $@ $(ICON_TMP_DIR)



$(DSO_DIR)/Transforms$(DSO_SUFFIX):	$(OBJ_DIR)/Transforms.o
				$(DSO_LD) $(OBJ_DIR)/Transforms.o $(PLFLAGS) -o $@



##================================================
## Animation
##================================================
$(OBJ_DIR)/Animation/%.o:	Animation/%.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Animation/AimConstraint$(DSO_SUFFIX):	$(OBJ_DIR)/Animation/AimConstraint.o
				$(DSO_LD) $(OBJ_DIR)/Animation/AimConstraint.o $(PLFLAGS) -o $@

$(DSO_DIR)/Animation/Constraints$(DSO_SUFFIX):	$(OBJ_DIR)/Animation/Constraints.o
				$(DSO_LD) $(OBJ_DIR)/Animation/Constraints.o $(PLFLAGS) -o $@

$(DSO_DIR)/Animation/Path$(DSO_SUFFIX):	$(OBJ_DIR)/Animation/Path.o
				$(DSO_LD) $(OBJ_DIR)/Animation/Path.o $(PLFLAGS) -o $@

$(DSO_DIR)/Animation/FCurves$(DSO_SUFFIX):$(OBJ_DIR)/Animation/FCurves.o
				$(DSO_LD) $(OBJ_DIR)/Animation/FCurves.o $(PLFLAGS) -o $@

$(DSO_DIR)/Animation/Shape$(DSO_SUFFIX):  $(OBJ_DIR)/Animation/Shape.o
				$(DSO_LD) $(OBJ_DIR)/Animation/Shape.o $(PLFLAGS) -o $@

$(DSO_DIR)/Animation/Skeleton$(DSO_SUFFIX):$(OBJ_DIR)/Animation/Skeleton.o
				$(DSO_LD) $(OBJ_DIR)/Animation/Skeleton.o $(PLFLAGS) -o $@


##================================================
## Particles
##================================================
$(OBJ_DIR)/Particles/%.o:	Particles/%.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Particles/Particles$(DSO_SUFFIX):	$(OBJ_DIR)/Particles/Particles.o
				$(DSO_LD) $(OBJ_DIR)/Particles/Particles.o $(PLFLAGS) -o $@


##================================================
## Physics
##================================================
$(OBJ_DIR)/Physics/%.o:		Physics/%.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Physics/Fluids$(DSO_SUFFIX):	$(OBJ_DIR)/Physics/Fluids.o
				$(DSO_LD) $(OBJ_DIR)/Physics/Fluids.o $(PLFLAGS) -o $@

$(OBJ_DIR)/Physics/Fluids.o:	Physics/Fluids.c Physics/2DFluids.c Physics/3DFluids.c



ICONS_Physics = $(ICON_DIR)/RBBox.o $(ICON_DIR)/RBSphere.o $(ICON_DIR)/RBMesh.o


$(ICON_DIR)/RBBox.o:		Icons/images/RBBox.png Icons/images/RBBox-Active.png Icons/images/RBBox-Wire.png scripts/iconproc_optionmenuW.sh
				$(SSHELL) scripts/iconproc_optionmenuW.sh RBBox $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/RBBox-all.c -o $@

$(ICON_DIR)/RBSphere.o:		Icons/images/RBSphere.png Icons/images/RBSphere-Active.png Icons/images/RBSphere-Wire.png $(IconRules.make) scripts/iconproc_optionmenuW.sh
				$(SSHELL) scripts/iconproc_optionmenuW.sh RBSphere $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/RBSphere-all.c -o $@

$(ICON_DIR)/RBMesh.o:		Icons/images/RBMesh.png Icons/images/RBMesh-Active.png Icons/images/RBMesh-Wire.png $(IconRules.make) scripts/iconproc_optionmenuW.sh
				$(SSHELL) scripts/iconproc_optionmenuW.sh RBMesh $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/RBMesh-all.c -o $@



Physics_Bullet_LIBDIR = $(BULLET_DIR)/src

Physics_Bullet_OBJS = $(OBJ_DIR)/Physics/RigidBodyBulletC.o $(OBJ_DIR)/Physics/RigidBodyBullet.o $(ICON_DIR)/RigidBodyBullet.o $(ICONS_Physics)

$(DSO_DIR)/Physics/RigidBodyBullet$(DSO_SUFFIX):	$(Physics_Bullet_OBJS)
ifeq ($(OSNAME),MacOSX)
					$(DSO_LD_CPP) $(Physics_Bullet_OBJS) -L$(Physics_Bullet_LIBDIR)/BulletCollision -L$(Physics_Bullet_LIBDIR)/BulletDynamics -L$(Physics_Bullet_LIBDIR)/LinearMath -Wl,-all_load -lBulletCollision -lBulletDynamics $(CPP_LIB) -o $@
else
					$(DSO_LD_CPP) $(Physics_Bullet_OBJS) -L$(Physics_Bullet_LIBDIR)/BulletCollision -L$(Physics_Bullet_LIBDIR)/BulletDynamics -L$(Physics_Bullet_LIBDIR)/LinearMath $(DSO_LD_CPP_WHOLE) -lBulletCollision -lBulletDynamics -lLinearMath $(DSO_LD_CPP_NO_WHOLE) $(CPP_LIB) -o $@
endif

$(OBJ_DIR)/Physics/RigidBodyBulletC.o:	Physics/RigidBody.c Physics/RigidBody.h $< $(INCLUDES)
					$(CC) $(CFLAGS) -DUSE_Bullet -I$(BULLET_DIR)/src $< -o $@

$(OBJ_DIR)/Physics/RigidBodyBullet.o:	Physics/RigidBodyBullet.cpp Physics/RigidBody.h $< $(INCLUDES)
					$(CPP) $(CFLAGS_NO_WARNINGS) -DUSE_Bullet -I$(BULLET_DIR)/src $< -o $@



$(DSO_DIR)/Physics/RigidBodyODE$(DSO_SUFFIX):	$(OBJ_DIR)/Physics/RigidBodyODEC.o $(OBJ_DIR)/Physics/RigidBodyODEcpp.o $(OBJ_DIR)/Physics/RigidBodyODE.o $(ICON_DIR)/RigidBodyODE.o $(ICONS_Physics)
					$(DSO_LD_CPP) $(OBJ_DIR)/Physics/RigidBodyODEC.o $(OBJ_DIR)/Physics/RigidBodyODEcpp.o $(OBJ_DIR)/Physics/RigidBodyODE.o $(ICON_DIR)/RigidBodyODE.o $(ICONS_Physics) $(ODE_LIB) $(PLFLAGS) $(CPP_LIB) -o $@

$(OBJ_DIR)/Physics/RigidBodyODEC.o:	Physics/RigidBody.c Physics/RigidBody.h $< $(INCLUDES) make.rules
					$(CC) $(CFLAGS) -DUSE_ODE -I$(ODE_DIR)/include $< -o $@

$(OBJ_DIR)/Physics/RigidBodyODEcpp.o:	Physics/RigidBodyODE.cpp Physics/RigidBody.h $< $(INCLUDES)
					$(CPP) $(CFLAGS) -DUSE_ODE -I$(ODE_DIR)/include $< -o $@

$(OBJ_DIR)/Physics/RigidBodyODE.o:	Physics/RigidBodyODE.c Physics/RigidBody.h $< $(INCLUDES)
					$(CC) $(CFLAGS) -DUSE_ODE -I$(ODE_DIR)/include $< -o $@

$(ICON_DIR)/RigidBodyODE.o:		$< Icons/images/RigidBodyODE.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
					$(SSHELL) scripts/iconproc1-3auto.sh RigidBodyODE "$(CC)" $@ $(ICON_TMP_DIR)



#PhysX_INC = -I$(PhysX_INC_DIR)/Foundation/include -I$(PhysX_INC_DIR)/Physics/include -I$(PhysX_INC_DIR)/PhysXLoader/include
PhysX_INC = -I$(PhysX_INC_DIR) -I$(PhysX_DIR)/pxshared/include

#./physx/bin/linux.clang/release/libPhysXCooking_static_64.a

$(DSO_DIR)/Physics/RigidBodyNx$(DSO_SUFFIX):	$(OBJ_DIR)/Physics/RigidBodyNxC.o $(OBJ_DIR)/Physics/RigidBodyNx.o $(ICON_DIR)/RigidBodyPhysX.o $(ICONS_Physics)
#					$(DSO_LD_CPP) $(OBJ_DIR)/Physics/RigidBodyNxC.o $(OBJ_DIR)/Physics/RigidBodyNx.o $(ICON_DIR)/RigidBodyPhysX.o $(ICONS_Physics) -L$(PhysX_LIB_DIR) -lPhysXCore -lNxCooking -lNxCharacter -lPhysXLoader $(PLFLAGS) $(CPP_LIB) -o $@
					$(DSO_LD_CPP) $(OBJ_DIR)/Physics/RigidBodyNxC.o $(OBJ_DIR)/Physics/RigidBodyNx.o $(ICON_DIR)/RigidBodyPhysX.o $(ICONS_Physics) -L$(PhysX_LIB_DIR) -lPhysX_static_64 -lPhysXFoundation_static_64 -lPhysXCommon_static_64 $(PLFLAGS) $(CPP_LIB) -o $@

$(ICON_DIR)/RigidBodyPhysX.o:		$< Icons/images/RigidBodyPhysX.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
					$(SSHELL) scripts/iconproc1-3auto.sh RigidBodyPhysX "$(CC)" $@ $(ICON_TMP_DIR)


$(ICON_DIR)/RigidBodyBullet.o:		$< Icons/images/RigidBodyBullet.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
					$(SSHELL) scripts/iconproc1-3auto.sh RigidBodyBullet "$(CC)" $@ $(ICON_TMP_DIR)



#NxFLAGS = -DNX32 -DLINUX -DNX_USE_SDK_STATICLIBS
#NxFLAGS = -DNX32 -DLINUX
#NxFLAGS = -DLINUX
NxFLAGS = -DNDEBUG

$(OBJ_DIR)/Physics/RigidBodyNxC.o:	Physics/RigidBody.c Physics/RigidBody.h $< $(INCLUDES)
					$(CC) $(CFLAGS) -DUSE_NovodeX $(NxFLAGS) $(PhysX_INC) $< -o $@

$(OBJ_DIR)/Physics/RigidBodyNx.o:	Physics/RigidBodyNx.cpp Physics/RigidBody.h $< $(INCLUDES)
					$(CPP) $(CFLAGS_NO_WARNINGS) -DUSE_NovodeX $(NxFLAGS) $(PhysX_INC) $< -o $@




## Rules to build the icons
##
$(ICON_DIR)/Waves.o:		Icons/images/Waves.sgi Icons/images/Waves-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Waves $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Waves-all.c -o $@

$(DSO_DIR)/Physics/Waves$(DSO_SUFFIX):	$(OBJ_DIR)/Physics/Waves.o $(ICON_DIR)/Waves.o
				$(DSO_LD) $(OBJ_DIR)/Physics/Waves.o $(ICON_DIR)/Waves.o $(PLFLAGS) -o $@



##================================================
## CAM - Computer Aided Manufacturing
##================================================
CAM_Objects =			$(OBJ_DIR)/CAM/CAM.o $(OBJ_DIR)/CAM/Simulator.o
$(DSO_DIR)/CAM/CAM$(DSO_SUFFIX):		$(CAM_Objects)
				$(DSO_LD) $(CAM_Objects) $(PLFLAGS) -o $@

$(OBJ_DIR)/CAM/CAM.o:		CAM/CAM.c CAM/CAM.h
				$(CC) $(CFLAGS) CAM/CAM.c -o $@

$(OBJ_DIR)/CAM/Simulator.o:	CAM/Simulator.c $< CAM/CAM.h
				$(CC) $(CFLAGS) $< -o $@


##================================================
## Deformers
##================================================

##----------------------------------------
## Deform along Spline
##----------------------------------------
DeformAlongSplineIcons =	$(ICON_DIR)/DeformAlongSpline.o


$(DSO_DIR)/Deformers/AlongSpline$(DSO_SUFFIX):$(OBJ_DIR)/Deformers/AlongSpline.o $(DeformAlongSplineIcons)
				$(DSO_LD) $(OBJ_DIR)/Deformers/AlongSpline.o $(DeformAlongSplineIcons) $(PLFLAGS) -o $@


$(ICON_DIR)/DeformAlongSpline.o:Icons/images/DeformAlongSpline.sgi Icons/images/DeformAlongSpline-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh DeformAlongSpline $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/DeformAlongSpline-all.c -o $@ $(ICON_TMP_DIR)





##================================================
## Primitives
##================================================
$(OBJ_DIR)/Primitives/%.o:	Primitives/%.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@


##----------------------------------------
## 2D primitives: circle, disc
##----------------------------------------
2DIcons =			$(ICON_DIR)/CircleDisc.o\
				$(ICON_DIR)/CircleLinear.o\
				$(ICON_DIR)/CircleBezier.o\
				$(ICON_DIR)/CircleBSpline.o\
				$(ICON_DIR)/CircleCardinal.o\
				$(ICON_DIR)/Gear.o

$(DSO_DIR)/Primitives/2D$(DSO_SUFFIX):	$(OBJ_DIR)/Primitives/2D.o $(2DIcons)
				$(DSO_LD) $(OBJ_DIR)/Primitives/2D.o $(2DIcons) $(PLFLAGS) -o $@


## Rules to build the icons
##
$(ICON_DIR)/CircleDisc.o:	Icons/images/CircleDisc.sgi $(IconRules.make) scripts/iconproc1-3auto.sh
				$(SSHELL) scripts/iconproc1-3auto.sh CircleDisc "$(CC)" $@ $(ICON_TMP_DIR)


$(ICON_DIR)/Gear.o:	Icons/images/Gear.sgi Icons/images/Gear-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Gear $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Gear-all.c -o $@

$(ICON_DIR)/CircleLinear.o:	Icons/images/CircleLinear.sgi $(IconRules.make) scripts/iconproc3auto1.sh
				$(SSHELL) scripts/iconproc3auto1.sh CircleLinear "$(CC)" $@ $(ICON_TMP_DIR)


$(ICON_DIR)/CircleBezier.o:	Icons/images/CircleBezier.sgi $(IconRules.make) scripts/iconproc3auto1.sh
				$(SSHELL) scripts/iconproc3auto1.sh CircleBezier "$(CC)" $@ $(ICON_TMP_DIR)


$(ICON_DIR)/CircleBSpline.o:	Icons/images/CircleBSpline.sgi $(IconRules.make) scripts/iconproc3auto1.sh
				$(SSHELL) scripts/iconproc3auto1.sh CircleBSpline "$(CC)" $@ $(ICON_TMP_DIR)


$(ICON_DIR)/CircleCardinal.o:	Icons/images/CircleCardinal.sgi $(IconRules.make) scripts/iconproc3auto1.sh
				$(SSHELL) scripts/iconproc3auto1.sh CircleCardinal "$(CC)" $@ $(ICON_TMP_DIR)


##----------------------------------------
## Box
##----------------------------------------
$(DSO_DIR)/Primitives/Box$(DSO_SUFFIX):	$(OBJ_DIR)/Primitives/Box.o\
				$(ICON_DIR)/Box.o
				$(DSO_LD) $(OBJ_DIR)/Primitives/Box.o $(ICON_DIR)/Box.o $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/Box.o:		Icons/images/Box.sgi Icons/images/Box-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Box $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Box-all.c -o $@



##----------------------------------------
## Cylinder
##----------------------------------------
CylIcons		=	$(ICON_DIR)/Cylinder.o $(ICON_DIR)/Capsule.o $(ICON_DIR)/Tube.o


$(DSO_DIR)/Primitives/Cylinder$(DSO_SUFFIX):	$(OBJ_DIR)/Primitives/Cylinder.o\
					$(CylIcons)
					$(DSO_LD) $(OBJ_DIR)/Primitives/Cylinder.o $(CylIcons) $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/Cylinder.o:		Icons/images/Cylinder.sgi Icons/images/Cylinder-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Cylinder $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Cylinder-all.c -o $@

$(ICON_DIR)/Capsule.o:		Icons/images/Capsule.sgi Icons/images/Capsule-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Capsule $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Capsule-all.c -o $@


##----------------------------------------
## Grid
##----------------------------------------
$(DSO_DIR)/Primitives/Grid$(DSO_SUFFIX):	$(OBJ_DIR)/Primitives/Grid.o\
				$(ICON_DIR)/Grid.o
				$(DSO_LD) $(OBJ_DIR)/Primitives/Grid.o $(ICON_DIR)/Grid.o $(PLFLAGS) -o $@


## Rules to build the icons
##
$(ICON_DIR)/Grid.o:		Icons/images/Grid.sgi Icons/images/Grid-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Grid $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Grid-all.c -o $@


##----------------------------------------
## Polyhedra
##----------------------------------------
PolyhedraIcons =		$(ICON_DIR)/Tetra.o $(ICON_DIR)/Icosa.o $(ICON_DIR)/Dodeca.o

$(DSO_DIR)/Primitives/Polyhedra$(DSO_SUFFIX):	$(OBJ_DIR)/Primitives/Polyhedra.o $(PolyhedraIcons)
				$(DSO_LD) $(OBJ_DIR)/Primitives/Polyhedra.o $(PolyhedraIcons) $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/Tetra.o:		Icons/images/Tetra.sgi Icons/images/Tetra-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Tetra $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Tetra-all.c -o $@

$(ICON_DIR)/Icosa.o:		Icons/images/Icosa.sgi Icons/images/Icosa-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Icosa $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Icosa-all.c -o $@

$(ICON_DIR)/Dodeca.o:		Icons/images/Dodeca.sgi Icons/images/Dodeca-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Dodeca $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Dodeca-all.c -o $@


TetGen_DIR = $(LIBS_DIR)/tetgen1.6.0


ifeq ($(OSNAME),Linux)
#PCL_LIBS = -lpcl_octree -lpcl_io -lpcl_search -lpcl_surface -lpcl_filters -lpcl_common -lpcl_tracking -lpcl_ml -lpcl_sample_consensus -lpcl_features -lpcl_apps -lpcl_keypoints -lpcl_io_ply -lpcl_stereo -lpcl_people -lpcl_visualization -lpcl_outofcore -lpcl_recognition -lpcl_kdtree -lpcl_segmentation -lpcl_registration
PCL_LIBS = -lpcl_octree -lpcl_io -lpcl_search -lpcl_surface -lpcl_filters -lpcl_common -lpcl_tracking -lpcl_ml -lpcl_sample_consensus -lpcl_features -lpcl_keypoints -lpcl_io_ply -lpcl_stereo -lpcl_recognition -lpcl_kdtree -lpcl_segmentation -lpcl_registration
endif

##----------------------------------------
## Volume
##----------------------------------------
#$(DSO_DIR)/Primitives/Volume$(DSO_SUFFIX):  $(OBJ_DIR)/Primitives/Volume.o $(OBJ_DIR)/Triangle.o $(OBJ_DIR)/Vector3D.o Makefile
#				$(DSO_LD_CPP) $(OBJ_DIR)/Primitives/Volume.o $(OBJ_DIR)/Triangle.o $(OBJ_DIR)/Vector3D.o $(PLFLAGS) -o $@
#$(DSO_DIR)/Primitives/Volume$(DSO_SUFFIX):  $(OBJ_DIR)/Primitives/Volume.o $(OBJ_DIR)/Delaunay.o $(OBJ_DIR)/DelaunayTriangulation.o $(OBJ_DIR)/Triangle.o $(OBJ_DIR)/Vector3D.o Makefile
#			$(DSO_LD_CPP) $(OBJ_DIR)/Primitives/Volume.o  $(OBJ_DIR)/Delaunay.o $(OBJ_DIR)/DelaunayTriangulation.o $(OBJ_DIR)/Triangle.o $(OBJ_DIR)/Vector3D.o $(PLFLAGS) -o $@
#$(DSO_DIR)/Primitives/Volume$(DSO_SUFFIX):  $(OBJ_DIR)/Primitives/Volume.o  $(TetGen_DIR)/tetgen.o $(TetGen_DIR)/predicates.o  $(OBJ_DIR)/Delaunay.o Makefile
#			$(DSO_LD_CPP) $(OBJ_DIR)/Primitives/Volume.o  $(TetGen_DIR)/tetgen.o $(TetGen_DIR)/predicates.o  $(OBJ_DIR)/Delaunay.o $(PLFLAGS) -o $@
ifeq ($(OSNAME),Linux)
$(DSO_DIR)/Primitives/Volume$(DSO_SUFFIX):  $(OBJ_DIR)/Primitives/Volume.o $(OBJ_DIR)/Delaunay.o Makefile
			$(DSO_LD_CPP) $(OBJ_DIR)/Primitives/Volume.o $(OBJ_DIR)/Delaunay.o $(PCL_LIBS) $(PLFLAGS) -o $@
else
$(DSO_DIR)/Primitives/Volume$(DSO_SUFFIX):  $(OBJ_DIR)/Primitives/Volume.o Makefile
			$(DSO_LD_CPP) $(OBJ_DIR)/Primitives/Volume.o $(PCL_LIBS) $(PLFLAGS) -o $@
endif

ifeq ($(OSNAME),MacOSX)
CPPFLAGSL = $(CFLAGS) -std=c++11
else
CPPFLAGSL = $(CFLAGS)
endif

$(OBJ_DIR)/Delaunay.o:  DelaunayTriangulation/Delaunay.cpp Primitives/Volume.h
	$(CPP) $(CPPFLAGSL) -I$(TetGen_DIR) -I/usr/include/pcl-1.14 -I$(LIBS_DIR)/eigen-3.4.0 DelaunayTriangulation/Delaunay.cpp -fPIC -o $@

$(OBJ_DIR)/Triangle.o:  DelaunayTriangulation/Source/Triangle.cpp
	$(CPP) $(CPPFLAGSL) DelaunayTriangulation/Source/Triangle.cpp -fPIC -o $@

$(OBJ_DIR)/Vector3D.o:  DelaunayTriangulation/Source/Vector3D.cpp
	$(CPP) $(CPPFLAGSL) DelaunayTriangulation/Source/Vector3D.cpp -fPIC -o $@

$(OBJ_DIR)/DelaunayTriangulation.o:  DelaunayTriangulation/Source/DelaunayTriangulation.cpp
	$(CPP) $(CPPFLAGSL) DelaunayTriangulation/Source/DelaunayTriangulation.cpp -fPIC -o $@

##----------------------------------------
## Sphere
##----------------------------------------
SphereIcons = $(ICON_DIR)/UVSphere.o\
				$(ICON_DIR)/GeoSphere.o\
				$(ICON_DIR)/Sphere.o


$(DSO_DIR)/Primitives/Sphere$(DSO_SUFFIX):$(OBJ_DIR)/Primitives/Sphere.o\
				$(SphereIcons)
				$(DSO_LD) $(OBJ_DIR)/Primitives/Sphere.o $(SphereIcons) $(PLFLAGS) -o $@

$(ICON_DIR)/UVSphere.o:		Icons/images/UVSphere.sgi $(IconRules.make) scripts/iconproc3auto2.sh
				$(SSHELL) scripts/iconproc3auto2.sh UVSphere $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/UVSphere-all.c -o $@

$(ICON_DIR)/GeoSphere.o:	Icons/images/GeoSphere.sgi $(IconRules.make) scripts/iconproc3auto2.sh
				$(SSHELL) scripts/iconproc3auto2.sh GeoSphere $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/GeoSphere-all.c -o $@


## Rules to build the icons
##
$(ICON_DIR)/Sphere.o:		Icons/images/Sphere.sgi Icons/images/Sphere-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Sphere $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Sphere-all.c -o $@


##----------------------------------------
## Fractal terrain
##----------------------------------------
$(DSO_DIR)/Primitives/Terrain$(DSO_SUFFIX):	$(OBJ_DIR)/Primitives/Terrain.o\
					$(ICON_DIR)/Terrain.o
					$(DSO_LD) $(OBJ_DIR)/Primitives/Terrain.o $(ICON_DIR)/Terrain.o $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/Terrain.o:		Icons/images/Terrain.sgi Icons/images/Terrain-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Terrain $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Terrain-all.c -o $@



##----------------------------------------
## 3D text
##----------------------------------------
## See freetype-x.x.x/modules.cfg

$(DSO_DIR)/Primitives/Text$(DSO_SUFFIX):	$(OBJ_DIR)/Primitives/Text.o $(ICON_DIR)/Text.o
				$(DSO_LD) $(OBJ_DIR)/Primitives/Text.o $(ICON_DIR)/Text.o $(PLFLAGS) -o $@

$(OBJ_DIR)/Primitives/Text.o:	Primitives/Text.c
				$(CC) $(CFLAGS) -I$(FREETYPE_DIR)/include Primitives/Text.c -o $@
#				$(CC) $(CFLAGS) -I/usr/include/freetype2 Primitives/Text.c -o $@

## Rules to build the icons
##
$(ICON_DIR)/Text.o:		Icons/images/Text.sgi Icons/images/Text-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Text $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Text-all.c -o $@




##----------------------------------------
## Torus
##----------------------------------------
$(DSO_DIR)/Primitives/Torus$(DSO_SUFFIX):	$(OBJ_DIR)/Primitives/Torus.o\
				$(ICON_DIR)/Torus.o
				$(DSO_LD) $(OBJ_DIR)/Primitives/Torus.o $(ICON_DIR)/Torus.o $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/Torus.o:		Icons/images/Torus.sgi Icons/images/Torus-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Torus $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Torus-all.c -o $@



##----------------------------------------
## Tube
##----------------------------------------
$(DSO_DIR)/Primitives/Tube$(DSO_SUFFIX):	$(OBJ_DIR)/Primitives/Tube.o $(ICON_DIR)/Tube.o
				$(DSO_LD) $(OBJ_DIR)/Primitives/Tube.o $(ICON_DIR)/Tube.o $(PLFLAGS) -o $@


## Rules to build the icons
##
$(ICON_DIR)/Tube.o:		Icons/images/Tube.sgi Icons/images/Tube-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Tube $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Tube-all.c -o $@


##----------------------------------------
## Vector made of Splines
##----------------------------------------
$(DSO_DIR)/Primitives/Vector$(DSO_SUFFIX):$(OBJ_DIR)/Primitives/Vector.o\
				$(ICON_DIR)/VectorBig.o
				$(DSO_LD) $(OBJ_DIR)/Primitives/Vector.o $(ICON_DIR)/VectorBig.o $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/VectorBig.o:	Icons/images/Vector.sgi $(IconRules.make)
				$(iDS) $(ICON128BIG_DROPSHADOW) $< $(ICON_TMP_DIR)/Vector.sgi
				$(iCR) -c $(ICON128BIG_CROP) $(ICON_TMP_DIR)/Vector.sgi $(ICON_TMP_DIR)/Vector.sgi
				$(iS) -s $(EICONBIG_SIZEX) $(EICONBIG_SIZEY) $(ICON_TMP_DIR)/Vector.sgi $(ICON_TMP_DIR)/VectorBig.c
				$(CC) -c $(ICON_TMP_DIR)/VectorBig.c -o $@




##================================================
## Nature
##================================================

##----------------------------------------
## Grass
##----------------------------------------
GrassIcons = $(ICON_DIR)/Grass.o

$(DSO_DIR)/Nature/Grass$(DSO_SUFFIX):	$(OBJ_DIR)/Nature/Grass.o $(GrassIcons)
				$(DSO_LD) $(OBJ_DIR)/Nature/Grass.o $(GrassIcons) $(PLFLAGS) -o $@

$(ICON_DIR)/Grass.o:		Icons/images/Grass.sgi Icons/images/Grass-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Grass $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Grass-all.c -o $@


##================================================
## Neuroscience
##================================================

##----------------------------------------
## Connectome
##----------------------------------------
ConnectomeIcons = $(ICON_DIR)/Connectome.o

$(DSO_DIR)/Neuroscience/Connectome$(DSO_SUFFIX):	$(OBJ_DIR)/Neuroscience/Connectome.o $(OBJ_DIR)/Neuroscience/FiberTrace.o $(ConnectomeIcons)
				$(DSO_LD_CPP) $(OBJ_DIR)/Neuroscience/Connectome.o $(OBJ_DIR)/Neuroscience/FiberTrace.o $(ConnectomeIcons) $(PLFLAGS) -o $@

$(ICON_DIR)/Connectome.o:  Icons/images/Connectome.sgi scripts/iconproc1-3auto.sh
				$(SSHELL) scripts/iconproc1-3auto.sh Connectome "$(CC)" $@ $(ICON_TMP_DIR)

$(OBJ_DIR)/Neuroscience/FiberTrace.o:  Neuroscience/FiberTrace.cpp $< $(INCLUDES)
	$(CPP) $(CPPFLAGSL) -I$(EINC_DIR)/External -fPIC $< -o $@ -lflann -llz4


##================================================
## Surface
##================================================
$(OBJ_DIR)/Surface/%.o:		Surface/%.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@



##----------------------------------------
## 3D scan
##----------------------------------------
$(DSO_DIR)/Surface/3DScan$(DSO_SUFFIX):	$(OBJ_DIR)/Surface/3DScan.o\
				$(ICON_DIR)/3DScan.o
				$(DSO_LD) $(OBJ_DIR)/Surface/3DScan.o $(ICON_DIR)/3DScan.o $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/3DScan.o:		Icons/images/3DScan.exr Icons/images/3DScan-Active.exr $(IconRules.make) scripts/iconproc2-3.sh
				igl $(EITHREADS) -ti 1 -t 1 -v -r 25 -p 1 -s 0.05 -l 0.05 Icons/images/3DScan.exr Icons/images/3DScan-Active.exr $(ICON_TMP_DIR)/.exr
				icn $(EITHREADS) -v -g 1.6 $(ICON_TMP_DIR)/3DScan*.exr Icons/images/.sgi
				$(SSHELL) scripts/iconproc2-3.sh 3DScan $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/3DScan-all.c -o $@


##----------------------------------------
## Extrude
##----------------------------------------
ExtrudeIcons =  $(ICON_DIR)/Extrude.o\
                $(ICON_DIR)/ExtrudeAlongSpline.o

$(OBJ_DIR)/Surface/ExtrudeSpline.o:       Surface/ExtrudeSpline.c $< $(INCLUDES) $(EINC_DIR)/E3D/Polygon.h ControlSpline.h Surface/ExtrudeTypes.h Surface/Extrude.h Surface/ExtrudeSpline.h
	$(CC) $(CFLAGS) $< -o $@

$(OBJ_DIR)/Surface/Extrude.o:             Surface/Extrude.c $< $(INCLUDES) Surface/ExtrudeTypes.h Surface/ExtrudeCommon.h Surface/Extrude.h Surface/ExtrudeSpline.h
	$(CC) $(CFLAGS) $< -o $@

$(OBJ_DIR)/Surface/ExtrudeAlongSpline.o:	Surface/ExtrudeAlongSpline.c $< $(INCLUDES) Surface/ExtrudeTypes.h Surface/ExtrudeCommon.h Surface/Extrude.h Surface/ExtrudeSpline.h PathNormalGUI.ci PathNormalGUI.h
	$(CC) $(CFLAGS) $< -o $@

$(OBJ_DIR)/Surface/ExtrudeMesh.o:         Surface/ExtrudeMesh.c $< $(INCLUDES) Surface/Extrude.h
	$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Surface/Extrude$(DSO_SUFFIX):	$(OBJ_DIR)/Surface/Extrude.o $(OBJ_DIR)/Surface/ExtrudeAlongSpline.o $(OBJ_DIR)/Surface/ExtrudeMesh.o $(OBJ_DIR)/Surface/ExtrudeSpline.o $(ExtrudeIcons)
				$(DSO_LD) $(OBJ_DIR)/Surface/Extrude.o $(OBJ_DIR)/Surface/ExtrudeAlongSpline.o $(OBJ_DIR)/Surface/ExtrudeMesh.o $(OBJ_DIR)/Surface/ExtrudeSpline.o $(ExtrudeIcons) $(PLFLAGS) -o $@


## Rules to build the icons
##
$(ICON_DIR)/Extrude.o:		Icons/images/Extrude.sgi Icons/images/Extrude-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Extrude $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Extrude-all.c -o $@


$(ICON_DIR)/ExtrudeAlongSpline.o:Icons/images/ExtrudeAlongSpline.sgi Icons/images/ExtrudeAlongSpline-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh ExtrudeAlongSpline $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/ExtrudeAlongSpline-all.c -o $@


##----------------------------------------
## Revolve Spline
##----------------------------------------
RevolveIcons =			$(ICON_DIR)/Revolve.o

$(OBJ_DIR)/Surface/Revolve.o:         Surface/Revolve.c $< $(INCLUDES) $(EINC_DIR)/E3D/PickInput.ci
	$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Surface/Revolve$(DSO_SUFFIX):	$(OBJ_DIR)/Surface/Revolve.o $(RevolveIcons)
				$(DSO_LD) $(OBJ_DIR)/Surface/Revolve.o $(RevolveIcons) $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/Revolve.o:		Icons/images/Revolve.sgi Icons/images/Revolve-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Revolve $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Revolve-all.c -o $@


##----------------------------------------
## Put skin on cross-sections
##----------------------------------------
$(DSO_DIR)/Surface/Skin$(DSO_SUFFIX):	$(OBJ_DIR)/Surface/Skin.o\
				$(ICON_DIR)/Skin.o
				$(DSO_LD) $(OBJ_DIR)/Surface/Skin.o $(ICON_DIR)/Skin.o $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/Skin.o:		Icons/images/Skin.sgi Icons/images/Skin-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh Skin $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/Skin-all.c -o $@


##----------------------------------------
## Subdivision surfaces
##----------------------------------------
SubdivisionSurfaceIcons =	$(ICON_DIR)/SubdivisionSurface.o

$(DSO_DIR)/Surface/SubdivisionSurface$(DSO_SUFFIX):	$(OBJ_DIR)/Surface/SubdivisionSurface.o $(SubdivisionSurfaceIcons)
				$(DSO_LD) $(OBJ_DIR)/Surface/SubdivisionSurface.o $(SubdivisionSurfaceIcons) $(PLFLAGS) -o $@

## Rules to build the icons
##
$(ICON_DIR)/SubdivisionSurface.o:	Icons/images/SubdivisionSurface.sgi Icons/images/SubdivisionSurface-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh SubdivisionSurface $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/SubdivisionSurface-all.c -o $@
#				$(SSHELL) scripts/iconproc2-3ShadowIndirectLightOnGround SubdivisionSurface "$(CC)" $@ $(EICON_SIZEX) $(EICON_SIZEY)


##----------------------------------------
## SurfaceFit
##----------------------------------------
SurfaceFitIcons =  $(ICON_DIR)/Extrude.o

$(OBJ_DIR)/Surface/SurfaceFit.o:          Surface/SurfaceFit.c $< $(INCLUDES)
	$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Surface/SurfaceFit$(DSO_SUFFIX):	$(OBJ_DIR)/Surface/SurfaceFit.o $(SurfaceFitIcons)
				$(DSO_LD) $(OBJ_DIR)/Surface/SurfaceFit.o $(SurfaceFitIcons) $(PLFLAGS) -o $@




$(DSO_DIR)/DICOMVolume$(DSO_SUFFIX):	$(OBJ_DIR)/DICOMVolume.o
				$(DSO_LD) $(OBJ_DIR)/DICOMVolume.o $(PLFLAGS) -o $@




##=======================================
## Rendering
##=======================================
$(OBJ_DIR)/Rendering/%.o:	Rendering/%.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@

$(OBJ_DIR)/Rendering/GPURendererGUI.o:  Rendering/GPURendererGUI.c $< $(EINC_DIR)/E3D/SL.h $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@

##
## Cg renderer
##
$(OBJ_DIR)/Rendering/Cg.o:	Rendering/Cg/Cg.c $< Rendering/Cg/Cg.h Rendering/SLCommon.ci $(EINC_DIR)/E3D/SL.h $(INCLUDES)
				$(CC) $(CFLAGS) $(CgINC) $< -o $@
 LDFLAGS +=	"-framework" "Cg"

Cg_OBJS = $(OBJ_DIR)/Rendering/GPURenderer.o $(OBJ_DIR)/Rendering/Cg.o $(OBJ_DIR)/Rendering/GPURendererGUI.o $(OBJ_DIR)/Rendering/BloomGUI.o

$(DSO_DIR)/Rendering/Cg$(DSO_SUFFIX):	$(Cg_OBJS)
ifneq ($(Cg_NEEDS_CPP),)
				$(DSO_LD_CPP) $(Cg_OBJS) $(PLFLAGS) -L$(LIB_DIR)  -o $@ $(Cg_LINK)
else
				$(DSO_LD) $(Cg_OBJS) $(PLFLAGS) -L$(LIB_DIR)  -o $@ $(Cg_LINK)
endif



##
## Universal shader code generator
##
SL_OBJS = $(OBJ_DIR)/Rendering/SL.o

$(OBJ_DIR)/Rendering/SL.o:	Rendering/SL.c $< $(EINC_DIR)/E3D/SL.h $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Rendering/SL$(DSO_SUFFIX):	$(SL_OBJS)
				$(DSO_LD) $(SL_OBJS) $(PLFLAGS) -o $@

##
## Spherical harmonics texture rendering
##
SH_OBJS = $(OBJ_DIR)/SH.o $(OBJ_DIR)/Rendering/SH.o

$(OBJ_DIR)/Rendering/SH.o:	Rendering/SH.c $<
				$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Rendering/SH$(DSO_SUFFIX): $(SH_OBJS)
				$(DSO_LD) $(SH_OBJS) $(PLFLAGS) -o $@

##
## GLSL renderer
##
GLSL_OBJS = $(OBJ_DIR)/Rendering/GPURenderer.o $(OBJ_DIR)/Rendering/GLSL.o $(OBJ_DIR)/Rendering/GPURendererGUI.o $(OBJ_DIR)/Rendering/BloomGUI.o

$(OBJ_DIR)/Rendering/GLSL.o:	Rendering/GLSL/GLSL.c Rendering/GLSL/GLSL.h $< Rendering/SLCommon.ci $(EINC_DIR)/E3D/SL.h $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Rendering/GLSL$(DSO_SUFFIX):	$(GLSL_OBJS)
				$(DSO_LD) $(GLSL_OBJS) $(PLFLAGS) -o $@



RayTracer_OBJ = $(OBJ_DIR)/Rendering/RayTracer.o $(OBJ_DIR)/Rendering/RayTracerGUI.o $(OBJ_DIR)/Rendering/BloomGUI.o

$(DSO_DIR)/Rendering/RayTracer$(DSO_SUFFIX):  $(RayTracer_OBJ)
				$(DSO_LD) $(RayTracer_OBJ) $(PLFLAGS) -o $@

$(OBJ_DIR)/Rendering/RayTracer.o:  Rendering/RayTracer.c $(EINC_DIR)/E3D/Raytracing.h $(EINC_DIR)/E3D/Raytracing.ci $(EINC_DIR)/E3D/PathTracer.h Rendering/RayTracer.h Rendering/PathTrace.ci
				$(CC) $(CFLAGS) Rendering/RayTracer.c -o $@
#				$(CC) -fomit-frame-pointer -ffast-math -fexpensive-optimizations -fstrict-aliasing $(CFLAGS) Rendering/RayTracer.c -o $@



$(OBJ_DIR)/Rendering/PhotonmapGI.o:  Rendering/PhotonmapGI.c $(EINC_DIR)/E3D/Raytracing.h $(EINC_DIR)/E3D/Raytracing.ci $(EINC_DIR)/E3D/PathTracer.h Rendering/RayTracer.h Rendering/PathTrace.ci
				$(CC) $(CFLAGS) Rendering/PhotonmapGI.c -o $@

PhotonmapGI_OBJ =  $(OBJ_DIR)/Rendering/PhotonmapGI.o $(OBJ_DIR)/Rendering/RayTracerGUI.o $(OBJ_DIR)/Rendering/BloomGUI.o

$(DSO_DIR)/Rendering/PhotonmapGI$(DSO_SUFFIX):  $(PhotonmapGI_OBJ)
				$(DSO_LD) $(PhotonmapGI_OBJ) $(PLFLAGS) -o $@



$(OBJ_DIR)/Rendering/RayTracerGUI.o:  Rendering/RayTracerGUI.c $(EINC_DIR)/E3D/Raytracing.h Rendering/RayTracerGUI.h
				$(CC) $(CFLAGS) Rendering/RayTracerGUI.c -o $@



##
## GPU ray-tracer
##
OptiX_DIR = $(WDIR)/OptiX

$(OBJ_DIR)/Rendering/%.cuo:	Rendering/GPURT/src/Shaders/%.cu $<
				carray $< $(ICON_TMP_DIR)/$*.cu.c;$(CC) $(CFLAGS) $(ICON_TMP_DIR)/$*.cu.c -o $@

$(DSO_DIR)/Rendering/GPURT-OptiX6$(DSO_SUFFIX):  $(OBJ_DIR)/Rendering/GPURT/ptx/Cameras $(OBJ_DIR)/Rendering/GPURT/ptx/Geometry $(OBJ_DIR)/Rendering/GPURT/ptx/Shaders $(PTX_DIR)/Shaders $(GPURT_OptiX6_DEP)
#				$(DSO_LD) $(GPURT_OptiX6_OBJ) $(PLFLAGS) -L$(OptiX_DIR)/lib -L$(OptiX_DIR)/lib64 -loptix -loptixu -L$(OptiX_DIR)/SDK/bin -lsutil -o $@
				$(DSO_LD) $(GPURT_OptiX6_OBJ) $(GPURT_PTX_OBJS) $(GPURT_HEADER_OBJS) $(PLFLAGS) -L$(CUDA_LIB_DIR)/lib -lnvrtc -L$(OptiX_DIR)/lib -L$(OptiX_DIR)/lib64 -loptix -loptixu -L$(OptiX_DIR)/SDK/bin -o $@


GPURT_OptiX8_DEP += $(GPURT_OptiX8_OBJ)

$(DSO_DIR)/Rendering/GPURT-OptiX8$(DSO_SUFFIX):  $(GPURT_OptiX8_DEP)
#				$(DSO_LD) $(GPURT_OptiX8_OBJ) $(PLFLAGS) -L$(OptiX_DIR)/lib -L$(OptiX_DIR)/lib64 -loptix -loptixu -L$(OptiX_DIR)/SDK/bin -lsutil -o $@
				$(DSO_LD) $(GPURT_OptiX8_OBJ) $(PLFLAGS) -L$(CUDA_LIB_DIR)/lib -lnvrtc -L$(OptiX_DIR)/lib -L$(OptiX_DIR)/lib64 -lcuda -L$(OptiX_DIR)/SDK/bin -o $@


#ispl -v  -i b.tif  -oA A.tif;icn -v -c 100 bA.tif .tif
#icm -v  -iRGB a.tif  -iA bA.tif  -o .tif
#icn -v -c -1 -b2 1 a0000-shadow.tif aInvShadow.tif
#icm -v  -i aInvShadow.tif  -i bA.tif  -o A.tif
#icm -v  -iRGB a.tif  -iA A.tif  -o .tif

$(ICON_DIR)/RT.o:		Icons/images/RT.sgi Icons/images/RT-Active.sgi $(IconRules.make) scripts/iconproc2-3.sh
				$(SSHELL) scripts/iconproc2-3.sh RT $(EICON_SIZEX) $(EICON_SIZEY) $(ICON_TMP_DIR)
				$(CC) -c $(ICON_TMP_DIR)/RT-all.c -o $@

$(OBJ_DIR)/Rendering/GPURT/cuda/include $(OBJ_DIR)/Rendering/GPURT/OptiX/include $(OBJ_DIR)/Rendering/GPURT/OptiX/include/internal $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optixu $(OBJ_DIR)/Rendering/GPURT/src/include $(OBJ_DIR)/Rendering/GPURT/ptx/Cameras $(OBJ_DIR)/Rendering/GPURT/ptx/Geometry $(OBJ_DIR)/Rendering/GPURT/ptx/Shaders $(PTX_DIR)/Shaders:
				mkdir -p $@

#NVCC = ccache nvcc -Xopencc "-woffall" --ptx -m32 -O3
NVCC = ccache nvcc --ptx -O3
#NVCC = ccache nvcc --ptx -m32 -O3

$(OBJ_DIR)/Rendering/GPURT-OptiX6.o:  Rendering/GPURT/GPURT.c Rendering/GPURT/OptiX/OptiX6.c Rendering/GPURT/src/include/GPURTTypes.h Rendering/GPURT/src/include/GPURTCPUTypes.h Rendering/GPURT/src/include/GPURT.h
#				$(CC) $(CFLAGS) -I$(OptiX_DIR)/include -I$(OptiX_DIR)/SDK/sutil -IRendering/GPURT/src/include Rendering/GPURT/GPURT.c -o $@
				$(CC) $(CFLAGS) -DRT_SDK_OPTIX6 -I$(CUDA_INC_DIR) -I$(OptiX_DIR)/include -IRendering/GPURT/src/include Rendering/GPURT/GPURT.c -o $@

$(OBJ_DIR)/Rendering/GPURT-OptiX8.o:  Rendering/GPURT/GPURT.c Rendering/GPURT/OptiX/OptiX8.c Rendering/GPURT/src/include/GPURTTypes.h Rendering/GPURT/src/include/GPURTCPUTypes.h Rendering/GPURT/src/include/GPURT.h
#				$(CC) $(CFLAGS) -I$(OptiX_DIR)/include -I$(OptiX_DIR)/SDK/sutil -IRendering/GPURT/src/include Rendering/GPURT/GPURT.c -o $@
				$(CC) $(CFLAGS) -DRT_SDK_OPTIX8 -I$(CUDA_INC_DIR) -I$(OptiX_DIR)/include -IRendering/GPURT/src/include Rendering/GPURT/GPURT.c -o $@

$(OBJ_DIR)/Rendering/GPURTCode.o:  Rendering/GPURT/GPURTCode.c Rendering/GPURT/src/include/GPURTTypes.h Rendering/GPURT/src/include/GPURT.h
				$(CC) $(CFLAGS) -IRendering/GPURT/src/include Rendering/GPURT/GPURTCode.c -o $@


$(OBJ_DIR)/Rendering/GPURT/ptx/Cameras/%.o:	Rendering/GPURT/src/Cameras/%.cu $<
				$(NVCC) -I/usr1/OptiX/include -IRendering/GPURT/src/include $< -o $(OBJ_DIR)/Rendering/GPURT/ptx/Cameras/$*.ptx
				carray -v -n Cameras_$*_ptx $(OBJ_DIR)/Rendering/GPURT/ptx/Cameras/$*.ptx $(OBJ_DIR)/Rendering/GPURT/ptx/Cameras/.c
				$(CC) $(CFLAGS) $(OBJ_DIR)/Rendering/GPURT/ptx/Cameras/$*.ptx.c -o $@

$(OBJ_DIR)/Rendering/GPURT/ptx/Geometry/%.o:	Rendering/GPURT/src/Geometry/%.cu $< Rendering/GPURT/src/include/OxMesh.h
				$(NVCC) -I/usr1/OptiX/include -IRendering/GPURT/src/include $< -o $(OBJ_DIR)/Rendering/GPURT/ptx/Geometry/$*.ptx
				carray -v -n Geometry_$*_ptx $(OBJ_DIR)/Rendering/GPURT/ptx/Geometry/$*.ptx $(OBJ_DIR)/Rendering/GPURT/ptx/Geometry/.c
				$(CC) $(CFLAGS) $(OBJ_DIR)/Rendering/GPURT/ptx/Geometry/$*.ptx.c -o $@

$(OBJ_DIR)/Rendering/GPURT/ptx/Shaders/%.o:	Rendering/GPURT/src/Shaders/%.cu $< $(INCLUDES) Rendering/GPURT/src/Shaders/Common.h Rendering/GPURT/src/Shaders/Shader.h Rendering/GPURT/src/include/GPURTTypes.h
				$(NVCC) -I/usr1/OptiX/include -IRendering/GPURT/src/include $< -o $(OBJ_DIR)/Rendering/GPURT/ptx/Shaders/$*.ptx
				carray -v -n Shaders_$*_ptx $(OBJ_DIR)/Rendering/GPURT/ptx/Shaders/$*.ptx $(OBJ_DIR)/Rendering/GPURT/ptx/Shaders/.c
				$(CC) $(CFLAGS) $(OBJ_DIR)/Rendering/GPURT/ptx/Shaders/$*.ptx.c -o $@

$(PTX_DIR)/Shaders/%.ptx:	Rendering/GPURT/src/Shaders/%.cu $< $(INCLUDES) Rendering/GPURT/src/Shaders/Common.h Rendering/GPURT/src/Shaders/Shader.h Rendering/GPURT/src/include/GPURTTypes.h
				$(NVCC) -I/usr1/OptiX/include -IRendering/GPURT/src/include $< -o $@

$(OBJ_DIR)/Rendering/GPURT/cuda/include/%.h.o:  $(CUDA_INC_DIR)/%.h $<
				carray -v -n cuda_$*_h $(CUDA_INC_DIR)/$*.h $(OBJ_DIR)/Rendering/GPURT/cuda/include/.c
				$(CC) $(CFLAGS) $(OBJ_DIR)/Rendering/GPURT/cuda/include/$*.h.c -o $@

$(OBJ_DIR)/Rendering/GPURT/OptiX/include/%.h.o:  $(OptiX_DIR)/include/%.h $<
				carray -v -n $*_h $(OptiX_DIR)/include/$*.h $(OBJ_DIR)/Rendering/GPURT/OptiX/include/.c
				$(CC) $(CFLAGS) $(OBJ_DIR)/Rendering/GPURT/OptiX/include/$*.h.c -o $@

$(OBJ_DIR)/Rendering/GPURT/OptiX/include/internal/%.h.o:  $(OptiX_DIR)/include/internal/%.h $<
				carray -v -n internal_$*_h $(OptiX_DIR)/include/internal/$*.h $(OBJ_DIR)/Rendering/GPURT/OptiX/include/internal/.c
				$(CC) $(CFLAGS) $(OBJ_DIR)/Rendering/GPURT/OptiX/include/internal/$*.h.c -o $@

$(OBJ_DIR)/Rendering/GPURT/OptiX/include/optixu/%.h.o:  $(OptiX_DIR)/include/optixu/%.h $<
				carray -v -n optixu_$*_h $(OptiX_DIR)/include/optixu/$*.h $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optixu/.c
				$(CC) $(CFLAGS) $(OBJ_DIR)/Rendering/GPURT/OptiX/include/optixu/$*.h.c -o $@

$(OBJ_DIR)/Rendering/GPURT/src/include/%.h.o:  Rendering/GPURT/src/include/%.h $<
				carray -v -n $*_h Rendering/GPURT/src/include/$*.h $(OBJ_DIR)/Rendering/GPURT/src/include/.c
				$(CC) $(CFLAGS) $(OBJ_DIR)/Rendering/GPURT/src/include/$*.h.c -o $@

## Multi-view RGBD images for 3D photos
##
3DPhoto_OBJS = $(OBJ_DIR)/Rendering/3DPhoto.o

$(OBJ_DIR)/Rendering/3DPhoto.o:	Rendering/3DPhoto.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@


$(DSO_DIR)/Rendering/3DPhoto$(DSO_SUFFIX):	$(3DPhoto_OBJS)
				$(DSO_LD) $(3DPhoto_OBJS) $(PLFLAGS) -o $@


RenderSettingsIcons	=	$(ICON_DIR)/LensOrtho.o\
				$(ICON_DIR)/LensPerspective.o


$(DSO_DIR)/Rendering/Main$(DSO_SUFFIX):	$(OBJ_DIR)/Rendering/GUI.o $(OBJ_DIR)/Rendering/Settings.o $(EINC_DIR)/E3D/RendererSettings.h $(RenderSettingsIcons)
				$(DSO_LD) $(OBJ_DIR)/Rendering/GUI.o $(OBJ_DIR)/Rendering/Settings.o $(RenderSettingsIcons) $(PLFLAGS) -o $@



## Rules to build the icons
##
$(ICON_DIR)/LensOrtho.o:	Icons/images/LensOrtho.sgi $(IconRules.make) ../../libsrc/E3D/Panel/scripts/iconproc3auto3.sh
				$(SSHELL) ../../libsrc/E3D/Panel/scripts/iconproc3auto3.sh LensOrtho 36 36 "$(CC)" $@ $(ICON_TMP_DIR)


$(ICON_DIR)/LensPerspective.o:	Icons/images/LensPerspective.sgi $(IconRules.make) ../../libsrc/E3D/Panel/scripts/iconproc3auto3.sh
				$(SSHELL) ../../libsrc/E3D/Panel/scripts/iconproc3auto3.sh LensPerspective 36 36 "$(CC)" $@ $(ICON_TMP_DIR)


##
## ShadeGraph view
##
$(DSO_DIR)/View_ShadeGraph$(DSO_SUFFIX):		$(OBJ_DIR)/View_ShadeGraph.o
				$(DSO_LD) $(OBJ_DIR)/View_ShadeGraph.o $(PLFLAGS) -o $@


## Tests/examples
##
$(DSO_DIR)/ATC$(DSO_SUFFIX):		$(OBJ_DIR)/ATC.o
				$(DSO_LD) $(OBJ_DIR)/ATC.o $(PLFLAGS) -o $@


##================================================
## Ap
##================================================
$(OBJ_DIR)/Ap/%.o:	Ap/%.c $< $(INCLUDES)
				$(CC) $(CFLAGS) $< -o $@

$(DSO_DIR)/Ap/VFu$(DSO_SUFFIX):	$(OBJ_DIR)/Ap/VFu.o
				$(DSO_LD) $(OBJ_DIR)/Ap/VFu.o $(PLFLAGS) -o $@
