# Makefile for PDFlib's Tcl binding
# $Id: Makefile.in,v 1.14 2001/04/18 13:39:04 tm Exp $

VERSION		= @VERSION@
LIBPDF		= lib@PDFLIBNAME@
LTVERSIONINFO	= @LTVERSIONINFO@
SHELL		= @SHELL@
INSTALL		= @INSTALL@
INSTALL_DATA 	= @INSTALL_DATA@
srcdir		= @srcdir@
top_builddir	= ../..
VPATH		= @srcdir@
EXE		= @EXEEXT@
OBJ		= @OBJEXT@
CC		= @CC@
RM      	= @RM@
LIBTOOL		= ../../libtool --silent

PDFLIBCONVENIENT= @PDFLIBCONVENIENT@

.SUFFIXES: .c .$(OBJ) .lo

.c.lo:
	$(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(DEFINES) $<

.c.$(OBJ):
	$(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(DEFINES) $<

LANG_LIBDIR 	= @TCLPACKAGEDIR@
TCLBIN		= @TCLBIN@

SWIG		= swig1.2 -I../../pdflib -tcl -stat
SWIG_LIB	= pdflib_tcl.la
SWIG_OBJ	= pdflib_tcl.lo

DEFINES		= -I../../pdflib @TCLINCLUDE@ @DEFINES@

all:	$(SWIG_LIB)

.PHONY: clean

# The swig-generated wrapper file
swig: ../../pdflib/pdflib.i ../../pdflib/pdflib.h
	$(SWIG) -o $@.XXX ../../pdflib/pdflib.i
	@echo "Wrapper templates generated!"

# The actual shared library for the language support
$(SWIG_LIB): $(SWIG_OBJ) ../../pdflib/$(LIBPDF).la ../../pdflib/pdflib.h
	$(RM) $(SWIG_LIB)
	$(LIBTOOL) --mode=link $(CC) -o $@ $(SWIG_OBJ) -rpath $(LANG_LIBDIR) -no-undefined -module -version-info $(LTVERSIONINFO) $(PDFLIBCONVENIENT)
	@-if test -f .libs/libpdflib_tcl.dylib; then			\
	    ln .libs/libpdflib_tcl.dylib .libs/pdflib_tcl.dylib;	\
	fi

test: all
	@cp pkgIndex.tcl .libs
	-$(LIBTOOL) --mode=execute -dlopen $(SWIG_LIB) $(TCLBIN) hello.tcl
	-$(LIBTOOL) --mode=execute -dlopen $(SWIG_LIB) $(TCLBIN) image.tcl
	-$(LIBTOOL) --mode=execute -dlopen $(SWIG_LIB) $(TCLBIN) pdfclock.tcl

pditest: test
	-$(LIBTOOL) --mode=execute -dlopen $(SWIG_LIB) $(TCLBIN) quickreference.tcl
	-$(LIBTOOL) --mode=execute -dlopen $(SWIG_LIB) $(TCLBIN) personalize.tcl

install: $(SWIG_LIB)
	if test ! -d $(LANG_LIBDIR) ; then 	\
	    mkdir -p $(LANG_LIBDIR);		\
	    chmod 755 $(LANG_LIBDIR);		\
	fi
	$(INSTALL_DATA) pkgIndex.tcl $(LANG_LIBDIR)
	@-if test -f .libs/libpdflib_tcl.dylib; then			\
	    $(INSTALL_DATA) .libs/pdflib_tcl.dylib $(LANG_LIBDIR);	\
	else								\
	    $(LIBTOOL) --mode=install $(INSTALL_DATA)			\
		$(SWIG_LIB) $(LANG_LIBDIR);				\
	fi

uninstall:
	@-if test -f .libs/libpdflib_tcl.dylib; then			\
	    $(LIBTOOL) --mode=uninstall $(RM)				\
		$(LANG_LIBDIR)/pdflib_tcl.dylib				\
		$(LANG_LIBDIR)/pkgIndex.tcl;				\
	else								\
	    $(LIBTOOL) --mode=uninstall $(RM)				\
		$(LANG_LIBDIR)/$(SWIG_LIB)				\
		$(LANG_LIBDIR)/pkgIndex.tcl;				\
	fi
	$(RM) $(LANG_LIBDIR)

clean:
	-$(RM) *.$(OBJ) *.lo *.la .libs hello_tcl.pdf image_tcl.pdf pdfclock_tcl.pdf personalize.pdf quickreference.pdf
