# Emacs, this is -*- Mode: makefile -*-
#
# Makefile.shared [20. Jan 2004]
# Makefile for Ayam (shared version)

# Choose an installation prefix.
PREFIX = /usr/local/ayam
#PREFIX = /opt/ayam
# if you use one of the following, be sure to change LIBDIR
# and DOCDIR to a more suitable (Ayam specific) path
#PREFIX = /usr/freeware
#PREFIX = /usr

# if PREFIX points to a generic directory (e.g. /usr) and not
# to a directory specific to Ayam (e.g. /usr/local/ayam) you
# probably want to switch LN to echo (this way the installation
# will not create a softlink named "plugins" in PREFIX/bin)
LN = ln -s
#LN = echo

# Where shall the executable be installed?
BINDIR = $(PREFIX)/bin

# Where shall the main tcl scripts, plugins, and custom objects be installed?
LIBDIR = $(PREFIX)/lib
#LIBDIR = $(PREFIX)/lib/ayam

# Where shall the documentation be installed?
DOCDIR = $(PREFIX)/doc
#DOCDIR = $(PREFIX)/doc/ayam

INSTALL = ./ninstall
#INSTALL = install
MKDIR = mkdir -p

# the compiler
CC = cc
#CC = gcc

# the linker
# Starting with BMRT2.5, libribout and libslcargs are in C++,
# which forces us to use "CC" or "g++" to link the right libraries
# automatically
LD = CC
# for Linux, use
#LD = g++
# MacOSX
#LD = cc

# flags for the compiler
# o add -DAYUSEAFFINE if you use the Affine Toolkit as libribout replacement
#   _else_
#   add -DAYUSEBMRTRIBOUT if you link with libribout from BMRT
#   _else_
#   add -DAYUSEAQSISRIB if you link with libri2rib from Aqsis
# o add -DAYUSESLCARGS if you use libslcargs from BMRT
#   _or_
#   add -DAYUSESLXARGS if you use libslxargs from Aqsis
# o add -DAYNOTEMPNAM if your system has no tempnam();
#   (unlikely, but tempnam() is not ANSI)
#   Note, that the preference setting TmpDir will always be ignored then!
# o add -DAYENABLEPPREV to enable the permanent preview feature
# o add -DAYENABLEWAIT to enable the waitPid command (Unix/Linux only)
# o add -DAYWITHAQUA if you use a Tcl/Tk for Aqua (not X11)
# o add -DAYNOUNISTDH if your system has no "unistd.h" (no "times()" system
#   call); if you add this option, the detection of held down keys will be
#   switched off and rotating views via keyboard will fill up the undo buffer
# o add -DAYOLDSLX if you compile with an Aqsis libslxargs prior to 0.7.19
# o add -DUSE_NON_CONST if you compile with Tcl/Tk 8.4.x

CFLAGS = -O -DAYUSESLCARGS -DAYUSEBMRTRIBOUT
# IRIX (-DAYIRIXBUG is needed by ncurve.c to work around a bug in libGLU)::
#CFLAGS = -O -fullwarn -DAYIRIXBUG -DAYUSESLCARGS -DAYUSEBMRTRIBOUT
# Linux:
#CFLAGS = -g -Wall -DAYUSESLCARGS -DAYUSEBMRTRIBOUT -DAYENABLEWAIT
# Solaris (-DSOLARIS_BUG is needed by togl.c to work around a bug in libXmu):
#CFLAGS = -O -DSOLARIS_BUG -DAYUSESLCARGS -DAYUSEBMRTRIBOUT
# MacOSX with Aqua:
#CFLAGS = -O -DAYWITHAQUA -DAYUSEAFFINE
# MacOSX with X11:
#CFLAGS = -O -DAYUSEAFFINE

# ld flag to switch to static linking
# IRIX:
#LDSWSTATIC = -static
# Linux:
LDSWSTATIC = -Wl,-Bstatic
#LDSWSTATIC = -Wl,-Bstatic
# MacOSX:
#LDSWSTATIC =

# ld flag to switch to dynamic linking
# IRIX:
#LDSWDYNAMIC = -dynamic
# Linux:
LDSWDYNAMIC = -Wl,-Bdynamic
#LDSWDYNAMIC = -Wl,-Bdynamic
# MacOSX:
#LDSWDYNAMIC =

# extra ld flags needed to compile Ayam
# (gcc needs -rdynamic to allow shared objects access to global symbols)
# IRIX:
EXLDFLAGS = 
# Linux:
#EXLDFLAGS = -rdynamic
# MacOSX:
#EXLDFLAGS = -flat_namespace -undefined suppress

# Togl
# Path to "togl.h":
TOGLINCDIR = togl

# Path to "togl.o":
TOGLOBJECT = togl/togl.o

# OpenGL
GLINCDIR = /usr/X11R6/include/
# link options for linking with OpenGL libraries
GLLIBS = -lGLU -lGL

# TIFF
TIFFINCDIR = /usr/include/
# link options for linking with TIFF library
TIFFLIB = -ltiff

# Tcl/Tk
# Tcl directory
#TCLDIR = ../../tcl8.2.2
TCLDIR = ../../tcl8.0

# Tcl includes
TCLINC = -I$(TCLDIR)/generic

# Tcl library
# link options for linking with Tcl library
#TCLLIB = -L$(TCLDIR)/unix -ltcl8.2
TCLLIB = -L$(TCLDIR)/unix -ltcl8.0
# if you have an installed Tcl/Tk, you probably just want:
#TCLLIB = -ltcl

# Tk sources directory
# Note: You really need the Tk _sources_ in order to compile Ayam!
#TKDIR = ../../tk8.2.2
TKDIR = ../../tk8.0

# Tk includes
TKINC = -I$(TKDIR)/generic -I$(TKDIR)/unix

# Tk library
# link options for linking with Tk library
#TKLIB = -L$(TKDIR)/unix -ltk8.2
TKLIB = -L$(TKDIR)/unix -ltk8.0
# if you have an installed Tcl/Tk, you probably just want:
#TKLIB = -ltk


# X11-libs
# link options for linking with X11
X11LIBS = -L/usr/X11R6/lib -lXmu -lXext -lX11
#X11LIBS = -L/usr/X11R6/lib -lXmu -lXext -lX11


# Affine Toolkit
# where is ributil.h?
AFFINEINCDIR = ./affine/include
# if you do not use Affine as BMRT libribout replacement:
AFFINEOBJS = 
# if you use Affine as BMRT libribout replacement
# (also add -DAYUSEAFFINE to CFLAGS!):
#AFFINEOBJS = ./affine/src/write.o ./affine/src/constant.o


# Aqsis
AQSISDIR = /usr/local/aqsis
AQSISINCDIR = $(AQSISDIR)/include
AQSISLIBDIR = $(AQSISDIR)/lib
# if you do not use Aqsis libslxargs as libslcargs replacement:
AQSISOBJS = 
# if you use Aqsis libslxargs (add -DAYUSESLXARGS to CFLAGS!):
#AQSISOBJS = $(AQSISLIBDIR)/rcdummy.o $(AQSISLIBDIR)/libshadervm.so $(AQSISLIBDIR)/libshaderexecenv.so $(AQSISLIBDIR)/libslxargs.so $(AQSISLIBDIR)/libaqsistypes.so -L /usr/local/lib -llog4cpp

# if you do not use Aqsis libri2rib as BMRT libribout replacement:
#AQSISRI2RIB =
# if you use Aqsis libri2rib (add -DAYUSEAQSISRIB to CFLAGS above!):
AQSISRI2RIB = $(AQSISLIBDIR)/libri2rib.so -L /usr/local/lib -llog4cpp


# BMRT
# If you use the libribout from BMRT2.x (x >= 5), do _not_ link with
# libslcargs (leave SLCARGSLIB empty), as its functionality is already
# present in libribout (in any case, keep -DAYUSESLCARGS set in CFLAGS above)!
BMRTDIR = ../../BMRT2.5
BMRTINCDIR = $(BMRTDIR)/include
BMRTLIBDIR = $(BMRTDIR)/lib
# if you use BMRT libribout and not Affine:
RIBOUTLIB = -L$(BMRTLIBDIR) -lribout
# if you use Affine or Aqsis libri2rib as BMRT libribout replacement:
#RIBOUTLIB =
# if you do not use libslcargs from BMRT:
SLCARGSLIB =
# if you use Affine as BMRT libribout replacement and libslcargs from BMRT:
#SLCARGSLIB = -L$(BMRTLIBDIR) -lslcargs


# Dynamic Loading
# Library for dynamic loading (contains dlopen())
# Linux, IRIX, Solaris, (MacOSX: get libdl from Fink!):
DL = -ldl
# NetBSD:
#DL =

# linker flags to produce shared modules:
# Linux, Solaris, IRIX:
SHLFLAGS = -shared
# MacOSX:
#SHLFLAGS = -bundle -flat_namespace -undefined suppress

# RRIB Plugin Required Libraries
# where is the complete Affine distribution?
AFFINEDIR = ../../affine0008
RRIBLIBS = -L$(AFFINEDIR)/lib -lribrdr -lribhash -lribnop -lm

# Ayslx Plugin (Aqsis)
AYSLXINCDIR = $(AQSISDIR)/include
AYSLXLIBS = $(AQSISDIR)/lib/rcdummy.o $(AQSISDIR)/lib/libshadervm.so $(AQSISDIR)/lib/libshaderexecenv.so $(AQSISDIR)/lib/libslxargs.so $(AQSISDIR)/lib/libaqsistypes.so -L/usr/local/lib -llog4cpp

# Ayso Plugin (RenderDotC, RDC)
RDCDIR = /usr/local/rdc
AYSOINCDIR = $(RDCDIR)/include
AYSOLIBS = -L$(RDCDIR)/lib -lsoargs

# Ayslo Plugin (PRman)
PRMANDIR = /usr/local/prman
AYSLOINCDIR = $(PRMANDIR)/include
AYSLOLIBS = -L$(PRMANDIR)/lib -lsloargs -ltarget -lzip

# Ayslo3d Plugin (3Delight)
# (add AYOLDSLO3D to CFLAGS above, if you compile with a 3Delight
#  older than 1.0.6)
3DLDIR = /usr/local/3delight
#3DLDIR = /usr/local/3delight-0.9.6/Linux-i686-libstdc++-3
AYSLO3DINCDIR = $(3DLDIR)/include
AYSLO3DLIBS = -L$(3DLDIR)/lib -l3delight

# Aysdr Plugin (Pixie)
SDRDIR = /usr/local
AYSDRINCDIR = $(SDRDIR)/include
PIXIESRC = /home/user/Pixie/src
AYSDRLIBS = $(PIXIESRC)/common/os.o -L$(SDRDIR)/lib -lsdr

#############################################
# nothing needs to be changed below this line
#############################################

AYAMOBJS = aycore/bbc.o\
	aycore/clear.o\
	aycore/clevel.o\
	aycore/clipb.o\
	aycore/comp.o\
	aycore/convert.o\
	aycore/draw.o\
	aycore/error.o\
	aycore/geom.o\
	aycore/instt.o\
	aycore/mopsi.o\
	aycore/notify.o\
	aycore/oact.o\
	aycore/object.o\
	aycore/objio.o\
	aycore/otype.o\
	aycore/matt.o\
	aycore/pact.o\
	aycore/pomesht.o\
	aycore/prop.o\
	aycore/provide.o\
	aycore/prefs.o\
	aycore/pv.o\
	aycore/quat.o\
	aycore/read.o\
	aycore/riattr.o\
	aycore/riopt.o\
	aycore/sdmesht.o\
	aycore/sel.o\
	aycore/selp.o\
	aycore/shade.o\
	aycore/shader.o\
	aycore/table.o\
	aycore/tags.o\
	aycore/tc.o\
	aycore/tcmd.o\
	aycore/toglcb.o\
	aycore/tmp.o\
	aycore/trafo.o\
	aycore/undo.o\
	aycore/vact.o\
	aycore/viewt.o\
	aycore/wrib.o\
	aycore/write.o\
	nurbs/capt.o\
	nurbs/ict.o\
	nurbs/knots.o\
	nurbs/nb.o\
	nurbs/nct.o\
	nurbs/npt.o\
	nurbs/pmt.o\
	nurbs/tess.o\
	objects/box.o\
	objects/bpatch.o\
	objects/camera.o\
	objects/cap.o\
	objects/clone.o\
	objects/cone.o\
	objects/concatnc.o\
	objects/cylinder.o\
	objects/disk.o\
	objects/extrude.o\
	objects/gordon.o\
	objects/hyperb.o\
	objects/icurve.o\
	objects/instance.o\
	objects/level.o\
	objects/light.o\
	objects/material.o\
	objects/ncurve.o\
	objects/npatch.o\
	objects/pamesh.o\
	objects/pomesh.o\
	objects/parab.o\
	objects/revolve.o\
	objects/riinc.o\
	objects/root.o\
	objects/sdmesh.o\
	objects/sphere.o\
	objects/skin.o\
	objects/sweep.o\
	objects/torus.o\
	objects/view.o\
	contrib/ai.o\
	contrib/sm.o\
	contrib/tree.o\
	contrib/objsel.o\
	ayam.o

MF3DOBJS = MF3D/mf3d.o\
 MF3D/mfbinrd.o\
 MF3D/mffile.o\
 MF3D/mfgroups.o\
 MF3D/mflabels.o\
 MF3D/mfmemory.o\
 MF3D/mfobject.o\
 MF3D/mfobjtyp.o\
 MF3D/mfprimtv.o\
 MF3D/mfrslntn.o\
 MF3D/mfstdchk.o\
 MF3D/mftextrd.o\
 MF3D/mftextut.o\
 MF3D/mftextwr.o

CSPHEREOBJS = plugins/csphere.o

IDROBJS = plugins/idr.o

METAOBJS = contrib/meta/metaobj.o \
	contrib/meta/metautils.o \
	contrib/meta/move.o \
	contrib/meta/marching.o \
	contrib/meta/adaptive.o

RRIBOBJS = plugins/rrib.o


.c.o: 
	$(CC) -c $(CFLAGS) $*.c -o $@ -I. -IMF3D -I$(TOGLINCDIR) $(TCLINC) $(TKINC) -I$(BMRTINCDIR) -I$(GLINCDIR) -I$(AFFINEINCDIR) -I$(AQSISINCDIR) -I$(TIFFINCDIR)

all: ayamsh csphere.so mfio.so metaobj.so

ayamsh: $(AYAMOBJS) $(TOGLOBJECT) $(AFFINEOBJS)
	$(LD) $(AYAMOBJS) $(TOGLOBJECT) $(EXLDFLAGS) -o ayamsh $(TKLIB) $(TCLLIB) $(GLLIBS) $(X11LIBS) $(RIBOUTLIB) $(AQSISRI2RIB) $(SLCARGSLIB) $(AFFINEOBJS) $(AQSISOBJS) $(TIFFLIB) -lm $(DL)

csphere.so: $(CSPHEREOBJS)
	$(CC) $(SHLFLAGS) $(CSPHEREOBJS) -o plugins/csphere.so

idr.so: $(IDROBJS)
	$(CC) $(SHLFLAGS) $(IDROBJS) -o plugins/idr.so $(TIFFLIB)

mf3d:
	cd MF3D; make -f Makefile.mf3d

mfio.so: plugins/mfio.o mf3d
	$(CC) $(SHLFLAGS) $(MF3DOBJS) plugins/mfio.o -o plugins/mfio.so

metaobj.so: $(METAOBJS)
	$(CC) $(SHLFLAGS) $(METAOBJS) -o contrib/meta/metaobj.so

rrib.so: $(RRIBOBJS)
	$(CC) $(SHLFLAGS) $(RRIBOBJS) -o plugins/rrib.so $(RRIBLIBS)

ayslx.so:
	$(CC) -c $(CFLAGS) plugins/ayslx.c -o plugins/ayslx.o -I. -IMF3D -I$(TOGLINCDIR) $(TCLINC) $(TKINC) -I$(BMRTINCDIR) -I$(GLINCDIR) -I$(AFFINEINCDIR) -I$(AQSISINCDIR) -I$(TIFFINCDIR) -I$(AYSLXINCDIR)
	$(CC) $(SHLFLAGS) plugins/ayslx.o -o plugins/ayslx.so $(AYSLXLIBS)

ayso.so:
	$(CC) -c $(CFLAGS) plugins/ayso.c -o plugins/ayso.o -I. -IMF3D -I$(TOGLINCDIR) $(TCLINC) $(TKINC) -I$(BMRTINCDIR) -I$(GLINCDIR) -I$(AFFINEINCDIR) -I$(AQSISINCDIR) -I$(TIFFINCDIR) -I$(AYSOINCDIR)
	$(CC) $(SHLFLAGS) plugins/ayso.o -o plugins/ayso.so $(AYSOLIBS)

ayslo.so:
	$(CC) -c $(CFLAGS) plugins/ayslo.c -o plugins/ayslo.o -I. -IMF3D -I$(TOGLINCDIR) $(TCLINC) $(TKINC) -I$(BMRTINCDIR) -I$(GLINCDIR) -I$(AFFINEINCDIR) -I$(AQSISINCDIR) -I$(TIFFINCDIR) -I$(AYSLOINCDIR)
	$(CC) $(SHLFLAGS) plugins/ayslo.o -o plugins/ayslo.so $(AYSLOLIBS)

ayslo3d.so:
	$(CC) -c $(CFLAGS) plugins/ayslo3d.c -o plugins/ayslo3d.o -I. -IMF3D -I$(TOGLINCDIR) $(TCLINC) $(TKINC) -I$(BMRTINCDIR) -I$(GLINCDIR) -I$(AFFINEINCDIR) -I$(AQSISINCDIR) -I$(TIFFINCDIR) -I$(AYSLO3DINCDIR)
	$(CC) $(SHLFLAGS) plugins/ayslo3d.o -o plugins/ayslo3d.so $(AYSLO3DLIBS)

ayslb.so:
	$(CC) -c $(CFLAGS) plugins/ayslb.c -o plugins/ayslb.o -I. -IMF3D -I$(TOGLINCDIR) $(TCLINC) $(TKINC) -I$(BMRTINCDIR) -I$(GLINCDIR) -I$(AFFINEINCDIR) -I$(AQSISINCDIR) -I$(TIFFINCDIR)
	$(CC) $(SHLFLAGS) plugins/ayslb.o -o plugins/ayslb.so

aysdr.so:
	$(CC) -c $(CFLAGS) plugins/aysdr.c -o plugins/aysdr.o -I. -IMF3D -I$(TOGLINCDIR) $(TCLINC) $(TKINC) -I$(BMRTINCDIR) -I$(GLINCDIR) -I$(AFFINEINCDIR) -I$(AQSISINCDIR) -I$(TIFFINCDIR) -I$(AYSDRINCDIR)
	$(CC) $(SHLFLAGS) plugins/aysdr.o -o plugins/aysdr.so $(LDSWSTATIC) $(AYSDRLIBS) $(LDSWDYNAMIC)

mostlyclean:
	-rm -f core
	-rm -f *.o
	-rm -f *.so
	-rm -f $(AYAMOBJS) 
	-rm -f $(TOGLOBJECT)
	-rm -f plugins/*.o
	-rm -f plugins/*.so
	-rm -f contrib/meta/*.o
	-rm -f contrib/meta/*.so
	-rm -f ayamsh ayam

clean: mostlyclean
	-rm -f $(AFFINEOBJS)
	-cd MF3D; make -f Makefile.mf3d clean

DOCFILES = ../Setup.txt ../Changes.txt ../License.txt ../doc/refcard.tcl\
../doc/refcard.ps ../doc/ayam.pdf

install:
	$(MKDIR) $(BINDIR)
	$(INSTALL) ayamsh $(BINDIR)
	./crtayamsh.sh $(BINDIR) $(LIBDIR)/tcl
	$(INSTALL) ayam $(BINDIR)
	$(MKDIR) $(LIBDIR)
	$(MKDIR) $(LIBDIR)/tcl
	-$(LN) $(LIBDIR) $(BINDIR)/plugins
	cp -R tcl $(LIBDIR)
	chmod -R 0755 $(LIBDIR)/tcl
	cp ../lib/ayam-splash.gif $(LIBDIR)/tcl
	-$(INSTALL) contrib/meta/metaobj.so $(LIBDIR)
	-$(INSTALL) contrib/meta/metaobj.tcl $(LIBDIR)
	-$(INSTALL) contrib/meta/metacomp.tcl $(LIBDIR)
	-$(INSTALL) plugins/mfio.so $(LIBDIR)
	-$(INSTALL) plugins/mfio.tcl $(LIBDIR)
	-$(INSTALL) plugins/loadmfio.tcl $(LIBDIR)
	-$(INSTALL) plugins/idr.so $(LIBDIR)
	-$(INSTALL) plugins/idr.tcl $(LIBDIR)
	-$(INSTALL) plugins/loadidr.tcl $(LIBDIR)
	-$(INSTALL) plugins/rrib.so $(LIBDIR)
	-$(INSTALL) plugins/rrib.tcl $(LIBDIR)
	-$(INSTALL) plugins/loadrrib.tcl $(LIBDIR)
	-$(INSTALL) plugins/loadayslb.tcl $(LIBDIR)
	-$(INSTALL) plugins/ayslb.so $(LIBDIR)
	-$(INSTALL) plugins/loadayslo.tcl $(LIBDIR)
	-$(INSTALL) plugins/ayslo.so $(LIBDIR)
	-$(INSTALL) plugins/loadayslo3d.tcl $(LIBDIR)
	-$(INSTALL) plugins/ayslo3d.so $(LIBDIR)
	-$(INSTALL) plugins/loadayslx.tcl $(LIBDIR)
	-$(INSTALL) plugins/ayslx.so $(LIBDIR)
	-$(INSTALL) plugins/loadayso.tcl $(LIBDIR)
	-$(INSTALL) plugins/ayso.so $(LIBDIR)
	-$(INSTALL) plugins/loadaysdr.tcl $(LIBDIR)
	-$(INSTALL) plugins/aysdr.so $(LIBDIR)
	-$(INSTALL) Makefile $(LIBDIR)
	$(MKDIR) $(DOCDIR)
	$(INSTALL) $(DOCFILES) $(DOCDIR)
	$(MKDIR) $(DOCDIR)/html
	$(MKDIR) $(DOCDIR)/html/pics
	$(INSTALL) ../doc/html/*.html $(DOCDIR)/html
	$(INSTALL) ../doc/html/pics/* $(DOCDIR)/html/pics
	@echo "Installation completed."
	@echo "Add $(BINDIR) to your PATH."
	@echo "Add $(LIBDIR) to your LD_LIBRARY_PATH."
	@echo "Use 'make -f $(LIBDIR)/Makefile uninstall' to uninstall."

uninstall:
	-rm -f $(BINDIR)/ayamsh
	-rm -f $(BINDIR)/ayam
	-rm -rf $(LIBDIR)/tcl $(LIBDIR)/ayam-splash.gif
	-rm -rf $(LIBDIR)/metaobj.so
	-rm -rf $(LIBDIR)/metaobj.tcl $(LIBDIR)/metacomp.tcl
	-rm -rf $(LIBDIR)/mfio.so $(LIBDIR)/mfio.tcl $(LIBDIR)/loadmfio.tcl
	-rm -rf $(LIBDIR)/idr.so $(LIBDIR)/idr.tcl
	-rm -rf $(LIBDIR)/rrib.so $(LIBDIR)/rrib.tcl
	-rm -rf $(LIBDIR)/loadrrib.tcl $(LIBDIR)/loadidr.tcl
	-rm -rf $(LIBDIR)/ayslb.so $(LIBDIR)/loadayslb.tcl
	-rm -rf $(LIBDIR)/ayslo.so $(LIBDIR)/loadayslo.tcl
	-rm -rf $(LIBDIR)/ayslo3d.so $(LIBDIR)/loadayslo3d.tcl
	-rm -rf $(LIBDIR)/ayslx.so $(LIBDIR)/loadayslx.tcl
	-rm -rf $(LIBDIR)/ayso.so $(LIBDIR)/loadayso.tcl
	-rm -rf $(LIBDIR)/aysdr.so $(LIBDIR)/loadaysdr.tcl
	-cd $(DOCDIR); rm -rf Setup.txt Changes.txt License.txt refcard.tcl\
refcard.ps ayam.pdf html;
	-rm -rf $(LIBDIR)/Makefile

.SUFFIXES: .so .o

.o.so: 
	$(CC) $(SHLFLAGS) -o $@ $*.o
