##################################################
#
#   Makefile for GEM
#   Graphics Environment for Multimedia
#
#   mark@danks.org
#
#   Copyright (c) 1997-2000 Mark Danks.
#   For information on usage and redistribution, and for a DISCLAIMER OF ALL
#   WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
#
#
##################################################

SHELL = /usr/bin/sh

# search path
#############
OBJ_DIR     	= Objects
VPATH	    	= ${OBJ_DIR}

# the objects
#############
BASE_CORE = CPPExtern.o GemMan.o GemBase.o sgiimage.o GemEvent.o
BASE_EXT_A = GemShape.o TextBase.o GemPathBase.o GemGluObj.o
BASE_EXT_B = GemPixObj.o GemPixDualObj.o GemLoadObj.o GemModelData.o
BASE_OBJ = ${BASE_CORE} ${BASE_EXT_A} ${BASE_EXT_B}
UTILS_BASE = GemSetup.o GemState.o GemCache.o GemDag.o
UTILS_PIX = GemFuncUtil.o GemPixUtil.o GemPixImageLoad.o
UTILS_OS = GemWinCreateXWin.o Matrix.o
UTILS = ${UTILS_BASE} ${UTILS_PIX} ${UTILS_OS}

CONTROLS_A = gemwin.o camera.o render_trigger.o gemhead.o
CONTROLS_B = gemmouse.o gemtablet.o gemorb.o
CONTROLS = ${CONTROLS_A} ${CONTROLS_B}
MANIPS_A = translateXYZ.o scaleXYZ.o rotateXYZ.o colorRGB.o
MANIPS_B = rotate.o translate.o scale.o color.o depth.o alpha.o separator.o
MANIPS_C = linear_path.o spline_path.o accumrotate.o ortho.o
MANIPS_D = ambient.o ambientRGB.o diffuse.o diffuseRGB.o
MANIPS_E = emission.o emissionRGB.o shininess.o specular.o specularRGB.o
MANIPULATORS = ${MANIPS_A} ${MANIPS_B} ${MANIPS_C} ${MANIPS_D} ${MANIPS_E}
2DGEOS = square.o triangle.o circle.o text2d.o primTri.o rectangle.o
3DGEOS = cube.o cone.o sphere.o imageVert.o text3d.o textoutline.o cylinder.o disk.o
SPEC_GEOS = polygon.o model.o multimodel.o curve.o colorSquare.o
GEOS = ${2DGEOS} ${3DGEOS} ${SPEC_GEOS}

MARKEX_A = MarkExSetup.o abs.o average.o counter.o m_control.o hsvrgb.o
MARKEX_B = multiselect.o randomF.o reson.o strcat.o tripleLine.o vector.o
MARKEX = ${MARKEX_A} ${MARKEX_B}

NONGEOS = world_light.o light.o

PART_A = part_color.o part_draw.o part_follow.o part_gravity.o part_damp.o
PART_B = part_head.o part_killold.o part_killslow.o part_orbitpoint.o
PART_C = part_size.o part_source.o part_velcone.o part_velsphere.o
PART_D = part_targetcolor.o part_targetsize.o
PARTICLE = ${PART_A} ${PART_B} ${PART_C} ${PART_D}

PIX_GEOS = pix_image.o pix_multiimage.o pix_texture.o pix_draw.o pix_snap.o
PIX_CONTROLS = pix_resize.o pix_buf.o pix_zoom.o pix_data.o
PIX_MANA = pix_add.o pix_subtract.o pix_multiply.o pix_a_2grey.o
PIX_MANB = pix_threshold.o pix_gain.o pix_color.o pix_bitmask.o pix_flip.o
PIX_MANC = pix_colormatrix.o pix_alpha.o pix_convolve.o pix_composite.o
PIX_MAND = pix_coloralpha.o pix_mask.o pix_clearblock.o pix_rectangle.o
PIX_MANE = pix_coordinate.o pix_2grey.o pix_invert.o
PIX_MANIPS = ${PIX_MANA} ${PIX_MANB} ${PIX_MANC} ${PIX_MAND} ${PIX_MANE}
PIXES = ${PIX_GEOS} ${PIX_CONTROLS} ${PIX_MANIPS}

SGI_SPECIFIC = pix_videoSGI.o pix_indycam.o

OBJ = ${BASE_OBJ} ${UTILS} ${CONTROLS} ${MANIPULATORS} \
      ${GEOS} ${NONGEOS} ${PIXES} ${MARKEX} ${PARTICLE}

SGI_OBJ = ${OBJ} ${SGI_SPECIFIC}
LINUX_OBJ = ${OBJ}

# the target
############
# SGI
TARGET = ../../Gem.pd_irix5
# Linux
# TARGET = ../../Gem.pd_linux

# compile flags
###############
# compilation targets
REL_CC_FLAGS   	= -DNDEBUG -UDEBUG -O2
DBG_CC_FLAGS 	= -DDEBUG -g

# AuxLib includes
AUXDIR			= ../AuxLibs
AUXINC_IMG		= -I${AUXDIR}/Jpeg -I${AUXDIR}/tiff/libtiff -I${AUXDIR}/liborb
AUXINC_POLY		= -I${AUXDIR}/gltt -I${AUXDIR}/td -I${AUXDIR}/particle
AUXINC			= ${AUXINC_IMG} ${AUXINC_POLY}
INC_FLAGS		= -I. -I.. -I../../../src ${AUXINC}
COMP_FLAGS		= -xansi

# SGI
WARN_FLAGS		= -woff 3157,3173
# Linux
#WARN_FLAGS		= -Wall

ALL_CC_FLAGS	= ${COMP_FLAGS} ${WARN_FLAGS} ${INC_FLAGS}

#linker flags
#############
# AuxLib libraries
AUXLIB_IMG		= -L${AUXDIR}/Jpeg -ljpeg -L${AUXDIR}/tiff -ltiff
AUXLIB_POLYA	= -L${AUXDIR}/gltt -lgltt -L${AUXDIR}/gltt/freetype/lib -lttf
AUXLIB_POLYB	= -L${AUXDIR}/td -ltd -L${AUXDIR}/particle -lparticle
AUXLIB_POLYC	= -L${AUXDIR}/liborb -lorb
AUXLIB_POLY		= ${AUXLIB_POLYA} ${AUXLIB_POLYB} ${AUXLIB_POLYC}
AUXLIB			= ${AUXLIB_IMG} ${AUXLIB_POLY}

# SGI
LIB = -lX11 -lGLU -lGL -lvl -lm ${AUXLIB}
LD_FLAGS = -elf -shared -rdata_shared

# Linux
#LIB = -lMesaGLU -lMesaGL -lm ${AUXLIB} -lX11 -lXext -ldl
#LD_FLAGS = -shared -L/usr/X11R6/lib

all: debug

# debug version
#--------------
debug:
	@echo "\n==========Compiling Debug=========="
	${MAKE} Application_objects "CC_FLAGS = ${ALL_CC_FLAGS} ${DBG_CC_FLAGS}"
	@echo "\n==========Linking Target=========="
	@${MAKE} ${TARGET}

# release version
#----------------
release:
	@echo "\n==========Compiling Release=========="
	${MAKE} Application_objects "CC_FLAGS = ${ALL_CC_FLAGS} ${REL_CC_FLAGS}"
	@echo "\n==========Linking Target=========="
	@${MAKE} ${TARGET}
	@echo "\n==========Striping Target=========="
	cd ${OBJ_DIR}; strip -f ${TARGET}


# program target
################
# SGI
${TARGET}: ${SGI_OBJ}
	cd ${OBJ_DIR}; CC -o32 -mips2 ${LD_FLAGS} -o $@ ${SGI_OBJ} ${LIB}

# Linux
#${TARGET}: ${LINUX_OBJ}
#	cd ${OBJ_DIR}; ld ${LD_FLAGS} -o ${TARGET} ${LINUX_OBJ} ${LIB}


TARG_DIR = Base Geos Nongeos Controls Manips Pixes Particles MarkEx

# make target
#############
# SGI
MAKE_TARG = sgi

# Linux
#MAKE_TARG = all

Application_objects:
	@for d in ${TARG_DIR}; do \
	    echo "\n----------$$d----------"; \
	    cd $$d ; ${MAKE} ${MAKE_TARG}; cd ..; \
	done


# helper targets
################
AUX_FILES = gem/GEM.*
DOC_FILES = gem/help gem/examples gem/doc
SRC_FILES = gem/src 
BCK_FILES = ${AUX_FILES} ${DOC_FILES} ${SRC_FILES}

backup:
	cd ../..; tar cvf GEMbackupC++.tar ${BCK_FILES}; \
	compress GEMbackupC++.tar; \
	mv GEMbackupC++.tar.Z ~/Backup/

clean:
	rm ${OBJ_DIR}/*.o

clobber: clean
	rm ${TARGET}
	rm Makefile.depend


#--------------------------
# Makedepend targets
#--------------------------
#
# header file dependencies
#---------
depend:
	@for d in ${TARG_DIR}; do \
	    echo "==== $$d ===="; \
	    cd $$d ; ${MAKE} dependencies 1>/dev/null 2>&1; cd ..; \
	done

# need a dummy file for Make.depend
#---------
firstTime:
	@for d in ${TARG_DIR}; do \
	    cd $$d ; touch Make.depend; cd ..; \
	done
