lalsuite_build.m4 28.2 KB
Newer Older
1
# -*- mode: autoconf; -*-
2 3
# lalsuite_build.m4 - top level build macros
#
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
# serial 73

# not present in older versions of pkg.m4
m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])

# forbid LALSUITE_... from appearing in output (./configure)
m4_pattern_forbid([^_?LALSUITE_[A-Z_]+$])
# apart from LALSUITE_PKG_SUFFIX
m4_pattern_allow([^LALSUITE_PKG_SUFFIX$])

# list of user variables; see section 4.8.1 of the Autoconf manual
m4_define([uvar_list],[CPPFLAGS CFLAGS CXXFLAGS FCFLAGS FFLAGS LDFLAGS])
# prefix used to save/restore user variables in
m4_define([uvar_orig_prefix],[lalsuite_uvar_])
m4_define([uvar_prefix],uvar_orig_prefix)

m4_append([AC_INIT],[
  # just after AC_INIT:
  # save user-supplied values of user variables
  m4_foreach_w([uvar],uvar_list,[
    uvar_prefix[]uvar="${uvar}"
  ])
  m4_pushdef([uvar_prefix],uvar_prefix[]p_)
])

AC_DEFUN([_LALSUITE_PRE_PROG_COMPILERS],[
  # $0: just before LALSUITE_PROG_COMPILERS:
  # save current values of user variables, then unset them
  m4_foreach_w([uvar],uvar_list,[
    uvar_prefix[]uvar="${uvar}"
    AS_UNSET(uvar)
  ])
  m4_pushdef([uvar_prefix],uvar_prefix[]p_)
  # end $0
])

AC_DEFUN([_LALSUITE_POST_PROG_COMPILERS],[
  # $0: just after LALSUITE_PROG_COMPILERS:
  # save current values of user variables, as set
  # during compiler configuration
  m4_popdef([uvar_prefix])
  m4_foreach_w([uvar],uvar_list,[
    lalsuite_compiler_[]uvar="${uvar}"
   _AS_ECHO_LOG([compiler configuration set uvar=${uvar}])
    uvar="${uvar_prefix[]uvar}"
  ])
  # end $0
])

m4_rename([AC_OUTPUT],[lalsuite_AC_OUTPUT])
AC_DEFUN([AC_OUTPUT],[
  # just before AC_OUTPUT:
  # check for unbalanced LALSUITE_{PUSH,POP}_UVAR pairs
  m4_popdef([uvar_prefix])
  m4_if(uvar_prefix,uvar_orig_prefix,[],[
    m4_fatal([unbalanced LALSUITE_{PUSH,POP}_UVAR pairs])
  ])
  # prepend compiler configuration e.g. CFLAGS to AM_CFLAGS,
  # then restore original user-supplied values of user variables
  m4_foreach_w([uvar],uvar_list,[
    AM_[]uvar="${lalsuite_compiler_[]uvar} ${AM_[]uvar}"
    uvar="${uvar_prefix[]uvar}"
  ])
  # call original AC_OUTPUT
  lalsuite_AC_OUTPUT
])

AC_DEFUN([LALSUITE_PUSH_UVARS],[
  # $0: save current values of user variables and LIBS
  m4_foreach_w([uvar],uvar_list[ LIBS],[
    uvar_prefix[]uvar="${uvar}"
    uvar_prefix[]uvar[]_lineno=$LINENO; _AS_ECHO_LOG([pushed uvar=${uvar}])
  ])
  m4_pushdef([uvar_prefix],uvar_prefix[]p_)
  # end $0
])

AC_DEFUN([LALSUITE_CLEAR_UVARS],[
  # $0: clear current values of user variables and LIBS
  m4_foreach_w([uvar],uvar_list[ LIBS],[
    AS_UNSET(uvar)
  ])
  # end $0
])

AC_DEFUN([LALSUITE_POP_UVARS],[
  # $0: restore previous values of user variables and LIBS
  m4_popdef([uvar_prefix])
  m4_foreach_w([uvar],uvar_list[ LIBS],[
    uvar="${uvar_prefix[]uvar}"
   _AS_ECHO_LOG([popped uvar from line ${uvar_prefix[]uvar[]_lineno}])
  ])
  # end $0
])

AC_DEFUN([LALSUITE_ADD_FLAGS],[
  # $0: prepend flags to AM_CPPFLAGS/AM_$1FLAGS/AM_LDFLAGS/LIBS,
  # and update values of CPPFLAGS/$1FLAGS/LDFLAGS for Autoconf tests
  m4_ifval([$1],[m4_ifval([$2],[
    prepend_CPPFLAGS=
    prepend_$1FLAGS=
    for flag in $2; do
      # AM_CPPFLAGS gets -I and -D flags, AM_$1FLAGS gets everything else from $2
      AS_CASE([${flag}],
        [-I*|-D*],[prepend_CPPFLAGS="${prepend_CPPFLAGS} ${flag}"],
        [prepend_$1FLAGS="${prepend_$1FLAGS} ${flag}"]
      )
    done
    AS_IF([test "x${prepend_CPPFLAGS}" != x],[
      AC_SUBST([AM_CPPFLAGS],["${prepend_CPPFLAGS} ${AM_CPPFLAGS}"])
      _AS_ECHO_LOG([prepended ${prepend_CPPFLAGS} to AM_CPPFLAGS])
      CPPFLAGS="${AM_CPPFLAGS} ${uvar_orig_prefix[]CPPFLAGS}"
117
    ])
118 119 120 121
    AS_IF([test "x${prepend_$1FLAGS}" != x],[
      AC_SUBST([AM_$1FLAGS],["${prepend_$1FLAGS} ${AM_$1FLAGS}"])
      _AS_ECHO_LOG([prepended ${prepend_$1FLAGS} to AM_$1FLAGS])
      $1FLAGS="${AM_$1FLAGS} ${uvar_orig_prefix[]$1FLAGS}"
122
    ])
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
  ])])
  m4_ifval([$3],[
    prepend_LDFLAGS=
    prepend_LIBS=
    for flag in $3; do
      # LIBS gets -l flags and .la files, AM_LDFLAGS gets everything else from $3
      AS_CASE([${flag}],
        [-l*|*.la],[prepend_LIBS="${prepend_LIBS} ${flag}"],
        [prepend_LDFLAGS="${prepend_LDFLAGS} ${flag}"]
      )
    done
    AS_IF([test "x${prepend_LDFLAGS}" != x],[
      AC_SUBST([AM_LDFLAGS],["${prepend_LDFLAGS} ${AM_LDFLAGS}"])
      _AS_ECHO_LOG([prepended ${prepend_LDFLAGS} to AM_LDFLAGS])
      LDFLAGS="${AM_LDFLAGS} ${uvar_orig_prefix[]LDFLAGS}"
138
    ])
139 140 141
    AS_IF([test "x${prepend_LIBS}" != x],[
      LIBS="${prepend_LIBS} ${LIBS}"
      _AS_ECHO_LOG([prepended ${prepend_LIBS} to LIBS])
142
    ])
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
  ])
  # end $0
])

AC_DEFUN([LALSUITE_ADD_PATH],[
  # $0: prepend path to $1, removing duplicates, first value taking precedence
  tokens=$2
  tokens=`echo ${tokens} ${$1} | sed 's/:/ /g'`
  $1=
  for token in ${tokens}; do
    AS_CASE([":${$1}:"],
      [*:${token}:*],[:],
      AS_IF([test "x${$1}" = x],[
        $1="${token}"
      ],[
        $1="${$1}:${token}"
      ])
    )
  done
  _AS_ECHO_LOG([$1=${$1}])
  # end $0
164
])
165 166 167 168 169 170 171 172 173 174 175 176

AC_DEFUN([LALSUITE_CHECK_GIT_REPO],[
  # check for git
  AC_PATH_PROGS(GIT,[git],[false])
  # check whether building from a git repository
  have_git_repo=no
  AS_IF([test "x${GIT}" != xfalse],[
    AC_MSG_CHECKING([whether building from a git repository])
    # git log will print:
    # * the last log message, if the cwd is in a git repository
    # * nothing, if the cwd is not part of the git repo (e.g. ignored)
    # * an error msg to stderr if the cwd is not in a git repository
Adam Mercer's avatar
Adam Mercer committed
177
    git_log=`( cd "${srcdir}" && ${GIT} log --pretty=oneline -n 1 -- . ) 2>/dev/null`
178
    AS_IF([test "x${git_log}" != x],[have_git_repo=yes])
179 180 181 182 183 184
    AC_MSG_RESULT([${have_git_repo}])
  ])
  # conditional for git and building from a git repository
  AM_CONDITIONAL(HAVE_GIT_REPO,[test "x${have_git_repo}" = xyes])
  # command line for version information generation script
  AM_COND_IF(HAVE_GIT_REPO,[
185
    m4_pattern_allow([AM_DEFAULT_VERBOSITY])
186 187 188
    m4_pattern_allow([AM_V_GEN])
    AC_SUBST([genvcsinfo_],["\$(genvcsinfo_\$(AM_DEFAULT_VERBOSITY))"])
    AC_SUBST([genvcsinfo_0],["--am-v-gen='\$(AM_V_GEN)'"])
189
    GENERATE_VCS_INFO="\$(PYTHON) \$(top_srcdir)/../gnuscripts/generate_vcs_info.py --git-path='\$(GIT)' \$(genvcsinfo_\$(V))"
190
  ],[GENERATE_VCS_INFO=false])
191 192
  AC_SUBST(GENERATE_VCS_INFO)
])
193 194 195 196 197 198

AC_DEFUN([LALSUITE_REQUIRE_CXX],[
  # require a C++ compiler
  lalsuite_require_cxx=true
])

199 200 201 202 203
AC_DEFUN([LALSUITE_REQUIRE_F77],[
  # require an F77 compiler
  lalsuite_require_f77=true
])

204 205 206 207 208 209 210 211 212 213
# because we want to conditionally decide whether to check for
# C++/Fortran compilers only at ./configure run time, we must erase the
# following macros; in Autoconf 2.64 and later, they AC_REQUIRE the
# C++/Fortran AC_PROG_... macros, which forces the C++/Fortran compilers
# to always be checked for, which prevents us from instead conditionally
# deciding that at ./configure run time
m4_foreach([lang],[[C++],[Fortran 77],[Fortran]],[
  m4_defun([AC_LANG_COMPILER(]lang[)],[])
  m4_defun([AC_LANG_PREPROC(]lang[)],[])
])
214

215
AC_DEFUN([LALSUITE_PROG_COMPILERS],[
216 217
  AC_REQUIRE([_LALSUITE_PRE_PROG_COMPILERS])

218 219 220 221
  # check for C99 compiler
  AC_REQUIRE([AC_PROG_CC])
  AC_REQUIRE([AC_PROG_CC_C99])
  AC_REQUIRE([AC_PROG_CPP])
Adam Mercer's avatar
Adam Mercer committed
222 223 224

  # check for clang
  AS_IF([test "x$GCC" = xyes],
Adam Mercer's avatar
Adam Mercer committed
225
    [AS_IF([test "`$CC -v 2>&1 | grep -c 'clang'`" != "0"],[CLANG_CC=1])],
Adam Mercer's avatar
Adam Mercer committed
226 227 228
    [CLANG_CC=])
  AC_SUBST(CLANG_CC)

229 230 231 232
  # check for C++ compiler, if needed
  AS_IF([test "${lalsuite_require_cxx}" = true],[
    AC_PROG_CXX
    AC_PROG_CXXCPP
Adam Mercer's avatar
Adam Mercer committed
233 234 235

    # check for clang++
    AS_IF([test "x$GXX" = xyes],
Adam Mercer's avatar
Adam Mercer committed
236
      [AS_IF([test "`$CXX -v 2>&1 | grep -c 'clang'`" != "0"],[CLANG_CXX=1])],
237
      [CLANG_CXX=])
Adam Mercer's avatar
Adam Mercer committed
238
    AC_SUBST(CLANG_CXX)
239 240 241
  ],[
    CXX=
    CXXCPP=
242
    AM_CONDITIONAL([am__fastdepCXX],[false])
243
  ])
Adam Mercer's avatar
Adam Mercer committed
244

245 246 247 248 249
  # check complex numbers
  LALSUITE_CHECK_C99_COMPLEX_NUMBERS
  AS_IF([test "${lalsuite_require_cxx}" = true],[
    LALSUITE_CHECK_CXX_COMPLEX_NUMBERS
  ])
250 251 252 253 254 255 256

  # check for F77 compiler, if needed
  AS_IF([test "${lalsuite_require_f77}" = true],[
    AC_PROG_F77
  ],[
    F77=
  ])
Adam Mercer's avatar
Adam Mercer committed
257

258 259
  _LALSUITE_POST_PROG_COMPILERS
  # end $0
260 261
])

Adam Mercer's avatar
Adam Mercer committed
262 263
AC_DEFUN([LALSUITE_USE_LIBTOOL],
[## $0: Generate a libtool script for use in configure tests
264
AC_REQUIRE([LT_INIT])
Adam Mercer's avatar
Adam Mercer committed
265 266 267 268 269 270 271 272 273 274
LT_OUTPUT
m4_append([AC_LANG(C)],
[ac_link="./libtool --mode=link --tag=CC $ac_link"
])[]dnl
AC_PROVIDE_IFELSE([AC_PROG_CXX],
[m4_append([AC_LANG(C++)],
[ac_link="./libtool --mode=link --tag=CXX $ac_link"
])])[]dnl
AC_LANG(_AC_LANG)[]dnl
]) # LALSUITE_USE_LIBTOOL
275

276 277 278 279
AC_DEFUN([LALSUITE_MULTILIB_LIBTOOL_HACK],
[## $0: libtool incorrectly determine library path on SL6
case "${host}" in
  x86_64-*-linux-gnu*)
280 281 282 283 284 285
    case `cat /etc/redhat-release 2> /dev/null` in
      "Scientific Linux"*|"CentOS"*)
        AC_MSG_NOTICE([hacking round broken libtool multilib support on RedHat systems])
        lt_cv_sys_lib_dlsearch_path_spec="/lib64 /usr/lib64"
        ;;
    esac
286 287 288 289
    ;;
esac
]) # LALSUITE_MULTILIB_LIBTOOL_HACK

290 291 292 293
# store configure flags for 'make distcheck'
AC_DEFUN([LALSUITE_DISTCHECK_CONFIGURE_FLAGS],[
  DISTCHECK_CONFIGURE_FLAGS=
  for arg in ${ac_configure_args}; do
294
    case ${arg} in
295 296 297 298 299 300 301 302
      (\'--enable-*\'|\'--disable-*\')
        # save any --enable/--disable arguments
        DISTCHECK_CONFIGURE_FLAGS="${DISTCHECK_CONFIGURE_FLAGS} ${arg}";;
      (\'--with-*\'|\'--without-*\')
        # save any --with/--without arguments
        DISTCHECK_CONFIGURE_FLAGS="${DISTCHECK_CONFIGURE_FLAGS} ${arg}";;
      (\'--*\')
        # skip all other ./configure arguments
303 304 305 306
        : ;;
      (\'DISTCHECK_CONFIGURE_FLAGS=*\')
        # append value of DISTCHECK_CONFIGURE_FLAGS
        DISTCHECK_CONFIGURE_FLAGS="${DISTCHECK_CONFIGURE_FLAGS} "`expr "X${arg}" : "X'DISTCHECK_CONFIGURE_FLAGS=\(.*\)'"`;;
307 308
      (\'*=*\')
        # save any environment variables given to ./configure
309 310
        DISTCHECK_CONFIGURE_FLAGS="${DISTCHECK_CONFIGURE_FLAGS} ${arg}";;
    esac
311 312 313 314
  done
  AC_SUBST(DISTCHECK_CONFIGURE_FLAGS)
])

Adam Mercer's avatar
Adam Mercer committed
315
AC_DEFUN([LALSUITE_ENABLE_MODULE],[
316 317 318 319 320 321 322 323 324 325 326 327 328
  # $0: enable/disable module $1
  m4_pushdef([lowercase],m4_translit([[$1]], [A-Z], [a-z]))
  m4_pushdef([uppercase],m4_translit([[$1]], [a-z], [A-Z]))
  AM_CONDITIONAL(uppercase,[test "x${lowercase}" = xtrue])
  AS_IF([test "${lowercase}" = "true"],[
    uppercase[]_ENABLE_VAL=ENABLED
  ],[
    uppercase[]_ENABLE_VAL=DISABLED
  ])
  _AS_ECHO_LOG([module $1 is ${]uppercase[_ENABLE_VAL}])
  m4_popdef([lowercase])
  m4_popdef([uppercase])
  # end $0
Adam Mercer's avatar
Adam Mercer committed
329 330
])

331
AC_DEFUN([LALSUITE_CHECK_LIB],[
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
  # $0: check for LAL library
  AC_REQUIRE([PKG_PROG_PKG_CONFIG])
  m4_pushdef([lowercase],m4_translit([[$1]], [A-Z], [a-z]))
  m4_pushdef([uppercase],m4_translit([[$1]], [a-z], [A-Z]))

  # build pkg-config library name and version
  AC_ARG_VAR([LALSUITE_PKG_SUFFIX],[suffix to add to LALSuite pkg-config library names])
  lal_pkg="lowercase[]${LALSUITE_PKG_SUFFIX} >= $2"

  # substitute required library version in pkg-config files
  AC_SUBST(uppercase[]_VERSION,[$2])

  # set up pkg-config environment
  export PKG_CONFIG_PATH
  AS_UNSET([PKG_CONFIG_DISABLE_UNINSTALLED])
  AS_UNSET([PKG_CONFIG_ALLOW_SYSTEM_CFLAGS])
  AS_UNSET([PKG_CONFIG_ALLOW_SYSTEM_LIBS])

  # check for $1
  AC_MSG_CHECKING([for ${lal_pkg}])
  lal_pkg_errors=`${PKG_CONFIG} --print-errors --cflags "${lal_pkg}" 2>&1 >/dev/null`
  AS_IF([test "x${lal_pkg_errors}" = x],[
    lowercase=true
    AC_MSG_RESULT([yes])

    # define that we have $1 in the configuration header
358
    AC_DEFINE([HAVE_LIB]uppercase,[1],[Define to 1 if you have the $1 library])
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412

    # add $1 to list of LALSuite libraries
    lalsuite_libs="${lalsuite_libs} lowercase"

    # add $1 compiler and linker flags to CPPFLAGS/CFLAGS/LDFLAGS/LIBS
    LALSUITE_ADD_FLAGS([C],[`${PKG_CONFIG} --cflags "${lal_pkg}"`],[`${PKG_CONFIG} --libs "${lal_pkg}"`])

    # add $1 include flags, including system directories, to LAL_INCLUDES_WITH_SYS_DIRS
    PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
    export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS
    LAL_INCLUDES_WITH_SYS_DIRS=`${PKG_CONFIG} --cflags-only-I "${lal_pkg}"`" ${LAL_INCLUDES_WITH_SYS_DIRS}"
    AS_UNSET([PKG_CONFIG_ALLOW_SYSTEM_CFLAGS])
    AC_SUBST([LAL_INCLUDES_WITH_SYS_DIRS])

    # add $1 data path to LAL_DATA_PATH
    LALSUITE_ADD_PATH(LAL_DATA_PATH,`${PKG_CONFIG} --variable=LAL_DATA_PATH "${lal_pkg}"`)
    AC_SUBST([LAL_DATA_PATH])

    # add $1 Octave extension path to LAL_OCTAVE_PATH
    LALSUITE_ADD_PATH(LAL_OCTAVE_PATH,`${PKG_CONFIG} --variable=LAL_OCTAVE_PATH "${lal_pkg}"`)
    AC_SUBST([LAL_OCTAVE_PATH])

    # add $1 Python extension path to LAL_PYTHON_PATH
    LALSUITE_ADD_PATH(LAL_PYTHON_PATH,`${PKG_CONFIG} --variable=LAL_PYTHON_PATH "${lal_pkg}"`)
    AC_SUBST([LAL_PYTHON_PATH])

    AS_IF([${PKG_CONFIG} --uninstalled "${lal_pkg}"],[

      # if $1 is not installed, add .pc.in file to ./config.status dependencies
      lal_pkg_pcin_dir=`${PKG_CONFIG} --variable=abs_top_srcdir "${lal_pkg}"`
      lal_pkg_pcin_file="${lal_pkg_pcin_dir}/lowercase[]${LALSUITE_PKG_SUFFIX}.pc.in"
      AS_IF([test ! -f "${lal_pkg_pcin_file}"],[
        AC_MSG_ERROR([could not find file ${lal_pkg_pcin_file}])
      ])
      CONFIG_STATUS_DEPENDENCIES="${CONFIG_STATUS_DEPENDENCIES} ${lal_pkg_pcin_file}"
      AC_SUBST([CONFIG_STATUS_DEPENDENCIES])

    ],[

      # if $1 is installed, check linking, headers, and VCS info consistency
      AC_CHECK_LIB(lowercase,[$3],[:],[AC_MSG_ERROR([could not link against the $1 library])])
      AC_CHECK_HEADERS([$4],[:],[AC_MSG_ERROR([could not find the $1 header $4])])
      AS_IF([test x`${PKG_CONFIG} --variable=no_header_library_mismatch_check "${lal_pkg}"` != xyes],[
        LALSUITE_HEADER_LIBRARY_MISMATCH_CHECK([$1])
      ])

    ])

  ],[
    lowercase=false
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([could not find the $1 library

${lal_pkg_errors}
413
])
414 415 416 417 418
  ])

  m4_popdef([lowercase])
  m4_popdef([uppercase])
  # end $0
419 420 421
])

AC_DEFUN([LALSUITE_CHECK_OPT_LIB],[
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
  # $0: check for optional LAL library
  m4_pushdef([lowercase],m4_translit([[$1]], [A-Z], [a-z]))
  m4_pushdef([uppercase],m4_translit([[$1]], [a-z], [A-Z]))

  # optional check for $1
  AS_IF([test "${lowercase}" = "true"],[
    LALSUITE_CHECK_LIB($1,$2,$3,$4)
  ])

  # enable/disable $1
  LALSUITE_ENABLE_MODULE($1)

  m4_popdef([lowercase])
  m4_popdef([uppercase])
  # end $0
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
])

AC_DEFUN([LALSUITE_HEADER_LIBRARY_MISMATCH_CHECK],[
AC_MSG_CHECKING([whether $1 headers match the library])
lib_structure=`echo $1 | sed 's/LAL/lal/'`VCSInfo
header_structure=`echo $1 | sed 's/LAL/lal/'`HeaderVCSInfo
AC_RUN_IFELSE(
  [AC_LANG_SOURCE([[
#include <string.h>
#include <stdlib.h>
#include <lal/$1VCSInfo.h>
int main(void) { exit(XLALVCSInfoCompare(&$lib_structure, &$header_structure) ? 1 : 0); }
  ]])],
  [
    AC_MSG_RESULT(yes)
  ],
  [
    AC_MSG_RESULT(no)
    AC_MSG_ERROR([Your $1 headers do not match your
library. Check config.log for details.
])
  ],
  [
    AC_MSG_WARN([cross compiling: not checking])
  ]
)
463
])
464

465 466 467 468 469
AC_DEFUN([LALSUITE_ENABLE_NIGHTLY],
[AC_ARG_ENABLE(
  [nightly],
  AC_HELP_STRING([--enable-nightly],[nightly build [default=no]]),
  [ case "${enableval}" in
470
      yes) NIGHTLY_VERSION=`date -u +"%Y%m%d"`
471 472 473 474 475 476 477 478 479
           VERSION="${VERSION}.${NIGHTLY_VERSION}" ;;
      no) NIGHTLY_VERSION="";;
      *) NIGHTLY_VERSION="${enableval}"
         VERSION="${VERSION}.${NIGHTLY_VERSION}" ;;
      esac ],
  [ NIGHTLY_VERSION="" ] )
  AC_SUBST(NIGHTLY_VERSION)
])

480 481 482 483
AC_DEFUN([LALSUITE_ENABLE_DEBUG],
[AC_ARG_ENABLE(
  [debug],
  AC_HELP_STRING([--enable-debug],[include standard LAL debugging code [default=yes]]),
484 485 486 487
  [AS_CASE(["${enableval}"],
    [yes],,
    [no],AC_DEFINE(LAL_NDEBUG, 1, Suppress debugging code),
    AC_MSG_ERROR(bad value for ${enableval} for --enable-debug))
488 489 490
  ], )
])

491 492 493 494 495 496 497 498 499 500 501 502
AC_DEFUN([LALSUITE_ENABLE_ALL_LAL],
[AC_ARG_ENABLE(
  [all_lal],
  AC_HELP_STRING([--enable-all-lal],[enable/disable compilation of all LAL libraries]),
  [ case "${enableval}" in
      yes) all_lal=true;;
      no) all_lal=false;;
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-all-lal) ;;
    esac
  ], [ all_lal= ] )
])

503
AC_DEFUN([LALSUITE_ENABLE_LALFRAME],
504 505
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
506 507 508 509 510
  [lalframe],
  AC_HELP_STRING([--enable-lalframe],[compile code that requires lalframe library [default=yes]]),
  [ case "${enableval}" in
      yes) lalframe=true;;
      no) lalframe=false;;
511
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalframe) ;;
512
    esac
513
  ], [ lalframe=${all_lal:-true} ] )
514 515 516 517 518 519
if test "$frame" = "false"; then
  lalframe=false
fi
])

AC_DEFUN([LALSUITE_ENABLE_LALMETAIO],
520 521
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
522 523 524 525 526
  [lalmetaio],
  AC_HELP_STRING([--enable-lalmetaio],[compile code that requires lalmetaio library [default=yes]]),
  [ case "${enableval}" in
      yes) lalmetaio=true;;
      no) lalmetaio=false;;
527
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalmetaio) ;;
528
    esac
529
  ], [ lalmetaio=${all_lal:-true} ] )
530 531 532 533 534
if test "$metaio" = "false"; then
  lalmetaio=false
fi
])

Adam Mercer's avatar
Adam Mercer committed
535
AC_DEFUN([LALSUITE_ENABLE_LALXML],
536 537
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
Adam Mercer's avatar
Adam Mercer committed
538 539 540 541 542 543 544
  [lalxml],
  AC_HELP_STRING([--enable-lalxml],[compile code that requires lalxml library [default=no]]),
  [ case "${enableval}" in
      yes) lalxml=true;;
      no) lalxml=false;;
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalxml) ;;
    esac
545
  ], [ lalxml=${all_lal:-false} ] )
Adam Mercer's avatar
Adam Mercer committed
546 547
])

Adam Mercer's avatar
Adam Mercer committed
548
AC_DEFUN([LALSUITE_ENABLE_LALSIMULATION],
549 550
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
Adam Mercer's avatar
Adam Mercer committed
551 552 553 554 555 556 557 558 559 560
  [lalsimulation],
  AC_HELP_STRING([--enable-lalsimulation],[compile code that requires lalsimulation library [default=yes]]),
  [ case "${enableval}" in
      yes) lalsimulation=true;;
      no) lalsimulation=false;;
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalsimulation) ;;
    esac
  ], [ lalsimulation=${all_lal:-true} ] )
])

561
AC_DEFUN([LALSUITE_ENABLE_LALBURST],
562 563
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
564 565 566 567 568
  [lalburst],
  AC_HELP_STRING([--enable-lalburst],[compile code that requires lalburst library [default=yes]]),
  [ case "${enableval}" in
      yes) lalburst=true;;
      no) lalburst=false;;
569
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalburst) ;;
570
    esac
571
  ], [ lalburst=${all_lal:-true} ] )
572 573
if test "$lalmetaio" = "false"; then
  lalburst=false
Adam Mercer's avatar
Adam Mercer committed
574 575 576 577 578
fi
if test "$lalsimulation" = "false"; then
  lalburst=false
fi
])
579

580 581 582 583 584 585 586 587 588 589
AC_DEFUN([LALSUITE_ENABLE_LALDETCHAR],
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
  [laldetchar],
  AC_HELP_STRING([--enable-laldetchar],[compile code that requires laldetchar library [default=no]]),
  [ case "${enableval}" in
      yes) laldetchar=true;;
      no) laldetchar=false;;
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-laldetchar) ;;
    esac
590
  ], [ laldetchar=${all_lal:-true} ] )
591 592 593 594 595 596 597 598
if test "$lalmetaio" = "false"; then
  laldetchar=false
fi
if test "$lalburst" = "false"; then
  laldetchar=false
fi
])

599
AC_DEFUN([LALSUITE_ENABLE_LALINSPIRAL],
600 601
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
602 603 604 605 606
  [lalinspiral],
  AC_HELP_STRING([--enable-lalinspiral],[compile code that requires lalinspiral library [default=yes]]),
  [ case "${enableval}" in
      yes) lalinspiral=true;;
      no) lalinspiral=false;;
607
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalinspiral) ;;
608
    esac
609
  ], [ lalinspiral=${all_lal:-true} ] )
610 611 612
if test "$lalframe" = "false"; then
  lalinspiral=false
fi
613 614 615
if test "$lalmetaio" = "false"; then
  lalinspiral=false
fi
Adam Mercer's avatar
Adam Mercer committed
616 617 618
if test "$lalsimulation" = "false"; then
  lalinspiral=false
fi
619 620 621
])

AC_DEFUN([LALSUITE_ENABLE_LALPULSAR],
622 623
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
624 625 626 627 628 629 630
  [lalpulsar],
  AC_HELP_STRING([--enable-lalpulsar],[compile code that requires lalpulsar library [default=yes]]),
  [ case "${enableval}" in
      yes) lalpulsar=true;;
      no) lalpulsar=false;;
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalpulsar) ;;
    esac
631
  ], [ lalpulsar=${all_lal:-true} ] )
632 633 634
])

AC_DEFUN([LALSUITE_ENABLE_LALSTOCHASTIC],
635 636
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
637 638 639 640 641
  [lalstochastic],
  AC_HELP_STRING([--enable-lalstochastic],[compile code that requires lalstochastic library [default=yes]]),
  [ case "${enableval}" in
      yes) lalstochastic=true;;
      no) lalstochastic=false;;
642
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalstochastic) ;;
643
    esac
644
  ], [ lalstochastic=${all_lal:-true} ] )
645 646
if test "$lalmetaio" = "false"; then
  lalstochastic=false
647 648 649 650
fi
])

AC_DEFUN([LALSUITE_ENABLE_LALINFERENCE],
651 652
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
653 654 655 656 657 658 659
  [lalinference],
  AC_HELP_STRING([--enable-lalinference],[compile code that requires lalinference library [default=yes]]),
  [ case "${enableval}" in
      yes) lalinference=true;;
      no) lalinference=false;;
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalinference) ;;
    esac
660
  ], [ lalinference=${all_lal:-true} ] )
661 662 663 664 665 666 667 668 669 670 671
if test "$lalmetaio" = "false"; then
  lalinference=false
fi
if test "$lalframe" = "false"; then
  lalinference=false
fi
if test "$lalinspiral" = "false"; then
  lalinference=false
fi
if test "$lalpulsar" = "false"; then
  lalinference=false
672 673
fi
])
Adam Mercer's avatar
Adam Mercer committed
674

675
AC_DEFUN([LALSUITE_ENABLE_LALAPPS],[
676
  AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
677 678 679 680 681 682 683 684 685 686
  AC_ARG_ENABLE(
    [lalapps],
    AC_HELP_STRING([--enable-lalapps],[compile lalapps [default=yes]]),
    [
      case "${enableval}" in
        yes) lalapps=true ;;
        no) lalapps=false ;;
        *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalapps) ;;
      esac
    ],[
687
      lalapps=${all_lal:-true}
688 689 690 691
    ]
  )
])

Adam Mercer's avatar
Adam Mercer committed
692 693 694 695 696 697 698 699 700 701
AC_DEFUN([LALSUITE_ENABLE_BOINC],
[AC_ARG_ENABLE(
  [boinc],
  AC_HELP_STRING([--enable-boinc],[enable BOINC support [default=no]]),
  [ case "${enableval}" in
      yes) boinc=true;;
      no) boinc=false;;
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-boinc);;
    esac
  ], [ boinc=false ] )
702 703
  AS_IF([test "${boinc}" = true],[LALSUITE_REQUIRE_CXX])
  AC_ARG_VAR([BOINC_PREFIX],[BOINC installation directory (optional)])
Adam Mercer's avatar
Adam Mercer committed
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
])

AC_DEFUN([LALSUITE_CHECK_BOINC],
[AC_MSG_CHECKING([whether LAL has been compiled with BOINC support])
AC_TRY_RUN([
#include <lal/LALConfig.h>
#ifdef LAL_BOINC_ENABLED
int main( void ) { return 0; }
#else
int main( void ) { return 1; }
#endif
],
AC_MSG_RESULT([yes])
[boinc=true],
AC_MSG_RESULT([no])
[boinc=false],
AC_MSG_RESULT([unknown])
[boinc=false])
])
723

Karl Wette's avatar
Karl Wette committed
724 725
AC_DEFUN([LALSUITE_WITH_CUDA],[
AC_ARG_WITH(
726
  [cuda],
Karl Wette's avatar
Karl Wette committed
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
  AC_HELP_STRING([--with-cuda=PATH],[specify location of CUDA [/opt/cuda]]),[
    AS_CASE([${with_cuda}],
      [no],[cuda=false],
      [yes],[cuda=true; cuda_path=/opt/cuda],
      [cuda=true; cuda_path=${with_cuda}]
    )
  ],[
    cuda=false
  ])
  AS_IF([test "${cuda}" = true],[
    LALSUITE_REQUIRE_CXX
    AC_MSG_NOTICE([Using ${with_cuda} as CUDA path])
    AS_CASE([$build_os],
      [linux*],[
        AS_IF([test "x$build_cpu" = "xx86_64"],[
          cuda_libdir=lib64
        ],[
          cuda_libdir=lib
        ])
      ],
      [cuda_libdir=lib]
    )
    CUDA_LIBS="-L${cuda_path}/${cuda_libdir} -Wl,-rpath -Wl,${cuda_path}/${cuda_libdir} -lcufft -lcudart"
750
    CUDA_CFLAGS="-I${with_cuda}/include"
751
    LALSUITE_ADD_FLAGS([C],${CUDA_CFLAGS},${CUDA_LIBS})
Karl Wette's avatar
Karl Wette committed
752
    AC_SUBST(CUDA_LIBS)
753
    AC_SUBST(CUDA_CFLAGS)
Karl Wette's avatar
Karl Wette committed
754 755 756 757 758
    AC_PATH_PROGS(NVCC,[nvcc],[],[${cuda_path}/bin:${PATH}])
    AS_IF([test "x${NVCC}" = x],[
      AC_MSG_ERROR([could not find 'nvcc' in path])
    ])
  ])
759
  LALSUITE_ENABLE_MODULE([CUDA])
760
])
761

762 763 764 765 766 767 768 769 770 771
AC_DEFUN([LALSUITE_ENABLE_FAST_GSL],
[AC_ARG_ENABLE(
  [fast_gsl],
  AC_HELP_STRING([--enable-fast-gsl],[enable fast/inline GSL code [default=no]]),
  AS_CASE(["${enableval}"],
    [yes],[AC_DEFINE([HAVE_INLINE],[1],[Define to 1 to use inline code])
           AC_DEFINE([GSL_C99_INLINE],[1],[Define to 1 to use GSL C99 inline code])
           AC_DEFINE([GSL_RANGE_CHECK_OFF],[1],[Define to 1 to turn GSL range checking off])],
    [no],,
    AC_MSG_ERROR([bad value ${enableval} for --enable-fast-gsl]))
772 773 774
  )
])

775 776 777
AC_DEFUN([LALSUITE_ENABLE_OSX_VERSION_CHECK],
[AC_ARG_ENABLE(
  [osx_version_check],
778
  AC_HELP_STRING([--enable-osx-version-check],[disable OS X version check [default=yes]]),
779 780 781 782 783
  AS_CASE(["${enableval}"],
    [yes],[osx_version_check=true],
    [no],[osx_version_check=false],
    AC_MSG_ERROR([bad value ${enableval} for --enable-osx-version-check])
  ),[osx_version_check=true])
784
])
785

786
AC_DEFUN([LALSUITE_OSX_VERSION_CHECK],[
787
LALSUITE_ENABLE_OSX_VERSION_CHECK
788
AS_IF([test "x${osx_version_check}" = "xtrue"],[
789
  AS_IF([test "x$build_vendor" = "xapple"],[
790
    AC_CHECK_PROGS([SW_VERS],[sw_vers])
791
    AS_IF([test "x$SW_VERS" != "x"],[
792 793
      AC_MSG_CHECKING([Mac OS X version])
      MACOSX_VERSION=`$SW_VERS -productVersion`
794
      AC_MSG_RESULT([$MACOSX_VERSION])])
795 796
    AS_CASE(["$MACOSX_VERSION"],
      [10.0*|10.1*|10.2*|10.3*],AC_MSG_ERROR([This version of Mac OS X is not supported]),
797
      [10.4*|10.5*|10.6*|10.7*|10.8*|10.9*],,
798
      AC_MSG_WARN([Unknown Mac OS X version]))
799
])])])
800 801 802 803 804

AC_DEFUN([LALSUITE_WITH_NVCC_CFLAGS],
[AC_ARG_WITH(
  [nvcc_cflags],
  AC_HELP_STRING([--with-nvcc-cflags=NVCC_CFLAGS],[NVCC compiler flags]),
805
  AS_IF([test -n "${with_nvcc_cflags}"],[NVCC_CFLAGS="$NVCC_CFLAGS ${with_nvcc_cflags}"]),)
806
])
Adam Mercer's avatar
Adam Mercer committed
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824

AC_DEFUN([LALSUITE_CHECK_CUDA],
[AC_MSG_CHECKING([whether LAL has been compiled with CUDA support])
AC_TRY_RUN([
#include <lal/LALConfig.h>
#ifdef LAL_CUDA_ENABLED
int main( void ) { return 0; }
#else
int main( void ) { return 1; }
#endif
],
AC_MSG_RESULT([yes])
[cuda=true],
AC_MSG_RESULT([no])
[cuda=false],
AC_MSG_RESULT([unknown])
[cuda=false])
])
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916

AC_DEFUN([LALSUITE_CHECK_COMPLEX_NUMBER_MEMORY_LAYOUT],[
  AC_MSG_CHECKING([memory layout of complex number type '$3'])
  AS_IF([test "$cross_compiling" = yes],[
    AC_MSG_WARN([cross compiling: not checking])
  ],[
    # compile a C file containing functions where
    # the complex number datatype is a struct
    AC_LANG_PUSH([C])
    AC_COMPILE_IFELSE([
AC_LANG_SOURCE([
AC_INCLUDES_DEFAULT
typedef struct {
  $2 re;
  $2 im;
} ComplexStruct;
const size_t zsize = sizeof(ComplexStruct);
const $2 zre = 1.414213562373095048801688724209;
const $2 zim = 3.141592653589793238462643383276;
void Function1(ComplexStruct *pz) {
  pz->re = zre;
  pz->im = zim;
}
int Function2(ComplexStruct pz) {
  return (pz.re == zre && pz.im == zim);
}
])
    ],[
      # if compilation was successful, save the compiled object
      mv -f conftest.$ac_objext conftestlink.$ac_objext
      _AS_ECHO_LOG([moved conftest.$ac_objext to conftestlink.$ac_objext])
    ],[
      AC_MSG_FAILURE([unexpected compile failure])
    ])
    AC_LANG_POP([C])
    # add the object compiled above to the objects
    # which will be linked against by the next test
    lalsuite_ccnml_LIBS=$LIBS
    LIBS="$LIBS conftestlink.$ac_objext"
    # push current language so that we can restore
    # previous linker settings at end of this test
    AC_LANG_PUSH(_AC_LANG)
    # compile a _AC_LANG file where the complex number
    # datatype is a C99/C++ complex number, and which
    # calls functions in the previously-compiled file
    # (where the complex number datatype was a struct).
    # link it against the previously-compiled object,
    # and run the resulting test program.
    AC_RUN_IFELSE([
AC_LANG_PROGRAM([
AC_INCLUDES_DEFAULT
#include <$1>
#ifdef __cplusplus
extern "C" {
#endif
extern const size_t zsize;
extern const $2 zre;
extern const $2 zim;
void Function1($3 *pz);
int Function2($3 pz);
#ifdef __cplusplus
}
#endif
],[
  $3 c;
  if (sizeof($3) != zsize) {
    return 1;
  }
  Function1(&c);
  if ($4(c) != zre || $5(c) != zim) {
    return 2;
  }
  if (!Function2(c)) {
    return 3;
  }
  return 0 /* ; */
])
    ],[
      # if test program compiled and exited
      # normally, test was successful
      AC_MSG_RESULT([compatible])
    ],[
      AC_MSG_FAILURE([memory layout of complex number type '$3' is incompatible])
    ])
    # restore previous linker settings and
    # delete remaining test object files
    LIBS=$lalsuite_ccnml_LIBS
    AC_LANG_POP(_AC_LANG)
    rm -f conftestlink.$ac_objext
  ])
])

917 918
AC_DEFUN([LALSUITE_CHECK_C99_COMPLEX_NUMBERS],[
  # check C99 complex numbers
919 920 921 922 923
  AC_LANG_PUSH([C])
  AC_CHECK_HEADERS([complex.h],[],[AC_MSG_ERROR([could not find 'complex.h'])])
  LALSUITE_CHECK_COMPLEX_NUMBER_MEMORY_LAYOUT([complex.h],[float],[float complex],[crealf],[cimagf])
  LALSUITE_CHECK_COMPLEX_NUMBER_MEMORY_LAYOUT([complex.h],[double],[double complex],[creal],[cimag])
  AC_LANG_POP([C])
924 925 926 927
])

AC_DEFUN([LALSUITE_CHECK_CXX_COMPLEX_NUMBERS],[
  # check C++ complex numbers
928 929 930 931 932 933
  AC_LANG_PUSH([C++])
  AC_CHECK_HEADERS([complex],[],[AC_MSG_ERROR([could not find 'complex'])])
  LALSUITE_CHECK_COMPLEX_NUMBER_MEMORY_LAYOUT([complex],[float],[std::complex<float>],[real],[imag])
  LALSUITE_CHECK_COMPLEX_NUMBER_MEMORY_LAYOUT([complex],[double],[std::complex<double>],[real],[imag])
  AC_LANG_POP([C++])
])