Commit fa3df18fc65ed7ae2dcad7996ad0fef6014d6a42
1 parent
51920ca3
make SWIG optional
Showing
2 changed files
with
46 additions
and
11 deletions
configure.ac
| ... | ... | @@ -146,9 +146,10 @@ else |
| 146 | 146 | fi |
| 147 | 147 | |
| 148 | 148 | |
| 149 | -dnl ============================================================================= | |
| 150 | -dnl Checks for python bindings. This is only set if SWIG and Python ar available. | |
| 151 | -dnl ============================================================================= | |
| 149 | +dnl ====================================================================== | |
| 150 | +dnl Checks for python binding. Python binding requires Python and either a | |
| 151 | +dnl gammalib_wrap.cpp file or SWIG to create this file. | |
| 152 | +dnl ====================================================================== | |
| 152 | 153 | # Checks for SWIG (HAVE_SWIG) |
| 153 | 154 | AC_PATH_PROG([SWIG], [swig]) |
| 154 | 155 | AM_CONDITIONAL(HAVE_SWIG, test "$SWIG") |
| ... | ... | @@ -159,15 +160,36 @@ AM_PATH_PYTHON([2.2], |
| 159 | 160 | [AC_MSG_WARN([Python not found. Python is required to build python binding. Python can be obtained from http://www.python.org])]) |
| 160 | 161 | AM_CONDITIONAL(HAVE_PYTHON, test "$PYTHON") |
| 161 | 162 | |
| 163 | +# Checks for gammalib_wrap.cpp and gammalib.py | |
| 164 | +AC_CHECK_FILES([pyext/gammalib_wrap.cpp pyext/gammalib.py], | |
| 165 | + [ac_has_python_wrap="yes"], | |
| 166 | + [ac_has_python_wrap="no"]) | |
| 167 | +if test "x$ac_has_python_wrap" = "xyes"; then | |
| 168 | + AC_MSG_NOTICE([Found gammalib_wrap.cpp and gammalib.py]) | |
| 169 | +else | |
| 170 | + AC_MSG_NOTICE([gammalib_wrap.cpp and/or gammalib.py not found]) | |
| 171 | +fi | |
| 172 | +AM_CONDITIONAL(HAS_PYTHON_WRAP, test "x$ac_has_python_wrap" = "xyes") | |
| 173 | + | |
| 162 | 174 | # Python bindings |
| 163 | 175 | AC_ARG_ENABLE([python-binding], |
| 164 | 176 | AS_HELP_STRING([--enable-python-binding], |
| 165 | 177 | [build python binding (default=yes)]), |
| 166 | - [ac_enable_python_binding=no], | |
| 167 | - [ac_enable_python_binding=yes]) | |
| 178 | + [ac_enable_python_binding="$enableval"], | |
| 179 | + [ac_enable_python_binding="yes"]) | |
| 168 | 180 | if test "x$ac_enable_python_binding" = "xyes"; then |
| 169 | - if test ! "$SWIG" -a ! "$PYTHON"; then | |
| 170 | - AC_MSG_WARN([Python binding for gammalib cannot be built. Ensure that SWIG and Python packages are available.]) | |
| 181 | + if test "$PYTHON"; then | |
| 182 | + if test "x$ac_has_python_wrap" = "xyes"; then | |
| 183 | + AC_MSG_NOTICE([Build Python binding using shipped gammalib_wrap.cpp]) | |
| 184 | + else | |
| 185 | + if test ! "$SWIG"; then | |
| 186 | + AC_MSG_WARN([Neither gammalib_wrap.cpp and/or gammalib.py files nor SWIG has not been found.]) | |
| 187 | + AC_MSG_WARN([Python binding for gammalib cannot be built.]) | |
| 188 | + AC_MSG_WARN([Either use a gammalib distribution with gammalib_wrap.cpp and gammalib.py shipped or install SWIG on your system.]) | |
| 189 | + fi | |
| 190 | + fi | |
| 191 | + else | |
| 192 | + AC_MSG_WARN([Python binding for gammalib cannot be built as Python seems not to be installed on your system.]) | |
| 171 | 193 | fi |
| 172 | 194 | else |
| 173 | 195 | AC_MSG_NOTICE([Python binding for gammalib will not be built.]) | ... | ... |
pyext/Makefile.am
| 1 | 1 | ## Process this file with automake to produce Makefile.in |
| 2 | +# | |
| 3 | +# Note that we could also ship gammalib_wrap.cpp with the code | |
| 4 | +# so that the call to SWIG is not required. We should add some | |
| 5 | +# test to the master configure.ac script that will test if | |
| 6 | +# gammalib_wrap.cpp is shipped with the distribution. In this | |
| 7 | +# case the SWIG call may be omitted and the gammalib_wrap.cpp | |
| 8 | +# file will be simply compiled. | |
| 2 | 9 | |
| 3 | 10 | if ENABLE_PYTHON_BINDING |
| 11 | +if HAVE_PYTHON | |
| 4 | 12 | |
| 5 | 13 | SWIG_INTERFACE = gammalib.i |
| 6 | 14 | BUILT_SOURCES = gammalib_wrap.cpp gammalib.py |
| ... | ... | @@ -32,11 +40,16 @@ install-exec-local: |
| 32 | 40 | clean-local: |
| 33 | 41 | rm -rf build |
| 34 | 42 | |
| 43 | +if HAVE_SWIG | |
| 35 | 44 | gammalib_wrap.cpp gammalib.py: $(SWIG_INTERFACE) |
| 36 | 45 | $(SWIG) -c++ -python -Wall -includeall -I$(top_srcdir)/src $(INC_INST) $(OPT_INST) -o gammalib_wrap.cpp -outdir . $(srcdir)/$(SWIG_INTERFACE) |
| 37 | - @if test "x`uname`" = "xCygwin"; then \ | |
| 38 | - echo "WARNING: working around bug in SWIG on Windows/Cygwin platforms ONLY"; \ | |
| 39 | - sed -i.bak -f $(srcdir)/fix_wrapper.sed gammalib_wrap.cpp; \ | |
| 40 | - fi | |
| 46 | +# @if test "x`uname`" = "xCygwin"; then \ | |
| 47 | +# echo "WARNING: working around bug in SWIG on Windows/Cygwin platforms ONLY"; \ | |
| 48 | +# sed -i.bak -f $(srcdir)/fix_wrapper.sed gammalib_wrap.cpp; \ | |
| 49 | +# fi | |
| 50 | +else | |
| 51 | +gammalib_wrap.cpp gammalib.py: $(SWIG_INTERFACE) | |
| 52 | +endif # HAVE_SWIG | |
| 41 | 53 | |
| 54 | +endif # HAVE_PYTHON | |
| 42 | 55 | endif # ENABLE_PYTHON_BINDING | ... | ... |