#******************************************************************************
#
#       Copyright:      2005-2010 Paul Obermeier (obermeier@tcl3d.org)
#
#                       See the file "Tcl3D_License.txt" for information on
#                       usage and redistribution of this file, and for a
#                       DISCLAIMER OF ALL WARRANTIES.
#
#       Module:         Tcl3D -> tcl3dOde
#       Filename:       Makefile
#
#       Author:         Paul Obermeier
#
#       Description:    Makefile for the tcl3dOde subpackage.
#                       The syntax is based on GNU make.
#
#******************************************************************************

.PHONY: all install clean distclean

include ../make.oscheck
include ../make.macros
include ../make.wrap

# The key file name to detect whether Tcl3D could be wrapped
# with ODE support. If this file does not exist, we can not wrap
# the ODE library, even if WRAP_ODE has been defined in make.wrap.
KEY_ODE  = ode/ode.h

HAVE_ODE =
ifdef WRAP_ODE
HAVE_ODE = $(strip $(wildcard $(KEY_ODE)))
endif

ODELIBS =
ifneq (,$(HAVE_ODE))
PPDEFS += -DUSE_ODE_IF
ifeq (win32,$(KERNEL))
ODELIBS = lib$(DSEP)ode$(LIBEXT)
else
ODELIBS = -L../extlibs/$(OS_TYPE) -lode
endif
endif

WRAPOBJS = \
        tcl3dOde_wrap$(OBJEXT)

SWIG_FILES = \
        $(COMMON_SWIGFILES) \
        swigfiles/ode.i \
        swigfiles/tcl3dOde.i

WRAPSRCS = $(WRAPOBJS:$(OBJEXT)=.c)
ALL_SRCS = $(WRAPSRCS)

PKG_NAME = tcl3dOde
PKG_LIB  = $(PKG_NAME)$(SHLIBEXT)

CFLAGS = $(OPT) $(PPDEFS) -I$(GL_INCDIR) -I$(GLU_INCDIR) -Iode $(INCL)

.SUFFIXES:                  # Delete the default suffixes.
.SUFFIXES: .c $(OBJEXT) .h  # Install our own suffixes.

.c$(OBJEXT):
	$(CC) $(CFLAGS) $<

all:    $(PKG_LIB)

install: all
	-$(MKDIR) $(TCL3D_INSTLIB)
	-$(MKDIR) $(TCL3D_INSTLIB)$(DSEP)$(PKG_NAME)
	$(CP) $(PKG_LIB)                       $(TCL3D_INSTLIB)$(DSEP)$(PKG_NAME)
	$(CP) tclfiles$(DSEP)tcl3dOdeQuery.tcl $(TCL3D_INSTLIB)$(DSEP)$(PKG_NAME)
	$(CP) tclfiles$(DSEP)tcl3dOdeUtil.tcl  $(TCL3D_INSTLIB)$(DSEP)$(PKG_NAME)
	$(CP) tclfiles$(DSEP)pkgIndex.tcl      $(TCL3D_INSTLIB)$(DSEP)$(PKG_NAME)
	$(CP) ..$(DSEP)pkgIndex.tcl            $(TCL3D_INSTLIB)

clean:
	-$(RM) $(WRAPOBJS)
	-$(RM) $(WRAPSRCS)
	-$(RM) $(VC_CLEANUP_FILES)

distclean: clean
	-$(RM) $(PKG_LIB)

tcl3dOde_wrap.c: $(SWIG_FILES)
	swig -tcl -pkgversion $(VERSION) $(PPDEFS) \
             -I../swigfiles -Iswigfiles -Iode -I$(GL_INCDIR) -I$(GLU_INCDIR) $(INCL) \
             -o $@ swigfiles/tcl3dOde.i

$(PKG_LIB): $(WRAPOBJS)
	$(SHLIB_LD) $(SHLIB_CFLAGS) $(LDOUT)$@ \
                    $(WRAPOBJS) \
                    $(TCLLIBS) $(ODELIBS) $(GLLIBS) $(SYSLIBS)
	$(MT32) -manifest $(PKG_LIB).manifest -outputresource:"$(PKG_LIB);2"
ifneq (,$(HAVE_ODE))
	@echo Tcl3D built with ODE support
else
	@echo Tcl3D built without ODE support
endif
