lalsuite_swig.m4 19 KB
Newer Older
1 2
# -*- mode: autoconf; -*-
# lalsuite_swig.m4 - SWIG configuration
3
# Author: Karl Wette, 2011--2017
4
#
5
# serial 101
6

Karl Wette's avatar
Karl Wette committed
7
AC_DEFUN([_LALSUITE_CHECK_SWIG_VERSION],[
8 9 10
  # $0: check the version of $1, and store it in ${swig_version}
  swig_version=
  swig_version_output=[`$1 -version 2>/dev/null`]
Karl Wette's avatar
Karl Wette committed
11 12 13
  AS_IF([test $? -eq 0],[
    swig_version_regex=['s|^ *SWIG [Vv]ersion \([0-9.][0-9.]*\)|\1|p;d']
    swig_version=[`echo "${swig_version_output}" | ${SED} -e "${swig_version_regex}"`]
14 15 16
  ])
  AS_IF([test "x${swig_version}" = x],[
    AC_MSG_ERROR([could not determine version of $1])
Karl Wette's avatar
Karl Wette committed
17 18 19 20 21 22
  ])
  # end $0
])

AC_DEFUN([LALSUITE_ENABLE_SWIG],[
  # $0: enable SWIG bindings
23 24 25 26
  AC_ARG_ENABLE(
    [swig],
    AC_HELP_STRING(
      [--enable-swig],
Karl Wette's avatar
Karl Wette committed
27
      [generate SWIG bindings for all languages]
28
    ),[
29 30 31
      AS_CASE(["${enableval}"],
        [yes],[swig_build_all=true],
        [no],[swig_build_all=false],
32
        [AC_MSG_ERROR([invalid value "${enableval}" for --enable-swig])]
33
      )
34 35 36 37
    ],[
      swig_build_all=
    ]
  )
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  AC_ARG_ENABLE(
    [swig_iface],
    AC_HELP_STRING(
      [--enable-swig-iface],
      [generate SWIG interface only]
    ),[
      AS_CASE(["${enableval}"],
        [yes],[swig_build_iface=true],
        [no],[swig_build_iface=false],
        [AC_MSG_ERROR([invalid value "${enableval}" for --enable-swig-iface])]
      )
    ],[
      swig_build_iface=false
    ]
  )
53 54 55 56
  LALSUITE_ENABLE_SWIG_LANGUAGE([Octave],[false],[
    # C++ is required to build Octave wrappings
    LALSUITE_REQUIRE_CXX
  ])
57
  LALSUITE_ENABLE_SWIG_LANGUAGE([Python],[true],[
58 59 60 61 62 63 64
    # Python is required to configure Python wrappings
    LALSUITE_REQUIRE_PYTHON([2.6])
  ])
  AS_IF([test "${swig_build_iface}" = true],[
    # Python is required to run generate_swig_iface.py
    LALSUITE_REQUIRE_PYTHON([2.6])
  ])
Karl Wette's avatar
Karl Wette committed
65
  # end $0
66
])
67

68
AC_DEFUN([LALSUITE_ENABLE_SWIG_LANGUAGE],[
Karl Wette's avatar
Karl Wette committed
69 70 71
  # $0: enable SWIG binding languages
  m4_pushdef([uppercase],m4_translit([$1],[a-z],[A-Z]))
  m4_pushdef([lowercase],m4_translit([$1],[A-Z],[a-z]))
72 73 74 75
  AC_ARG_ENABLE(
    [swig-]lowercase,
    AC_HELP_STRING(
      [--enable-swig-]lowercase,
76
      [generate SWIG bindings for $1]
77 78 79 80
    ),[
      AS_CASE(["${enableval}"],
        [yes],[swig_build_]lowercase[=true],
        [no],[swig_build_]lowercase[=false],
81
        [AC_MSG_ERROR([invalid value "${enableval}" for --enable-swig-]]lowercase[)]
82 83 84 85 86
      )
    ],[
      swig_build_]lowercase[=${swig_build_all:-$2}
    ]
  )
Karl Wette's avatar
Karl Wette committed
87
  AS_IF([test "${swig_build_]lowercase[}" = true],[
88
    swig_build_iface=true
Karl Wette's avatar
Karl Wette committed
89 90 91 92
    SWIG_BUILD_]uppercase[_ENABLE_VAL=ENABLED
    $3
  ],[
    SWIG_BUILD_]uppercase[_ENABLE_VAL=DISABLED
93
  ])
Karl Wette's avatar
Karl Wette committed
94 95
  AM_CONDITIONAL([SWIG_BUILD_]uppercase,[test "${swig_build_]lowercase[}" = true])
  m4_popdef([uppercase])
96
  m4_popdef([lowercase])
Karl Wette's avatar
Karl Wette committed
97
  # end $0
98 99 100
])

AC_DEFUN([LALSUITE_USE_SWIG],[
Karl Wette's avatar
Karl Wette committed
101
  # $0: configure enabled SWIG bindings
102
  AS_IF([test "${swig_build_iface}" = true],[
Karl Wette's avatar
Karl Wette committed
103

104
    # configure SWIG binding languages
105
    swig_min_version=2.0.12
106 107 108 109
    swig_min_version_info=""
    LALSUITE_USE_SWIG_OCTAVE
    LALSUITE_USE_SWIG_PYTHON

110 111
    # check for SWIG binary with version ${swig_min_version} or later;
    # use ${SWIG} if set, otherwise check common SWIG binary names
112
    AC_SUBST([SWIG])
113 114 115 116 117
    AS_IF([test "x${SWIG}" != x],[
      AC_MSG_CHECKING([if ${SWIG} version is at least ${swig_min_version}])
      _LALSUITE_CHECK_SWIG_VERSION([${SWIG}])
      LALSUITE_VERSION_COMPARE([${swig_version}],[<],[${swig_min_version}],[
        AC_MSG_RESULT([no (${swig_version})])
118 119
        AC_MSG_ERROR([[SWIG version ${swig_min_version} or later is required ${swig_min_version_info}
SWIG support can be disabled by using the --disable-swig configure option]])
120
      ])
121
      AC_MSG_RESULT([yes (${swig_version})])
Karl Wette's avatar
Karl Wette committed
122
    ],[
123
      AC_PATH_PROGS_FEATURE_CHECK([SWIG],[swig swig2.0 swig3.0],[
124 125 126 127 128 129
        AC_MSG_CHECKING([if ${ac_path_SWIG} version is at least ${swig_min_version}])
        _LALSUITE_CHECK_SWIG_VERSION([${ac_path_SWIG}])
        LALSUITE_VERSION_COMPARE([${swig_version}],[>=],[${swig_min_version}],[
          ac_path_SWIG_found=true
          AC_MSG_RESULT([yes (${swig_version})])
          ac_cv_path_SWIG="${ac_path_SWIG}"
130
        ],[
131 132
          ac_path_SWIG_found=false
          AC_MSG_RESULT([no (${swig_version})])
133
        ])
134
      ],[
135 136
        AC_MSG_ERROR([[SWIG version ${swig_min_version} or later is required ${swig_min_version_info}
SWIG support can be disabled by using the --disable-swig configure option]])
137
      ])
138
      SWIG="${ac_cv_path_SWIG}"
139 140
    ])

141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    # check if SWIG works with ccache
    ccache_swig_env="CCACHE_CPP2=1"
    AC_MSG_CHECKING([if ${SWIG} works with ${ccache_swig_env}])
    echo '%module conftest;' > conftest-swig.i
    env_ccache_swig_cmd="env ${ccache_swig_env} ${SWIG} -includeall -ignoremissing -xml -xmllite -MP -MD -MF conftest-swig.deps -o conftest-swig.xml conftest-swig.i"
    _AS_ECHO_LOG([${env_ccache_swig_cmd}])
    ${env_ccache_swig_cmd} >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
    result=$?
    _AS_ECHO_LOG([\$? = ${result}])
    AS_IF([test ${result} -eq 0],[
      AC_MSG_RESULT([yes])
    ],[
      AC_MSG_RESULT([no])
      ccache_swig_env="CCACHE_DISABLE=1"
    ])
    SWIG="env ${ccache_swig_env} ${SWIG}"
    rm -f conftest-swig.i conftest-swig.deps conftest-swig.xml

Karl Wette's avatar
Karl Wette committed
159 160 161 162 163
    # extract -I and -D flags from LALSuite library preprocessor flags
    AC_SUBST([SWIG_CPPFLAGS],[])
    for flag in ${CPPFLAGS}; do
      AS_CASE([${flag}],
        [-I*|-D*],[SWIG_CPPFLAGS="${SWIG_CPPFLAGS} ${flag}"]
164 165
      )
    done
Karl Wette's avatar
Karl Wette committed
166 167 168 169 170 171

    # extract -L flags from LALSuite library linker flags
    AC_SUBST([SWIG_LDFLAGS],[])
    for flag in ${LDFLAGS}; do
      AS_CASE([${flag}],
        [-L*],[SWIG_LDFLAGS="${SWIG_LDFLAGS} ${flag}"]
172 173
      )
    done
174

Karl Wette's avatar
Karl Wette committed
175 176 177
    # determine various libtool parameters
    AC_SUBST([SWIG_LTLIBDIR],["${objdir}"])
    AC_SUBST([SWIG_SOEXT],[`module=yes; eval shrext=\"${shrext_cmds}\"; echo ${shrext}`])
178

Karl Wette's avatar
Karl Wette committed
179 180 181 182 183 184 185 186
    # substitute list of LALSuite bindings that these bindings depend on
    AC_MSG_CHECKING([for LALSuite binding dependencies])
    AC_SUBST([SWIG_DEPENDENCIES],[])
    for arg in ${lalsuite_libs}; do
      AS_CASE([${arg}],
        [lalsupport],[:],
        [SWIG_DEPENDENCIES="${SWIG_DEPENDENCIES} ${arg}"]
      )
187
    done
Karl Wette's avatar
Karl Wette committed
188 189
    AS_IF([test "x${SWIG_DEPENDENCIES}" = x],[
      AC_MSG_RESULT([none])
190
    ],[
Karl Wette's avatar
Karl Wette committed
191
      AC_MSG_RESULT([${SWIG_DEPENDENCIES}])
192 193
    ])

194
  ])
195
  AM_CONDITIONAL([SWIG_BUILD],[test "${swig_build_iface}" = true])
196 197 198 199

  # run SWIG binding language post-actions
  _LALSUITE_USE_SWIG_POST_ACTIONS

Karl Wette's avatar
Karl Wette committed
200
  # end $0
201 202
])

203 204
m4_define([_LALSUITE_USE_SWIG_POST_ACTIONS],[])

205
AC_DEFUN([LALSUITE_USE_SWIG_LANGUAGE],[
Karl Wette's avatar
Karl Wette committed
206 207 208 209
  # $0: configure SWIG binding languages
  m4_pushdef([uppercase],m4_translit([$1],[a-z],[A-Z]))
  m4_pushdef([lowercase],m4_translit([$1],[A-Z],[a-z]))
  AS_IF([test "${swig_build_]lowercase[}" = true],[
210
    AC_LANG_PUSH([$2])
Karl Wette's avatar
Karl Wette committed
211
    swig_build=true
212
    $3
213
    AC_LANG_POP([$2])
214
  ])
215 216 217 218 219
  m4_append([_LALSUITE_USE_SWIG_POST_ACTIONS],[
    AS_IF([test "${swig_build_]]lowercase[[}" = true],[
      $4
    ])
  ])
220 221
  m4_popdef([uppercase])
  m4_popdef([lowercase])
Karl Wette's avatar
Karl Wette committed
222
  # end $0
223 224
])

225
AC_DEFUN([LALSUITE_USE_SWIG_OCTAVE],[
Karl Wette's avatar
Karl Wette committed
226
  # $0: configure SWIG Octave bindings
227
  LALSUITE_USE_SWIG_LANGUAGE([Octave],[C++],[
228

229
    # check for GSL, needed for LAL complex number support in C++
230 231 232 233
    PKG_CHECK_MODULES([GSL],[gsl],[true],[false])
    LALSUITE_ADD_FLAGS([C],[${GSL_CFLAGS}],[${GSL_LIBS}])
    AC_CHECK_HEADERS([gsl/gsl_complex.h],,[AC_MSG_ERROR([could not find the gsl/gsl_complex.h header])])

Karl Wette's avatar
Karl Wette committed
234
    # check for Octave
235
    AC_PATH_PROGS(OCTAVE,[octave-cli octave],[],[])
236
    AS_IF([test "x${OCTAVE}" = x],[
Karl Wette's avatar
Karl Wette committed
237
      AC_MSG_ERROR([could not find octave in PATH])
238 239
    ])

Karl Wette's avatar
Karl Wette committed
240 241 242 243 244 245 246 247 248 249 250
    # check for Octave utilities octave-config and mkoctfile
    octave_dir=`AS_DIRNAME(["${OCTAVE}"])`
    AC_MSG_CHECKING([for octave-config])
    octave_cfg="${octave_dir}/octave-config"
    AS_IF([test -x "${octave_cfg}"],[
      AC_MSG_RESULT([${octave_cfg}])
    ],[
      AC_MSG_RESULT([not found])
      AC_MSG_ERROR([could not find octave-config in ${octave_dir}])
    ])
    octave_cfg="env - ${octave_cfg}"
251
    AC_MSG_CHECKING([for mkoctfile])
Karl Wette's avatar
Karl Wette committed
252 253 254
    mkoctfile="${octave_dir}/mkoctfile"
    AS_IF([test -x "${mkoctfile}"],[
      AC_MSG_RESULT([${mkoctfile}])
255
    ],[
Karl Wette's avatar
Karl Wette committed
256 257
      AC_MSG_RESULT([not found])
      AC_MSG_ERROR([could not find mkoctfile in ${octave_dir}])
258
    ])
Karl Wette's avatar
Karl Wette committed
259
    mkoctfile="env - ${mkoctfile}"
260 261 262 263

    # check Octave version
    octave_min_version=3.2.0
    AC_MSG_CHECKING([${OCTAVE} version])
Karl Wette's avatar
Karl Wette committed
264
    octave_version=[`${octave_cfg} -p VERSION 2>/dev/null`]
265
    AS_IF([test "x${octave_version}" = x],[
266
      AC_MSG_ERROR([could not determine ${OCTAVE} version])
267 268
    ])
    AC_MSG_RESULT([${octave_version}])
269
    LALSUITE_VERSION_COMPARE([${octave_version}],[<],[${octave_min_version}],[
270 271
      AC_MSG_ERROR([Octave version ${octave_min_version} or later is required])
    ])
272
    LALSUITE_VERSION_COMPARE([${octave_version}],[>=],[4.0.0],[
273 274 275 276
      LALSUITE_VERSION_COMPARE([${swig_min_version}],[<],[3.0.7],[
        swig_min_version=3.0.7
        swig_min_version_info="for Octave version ${octave_version}"
      ])
277
    ])
278 279 280 281 282 283
    LALSUITE_VERSION_COMPARE([${octave_version}],[>=],[4.2.0],[
      LALSUITE_VERSION_COMPARE([${swig_min_version}],[<],[3.0.12],[
        swig_min_version=3.0.12
        swig_min_version_info="for Octave version ${octave_version}"
      ])
    ])
284

285 286 287 288
    # determine where to install Octave bindings: take versioned site .oct file
    # directory given by octave-config, and strip off prefix; thus, if LALSuite
    # is installed in the same directory as Octave, .oct files will be found by
    # Octave without having to add to OCTAVE_PATH
Karl Wette's avatar
Karl Wette committed
289 290 291 292 293 294 295 296 297 298 299
    AC_MSG_CHECKING([${OCTAVE} .oct installation directory])
    octave_prefix=[`${octave_cfg} -p PREFIX 2>/dev/null | ${SED} -e 's|/*$||'`]
    octexecdir=[`${octave_cfg} -p LOCALVEROCTFILEDIR 2>/dev/null | ${SED} -e 's|/*$||'`]
    octexecdir=[`echo ${octexecdir} | ${SED} -e "s|^${octave_prefix}/||"`]
    AS_IF([test "x`echo ${octexecdir} | ${SED} -n -e '\|^/|p'`" != x],[
      AC_MSG_ERROR([could not build relative path from "${octexecdir}"])
    ])
    octexecdir='${prefix}'/"${octexecdir}"
    AC_MSG_RESULT([${octexecdir}])
    AC_SUBST([octexecdir])

300
    # determine C++ compiler used to compile Octave itself
301
    AC_MSG_CHECKING([C++ compiler used for building ${OCTAVE}])
Karl Wette's avatar
Karl Wette committed
302
    octave_CXX=`${mkoctfile} -p CXX 2>/dev/null`
303
    AC_MSG_RESULT([${octave_CXX}])
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341

    # check that configured C++ compiler is compatible with C++ compiler used to
    # compile Octave itself, i.e. that both compilers link against compatible C++
    # libraries (e.g. libstdc++ vs libc++).
    AC_MSG_CHECKING([configured C++ compiler "${CXX}" is compatible with ${OCTAVE} C++ compiler "${octave_CXX}"])
    AS_IF([test "x${build_vendor}" = xapple && otool --version >/dev/null 2>&1],[
      print_shared_libs="otool -L"
    ],[ldd --version >/dev/null 2>&1],[
      print_shared_libs="ldd"
    ],[
      AC_MSG_ERROR([could not determine tool to print shared library dependencies])
    ])
    swig_save_CXX=${CXX}
    LALSUITE_PUSH_UVARS
    LALSUITE_CLEAR_UVARS
    m4_foreach([cxxloop],[CXX,octave_CXX],[
      CXX=${cxxloop}
      AC_LINK_IFELSE([
        AC_LANG_SOURCE([[
#include <string>
int main() { std::string s = "a"; return 0; }
        ]])
      ],[
        print_shared_libs_regex=["\|conftest${EXEEXT}|d;"'s|(0x[^)]*)||g;s|^ *||g;s| *$||g']
        ${print_shared_libs} conftest${EXEEXT} | ${SED} -e "${print_shared_libs_regex}" | sort > conftest_lalsuite_swig_[]cxxloop[]_shared_libs
        echo "${as_me}:${as_lineno-$LINENO}:${CXX} shared libraries:" >&AS_MESSAGE_LOG_FD
        ${SED} -e ["s/^/${as_me}:${as_lineno-$LINENO}:/"] conftest_lalsuite_swig_[]cxxloop[]_shared_libs >&AS_MESSAGE_LOG_FD
      ],[
        AC_MSG_ERROR([could not link using ${CXX}])
      ])
    ])
    LALSUITE_POP_UVARS
    CXX=${swig_save_CXX}
    AS_IF([diff conftest_lalsuite_swig_CXX_shared_libs conftest_lalsuite_swig_octave_CXX_shared_libs >/dev/null 2>&1],[
      AC_MSG_RESULT([yes])
    ],[
      AC_MSG_RESULT([no])
      AC_MSG_ERROR([configured C++ compiler "${CXX}" is incompatible with ${OCTAVE} C++ compiler "${octave_CXX}"])
342
    ])
343

Karl Wette's avatar
Karl Wette committed
344 345
    # determine Octave preprocessor flags
    AC_SUBST([SWIG_OCTAVE_CPPFLAGS],[])
346
    AC_SUBST([SWIG_OCTAVE_CPPFLAGS_IOCTAVE],[])
347
    for arg in CPPFLAGS INCFLAGS; do
348 349 350 351 352 353
      for flag in `${mkoctfile} -p ${arg} 2>/dev/null`; do
        AS_CASE([${flag}],
          [-I*/octave],[SWIG_OCTAVE_CPPFLAGS_IOCTAVE="${flag}"],
          [SWIG_OCTAVE_CPPFLAGS="${SWIG_OCTAVE_CPPFLAGS} ${flag}"]
        )
      done
354
    done
Karl Wette's avatar
Karl Wette committed
355 356 357

    # determine Octave compiler flags
    AC_SUBST([SWIG_OCTAVE_CXXFLAGS],[])
358
    swig_octave_cxxflags=
359
    for arg in CXX CXXPICFLAG ALL_CXXFLAGS; do
360
      for flag in `${mkoctfile} -p ${arg} 2>/dev/null`; do
361 362 363
        AS_CASE([${flag}],
          [-*],[swig_octave_cxxflags="${swig_octave_cxxflags} ${flag}"]
        )
364
      done
Karl Wette's avatar
Karl Wette committed
365
    done
366 367
    LALSUITE_CHECK_COMPILE_FLAGS([
      ${swig_octave_cxxflags}
368 369 370 371 372
      -Wno-uninitialized
      -Wno-unused-variable
      -Wno-unused-but-set-variable
      -Wno-format-extra-args
      -Wno-tautological-compare
373
      -Wno-deprecated-declarations
374 375 376
      -fno-strict-aliasing
      -O0
      -Wp[,]-U_FORTIFY_SOURCE
377 378
      ],[SWIG_OCTAVE_CXXFLAGS="${SWIG_OCTAVE_CXXFLAGS} ${flag}"]
    )
Karl Wette's avatar
Karl Wette committed
379 380 381

    # determine Octave linker flags
    AC_SUBST([SWIG_OCTAVE_LDFLAGS],[])
382
    swig_octave_ldflags=
Karl Wette's avatar
Karl Wette committed
383
    for arg in LFLAGS LIBOCTINTERP LIBOCTAVE LIBCRUFT OCT_LINK_OPTS OCT_LINK_DEPS; do
384 385 386
      for flag in `${mkoctfile} -p ${arg} 2>/dev/null`; do
        AS_CASE([${flag}],
          [-L/usr/lib|-L/usr/lib64],[:],
387 388
          [-Xlinker],[swig_octave_ldflags="${swig_octave_ldflags}-Wl,"],
          [swig_octave_ldflags="${swig_octave_ldflags}${flag} "]
389 390
        )
      done
391
    done
392 393 394 395
    LALSUITE_CHECK_LINK_FLAGS([
      ${swig_octave_ldflags}
      ],[SWIG_OCTAVE_LDFLAGS="${SWIG_OCTAVE_LDFLAGS} ${flag}"]
    )
396 397

    # check for Octave headers
Karl Wette's avatar
Karl Wette committed
398
    LALSUITE_PUSH_UVARS
399
    CPPFLAGS="${SWIG_OCTAVE_CPPFLAGS_IOCTAVE} ${SWIG_OCTAVE_CPPFLAGS}"
400
    CXXFLAGS="${SWIG_OCTAVE_CXXFLAGS}"
401
    AC_CHECK_HEADER([octave/oct.h],[],[
402 403 404
      AC_MSG_ERROR([could not find the header "octave/oct.h"])
    ],[
      AC_INCLUDES_DEFAULT
405
    ])
Karl Wette's avatar
Karl Wette committed
406
    LALSUITE_POP_UVARS
407

408 409 410 411 412
  ],[

    # determine SWIG Octave flags
    AC_SUBST([SWIG_OCTAVE_FLAGS],["-globals . -DSWIG_CPLUSPLUS_CAST"])

413
  ])
Karl Wette's avatar
Karl Wette committed
414
  # end $0
415
])
416

417
AC_DEFUN([LALSUITE_USE_SWIG_PYTHON],[
Karl Wette's avatar
Karl Wette committed
418
  # $0: configure SWIG Python bindings
419
  LALSUITE_USE_SWIG_LANGUAGE([Python],[C],[
420

421 422 423 424 425
    # check for distutils
    AC_MSG_CHECKING([for distutils])
    cat <<EOD | ${PYTHON} - 2>/dev/null
import distutils
EOD
426
    AS_IF([test $? -ne 0],[
427
      AC_MSG_ERROR([could not import distutils])
428 429 430
    ])
    AC_MSG_RESULT([yes])

431 432 433 434 435 436 437 438 439 440 441 442 443 444
    # check for NumPy
    numpy_min_version=1.3
    AC_MSG_CHECKING([for NumPy])
    numpy_version=[`cat <<EOD | ${PYTHON} - 2>/dev/null
import numpy
print(numpy.__version__)
EOD`]
    AS_IF([test $? -ne 0],[
      AC_MSG_ERROR([could not import NumPy])
    ])
    AC_MSG_RESULT([yes])

    # check NumPy version
    AC_MSG_CHECKING([NumPy version])
445
    LALSUITE_VERSION_COMPARE([${numpy_version}],[<],[${numpy_min_version}],[
446
      AC_MSG_ERROR([NumPy version ${numpy_min_version} or later is required])
447 448 449
    ])
    AC_MSG_RESULT([${numpy_version}])

Karl Wette's avatar
Karl Wette committed
450 451 452
    # determine Python preprocessor flags
    AC_SUBST([SWIG_PYTHON_CPPFLAGS],[])
    python_out=[`cat <<EOD | ${PYTHON} - 2>/dev/null
453 454 455 456 457 458 459 460
import sys
import distutils.sysconfig as cfg
import numpy.lib.utils as npyutil
sys.stdout.write( '-I' + cfg.get_python_inc())
sys.stdout.write(' -I' + cfg.get_python_inc(plat_specific=1))
sys.stdout.write(' -I' + npyutil.get_include())
EOD`]
    AS_IF([test $? -ne 0],[
Karl Wette's avatar
Karl Wette committed
461
      AC_MSG_ERROR([could not determine Python preprocessor flags])
462
    ])
463 464 465
    for flag in ${python_out}; do
      SWIG_PYTHON_CPPFLAGS="${SWIG_PYTHON_CPPFLAGS} ${flag}"
    done
466

Karl Wette's avatar
Karl Wette committed
467 468 469
    # determine Python compiler flags
    AC_SUBST([SWIG_PYTHON_CFLAGS],[])
    python_out=[`cat <<EOD | ${PYTHON} - 2>/dev/null
470 471 472 473 474 475 476
import sys
import distutils.sysconfig as cfg
cflags = cfg.get_config_var('CFLAGS').split()
cflags = [f for f in cflags if f != '-DNDEBUG']
sys.stdout.write(" ".join(cflags))
EOD`]
    AS_IF([test $? -ne 0],[
Karl Wette's avatar
Karl Wette committed
477 478
      AC_MSG_ERROR([could not determine Python compiler flags])
    ])
479
    for flag in ${python_out}; do
480
      swig_python_cflags="${swig_python_cflags} ${flag}"
481
    done
482 483
    LALSUITE_CHECK_COMPILE_FLAGS([
      ${swig_python_cflags}
484 485 486 487 488 489
      -Wno-uninitialized
      -Wno-unused-variable
      -Wno-unused-but-set-variable
      -Wno-format-extra-args
      -Wno-tautological-compare
      -fno-strict-aliasing
490 491
      ],[SWIG_PYTHON_CFLAGS="${SWIG_PYTHON_CFLAGS} ${flag}"]
    )
Karl Wette's avatar
Karl Wette committed
492 493 494 495 496 497

    # determine Python linker flags
    AC_SUBST([SWIG_PYTHON_LDFLAGS],[])
    python_out=[`cat <<EOD | ${PYTHON} - 2>/dev/null
import sys, os
import distutils.sysconfig as cfg
498
sys.stdout.write(cfg.get_config_var('LDFLAGS'))
Karl Wette's avatar
Karl Wette committed
499 500 501 502 503 504 505
sys.stdout.write(' -L' + cfg.get_python_lib())
sys.stdout.write(' -L' + cfg.get_python_lib(plat_specific=1))
sys.stdout.write(' -L' + cfg.get_python_lib(plat_specific=1,standard_lib=1))
sys.stdout.write(' -L' + cfg.get_config_var('LIBDIR'))
EOD`]
    AS_IF([test $? -ne 0],[
      AC_MSG_ERROR([could not determine Python linker flags])
506
    ])
507
    swig_python_ldflags=
508 509 510
    for flag in ${python_out}; do
      AS_CASE([${flag}],
        [-L/usr/lib|-L/usr/lib64],[:],
511 512
        [-Xlinker],[swig_python_ldflags="${swig_python_ldflags}-Wl,"],
        [swig_python_ldflags="${swig_python_ldflags}${flag} "]
513 514
      )
    done
515 516 517 518
    LALSUITE_CHECK_LINK_FLAGS([
      ${swig_python_ldflags}
      ],[SWIG_PYTHON_LDFLAGS="${SWIG_PYTHON_LDFLAGS} ${flag}"]
    )
519

520 521 522
    # allow addition of extra Python linker flags
    AC_ARG_VAR([EXTRA_SWIG_PYTHON_LDFLAGS],[Extra linker flags for SWIG Python bindings])

Karl Wette's avatar
Karl Wette committed
523 524 525
    # check for Python and NumPy headers
    LALSUITE_PUSH_UVARS
    CPPFLAGS="${SWIG_PYTHON_CPPFLAGS}"
526
    AC_CHECK_HEADER([Python.h],[],[
527 528 529 530
      AC_MSG_ERROR([could not find the header "Python.h"])
    ],[
      AC_INCLUDES_DEFAULT
    ])
531
    AC_CHECK_HEADER([numpy/arrayobject.h],[],[
532 533 534 535 536
      AC_MSG_ERROR([could not find the header "numpy/arrayobject.h"])
    ],[
      AC_INCLUDES_DEFAULT
      #include <Python.h>
    ])
Karl Wette's avatar
Karl Wette committed
537
    LALSUITE_POP_UVARS
538

539
    # remove deprecated code in NumPy API >= 1.7
Karl Wette's avatar
Karl Wette committed
540
    SWIG_PYTHON_CPPFLAGS="${SWIG_PYTHON_CPPFLAGS} -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION"
541 542

    # check for declarations which may need compatibility code for NumPy API < 1.7
Karl Wette's avatar
Karl Wette committed
543 544
    LALSUITE_PUSH_UVARS
    CPPFLAGS="${SWIG_PYTHON_CPPFLAGS}"
545 546 547 548 549 550 551 552 553 554
    AC_CHECK_DECL([NPY_ARRAY_WRITEABLE],[
      SWIG_PYTHON_CPPFLAGS="${SWIG_PYTHON_CPPFLAGS} -DSWIGLAL_HAVE_NPY_ARRAY_WRITEABLE"
    ],[],[
      AC_INCLUDES_DEFAULT
      #include <Python.h>
      #include <numpy/arrayobject.h>
    ])
    AC_CHECK_DECL([PyArray_SetBaseObject],[
      SWIG_PYTHON_CPPFLAGS="${SWIG_PYTHON_CPPFLAGS} -DSWIGLAL_HAVE_PyArray_SetBaseObject"
    ],[],[
555 556 557 558
      AC_INCLUDES_DEFAULT
      #include <Python.h>
      #include <numpy/arrayobject.h>
    ])
Karl Wette's avatar
Karl Wette committed
559
    LALSUITE_POP_UVARS
560

561 562 563 564 565 566 567 568 569 570 571 572
  ],[

    # determine SWIG Python flags
    AC_SUBST([SWIG_PYTHON_FLAGS],["-O -builtin -globals globalvar"])
    AC_MSG_CHECKING([if SWIG supports relative Python imports])
    LALSUITE_VERSION_COMPARE([${swig_version}],[<],[3.0.0],[
      AC_MSG_RESULT([no])
    ],[
      AC_MSG_RESULT([yes])
      SWIG_PYTHON_FLAGS="-py3 -relativeimport ${SWIG_PYTHON_FLAGS}"
    ])

573
  ])
Karl Wette's avatar
Karl Wette committed
574
  # end $0
575
])