#******************************************************************************
#
#       Copyright:      2006-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 -> tcl3dGl2ps
#       Filename:       Makefile
#
#       Author:         Paul Obermeier
#
#       Description:    Makefile for the tcl3dGl2ps 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 gl2ps support. If this file does not exist, we can not wrap
# the gl2ps library, even if WRAP_GL2PS has been defined in make.wrap.
KEY_GL2PS = gl2ps.h

HAVE_GL2PS =
ifdef WRAP_GL2PS
HAVE_GL2PS = $(strip $(wildcard $(KEY_GL2PS)))
PPDEFS += -DUSE_GL2PS_IF
endif

GL2PSOBJS = \
	gl2ps$(OBJEXT)

GL2PSHDRS = \
	gl2ps.h

WRAPOBJS = \
	gl2ps_wrap$(OBJEXT) 

SWIG_FILES = \
	$(COMMON_SWIGFILES) \
	swigfiles$(DSEP)gl2ps.i \
	swigfiles$(DSEP)tcl3dGl2ps.i

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

PKG_NAME = tcl3dGl2ps
PKG_LIB  = $(PKG_NAME)$(SHLIBEXT)

CFLAGS = $(OPT) $(PPDEFS) -I$(GL_INCDIR) -I$(GLU_INCDIR) $(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)tcl3dGl2psQuery.tcl $(TCL3D_INSTLIB)$(DSEP)$(PKG_NAME)
	$(CP) tclfiles$(DSEP)tcl3dGl2psUtil.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) $(GL2PSOBJS)
	-$(RM) $(WRAPSRCS)
	-$(RM) $(VC_CLEANUP_FILES)

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

gl2ps_wrap.c: $(SWIG_FILES) $(GL2PSHDRS)
	swig -tcl -pkgversion $(VERSION) $(PPDEFS) \
             -I../swigfiles -Iswigfiles $(INCL) \
             -o $@ swigfiles/tcl3dGl2ps.i

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