lalsuite_build.m4 29.2 KB
Newer Older
1
# -*- mode: autoconf; -*-
2 3
# lalsuite_build.m4 - top level build macros
#
4
# serial 89
5 6 7 8 9 10

# 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)
11
#m4_pattern_forbid([^_?LALSUITE_[A-Z_]+$])
12 13 14 15 16 17 18

# 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)

19 20 21 22 23 24 25
AC_DEFUN([LALSUITE_ARG_VAR],[
  AC_ARG_VAR(LAL_DATA_PATH,[Location of LAL data files])
  AC_ARG_VAR(LAL_OCTAVE_PATH,[Location of LAL octave files])
  AC_ARG_VAR(LAL_PYTHON_PATH,[Location of LAL python files])
  AC_ARG_VAR(LALSUITE_BUILD,[Set if part of lalsuite build])
])

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
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_)
])

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,[
46
    AC_SUBST(AM_[]uvar,"${AM_[]uvar} ${sys_[]uvar}")
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
    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
84 85 86
  # - arg 1: prefix of the compiler flag variable, e.g. C for CFLAGS, CXX for CXXFLAGS
  # - arg 2: compiler flags
  # - arg 3: linker flags
87
  m4_ifval([$1],[m4_ifval([$2],[
88 89 90
    pre_AM_CPPFLAGS=
    pre_sys_CPPFLAGS=
    pre_AM_$1FLAGS=
91
    for flag in $2; do
92 93 94
      # AM_CPPFLAGS gets unique -I, -D and -U flags
      # sys_CPPFLAGS gets unique system -I flags
      # AM_$1FLAGS gets everything else
95
      AS_CASE([${flag}],
96 97 98 99 100 101 102 103 104 105 106 107 108 109
        [-I/opt/*|-I/usr/*],[
          AS_CASE([" ${sys_CPPFLAGS} "],
            [*" ${flag} "*],[:],
            [pre_sys_CPPFLAGS="${pre_sys_CPPFLAGS} ${flag}"]
          )
        ],
        [-I*],[
          AS_CASE([" ${AM_CPPFLAGS} "],
            [*" ${flag} "*],[:],
            [pre_AM_CPPFLAGS="${pre_AM_CPPFLAGS} ${flag}"]
          )
        ],
        [-D*|-U*],[pre_AM_CPPFLAGS="${pre_AM_CPPFLAGS} ${flag}"],
        [pre_AM_$1FLAGS="${pre_AM_$1FLAGS} ${flag}"]
110 111
      )
    done
112 113 114
    AS_IF([test "x${pre_AM_CPPFLAGS}" != x],[
      AM_CPPFLAGS="${pre_AM_CPPFLAGS} ${AM_CPPFLAGS}"
      _AS_ECHO_LOG([prepended ${pre_AM_CPPFLAGS} to AM_CPPFLAGS])
115
    ])
116 117 118
    AS_IF([test "x${pre_sys_CPPFLAGS}" != x],[
      sys_CPPFLAGS="${pre_sys_CPPFLAGS} ${sys_CPPFLAGS}"
      _AS_ECHO_LOG([prepended ${pre_sys_CPPFLAGS} to system AM_CPPFLAGS])
119
    ])
120 121 122 123 124 125
    AS_IF([test "x${pre_AM_$1FLAGS}" != x],[
      AM_$1FLAGS="${pre_AM_$1FLAGS} ${AM_$1FLAGS}"
      _AS_ECHO_LOG([prepended ${pre_AM_$1FLAGS} to AM_$1FLAGS])
    ])
    CPPFLAGS="${AM_CPPFLAGS} ${sys_CPPFLAGS} ${uvar_orig_prefix[]CPPFLAGS}"
    $1FLAGS="${AM_$1FLAGS} ${uvar_orig_prefix[]$1FLAGS}"
126 127
  ])])
  m4_ifval([$3],[
128 129 130
    pre_AM_LDFLAGS=
    pre_sys_LDFLAGS=
    pre_LIBS=
131
    for flag in $3; do
132 133 134
      # LIBS gets -l flags and .la files
      # sys_LDFLAGS gets unique system -L flags
      # AM_LDFLAGS gets unique -L flags and everything else
135
      AS_CASE([${flag}],
136 137 138 139 140 141 142 143 144 145 146 147 148 149
        [-L/opt/*|-L/usr/*],[
          AS_CASE([" ${sys_LDFLAGS} "],
            [*" ${flag} "*],[:],
            [pre_sys_LDFLAGS="${pre_sys_LDFLAGS} ${flag}"]
          )
        ],
        [-L*],[
          AS_CASE([" ${AM_LDFLAGS} "],
            [*" ${flag} "*],[:],
            [pre_AM_LDFLAGS="${pre_AM_LDFLAGS} ${flag}"]
          )
        ],
        [-l*|*.la],[pre_LIBS="${pre_LIBS} ${flag}"],
        [pre_AM_LDFLAGS="${pre_AM_LDFLAGS} ${flag}"]
150 151
      )
    done
152 153 154 155 156 157 158
    AS_IF([test "x${pre_AM_LDFLAGS}" != x],[
      AM_LDFLAGS="${pre_AM_LDFLAGS} ${AM_LDFLAGS}"
      _AS_ECHO_LOG([prepended ${pre_AM_LDFLAGS} to AM_LDFLAGS])
    ])
    AS_IF([test "x${pre_sys_LDFLAGS}" != x],[
      sys_LDFLAGS="${pre_sys_LDFLAGS} ${sys_LDFLAGS}"
      _AS_ECHO_LOG([prepended ${pre_sys_LDFLAGS} to system AM_LDFLAGS])
159
    ])
160 161 162
    AS_IF([test "x${pre_LIBS}" != x],[
      LIBS="${pre_LIBS} ${LIBS}"
      _AS_ECHO_LOG([prepended ${pre_LIBS} to LIBS])
163
    ])
164
    LDFLAGS="${AM_LDFLAGS} ${sys_LDFLAGS} ${uvar_orig_prefix[]LDFLAGS}"
165 166 167 168 169 170
  ])
  # end $0
])

AC_DEFUN([LALSUITE_ADD_PATH],[
  # $0: prepend path to $1, removing duplicates, first value taking precedence
171 172
  # - arg 1: name of path variable
  # - arg 2: path to prepend
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
  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
188
])
189 190

AC_DEFUN([LALSUITE_CHECK_GIT_REPO],[
191
  # $0: check for git
192
  AC_PATH_PROGS([GIT],[git],[false])
193 194 195 196 197 198 199 200
  # 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
201
    git_log=`( cd "${srcdir}" && ${GIT} log --pretty=oneline -n 1 -- . ) 2>/dev/null`
202
    AS_IF([test "x${git_log}" != x],[have_git_repo=yes])
203 204 205
    AC_MSG_RESULT([${have_git_repo}])
  ])
  # conditional for git and building from a git repository
206
  AM_CONDITIONAL([HAVE_GIT_REPO],[test "x${have_git_repo}" = xyes])
207
  # end $0
208
])
209

210 211 212
AC_DEFUN([LALSUITE_VERSION_CONFIGURE_INFO],[
  # $0: define version/configure info
  m4_pushdef([uppercase],m4_translit(AC_PACKAGE_NAME, [a-z], [A-Z]))
213 214
  m4_pushdef([lowercase],m4_translit(AC_PACKAGE_NAME, [A-Z], [a-z]))
  m4_pushdef([withoutlal],m4_bpatsubst(AC_PACKAGE_NAME, [^LAL], []))
215 216 217 218 219 220 221 222 223 224 225 226 227 228
  version_major=`echo "$VERSION" | cut -d. -f1`
  version_minor=`echo "$VERSION" | cut -d. -f2`
  version_micro=`echo "$VERSION" | cut -d. -f3`
  version_devel=`echo "$VERSION" | cut -d. -f4-`
  test -z "$version_micro" && version_micro=0
  test -z "$version_devel" && version_devel=0
  configure_date=`date +"%Y-%m-%dT%H:%M:%S%z"`
  AC_DEFINE_UNQUOTED(uppercase[_VERSION],["$VERSION"],AC_PACKAGE_NAME[ Version])
  AC_DEFINE_UNQUOTED(uppercase[_VERSION_MAJOR],[$version_major],AC_PACKAGE_NAME[ Version Major Number])
  AC_DEFINE_UNQUOTED(uppercase[_VERSION_MINOR],[$version_minor],AC_PACKAGE_NAME[ Version Minor Number])
  AC_DEFINE_UNQUOTED(uppercase[_VERSION_MICRO],[$version_micro],AC_PACKAGE_NAME[ Version Micro Number])
  AC_DEFINE_UNQUOTED(uppercase[_VERSION_DEVEL],[$version_devel],AC_PACKAGE_NAME[ Version Devel Number])
  AC_SUBST([ac_configure_args])
  AC_SUBST([configure_date])
229 230 231
  AC_SUBST([PACKAGE_NAME_UCASE],uppercase)
  AC_SUBST([PACKAGE_NAME_LCASE],lowercase)
  AC_SUBST([PACKAGE_NAME_NOLAL],withoutlal)
232
  m4_popdef([uppercase])
233 234
  m4_popdef([lowercase])
  m4_popdef([withoutlal])
235 236 237
  # end $0
])

238
AC_DEFUN([LALSUITE_REQUIRE_CXX],[
239
  # $0: require a C++ compiler
240
  lalsuite_require_cxx=true
241
  # end $0
242 243
])

244
AC_DEFUN([LALSUITE_REQUIRE_F77],[
245
  # $0: require an F77 compiler
246
  lalsuite_require_f77=true
247
  # end $0
248 249
])

250 251 252 253 254 255 256 257 258 259
# 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[)],[])
])
260

261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
AC_DEFUN([_LALSUITE_PRE_PROG_COMPILERS],[
  # $0: just before LALSUITE_PROG_COMPILERS:
  # save current values of user variables, then unset them
  LALSUITE_PUSH_UVARS
  LALSUITE_CLEAR_UVARS
  # end $0
])

AC_DEFUN([_LALSUITE_POST_PROG_COMPILERS],[
  # $0: just after LALSUITE_PROG_COMPILERS:
  # save values of user variables set during compiler configuration,
  # restore previous values of user variables, then add compiler values
  # of user variables to then using LALSUITE_ADD_FLAGS
  m4_foreach_w([uvar],uvar_list,[
    lalsuite_compiler_[]uvar="${uvar}"
  ])
  LALSUITE_POP_UVARS
  LALSUITE_ADD_FLAGS([C],[${lalsuite_compiler_CPPFLAGS} ${lalsuite_compiler_CFLAGS}],[${lalsuite_compiler_LDFLAGS}])
  AS_IF([test "${lalsuite_require_cxx}" = true],[
    LALSUITE_ADD_FLAGS([CXX],[${lalsuite_compiler_CXXFLAGS}],[])
  ])
  AS_IF([test "${lalsuite_require_f77}" = true],[
    LALSUITE_ADD_FLAGS([FC],[${lalsuite_compiler_FCFLAGS}],[])
    LALSUITE_ADD_FLAGS([F],[${lalsuite_compiler_FFLAGS}],[])
  ])
  # end $0
])

289
AC_DEFUN([LALSUITE_PROG_COMPILERS],[
290
  # $0: check for C/C++/Fortran compilers
291 292
  AC_REQUIRE([_LALSUITE_PRE_PROG_COMPILERS])

293 294 295 296
  # 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
297 298 299

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

304 305 306 307
  # 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
308 309 310

    # check for clang++
    AS_IF([test "x$GXX" = xyes],
Adam Mercer's avatar
Adam Mercer committed
311
      [AS_IF([test "`$CXX -v 2>&1 | grep -c 'clang'`" != "0"],[CLANG_CXX=1])],
312
      [CLANG_CXX=])
Adam Mercer's avatar
Adam Mercer committed
313
    AC_SUBST(CLANG_CXX)
Karl Wette's avatar
Karl Wette committed
314 315

    # define C99 constant and limit macros for C++ sources
316
    CXXFLAGS="${CXXFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS"
Karl Wette's avatar
Karl Wette committed
317

318 319 320
  ],[
    CXX=
    CXXCPP=
321
    AM_CONDITIONAL([am__fastdepCXX],[false])
322
  ])
Adam Mercer's avatar
Adam Mercer committed
323

324 325 326 327 328 329
  # check for F77 compiler, if needed
  AS_IF([test "${lalsuite_require_f77}" = true],[
    AC_PROG_F77
  ],[
    F77=
  ])
Adam Mercer's avatar
Adam Mercer committed
330

331 332
  _LALSUITE_POST_PROG_COMPILERS
  # end $0
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 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
AC_DEFUN([LALSUITE_REQUIRE_PYTHON],[
  # $0: require Python version $1 or later
  AS_IF([test "x${lalsuite_require_pyvers}" = x],[
    lalsuite_require_pyvers="$1"
  ],[
    AS_VERSION_COMPARE([${lalsuite_require_pyvers}],[$1],[
      lalsuite_require_pyvers="$1"
    ])
  ])
  # end $0
])

AC_DEFUN([LALSUITE_CHECK_PYTHON],[
  # $0: check for Python
  lalsuite_pyvers="$1"
  AS_IF([test "x${lalsuite_require_pyvers}" != x],[
    AS_VERSION_COMPARE([${lalsuite_pyvers}],[${lalsuite_require_pyvers}],[
      lalsuite_pyvers="${lalsuite_require_pyvers}"
    ])
  ])
  AS_IF([test "x${PYTHON}" != xfalse],[
    AM_PATH_PYTHON([${lalsuite_pyvers}],,[
      AS_IF([test "x${lalsuite_require_pyvers}" = x],[
        PYTHON=false
      ],[
        AC_MSG_ERROR([Python version ${lalsuite_pyvers} or higher is required])
      ])
    ])
  ])
  AM_CONDITIONAL([HAVE_PYTHON],[test "x${PYTHON}" != xfalse])
  AM_COND_IF([HAVE_PYTHON],[
    AC_SUBST([python_prefix], [`${PYTHON} -c 'import sys; print(sys.prefix)' 2>/dev/null`])
    AC_SUBST([python_exec_prefix], [`${PYTHON} -c 'import sys; print(sys.exec_prefix)' 2>/dev/null`])
    PYTHON_ENABLE_VAL=ENABLED
  ],[
    PYTHON_ENABLE_VAL=DISABLED
  ])
  # end $0
])

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
AC_DEFUN([LALSUITE_USE_LIBTOOL],[
  # $0: Generate a libtool script for use in configure tests
  AC_REQUIRE([LT_INIT])
  LT_OUTPUT
  m4_append([AC_LANG(C)],[
    ac_link="./libtool --mode=link --tag=CC $ac_link"
  ])
  AC_PROVIDE_IFELSE([AC_PROG_CXX],[
    m4_append([AC_LANG(C++)],[
      ac_link="./libtool --mode=link --tag=CXX $ac_link"
    ])
  ])
  AC_LANG(_AC_LANG)
  # end $0
])

AC_DEFUN([LALSUITE_MULTILIB_LIBTOOL_HACK],[
  # $0: libtool incorrectly determine library path on SL6
  case "${host}" in
    x86_64-*-linux-gnu*)
      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
      ;;
  esac
  # end $0
])
405

406
AC_DEFUN([LALSUITE_DISTCHECK_CONFIGURE_FLAGS],[
407
  # $0: store configure flags for 'make distcheck'
408 409
  DISTCHECK_CONFIGURE_FLAGS=
  for arg in ${ac_configure_args}; do
410
    case ${arg} in
411 412 413 414 415 416 417 418
      (\'--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
419 420 421 422
        : ;;
      (\'DISTCHECK_CONFIGURE_FLAGS=*\')
        # append value of DISTCHECK_CONFIGURE_FLAGS
        DISTCHECK_CONFIGURE_FLAGS="${DISTCHECK_CONFIGURE_FLAGS} "`expr "X${arg}" : "X'DISTCHECK_CONFIGURE_FLAGS=\(.*\)'"`;;
423 424
      (\'*=*\')
        # save any environment variables given to ./configure
425 426
        DISTCHECK_CONFIGURE_FLAGS="${DISTCHECK_CONFIGURE_FLAGS} ${arg}";;
    esac
427 428
  done
  AC_SUBST(DISTCHECK_CONFIGURE_FLAGS)
429
  # end $0
430 431
])

Adam Mercer's avatar
Adam Mercer committed
432
AC_DEFUN([LALSUITE_ENABLE_MODULE],[
433 434 435 436 437 438 439 440 441 442 443 444 445
  # $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
446 447
])

448
AC_DEFUN([LALSUITE_CHECK_LIB],[
449
  # $0: check for LAL library
450 451 452 453
  # - arg 1: name of LAL library
  # - arg 2: minimum version required
  # - arg 3: library function to check for
  # - arg 4: library header to check for
454 455
  m4_pushdef([lowercase],m4_translit([[$1]], [A-Z], [a-z]))
  m4_pushdef([uppercase],m4_translit([[$1]], [a-z], [A-Z]))
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
  PKG_CHECK_MODULES(uppercase, [lowercase >= $2], [lowercase="true"], [lowercase="false"])
  PKG_CHECK_VAR(uppercase[]_DATA_PATH, [lowercase >= $2], uppercase[]_DATA_PATH,,)
  PKG_CHECK_VAR(uppercase[]_OCTAVE_PATH, [lowercase >= $2], uppercase[]_OCTAVE_PATH,,)
  PKG_CHECK_VAR(uppercase[]_PYTHON_PATH, [lowercase >= $2], uppercase[]_PYTHON_PATH,,)
  if test "$lowercase" = "true"; then
    LALSUITE_ADD_FLAGS([C],$[]uppercase[]_CFLAGS,$[]uppercase[]_LIBS)
    LALSUITE_ADD_PATH(LAL_DATA_PATH,"$[]uppercase[]_DATA_PATH")
    LALSUITE_ADD_PATH(LAL_OCTAVE_PATH,"$[]uppercase[]_OCTAVE_PATH")
    LALSUITE_ADD_PATH(LAL_PYTHON_PATH,"$[]uppercase[]_PYTHON_PATH")
  fi
  if test "$LALSUITE_BUILD" = "true"; then
    if test "$lowercase" = "false"; then
      # should never get here: bug in build system
      AC_MSG_ERROR([could not find the $1 library])
    fi
  else
    AC_CHECK_LIB(lowercase,[$3],,[AC_MSG_ERROR([could not find the $1 library])])
    AC_CHECK_HEADERS([$4],,[AC_MSG_ERROR([could not find the $4 header])])
    if test "$1" != "LALSupport"; then
      LALSUITE_HEADER_LIBRARY_MISMATCH_CHECK([$1])
    fi
  fi
  AC_DEFINE([HAVE_LIB]uppercase,[1],[Define to 1 if you have the $1 library])
  # add $1 to list of LALSuite libraries
  lalsuite_libs="${lalsuite_libs} lowercase"
  lowercase="true"
  LALSUITE_ENABLE_MODULE($1)
483 484 485
  m4_popdef([lowercase])
  m4_popdef([uppercase])
  # end $0
486 487 488
])

AC_DEFUN([LALSUITE_CHECK_OPT_LIB],[
489
  # $0: check for optional LAL library
490 491 492 493
  # - arg 1: name of LAL library
  # - arg 2: minimum version required
  # - arg 3: library function to check for
  # - arg 4: library header to check for
494 495 496 497 498 499 500 501 502 503 504 505 506 507
  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
508 509 510
])

AC_DEFUN([LALSUITE_HEADER_LIBRARY_MISMATCH_CHECK],[
511 512 513 514 515 516
  # $0: check for version mismatch between library $1 and its headers
  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/'`VCSInfoHeader
  AC_RUN_IFELSE([
    AC_LANG_SOURCE([[
517 518
#include <string.h>
#include <stdlib.h>
519
#include <lal/$1VCSInfoHeader.h>
520
int main(void) { exit(XLALVCSInfoCompare(&$lib_structure, &$header_structure) ? 1 : 0); }
521 522
    ]])
  ],[
523
    AC_MSG_RESULT(yes)
524
  ],[
525
    AC_MSG_RESULT(no)
526 527
    AC_MSG_ERROR([Your $1 headers do not match your library. Check config.log for details.])
  ],[
528
    AC_MSG_WARN([cross compiling: not checking])
529 530
  ])
  # end $0
531
])
532

Karl Wette's avatar
Karl Wette committed
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
AC_DEFUN([LALSUITE_CHECK_LIBRARY_FOR_SUPPORT],[
  # $0: check if library $1 supports $2
  m4_pushdef([uppercase],m4_translit([[$1]], [a-z], [A-Z]))
  LALSUITE_PUSH_UVARS
  # because library may be uninstalled, remove everything but -I flags
  save_CPPFLAGS="${CPPFLAGS}"
  LALSUITE_CLEAR_UVARS
  CPPFLAGS="${save_CPPFLAGS}"
  AC_MSG_CHECKING([whether $1 has been compiled with $2 support])
  AC_COMPILE_IFELSE([
    AC_LANG_SOURCE([[
#include <lal/$1Config.h>
#ifndef ]uppercase[_$2_ENABLED
#error ]uppercase[_$2_ENABLED is not defined
#endif
    ]])
  ],[
    AC_MSG_RESULT([yes])
    m4_default([$3],[:])
  ],[
    AC_MSG_RESULT([no])
    m4_default([$4],[:])
  ])
  LALSUITE_POP_UVARS
  m4_popdef([uppercase])
  # end $0
])

561 562 563 564 565
AC_DEFUN([LALSUITE_ENABLE_NIGHTLY],
[AC_ARG_ENABLE(
  [nightly],
  AC_HELP_STRING([--enable-nightly],[nightly build [default=no]]),
  [ case "${enableval}" in
566
      yes) NIGHTLY_VERSION=`date -u +"%Y%m%d"`
567 568 569 570 571 572 573 574 575
           VERSION="${VERSION}.${NIGHTLY_VERSION}" ;;
      no) NIGHTLY_VERSION="";;
      *) NIGHTLY_VERSION="${enableval}"
         VERSION="${VERSION}.${NIGHTLY_VERSION}" ;;
      esac ],
  [ NIGHTLY_VERSION="" ] )
  AC_SUBST(NIGHTLY_VERSION)
])

576 577 578 579 580 581 582 583 584 585 586 587
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= ] )
])

588
AC_DEFUN([LALSUITE_ENABLE_LALFRAME],
589 590
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
591 592 593 594 595
  [lalframe],
  AC_HELP_STRING([--enable-lalframe],[compile code that requires lalframe library [default=yes]]),
  [ case "${enableval}" in
      yes) lalframe=true;;
      no) lalframe=false;;
596
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalframe) ;;
597
    esac
598
  ], [ lalframe=${all_lal:-true} ] )
599 600 601 602 603 604
if test "$frame" = "false"; then
  lalframe=false
fi
])

AC_DEFUN([LALSUITE_ENABLE_LALMETAIO],
605 606
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
607 608 609 610 611
  [lalmetaio],
  AC_HELP_STRING([--enable-lalmetaio],[compile code that requires lalmetaio library [default=yes]]),
  [ case "${enableval}" in
      yes) lalmetaio=true;;
      no) lalmetaio=false;;
612
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalmetaio) ;;
613
    esac
614
  ], [ lalmetaio=${all_lal:-true} ] )
615 616 617 618 619
if test "$metaio" = "false"; then
  lalmetaio=false
fi
])

Adam Mercer's avatar
Adam Mercer committed
620
AC_DEFUN([LALSUITE_ENABLE_LALXML],
621 622
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
Adam Mercer's avatar
Adam Mercer committed
623 624 625 626 627 628 629
  [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
630
  ], [ lalxml=${all_lal:-false} ] )
Adam Mercer's avatar
Adam Mercer committed
631 632
])

Adam Mercer's avatar
Adam Mercer committed
633
AC_DEFUN([LALSUITE_ENABLE_LALSIMULATION],
634 635
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
Adam Mercer's avatar
Adam Mercer committed
636 637 638 639 640 641 642 643 644 645
  [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} ] )
])

646
AC_DEFUN([LALSUITE_ENABLE_LALBURST],
647 648
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
649 650 651 652 653
  [lalburst],
  AC_HELP_STRING([--enable-lalburst],[compile code that requires lalburst library [default=yes]]),
  [ case "${enableval}" in
      yes) lalburst=true;;
      no) lalburst=false;;
654
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalburst) ;;
655
    esac
656
  ], [ lalburst=${all_lal:-true} ] )
657 658
if test "$lalmetaio" = "false"; then
  lalburst=false
Adam Mercer's avatar
Adam Mercer committed
659 660 661 662 663
fi
if test "$lalsimulation" = "false"; then
  lalburst=false
fi
])
664

665 666 667 668 669 670 671 672 673 674
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
675
  ], [ laldetchar=${all_lal:-true} ] )
676 677 678 679 680 681 682 683
if test "$lalmetaio" = "false"; then
  laldetchar=false
fi
if test "$lalburst" = "false"; then
  laldetchar=false
fi
])

684
AC_DEFUN([LALSUITE_ENABLE_LALINSPIRAL],
685 686
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
687 688 689 690 691
  [lalinspiral],
  AC_HELP_STRING([--enable-lalinspiral],[compile code that requires lalinspiral library [default=yes]]),
  [ case "${enableval}" in
      yes) lalinspiral=true;;
      no) lalinspiral=false;;
692
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalinspiral) ;;
693
    esac
694
  ], [ lalinspiral=${all_lal:-true} ] )
695 696 697
if test "$lalframe" = "false"; then
  lalinspiral=false
fi
698 699 700
if test "$lalmetaio" = "false"; then
  lalinspiral=false
fi
Adam Mercer's avatar
Adam Mercer committed
701 702 703
if test "$lalsimulation" = "false"; then
  lalinspiral=false
fi
704 705 706
])

AC_DEFUN([LALSUITE_ENABLE_LALPULSAR],
707 708
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
709 710 711 712 713 714 715
  [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
716
  ], [ lalpulsar=${all_lal:-true} ] )
717 718 719
])

AC_DEFUN([LALSUITE_ENABLE_LALSTOCHASTIC],
720 721
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
722 723 724 725 726
  [lalstochastic],
  AC_HELP_STRING([--enable-lalstochastic],[compile code that requires lalstochastic library [default=yes]]),
  [ case "${enableval}" in
      yes) lalstochastic=true;;
      no) lalstochastic=false;;
727
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalstochastic) ;;
728
    esac
729
  ], [ lalstochastic=${all_lal:-true} ] )
730 731
if test "$lalmetaio" = "false"; then
  lalstochastic=false
732 733 734 735
fi
])

AC_DEFUN([LALSUITE_ENABLE_LALINFERENCE],
736 737
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
738 739 740 741 742 743 744
  [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
745
  ], [ lalinference=${all_lal:-true} ] )
746 747 748 749 750 751 752 753 754 755 756
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
757 758
fi
])
Adam Mercer's avatar
Adam Mercer committed
759

760
AC_DEFUN([LALSUITE_ENABLE_LALAPPS],[
761
  AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
762 763 764 765 766 767 768 769 770 771
  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
    ],[
772
      lalapps=${all_lal:-true}
773 774 775 776
    ]
  )
])

Karl Wette's avatar
Karl Wette committed
777 778 779 780 781 782 783 784 785 786 787 788 789
AC_DEFUN([LALSUITE_ENABLE_BOINC],[
  # $0: enable/disable BOINC
  AC_ARG_ENABLE(
    [boinc],
    AC_HELP_STRING([--enable-boinc],[enable BOINC support [default=no]]),
    AS_CASE([${enableval}],
      [yes],[boinc=true],
      [no],[boinc=false],
      AC_MSG_ERROR([bad value '${enableval}' for --enable-boinc])
    ),
    [boinc=false]
  )
  LALSUITE_ENABLE_MODULE([BOINC])
790
  AS_IF([test "${boinc}" = true],[LALSUITE_REQUIRE_CXX])
Karl Wette's avatar
Karl Wette committed
791
  # end $0
Adam Mercer's avatar
Adam Mercer committed
792 793
])

Karl Wette's avatar
Karl Wette committed
794 795 796 797 798 799 800 801
AC_DEFUN([LALSUITE_CHECK_BOINC],[
  # $0: check for BOINC support
  AS_IF([test "${boinc}" = "true"],[
    LALSUITE_CHECK_LIBRARY_FOR_SUPPORT([LAL],[BOINC],[:],[
      AC_MSG_ERROR([BOINC was enabled but LAL was not compiler with BOINC support])
    ])
  ])
  # end $0
Adam Mercer's avatar
Adam Mercer committed
802
])
803

Karl Wette's avatar
Karl Wette committed
804 805
AC_DEFUN([LALSUITE_WITH_CUDA],[
AC_ARG_WITH(
806
  [cuda],
Karl Wette's avatar
Karl Wette committed
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829
  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"
830
    CUDA_CFLAGS="-I${with_cuda}/include"
831
    LALSUITE_ADD_FLAGS([C],${CUDA_CFLAGS},${CUDA_LIBS})
Karl Wette's avatar
Karl Wette committed
832
    AC_SUBST(CUDA_LIBS)
833
    AC_SUBST(CUDA_CFLAGS)
Karl Wette's avatar
Karl Wette committed
834 835 836 837 838
    AC_PATH_PROGS(NVCC,[nvcc],[],[${cuda_path}/bin:${PATH}])
    AS_IF([test "x${NVCC}" = x],[
      AC_MSG_ERROR([could not find 'nvcc' in path])
    ])
  ])
839
  LALSUITE_ENABLE_MODULE([CUDA])
840
])
841

Karl Wette's avatar
Karl Wette committed
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

AC_DEFUN([LALSUITE_CHECK_GSL_VERSION],[
  # $0: check for GSL version
  lal_min_gsl_version=m4_normalize([$1])
  AC_MSG_CHECKING(for GSL version >= $lal_min_gsl_version)
  AC_TRY_RUN([
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gsl/gsl_version.h>
int main(void)
{
  int required_major, required_minor;
  int major, minor;
  char required_version[] = "$lal_min_gsl_version";
  char version[] = GSL_VERSION;
  if ( strcmp(GSL_VERSION, gsl_version) ) {
    printf("error\n*** mismatch between header and library versions of GSL\n" );
    printf("\n*** header  has version %s\n", GSL_VERSION);
    printf("\n*** library has version %s\n", gsl_version);
    exit(1);
  }
  sscanf(required_version, "%d.%d", &required_major, &required_minor);
  sscanf(version, "%d.%d", &major, &minor);
  if ( major < required_major || (major == required_major && minor < required_minor) ) {
    printf("no\n*** found version %s of GSL but minimum version is %d.%d\n", GSL_VERSION, required_major, required_minor );
    exit(1);
  }
  return 0;
}
  ],[
    AC_MSG_RESULT([yes])
  ],[
    AC_MSG_ERROR([could not find required version of GSL])
  ],[
    AC_MSG_WARN([cross compiling; assumed OK...])
  ])
  # end $0
])

AC_DEFUN([LALSUITE_ENABLE_FAST_GSL],[
  # $0: enable/disable fast/inline GSL code
  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])
    )
896
  )
Karl Wette's avatar
Karl Wette committed
897
  # end $0
898 899
])

900 901 902
AC_DEFUN([LALSUITE_ENABLE_OSX_VERSION_CHECK],
[AC_ARG_ENABLE(
  [osx_version_check],
903
  AC_HELP_STRING([--enable-osx-version-check],[disable OS X version check [default=yes]]),
904 905 906 907 908
  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])
909
])
910

911
AC_DEFUN([LALSUITE_OSX_VERSION_CHECK],[
912
LALSUITE_ENABLE_OSX_VERSION_CHECK
913
AS_IF([test "x${osx_version_check}" = "xtrue"],[
914
  AS_IF([test "x$build_vendor" = "xapple"],[
915
    AC_CHECK_PROGS([SW_VERS],[sw_vers])
916
    AS_IF([test "x$SW_VERS" != "x"],[
917 918
      AC_MSG_CHECKING([Mac OS X version])
      MACOSX_VERSION=`$SW_VERS -productVersion`
919
      AC_MSG_RESULT([$MACOSX_VERSION])])
920
    AS_CASE(["$MACOSX_VERSION"],
Adam Mercer's avatar
Adam Mercer committed
921 922
      [10.0*|10.1|10.1.*|10.2*|10.3*],AC_MSG_ERROR([This version of Mac OS X is not supported]),
      [10.4*|10.5*|10.6*|10.7*|10.8*|10.9*|10.10*],,
923
      AC_MSG_WARN([Unknown Mac OS X version]))
924
])])])
925 926 927 928 929

AC_DEFUN([LALSUITE_WITH_NVCC_CFLAGS],
[AC_ARG_WITH(
  [nvcc_cflags],
  AC_HELP_STRING([--with-nvcc-cflags=NVCC_CFLAGS],[NVCC compiler flags]),
930
  AS_IF([test -n "${with_nvcc_cflags}"],[NVCC_CFLAGS="$NVCC_CFLAGS ${with_nvcc_cflags}"]),)
931
])
Adam Mercer's avatar
Adam Mercer committed
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949

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])
])