#******************************************************************************
#
#       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 -> tcl3dSDL
#       Filename:       Makefile
#
#       Author:         Paul Obermeier
#
#       Description:    Makefile for the tcl3dSDL 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 SDL support. If this file does not exist, we can not wrap
# the SDL library, even if WRAP_SDL has been defined in make.wrap.
KEY_SDL  = include/SDL.h

HAVE_SDL =
ifdef WRAP_SDL
HAVE_SDL = $(strip $(wildcard $(KEY_SDL)))
endif

SDLLIBS =
ifneq (,$(HAVE_SDL))
PPDEFS += -DUSE_SDL_IF
ifeq (win32,$(KERNEL))
SDLLIBS = lib$(DSEP)SDL$(LIBEXT)
else
ifeq (mingw,$(KERNEL))
SDLLIBS = lib$(DSEP)SDL$(LIBEXT)
else
SDLLIBS = -L../extlibs/$(OS_TYPE) -lSDL-1.2
endif
endif
endif

WRAPOBJS = \
        tcl3dSDL_wrap$(OBJEXT)

SWIG_FILES = \
        $(COMMON_SWIGFILES) \
        swigfiles/sdl.i \
        swigfiles/tcl3dSDL.i

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

PKG_NAME = tcl3dSDL
PKG_LIB  = $(PKG_NAME)$(SHLIBEXT)

CFLAGS = $(OPT) $(PPDEFS) -I$(GL_INCDIR) -I$(GLU_INCDIR) -Iinclude $(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)tcl3dSDLQuery.tcl $(TCL3D_INSTLIB)$(DSEP)$(PKG_NAME)
	$(CP) tclfiles$(DSEP)tcl3dSDLUtil.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)

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

$(PKG_LIB): $(WRAPOBJS)
	$(SHLIB_LDXX) $(SHLIB_CFLAGS) $(LDOUT)$@ \
                    $(WRAPOBJS) \
                    $(TCLLIBS) $(SDLLIBS) $(GLLIBS) $(SYSLIBS)
	$(MT32) -manifest $(PKG_LIB).manifest -outputresource:"$(PKG_LIB);2"
ifneq (,$(HAVE_SDL))
	@echo Tcl3D built with SDL support
else
	@echo Tcl3D built without SDL support
endif
