Support VPATH builds when invoking SWIG fixups.
[xapian.git] / xapian-bindings / python / Makefile.am
blob5d5b29b8ee4902a6854e05ebc896e1278935637d
1 ## Process this file with automake to produce Makefile.in
3 include ../generic/generic.mk
5 ## Test programs to be run
6 TESTS = smoketest.py pythontest.py
7 AM_TESTS_ENVIRONMENT = \
8         abs_builddir='$(abs_builddir)' ;\
9         srcdir='$(srcdir)' ;\
10         PYTHON='$(PYTHON2)' ;\
11         export abs_builddir ;\
12         export srcdir ;\
13         export PYTHON ;
14 LOG_COMPILER = '$(srcdir)'/run-python-test
16 installcheck-local:
17         $(MAKE) check  LOG_COMPILER='$(PYTHON2)' AM_TESTS_ENVIRONMENT= \
18             PYTHONDONTWRITEBYTECODE=1
20 RST_DOCS = \
21         docs/examples.rst \
22         docs/index.rst \
23         docs/introduction.rst \
24         docs/xapian.rst
26 # FIXME: replicationtest.py attempts to test performing replication whilst
27 # modifications are in progress.  However, it sometimes fails due to a race
28 # condition in it.  It also contains hard-coded paths to the replication
29 # server and client, which assume the file layout in a repo checkout.
30 # Therefore, we don't run it by default currently.
31 # replicationtest.py
33 BUILT_SOURCES = xapian_wrap.cc xapian_wrap.h xapian.py
35 EXTRA_DIST = python.i util.i extra.i extracomments.i except.i \
36         doxy2swig.py \
37         fixup-swig-py2-wrapper \
38         generate-python-exceptions \
39         run-python-test \
40         testsuite.py \
41         test_xapian_star.py \
42         replicationtest.py \
43         $(TESTS) $(BUILT_SOURCES) $(RST_DOCS)
45 pkgpylibdir = @PYTHON2_LIB@/xapian
47 # Install as _DATA rather than _SCRIPTS because we don't want to make these
48 # executable (they don't have a #! line).
49 pkgpylib_DATA = xapian/__init__.py \
50                 xapian/__init__.pyc \
51                 xapian/__init__.pyo
53 pkgpylib_LTLIBRARIES = _xapian.la
55 # Remove the .la file - _xapian.la is never linked against (it's a module)
56 # and Python doesn't use libltdl.  Note that the library gets installed by
57 # install-data, so that's where we need to hook.
58 install-data-hook:
59         rm -f $(DESTDIR)$(pkgpylibdir)/_xapian.la
61 # Because we don't install the .la file, "make uninstall" doesn't work and
62 # we need to remove the file ourselves.
63 uninstall-local:
64         rm -f $(DESTDIR)$(pkgpylibdir)/_xapian$(PYTHON2_SO)
66 AM_CPPFLAGS = -I$(PYTHON2_INC)
67 AM_CXXFLAGS = $(SWIG_CXXFLAGS) $(XAPIAN_CXXFLAGS)
68 _xapian_la_LDFLAGS = -avoid-version -module -shrext "$(PYTHON2_SO)" $(NO_UNDEFINED)
69 _xapian_la_SOURCES = xapian_wrap.cc
70 _xapian_la_LIBADD = $(XAPIAN_LIBS) $(PYTHON2_LIBS)
72 # We want `xapian/__init__.py` rather than xapian.py so the module is treated
73 # as a package.
74 xapian/__init__.py: xapian.py
75         $(MKDIR_P) xapian
76         cp `test -f xapian.py || echo '$(srcdir)/'`xapian.py xapian/__init__.py
78 # We "import _xapian" first so that if we fail to import the glue library
79 # we don't generate a broken .pyc or .pyo, and we do it with the current
80 # directory set to where the module is as Python with -c always searches the
81 # current directory first.
83 # We then "import xapian" as a separate command, as that's more like how things
84 # are once installed - in particular this will fail if the SWIG shadow wrapper
85 # doesn't cope with being xapian/__init__.py (currently it needs fixing
86 # up, which is done by fixup-swig-py2-wrapper).
87 xapian/__init__.pyc: xapian/__init__.py xapian/_xapian$(PYTHON2_SO)
88         cd xapian && $(PYTHON2) -c 'import _xapian'
89         $(PYTHON2) -c 'import xapian'
91 xapian/__init__.pyo: xapian/__init__.py xapian/_xapian$(PYTHON2_SO)
92         cd xapian && $(PYTHON2) -O -c 'import _xapian'
93         $(PYTHON2) -O -c 'import xapian'
95 xapian/_xapian$(PYTHON2_SO): _xapian.la
96         $(MKDIR_P) xapian
97         $(LIBTOOL) --config > libtoolconfig.tmp
98 ## ksh requires a path on the sourced file.
99         . ./libtoolconfig.tmp; cp $$objdir/_xapian$(PYTHON2_SO) xapian
100         rm -f libtoolconfig.tmp
102 CLEANFILES = \
103     xapian/_xapian$(PYTHON2_SO) \
104     xapian/__init__.py xapian/__init__.pyc xapian/__init__.pyo \
105     $(srcdir)/*.pyc
107 # Clean the xapian directory which we created, if it's empty, and any
108 # databases created by test cases.
109 clean-local:
110         -rmdir xapian
111         rm -rf db_test_* dbs_replication
113 if MAINTAINER_MODE
114 BUILT_SOURCES += except.i doccomments.i
115 except.i: $(srcdir)/generate-python-exceptions ../../xapian-core/exception_data.pm
116         $(PERL) -w -I$(srcdir)/../../xapian-core $(srcdir)/generate-python-exceptions
118 if MAINTAINER_NO_DOCS
119 doccomments.i:
120         : > doccomments.i
121 else
122 doccomments.i: doxy2swig.py ../../xapian-core/exception_data.pm ../doxygen-xml/index.xml
123         $(PYTHON) $(srcdir)/doxy2swig.py ../doxygen-xml/index.xml doccomments.i
124 endif
126 # We need to explicitly set -outdir because on Windows, SWIG splits paths at
127 # "\" when extracting the output directory from the value passed to the -o
128 # option.
130 stamp = xapian_wrap.stamp
131 RUN_SWIG = stamp='$(stamp)' $(PERL) '$(top_srcdir)'/swig-depcomp $(SWIG)
132 SWIG_FLAGS += -DSWIG_PYTHON_LEGACY_BOOL
134 xapian_wrap.cc xapian_wrap.h xapian.py xapian_wrap.d: $(stamp)
135         $(make_many_locked)
136 $(stamp): except.i doccomments.i
137         $(multitarget_begin)
138         $(RUN_SWIG) $(SWIG_WERROR) -I. -I'$(srcdir)' $(SWIG_FLAGS) -c++ \
139             -python -threads -shadow -modern -O \
140             -o xapian_wrap.cc '$(srcdir)/'python.i
141         $(PERL) -i $(srcdir)/fixup-swig-py2-wrapper xapian.py
142         $(multitarget_end)
144 -include xapian_wrap.d
146 CLEANFILES += xapian_wrap.d $(stamp)
147 endif
148 MAINTAINERCLEANFILES = $(BUILT_SOURCES)
150 exampledatadir = $(docdir)/python/examples
151 dist_exampledata_DATA = \
152         docs/examples/simpleindex.py \
153         docs/examples/simpleexpand.py \
154         docs/examples/simplematchdecider.py \
155         docs/examples/simplesearch.py
157 sphinxdocs = docs/html/index.html
159 install-data-local:
160         $(mkinstalldirs) '$(DESTDIR)$(docdir)/python'
161         cp -R -p `test -r docs/html || echo '$(srcdir)/'`docs/html '$(DESTDIR)$(docdir)/python'
163 all-local: $(sphinxdocs)
165 $(sphinxdocs): xapian/__init__.py docs/conf.py $(RST_DOCS) $(dist_exampledata_DATA)
166         PYTHONPATH=..:$$PYTHONPATH $(PYTHON2) $(SPHINX_BUILD) -b html -d doctrees -c docs $(srcdir)/docs docs/html