# Makefile for PDFlib's Python binding
# $Id: Makefile.in,v 1.15 2001/04/18 17:12:17 rjs Exp $

VERSION		= @VERSION@
LTVERSIONINFO	= @LTVERSIONINFO@
LIBPDF		= lib@PDFLIBNAME@
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 	= @PYTHONLIBDIR@

SWIG		= swig1.2 -I../../pdflib -python -stat
SWIG_LIB	= pdflib_py.la
SWIG_OBJ	= pdflib_py.lo

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

all:	$(SWIG_LIB)

.PHONY: clean

# The swig-generated wrapper file
swig: ../../pdflib/pdflib.i ../../pdflib/pdflib.h
	$(SWIG) $(SWIGFLAGS) -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_py.dylib; then		\
	    ln .libs/libpdflib_py.dylib .libs/pdflib_py.so;	\
	fi

test: all
	@-(. ./pdflib_py.la; cd .libs; cp $$library_names ..)
	-$(LIBTOOL) --mode=execute -dlopen $(SWIG_LIB) python hello.py
	-$(LIBTOOL) --mode=execute -dlopen $(SWIG_LIB) python image.py
	-$(LIBTOOL) --mode=execute -dlopen $(SWIG_LIB) python pdfclock.py

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

install: $(SWIG_LIB)
	@-if test -f .libs/libpdflib_py.dylib; then		\
	    $(INSTALL_DATA) .libs/pdflib_py.so $(LANG_LIBDIR);	\
	else							\
	    $(LIBTOOL) --mode=install $(INSTALL_DATA) 		\
		$(SWIG_LIB) $(LANG_LIBDIR);			\
	fi

uninstall:
	@-if test -f .libs/libpdflib_py.dylib; then			 \
	    $(LIBTOOL) --mode=uninstall $(RM) $(LANG_LIBDIR)/pdflib_py.so\
	else 								 \
	    $(LIBTOOL) --mode=uninstall $(RM) $(LANG_LIBDIR)/$(SWIG_LIB) \
	fi

clean:
	@-if test -f pdflib_py.la; then			\
	    (. ./pdflib_py.la; $(RM) $$library_names)	\
	fi
	-$(RM) *.$(OBJ) *.lo *.la .libs hello_py.pdf image_py.pdf pdfclock_py.pdf personalize.pdf quickreference.pdf
