lalsuite_build.m4 47.3 KB
Newer Older
1
# -*- mode: autoconf; -*-
2 3
# lalsuite_build.m4 - top level build macros
#
4
# serial 152
5

6 7 8 9
# restrict which LALSUITE_... patterns can appearing in output (./configure);
# useful for debugging problems with unexpanded LALSUITE_... Autoconf macros
m4_pattern_forbid([^_?LALSUITE_[A-Z_]+$])
m4_pattern_allow([^LALSUITE_(BUILD)$])
10 11 12 13 14 15 16

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

17 18 19 20 21 22 23
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])
])

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
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,[
44
    AC_SUBST(AM_[]uvar,"${AM_[]uvar} ${sys_[]uvar}")
45 46
    uvar="${uvar_prefix[]uvar}"
  ])
47 48 49 50 51
  # append extra values for user variables to be added after configuration
  m4_foreach_w([uvar],uvar_list,[
    AC_ARG_VAR([POSTCONFIG_]uvar,[Extra ]uvar[ to be added after configuration])
    uvar="${uvar} ${POSTCONFIG_[]uvar}"
  ])
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
  # 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
])

84 85 86 87
AC_DEFUN([LALSUITE_CHECK_COMPILE_FLAGS],[
  # $0: check multiple compile flags
  LALSUITE_PUSH_UVARS
  LALSUITE_CLEAR_UVARS
88 89
  lalsuite_save_werror_flag=${ac_[]_AC_LANG_ABBREV[]_werror_flag}
  ac_[]_AC_LANG_ABBREV[]_werror_flag=yes
90
  for flag in m4_normalize($1); do
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    AS_VAR_PUSHDEF([CACHEVAR],[lalsuite_cv_check_compile_[]_AC_LANG_ABBREV[]_${flag}])
    AC_CACHE_CHECK([whether ]_AC_LANG[ compiler accepts ${flag}],CACHEVAR,[
      _AC_LANG_PREFIX[]FLAGS="${uvar_orig_prefix[]_AC_LANG_PREFIX[]FLAGS} ${flag}"
      AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],[
        AS_VAR_SET(CACHEVAR,[yes])
      ],[
        AS_VAR_SET(CACHEVAR,[no])
      ])
    ])
    AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],[
      m4_default([$2], :)
    ],[
      m4_default([$3], :)
    ])
    AS_VAR_POPDEF([CACHEVAR])
106
  done
107
  ac_[]_AC_LANG_ABBREV[]_werror_flag=${lalsuite_save_werror_flag}
108 109 110 111 112 113 114 115
  LALSUITE_POP_UVARS
  # end $0
])

AC_DEFUN([LALSUITE_CHECK_LINK_FLAGS],[
  # $0: check multiple link flags
  LALSUITE_PUSH_UVARS
  LALSUITE_CLEAR_UVARS
116 117
  lalsuite_save_werror_flag=${ac_[]_AC_LANG_ABBREV[]_werror_flag}
  ac_[]_AC_LANG_ABBREV[]_werror_flag=yes
118
  for flag in m4_normalize($1); do
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
    AS_VAR_PUSHDEF([CACHEVAR],[lalsuite_cv_check_link_[]_AC_LANG_ABBREV[]_${flag}])
    AC_CACHE_CHECK([whether ]_AC_LANG[ linker accepts ${flag}],CACHEVAR,[
      LDFLAGS="${uvar_orig_prefix[]LDFLAGS} ${flag}"
      AC_LINK_IFELSE([AC_LANG_PROGRAM([])],[
        AS_VAR_SET(CACHEVAR,[yes])
      ],[
        AS_VAR_SET(CACHEVAR,[no])
      ])
    ])
    AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],[
      m4_default([$2],[:])
    ],[
      m4_default([$3],[:])
    ])
    AS_VAR_POPDEF([CACHEVAR])
134
  done
135
  ac_[]_AC_LANG_ABBREV[]_werror_flag=${lalsuite_save_werror_flag}
136 137 138 139
  LALSUITE_POP_UVARS
  # end $0
])

140
AC_DEFUN([LALSUITE_ADD_FLAGS],[
141
  # $0: prepend/append flags to AM_CPPFLAGS/AM_$1FLAGS/AM_LDFLAGS/LIBS,
142
  # and update values of CPPFLAGS/$1FLAGS/LDFLAGS for Autoconf tests
143 144 145
  # - arg 1: prefix of the compiler flag variable, e.g. C for CFLAGS, CXX for CXXFLAGS
  # - arg 2: compiler flags
  # - arg 3: linker flags
146
  m4_ifval([$1],[m4_ifval([$2],[
147
    pre_AM_CPPFLAGS=
148
    post_AM_CPPFLAGS=
149
    pre_sys_CPPFLAGS=
150
    post_AM_$1FLAGS=
151
    for flag in $2; do
152 153 154
      # AM_CPPFLAGS gets unique -I, -D and -U flags
      # sys_CPPFLAGS gets unique system -I flags
      # AM_$1FLAGS gets everything else
155
      AS_CASE([${flag}],
156 157 158 159 160 161 162 163 164 165 166 167
        [-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}"]
          )
        ],
168 169
        [-D*|-U*],[post_AM_CPPFLAGS="${post_AM_CPPFLAGS} ${flag}"],
        [post_AM_$1FLAGS="${post_AM_$1FLAGS} ${flag}"]
170 171
      )
    done
172 173 174
    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])
175
    ])
176 177 178 179
    AS_IF([test "x${post_AM_CPPFLAGS}" != x],[
      AM_CPPFLAGS="${AM_CPPFLAGS} ${post_AM_CPPFLAGS}"
      _AS_ECHO_LOG([appended ${post_AM_CPPFLAGS} to AM_CPPFLAGS])
    ])
180 181 182
    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])
183
    ])
184 185 186
    AS_IF([test "x${post_AM_$1FLAGS}" != x],[
      AM_$1FLAGS="${AM_$1FLAGS} ${post_AM_$1FLAGS}"
      _AS_ECHO_LOG([appended ${post_AM_$1FLAGS} to AM_$1FLAGS])
187 188 189
    ])
    CPPFLAGS="${AM_CPPFLAGS} ${sys_CPPFLAGS} ${uvar_orig_prefix[]CPPFLAGS}"
    $1FLAGS="${AM_$1FLAGS} ${uvar_orig_prefix[]$1FLAGS}"
190 191
  ])])
  m4_ifval([$3],[
192
    pre_AM_LDFLAGS=
193
    post_AM_LDFLAGS=
194 195
    pre_sys_LDFLAGS=
    pre_LIBS=
196
    for flag in $3; do
197 198 199
      # LIBS gets -l flags and .la files
      # sys_LDFLAGS gets unique system -L flags
      # AM_LDFLAGS gets unique -L flags and everything else
200
      AS_CASE([${flag}],
201 202 203 204 205 206 207 208 209 210 211 212 213
        [-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}"],
214
        [post_AM_LDFLAGS="${post_AM_LDFLAGS} ${flag}"]
215 216
      )
    done
217 218 219 220
    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])
    ])
221 222 223 224
    AS_IF([test "x${post_AM_LDFLAGS}" != x],[
      AM_LDFLAGS="${AM_LDFLAGS} ${post_AM_LDFLAGS}"
      _AS_ECHO_LOG([appended ${post_AM_LDFLAGS} to AM_LDFLAGS])
    ])
225 226 227
    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])
228
    ])
229 230 231
    AS_IF([test "x${pre_LIBS}" != x],[
      LIBS="${pre_LIBS} ${LIBS}"
      _AS_ECHO_LOG([prepended ${pre_LIBS} to LIBS])
232
    ])
233
    LDFLAGS="${AM_LDFLAGS} ${sys_LDFLAGS} ${uvar_orig_prefix[]LDFLAGS}"
234 235 236 237 238 239
  ])
  # end $0
])

AC_DEFUN([LALSUITE_ADD_PATH],[
  # $0: prepend path to $1, removing duplicates, first value taking precedence
240 241
  # - arg 1: name of path variable
  # - arg 2: path to prepend
242
  # - arg 3: whether to exclude /opt/... and /usr/... directories (default: yes)
243 244 245 246
  tokens=$2
  tokens=`echo ${tokens} ${$1} | sed 's/:/ /g'`
  $1=
  for token in ${tokens}; do
247 248 249 250 251 252 253 254 255 256
    AS_CASE([m4_default([$3],[yes]):${token}],
      [yes:/opt/*|yes:/usr/*],[:],
      AS_CASE([":${$1}:"],
        [*:${token}:*],[:],
        AS_IF([test "x${$1}" = x],[
          $1="${token}"
        ],[
          $1="${$1}:${token}"
        ])
      )
257 258 259 260
    )
  done
  _AS_ECHO_LOG([$1=${$1}])
  # end $0
261
])
262

263 264 265 266
AC_DEFUN([LALSUITE_VERSION_COMPARE],[
  # $0: compare versions using the given operator
  m4_case([$2],[<],,[<=],,[=],,[>=],,[>],,[m4_fatal([$0: invalid operator $2])])
  AS_VERSION_COMPARE([$1],[$3],[lalsuite_op='<'],[lalsuite_op='='],[lalsuite_op='>'])
267
  AS_CASE(['$2'],[*${lalsuite_op}*],[m4_default([$4],[:])],[m4_default([$5],[:])])
268 269 270
  # end $0
])

271
AC_DEFUN([LALSUITE_CHECK_GIT_REPO],[
272
  # $0: check for git
273
  AC_PATH_PROGS([GIT],[git],[false])
274 275 276 277 278 279 280 281
  # 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
282
    git_log=`( cd "${srcdir}" && ${GIT} log --pretty=oneline -n 1 -- . ) 2>/dev/null`
283
    AS_IF([test "x${git_log}" != x],[have_git_repo=yes])
284 285 286
    AC_MSG_RESULT([${have_git_repo}])
  ])
  # conditional for git and building from a git repository
287
  AM_CONDITIONAL([HAVE_GIT_REPO],[test "x${have_git_repo}" = xyes])
288
  # end $0
289
])
290

291 292 293
AC_DEFUN([LALSUITE_VERSION_CONFIGURE_INFO],[
  # $0: define version/configure info
  m4_pushdef([uppercase],m4_translit(AC_PACKAGE_NAME, [a-z], [A-Z]))
294 295
  m4_pushdef([lowercase],m4_translit(AC_PACKAGE_NAME, [A-Z], [a-z]))
  m4_pushdef([withoutlal],m4_bpatsubst(AC_PACKAGE_NAME, [^LAL], []))
296 297 298 299 300 301 302 303 304 305 306 307 308 309
  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])
310 311 312
  AC_SUBST([PACKAGE_NAME_UCASE],uppercase)
  AC_SUBST([PACKAGE_NAME_LCASE],lowercase)
  AC_SUBST([PACKAGE_NAME_NOLAL],withoutlal)
313
  m4_popdef([uppercase])
314 315
  m4_popdef([lowercase])
  m4_popdef([withoutlal])
316 317 318
  # end $0
])

319
AC_DEFUN([LALSUITE_REQUIRE_CXX],[
320
  # $0: require a C++ compiler
321
  lalsuite_require_cxx=true
322
  # end $0
323 324
])

325
AC_DEFUN([LALSUITE_REQUIRE_F77],[
326
  # $0: require an F77 compiler
327
  lalsuite_require_f77=true
328
  # end $0
329 330
])

331 332 333 334 335 336 337 338 339 340
# 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[)],[])
])
341

342
AC_DEFUN([LALSUITE_PROG_COMPILERS],[
343
  # $0: check for C/C++/Fortran compilers
344

345 346 347 348
  # check for C99 compiler
  AC_REQUIRE([AC_PROG_CC])
  AC_REQUIRE([AC_PROG_CC_C99])
  AC_REQUIRE([AC_PROG_CPP])
349

350 351 352 353 354 355 356 357 358
  # set default CFLAGS
  CFLAGS=
  AS_IF([test "x${GCC}" = xyes],[
    CFLAGS="${CFLAGS} -O2"
  ])
  AS_IF([test "x${ac_cv_prog_cc_g}" = xyes],[
    CFLAGS="${CFLAGS} -g"
  ])

359 360 361
  # only include ISO C99 definitions from system headers
  CFLAGS="${CFLAGS} -D_ISOC99_SOURCE"

362 363 364 365
  # check for C++ compiler, if needed
  AS_IF([test "${lalsuite_require_cxx}" = true],[
    AC_PROG_CXX
    AC_PROG_CXXCPP
366

367 368 369 370 371 372 373 374 375
    # set default CXXFLAGS
    CXXFLAGS=
    AS_IF([test "x${GXX}" = xyes],[
      CXXFLAGS="${CXXFLAGS} -O2"
    ])
    AS_IF([test "x${ac_cv_prog_cxx_g}" = xyes],[
      CXXFLAGS="${CXXFLAGS} -g"
    ])

376
    # define C99 constant and limit macros for C++ sources
377
    CXXFLAGS="${CXXFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS"
378

379 380 381
  ],[
    CXX=
    CXXCPP=
382
    CXXFLAGS=
383
    AM_CONDITIONAL([am__fastdepCXX],[false])
384
  ])
385

386 387 388
  # check for F77 compiler, if needed
  AS_IF([test "${lalsuite_require_f77}" = true],[
    AC_PROG_F77
389 390 391 392 393 394 395 396 397 398

    # set default FFLAGS
    FFLAGS=
    AS_IF([test "x${ac_cv_f77_compiler_gnu}" = xyes],[
      FFLAGS="${FFLAGS} -O2"
    ])
    AS_IF([test "x${ac_cv_prog_f77_g}" = xyes],[
      FFLAGS="${FFLAGS} -g"
    ])

399 400
  ],[
    F77=
401
    FFLAGS=
402
  ])
403

404 405 406 407 408
  # add flags
  LALSUITE_ADD_FLAGS([C],[${CFLAGS}])
  LALSUITE_ADD_FLAGS([CXX],[${CXXFLAGS}])
  LALSUITE_ADD_FLAGS([F],[${FFLAGS}])

409
  # end $0
410 411
])

412 413 414 415 416
AC_DEFUN([LALSUITE_REQUIRE_PYTHON],[
  # $0: require Python version $1 or later
  AS_IF([test "x${lalsuite_require_pyvers}" = x],[
    lalsuite_require_pyvers="$1"
  ],[
417
    LALSUITE_VERSION_COMPARE([$1],[>],[${lalsuite_require_pyvers}],[
418 419 420 421 422 423 424 425
      lalsuite_require_pyvers="$1"
    ])
  ])
  # end $0
])

AC_DEFUN([LALSUITE_CHECK_PYTHON],[
  # $0: check for Python
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
  AC_ARG_ENABLE(
    [python],
    AC_HELP_STRING(
      [--enable-python],
      [build Python programs and modules]
    ),[
      AS_CASE(["${enableval}"],
        [yes],[python=true],
        [no],[python=false],
        [AC_MSG_ERROR([invalid value "${enableval}" for --enable-python])]
      )
    ],[
      python=
    ]
  )
441 442
  lalsuite_pyvers="$1"
  AS_IF([test "x${lalsuite_require_pyvers}" != x],[
443
    LALSUITE_VERSION_COMPARE([${lalsuite_require_pyvers}],[>],[${lalsuite_pyvers}],[
444 445 446
      lalsuite_pyvers="${lalsuite_require_pyvers}"
    ])
  ])
447 448 449 450 451 452
  AS_IF([test "x${python}" != xfalse || test "x${lalsuite_require_pyvers}" != x],[
    AM_PATH_PYTHON([${lalsuite_pyvers}],[
      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`])
    ],[
      AS_IF([test "x${python}" = xtrue || test "x${lalsuite_require_pyvers}" != x],[
453
        AC_MSG_ERROR([Python version ${lalsuite_pyvers} or later is required])
454 455
      ],[
        python=false
456 457 458
      ])
    ])
  ])
459 460 461 462
  AS_IF([test "x${python}" = xfalse && test "x${lalsuite_require_pyvers}" = x],[
    AC_SUBST([PYTHON],["${SHELL} -c 'echo ERROR: Python is missing >&2; exit 1' --"])
  ])
  AM_CONDITIONAL([HAVE_PYTHON],[test "x${python}" != xfalse])
463 464 465 466 467 468 469 470
  AM_COND_IF([HAVE_PYTHON],[
    PYTHON_ENABLE_VAL=ENABLED
  ],[
    PYTHON_ENABLE_VAL=DISABLED
  ])
  # end $0
])

471
AC_DEFUN([LALSUITE_USE_LIBTOOL],[
472 473
  # $0: Generate a libtool script for use in configure tests. Arguments
  # are added to link command in variable ${lalsuite_libtool_flags}
474 475 476
  AC_REQUIRE([LT_INIT])
  LT_OUTPUT
  m4_append([AC_LANG(C)],[
477
    ac_link="./libtool --mode=link --tag=CC ${ac_link} ${lalsuite_libtool_flags}"
478 479 480
  ])
  AC_PROVIDE_IFELSE([AC_PROG_CXX],[
    m4_append([AC_LANG(C++)],[
481
      ac_link="./libtool --mode=link --tag=CXX ${ac_link} ${lalsuite_libtool_flags}"
482 483 484
    ])
  ])
  AC_LANG(_AC_LANG)
485
  LALSUITE_ADD_FLAGS([],[],[${lalsuite_libtool_flags}])
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
  # 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
])
503

504
AC_DEFUN([LALSUITE_DISTCHECK_CONFIGURE_FLAGS],[
505
  # $0: store configure flags for 'make distcheck'
506
  DISTCHECK_CONFIGURE_FLAGS=
507 508 509 510 511 512
  eval set x "${ac_configure_args}"
  shift
  for arg
  do
    AS_CASE(["${arg}"],
      [--enable-*|--disable-*],[
513
        # save any --enable/--disable arguments
514 515 516
        DISTCHECK_CONFIGURE_FLAGS="${DISTCHECK_CONFIGURE_FLAGS} '${arg}'"
      ],
      [--with-*|--without-*],[
517
        # save any --with/--without arguments
518 519 520
        DISTCHECK_CONFIGURE_FLAGS="${DISTCHECK_CONFIGURE_FLAGS} '${arg}'"
      ],
      [--*],[
521
        # skip all other ./configure arguments
522 523 524
        :
      ],
      [DISTCHECK_CONFIGURE_FLAGS=*],[
525
        # append value of DISTCHECK_CONFIGURE_FLAGS
526 527 528
        DISTCHECK_CONFIGURE_FLAGS="${DISTCHECK_CONFIGURE_FLAGS} '`expr "X${arg}" : "XDISTCHECK_CONFIGURE_FLAGS=\(.*\)"`'"
      ],
      [*=*],[
529
        # save any environment variables given to ./configure
530 531 532
        DISTCHECK_CONFIGURE_FLAGS="${DISTCHECK_CONFIGURE_FLAGS} '${arg}'"
      ]
    )
533 534
  done
  AC_SUBST(DISTCHECK_CONFIGURE_FLAGS)
535
  # end $0
536 537
])

538
AC_DEFUN([LALSUITE_ENABLE_MODULE],[
539 540 541 542 543 544 545 546 547 548 549 550 551
  # $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
552 553
])

554
AC_DEFUN([LALSUITE_CHECK_LIB],[
555
  # $0: check for LAL library
556 557 558 559
  # - 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
560 561
  m4_pushdef([lowercase],m4_translit([[$1]], [A-Z], [a-z]))
  m4_pushdef([uppercase],m4_translit([[$1]], [a-z], [A-Z]))
562

563 564
  # substitute required library version in pkg-config files
  AC_SUBST(uppercase[]_VERSION,[$2])
565 566 567 568 569

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

570
  # prepend to CFLAGS, CPPFLAGS, LDFLAGS, LIBS, LAL_DATA_PATH, LAL_OCTAVE_PATH, LAL_PYTHON_PATH, LAL_HTMLDIR
571 572 573 574
  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,,)
575
  PKG_CHECK_VAR(uppercase[]_HTMLDIR, [lowercase >= $2], htmldir,,)
576 577 578 579 580 581
  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
582 583

  # add system include flags to LAL_SYSTEM_INCLUDES
584
  if test -n "$PKG_CONFIG" -a "$LALSUITE_BUILD" != "true"; then
585 586 587 588 589 590 591 592 593 594 595 596 597 598
    # use pkg-config to get system paths
    PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
    export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS
    for flag in `$PKG_CONFIG --cflags-only-I "lowercase >= $2"`; do
      AS_CASE([" $CPPFLAGS $LAL_SYSTEM_INCLUDES "],
        [*" ${flag} "*],[:],
        [LAL_SYSTEM_INCLUDES="$LAL_SYSTEM_INCLUDES $flag"]
      )
    done
    AS_UNSET([PKG_CONFIG_ALLOW_SYSTEM_CFLAGS])
  else
    # use standard include paths
    save_IFS="$IFS"
    IFS=:
599
    for flag in $C_INCLUDE_PATH $CPLUS_INCLUDE_PATH /usr/include ; do
600 601 602 603 604 605 606 607 608 609
      test -n "$flag" && flag="-I$flag"
      AS_CASE([" $CPPFLAGS $LAL_SYSTEM_INCLUDES "],
        [*" ${flag} "*],[:],
        [LAL_SYSTEM_INCLUDES="$LAL_SYSTEM_INCLUDES $flag"]
      )
    done
    IFS="$save_IFS"
  fi
  AC_SUBST([LAL_SYSTEM_INCLUDES])

610 611 612 613 614 615 616 617
  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])])
618
    m4_if(lowercase,[lalsupport],[],[
619
      LALSUITE_HEADER_LIBRARY_MISMATCH_CHECK([$1])
620
    ])
621 622 623 624 625 626
  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)
627 628 629
  m4_popdef([lowercase])
  m4_popdef([uppercase])
  # end $0
630 631 632
])

AC_DEFUN([LALSUITE_CHECK_OPT_LIB],[
633
  # $0: check for optional LAL library
634 635 636 637
  # - 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
638 639 640 641 642 643 644 645 646 647 648 649 650 651
  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
652 653 654
])

AC_DEFUN([LALSUITE_HEADER_LIBRARY_MISMATCH_CHECK],[
655
  # $0: check for version mismatch between library $1 and its headers
656 657
  m4_pushdef([uppercase],m4_translit([[$1]], [a-z], [A-Z]))
  m4_pushdef([withoutlal],m4_bpatsubst([$1], [^LAL], []))
658
  AC_MSG_CHECKING([whether $1 headers match the library])
659
  AC_LINK_IFELSE([
660
    AC_LANG_SOURCE([[
661
#include <lal/$1VCSInfoHeader.h>
662 663 664 665 666 667
int main(void) {
#if ]uppercase[_VERSION_DEVEL != 0
  ]uppercase[_VCS_LINK_CHECK();
#endif
  return 0;
}
668 669
    ]])
  ],[
670
    AC_MSG_RESULT([yes])
671
  ],[
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
    AC_MSG_RESULT([no])
    AC_LINK_IFELSE([
      AC_LANG_SOURCE([[
#include <stdio.h>
#include <lal/$1VCSInfoHeader.h>
int main(void) {
  printf("$1 headers: %s %s %s\n", ]uppercase[_VERSION, ]uppercase[_VCS_ID, ]uppercase[_VCS_STATUS);
  printf("$1 library: %s %s %s\n", lal]withoutlal[VCSInfo.version, lal]withoutlal[VCSInfo.vcsId, lal]withoutlal[VCSInfo.vcsStatus);
  return 0;
}
      ]])
    ],[
      AS_IF([test ${cross_compiling} != yes],[
        ./conftest${EXEEXT} | ${SED} -e "s/^/${as_me}:${as_lineno-$LINENO}: /" >&AS_MESSAGE_LOG_FD
      ])
    ],[
      _AS_ECHO_LOG([could not determine further details of $1 header-library mismatch (compile/link error)])
    ],[
      _AS_ECHO_LOG([could not determine further details of $1 header-library mismatch (cross compiling)])
    ])
692 693
    AC_MSG_ERROR([Your $1 headers do not match your library. Check config.log for details.])
  ])
694 695
  m4_popdef([uppercase])
  m4_popdef([withoutlal])
696
  # end $0
697
])
698

699 700 701 702 703 704 705 706
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}"
707 708 709 710 711 712 713 714 715 716
  AS_IF([test "x${LALSUITE_BUILD}" = xtrue],[
    for arg in ${lalsuite_libs}; do
      AS_CASE([${arg}],
        [lalsupport],[:],[
          CPPFLAGS="-I${ac_pwd}/../${arg}/src ${CPPFLAGS}"
        ]
      )
    done
    CPPFLAGS="-DLALSUITE_BUILD ${CPPFLAGS}"
  ])
717 718 719
  AC_MSG_CHECKING([whether $1 has been compiled with $2 support])
  AC_COMPILE_IFELSE([
    AC_LANG_SOURCE([[
720 721 722
#ifdef LALSUITE_BUILD
#include "$1Config.h"
#else
723
#include <lal/$1Config.h>
724
#endif
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
#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
])

741
AC_DEFUN([LALSUITE_ENABLE_NIGHTLY],
742 743 744 745 746 747 748 749 750 751 752 753 754
[
  BASE_VERSION="${VERSION}"
  AC_ARG_ENABLE(
    [nightly],
    AC_HELP_STRING([--enable-nightly],[nightly build [default=no]]),
    [ case "${enableval}" in
        yes) NIGHTLY_VERSION=dev`date -u +"%Y%m%d"`
             VERSION="${BASE_VERSION}-${NIGHTLY_VERSION}" ;;
        no) NIGHTLY_VERSION="";;
        *) NIGHTLY_VERSION="${enableval}"
           VERSION="${BASE_VERSION}-${NIGHTLY_VERSION}" ;;
        esac ],
    [ NIGHTLY_VERSION="" ] )
755 756 757
    AC_SUBST([VERSION])
    AC_SUBST([BASE_VERSION])
    AC_SUBST([NIGHTLY_VERSION])
758 759
])

760 761 762 763 764 765 766 767 768 769 770 771
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= ] )
])

772
AC_DEFUN([LALSUITE_ENABLE_LALFRAME],
773 774
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
775 776 777 778 779
  [lalframe],
  AC_HELP_STRING([--enable-lalframe],[compile code that requires lalframe library [default=yes]]),
  [ case "${enableval}" in
      yes) lalframe=true;;
      no) lalframe=false;;
780
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalframe) ;;
781
    esac
782
  ], [ lalframe=${all_lal:-true} ] )
783 784 785 786 787 788
if test "$frame" = "false"; then
  lalframe=false
fi
])

AC_DEFUN([LALSUITE_ENABLE_LALMETAIO],
789 790
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
791 792 793 794 795
  [lalmetaio],
  AC_HELP_STRING([--enable-lalmetaio],[compile code that requires lalmetaio library [default=yes]]),
  [ case "${enableval}" in
      yes) lalmetaio=true;;
      no) lalmetaio=false;;
796
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalmetaio) ;;
797
    esac
798
  ], [ lalmetaio=${all_lal:-true} ] )
799 800 801 802 803
if test "$metaio" = "false"; then
  lalmetaio=false
fi
])

804
AC_DEFUN([LALSUITE_ENABLE_LALSIMULATION],
805 806
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
807 808 809 810 811 812 813 814 815 816
  [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} ] )
])

817
AC_DEFUN([LALSUITE_ENABLE_LALBURST],
818 819
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
820 821 822 823 824
  [lalburst],
  AC_HELP_STRING([--enable-lalburst],[compile code that requires lalburst library [default=yes]]),
  [ case "${enableval}" in
      yes) lalburst=true;;
      no) lalburst=false;;
825
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalburst) ;;
826
    esac
827
  ], [ lalburst=${all_lal:-true} ] )
828 829
if test "$lalmetaio" = "false"; then
  lalburst=false
830 831 832 833 834
fi
if test "$lalsimulation" = "false"; then
  lalburst=false
fi
])
835 836

AC_DEFUN([LALSUITE_ENABLE_LALINSPIRAL],
837 838
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
839 840 841 842 843
  [lalinspiral],
  AC_HELP_STRING([--enable-lalinspiral],[compile code that requires lalinspiral library [default=yes]]),
  [ case "${enableval}" in
      yes) lalinspiral=true;;
      no) lalinspiral=false;;
844
      *) AC_MSG_ERROR(bad value ${enableval} for --enable-lalinspiral) ;;
845
    esac
846
  ], [ lalinspiral=${all_lal:-true} ] )
847 848 849
if test "$lalframe" = "false"; then
  lalinspiral=false
fi
850 851 852
if test "$lalmetaio" = "false"; then
  lalinspiral=false
fi
853 854 855
if test "$lalsimulation" = "false"; then
  lalinspiral=false
fi
856 857 858
])

AC_DEFUN([LALSUITE_ENABLE_LALPULSAR],
859 860
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
861 862 863 864 865 866 867
  [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
868
  ], [ lalpulsar=${all_lal:-true} ] )
869 870
])

871
AC_DEFUN([LALSUITE_ENABLE_LALINFERENCE],
872 873
[AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
AC_ARG_ENABLE(
874 875 876 877 878 879 880
  [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
881
  ], [ lalinference=${all_lal:-true} ] )
882 883 884 885 886 887 888 889 890 891 892
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
893 894
fi
])
895

896
AC_DEFUN([LALSUITE_ENABLE_LALAPPS],[
897
  AC_REQUIRE([LALSUITE_ENABLE_ALL_LAL])
898 899 900 901 902 903 904 905 906 907
  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
    ],[
908
      lalapps=${all_lal:-true}
909 910 911 912
    ]
  )
])

913 914 915 916 917 918 919 920 921 922 923 924 925
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])
926
  AS_IF([test "${boinc}" = true],[LALSUITE_REQUIRE_CXX])
927
  # end $0
928 929
])

930
AC_DEFUN([LALSUITE_CHECK_BOINC],[
931
  # $0: check for BOINC, and modify compiler for lal library checks
932
  AS_IF([test "${boinc}" = "true"],[
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968

    # do compilation checks with c++
    AC_LANG_PUSH([C++])

    # check for BOINC libraries
    AC_SUBST([BOINC_CFLAGS],[""])
    AC_SUBST([BOINC_LIBS],["-lboinc_api -lboinc"])
    LALSUITE_ADD_FLAGS([C],[${BOINC_CFLAGS}],[${BOINC_LIBS}])
    AC_CHECK_LIB([boinc],[boinc_fopen],[:],[AC_MSG_ERROR([could not find the boinc library])])
    AC_CHECK_LIB([boinc_api],[boinc_finish],[:],[AC_MSG_ERROR([could not find the boinc_api library])])

    # check for BOINC headers
    AC_CHECK_HEADERS([boinc/boinc_api.h],[:],[AC_MSG_ERROR([could not find the boinc_api.h header])])

  ])
  # end $0
])

AC_DEFUN([LALSUITE_END_CHECK_BOINC],[
  # $0: finish BOINC checks, and restore compiler after lal library checks
  m4_pushdef([lowercase],m4_translit(AC_PACKAGE_NAME, [A-Z], [a-z]))
  AC_REQUIRE([LALSUITE_CHECK_BOINC])
  AS_IF([test "${boinc}" = "true"],[

    m4_if(lowercase,[lal],[

      # if LAL, define macro to indicate BOINC support
      AC_DEFINE([LAL_BOINC_ENABLED],[1],[Define if using BOINC library])

    ],[

      # if not LAL, check LAL was compiled with BOINC support
      LALSUITE_CHECK_LIBRARY_FOR_SUPPORT([LAL],[BOINC],[:],[
        AC_MSG_ERROR([BOINC enabled but LAL not compiled with BOINC support])
      ])

969
    ])
970 971 972 973 974 975 976 977 978 979 980 981

    # go back to c
    AC_LANG_POP([C++])

    # force automake to use c++ compiler for linking
    AC_MSG_WARN([using C++ compiler for linking (forced by BOINC)])
    AC_SUBST([CCLD],['$(CXX)'])
    AC_SUBST([am__v_CCLD_0],['@echo "  CXXLD(B)" $][@;'])

  ],[
    AC_SUBST([CCLD],['$(CC)'])
    AC_SUBST([am__v_CCLD_0],['@echo "  CCLD    " $][@;'])
982
  ])
983
  m4_popdef([lowercase])
984
  # end $0
985
])
986

Karl Wette's avatar
Karl Wette committed
987 988
AC_DEFUN([LALSUITE_WITH_CUDA],[
AC_ARG_WITH(
989
  [cuda],
Karl Wette's avatar
Karl Wette committed
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
  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"
1013
    CUDA_CFLAGS="-I${with_cuda}/include"
1014
    LALSUITE_ADD_FLAGS([C],${CUDA_CFLAGS},${CUDA_LIBS})
Karl Wette's avatar
Karl Wette committed
1015
    AC_SUBST(CUDA_LIBS)
1016
    AC_SUBST(CUDA_CFLAGS)
Karl Wette's avatar
Karl Wette committed
1017 1018 1019 1020
    AC_PATH_PROGS(NVCC,[nvcc],[],[${cuda_path}/bin:${PATH}])
    AS_IF([test "x${NVCC}" = x],[
      AC_MSG_ERROR([could not find 'nvcc' in path])
    ])
1021
    AC_SUBST(NVCC_CFLAGS)
Karl Wette's avatar
Karl Wette committed
1022
  ])
1023
  LALSUITE_ENABLE_MODULE([CUDA])
1024 1025 1026 1027 1028 1029 1030
  AC_ARG_WITH(
    [nvcc_cflags],
    AC_HELP_STRING([--with-nvcc-cflags=NVCC_CFLAGS],[NVCC compiler flags]),
    [
      NVCC_CFLAGS="$NVCC_CFLAGS ${with_nvcc_cflags}"
    ]
  )
1031
])
1032

1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086

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])
    )
1087
  )
1088
  # end $0
1089 1090
])

1091 1092 1093
AC_DEFUN([LALSUITE_ENABLE_OSX_VERSION_CHECK],
[AC_ARG_ENABLE(
  [osx_version_check],
1094
  AC_HELP_STRING([--enable-osx-version-check],[disable OS X version check [default=yes]]),
1095 1096 1097 1098 1099
  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])
1100
])
1101

1102
AC_DEFUN([LALSUITE_OSX_VERSION_CHECK],[
1103
LALSUITE_ENABLE_OSX_VERSION_CHECK
1104
AS_IF([test "x${osx_version_check}" = "xtrue"],[
1105
  AS_IF([test "x$build_vendor" = "xapple"],[
1106
    AC_CHECK_PROGS([SW_VERS],[sw_vers])
1107
    AS_IF([test "x$SW_VERS" != "x"],[
1108 1109
      AC_MSG_CHECKING([Mac OS X version])
      MACOSX_VERSION=`$SW_VERS -productVersion`
1110
      AC_MSG_RESULT([$MACOSX_VERSION])])
1111
    AS_CASE(["$MACOSX_VERSION"],
1112
      [10.0*|10.1|10.1.*|10.2*|10.3*],AC_MSG_ERROR([This version of Mac OS X is not supported]),
1113
      [10.4*|10.5*|10.6*|10.7*|10.8*|10.9*|10.10*|10.11*|10.12*|10.13*|10.14*],,
1114
      AC_MSG_WARN([Unknown Mac OS X version]))
1115
])])])
1116

1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
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])
])
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182

AC_DEFUN([LALSUITE_ENABLE_DOXYGEN],[
  # $0: enable Doxygen documentation
  AC_ARG_ENABLE(
    [doxygen],
    AC_HELP_STRING(
      [--enable-doxygen],
      [generate Doxygen documentation]
    ),[
      AS_CASE(["${enableval}"],
        [yes],[doxygen=true],
        [no],[doxygen=false],
        [AC_MSG_ERROR([invalid value "${enableval}" for --enable-doxygen])]
      )
    ],[
      doxygen=false
    ]
  )
  # end $0
])

AC_DEFUN([LALSUITE_USE_DOXYGEN],[
  # $0: configure Doxygen documentation
  AC_REQUIRE([LALSUITE_CHECK_GIT_REPO])

  # add configuration option for MathJax installation
  AC_ARG_WITH(
    [mathjax],
    AC_HELP_STRING(
      [--with-mathjax=PATH],
      [use MathJax installation at PATH [default: use CDN]]
    ),[
      DOXYGEN_MATHJAXDIR="${withval}"
    ],[
      DOXYGEN_MATHJAXDIR=
    ]
  )

  # enable Doxygen module
  LALSUITE_ENABLE_MODULE([DOXYGEN])

  AS_IF([test "x${doxygen}" = xtrue],[

    # configure Doxygen filter script
    AC_CONFIG_FILES([doxygen/filter],[chmod +x doxygen/filter])

    # Python is required to run some scripts
    LALSUITE_REQUIRE_PYTHON([2.6])

1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
    # Perl and BibTeX are required to build the references
    AC_PATH_PROG([PERL],[perl],[],[])
    AS_IF([test "x${PERL}" = x],[
      AC_MSG_ERROR([could not find 'perl' in PATH (required for Doxygen references)])
    ])
    AC_PATH_PROG([BIBTEX],[bibtex],[],[])
    AS_IF([test "x${BIBTEX}" = x],[
      AC_MSG_ERROR([could not find 'bibtex' in PATH (required for Doxygen references)])
    ])

1193 1194 1195
    # check for Doxygen
    AC_PATH_PROG([DOXYGEN],[doxygen],[],[])
    AS_IF([test "x${DOXYGEN}" = x],[
1196
      AC_MSG_ERROR([could not find 'doxygen' in PATH])
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
    ])
    doxygen_min_version=1.8.1.2   # minimum required Doxygen version
    AC_MSG_CHECKING([if ${DOXYGEN} version is at least ${doxygen_min_version}])
    doxygen_version=`${DOXYGEN} --version 2>/dev/null`
    LALSUITE_VERSION_COMPARE([${doxygen_version}],[<],[${doxygen_min_version}],[
      AC_MSG_RESULT([no (${doxygen_version})])
      AC_MSG_ERROR([Doxygen version ${doxygen_min_version} or later is required])
    ])
    AC_MSG_RESULT([yes (${doxygen_version})])

1207
    # ignore some Doxygen warnings due to Doxygen bugs
Karl Wette's avatar
Karl Wette committed
1208
    AC_SUBST([DOXYGEN_WARNING_REGEX],["-e '/^\$$/d'"])
1209 1210 1211
    LALSUITE_VERSION_COMPARE([${doxygen_version}],[<],[1.8.9.1],[
      # https://bugzilla.gnome.org/show_bug.cgi?id=742151
      DOXYGEN_WARNING_REGEX=["${DOXYGEN_WARNING_REGEX} -e '/^citelist/d'"]
1212 1213
    ])
    LALSUITE_VERSION_COMPARE([1.8.8],[<=],[${doxygen_version}],[
1214
      LALSUITE_VERSION_COMPARE([${doxygen_version}],[<],[1.8.11],[
1215 1216
        # https://bugzilla.gnome.org/show_bug.cgi?id=743604
        DOXYGEN_WARNING_REGEX=["${DOXYGEN_WARNING_REGEX} -e '/warning: Duplicate anchor/d'"]
Karl Wette's avatar
Karl Wette committed
1217
        DOXYGEN_WARNING_REGEX=["${DOXYGEN_WARNING_REGEX} -e '/warning: multiple use of section label/d'"]
1218 1219 1220
      ])
    ])
    LALSUITE_VERSION_COMPARE([1.8.8],[<=],[${doxygen_version}],[
1221
      LALSUITE_VERSION_COMPARE([${doxygen_version}],[<=],[1.8.9.1],[
1222 1223 1224 1225 1226
        # https://bugzilla.gnome.org/show_bug.cgi?id=743605
        DOXYGEN_WARNING_REGEX=["${DOXYGEN_WARNING_REGEX} -e '/warning: explicit link request/d'"]
      ])
    ])

1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
    # build some substituted variables from list of configured LAL libraries
    AC_SUBST([DOXYGEN_ENABLED_SECTIONS])
    AC_SUBST([DOXYGEN_TAGFILES],[])
    AC_SUBST([DOXYGEN_INSTALL_DIRMAP],[])
    for arg in ${lalsuite_libs}; do
      AS_CASE([${arg}],
        [lalsupport],[:],[
          ucarg=[`echo ${arg} | tr '[a-z]' '[A-Z]'`]
          DOXYGEN_ENABLED_SECTIONS="${DOXYGEN_ENABLED_SECTIONS} ${ucarg}"
          arg_htmldir_name="${ucarg}_HTMLDIR"
          AS_VAR_COPY([arg_htmldir],[${arg_htmldir_name}])
          AS_IF([test "x${LALSUITE_BUILD}" = xtrue],[
            tagpath="\$(abs_top_builddir)/../${arg}/doxygen/out"
          ],[
            tagpath="${arg_htmldir}"
          ])
          DOXYGEN_TAGFILES="${DOXYGEN_TAGFILES} ${tagpath}/${arg}.tag=${tagpath}"
          DOXYGEN_INSTALL_DIRMAP="${DOXYGEN_INSTALL_DIRMAP} ${tagpath}:${arg_htmldir}"
        ]
      )
    done

    # configure MathJax
    AC_SUBST([DOXYGEN_MATHJAXDIR])
    AS_IF([test "x${DOXYGEN_MATHJAXDIR}" != x],[
      AS_IF([test ! -f "${DOXYGEN_MATHJAXDIR}/MathJax.js"],[
        AC_MSG_ERROR([no MathJax installation found in ${DOXYGEN_MATHJAXDIR}])
      ])
    ],[
      for dir in /usr/share/javascript/mathjax; do
        AC_MSG_CHECKING([for MathJax installation in ${dir}])
        AS_IF([test -f "${dir}/MathJax.js"],[
          AC_MSG_RESULT([yes])
          DOXYGEN_MATHJAXDIR="${dir}"
          break
        ],[
          AC_MSG_RESULT([no])
        ])
      done
      AS_IF([test "x${DOXYGEN_MATHJAXDIR}" = x],[
        DOXYGEN_MATHJAXDIR='https://cdn.mathjax.org/mathjax/latest'
        AC_MSG_NOTICE([using MathJax CDN at ${DOXYGEN_MATHJAXDIR}])
      ])
    ])

  ])
  # end $0
])
1275

1276
AC_DEFUN([LALSUITE_CHECK_SIMD],[
1277
  # $0: check for SIMD extensions
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304

  # list of recognised SIMD instruction sets
  m4_define([simd_isets],[m4_normalize([
    [SSE],[SSE2],[SSE3],[SSSE3],[SSE4.1],[SSE4.2],
    [AVX],[AVX2]
  ])])

  # push compiler environment
  LALSUITE_PUSH_UVARS
  LALSUITE_CLEAR_UVARS
  AC_LANG_PUSH([C])

  # check compiler support for each SIMD instruction set
  simd_supported=
  m4_foreach([iset],simd_isets,[
    m4_pushdef([option],m4_translit(iset,[A-Z.],[a-z.]))
    m4_pushdef([symbol],m4_translit(iset,[A-Z.],[A-Z_]))

    # assume supported until test fails, in which break out of loop
    for iset_supported in yes; do

      # check -m[]option flag
      LALSUITE_CHECK_COMPILE_FLAGS([-m[]option],[],[iset_supported=no])
      AS_IF([test x"${iset_supported}" = xno],[break])

      # check that compiler defines __]symbol[__ preprocessor symbol
      AC_MSG_CHECKING([whether ]_AC_LANG[ compiler defines __]symbol[__ with -m[]option])
1305
      CFLAGS="${uvar_orig_prefix[]CFLAGS} -m[]option"
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
      AC_COMPILE_IFELSE([
        AC_LANG_PROGRAM([],[[
#if !defined(__]]symbol[[__)
#error Preprocessor macro not defined by compiler
#endif
]])
      ],[
        AC_MSG_RESULT([yes])
      ],[
        AC_MSG_RESULT([no])
        iset_supported=no
      ])
      AS_IF([test x"${iset_supported}" = xno],[break])

      # check that compiler compiles floating-point math with -m[]option
      AC_MSG_CHECKING([whether ]_AC_LANG[ compiler compiles floating-point math with -m[]option])
1322
      CFLAGS="${uvar_orig_prefix[]CFLAGS} -m[]option"
1323 1324 1325 1326 1327
      AC_COMPILE_IFELSE([
        AC_LANG_PROGRAM([
AC_INCLUDES_DEFAULT
#include <math.h>
],[[
1328 1329 1330
double volatile a = 1.2;
double volatile b = 3.4;
double volatile c = a * b;
1331 1332 1333
double volatile d = round(c);
]])
      ],[
1334 1335
        AC_MSG_RESULT([yes])
      ],[
1336 1337
        AC_MSG_RESULT([no])
        iset_supported=no
1338
      ])
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
      AS_IF([test x"${iset_supported}" = xno],[break])

    done

    # define Automake conditional HAVE_<SIMD>_COMPILER
    AM_CONDITIONAL([HAVE_]symbol[_COMPILER],[test x"${iset_supported}" = xyes])
    AM_COND_IF([HAVE_]symbol[_COMPILER],[

      # define config.h preprocessor symbol HAVE_<SIMD>_COMPILER
      AC_DEFINE([HAVE_]symbol[_COMPILER],[1],[Define to 1 if compiler supports ]iset[ SIMD extensions])

      # substitute Automake variable <SIMD>_CFLAGS
      AC_SUBST(symbol[_CFLAGS],["-DSIMD_INSTRSET=]symbol[ -m[]option"])

      # add to list of supported instruction sets
      simd_supported="${simd_supported} iset"

1356
    ])
1357

1358 1359
    m4_popdef([option])
    m4_popdef([symbol])
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
  ])

  # string listing all the SIMD extensions supported by the compiler
  simd_supported=`echo ${simd_supported}`
  AC_DEFINE_UNQUOTED([HAVE_SIMD_COMPILER],["${simd_supported}"],
    [Define to a string listing all the SIMD extensions supported by the ]_AC_LANG[ compiler]
  )
  AS_IF([test x"${simd_supported}" = x],[
    AC_MSG_NOTICE([]_AC_LANG[ compiler does not support SIMD instruction sets])
  ],[
    AC_MSG_NOTICE([]_AC_LANG[ compiler supports SIMD instruction sets: ${simd_supported}])
1371
  ])
1372 1373 1374 1375 1376

  # pop compiler environment
  AC_LANG_POP([C])
  LALSUITE_POP_UVARS

1377 1378
  # end $0
])
1379 1380 1381 1382 1383

AC_DEFUN([LALSUITE_ENABLE_CFITSIO],[
  # $0: enable/disable cfitsio library
  AC_ARG_ENABLE(
    [cfitsio],
1384
    AC_HELP_STRING([--enable-cfitsio],[compile code that requires cfitsio library [default=yes]]),
1385 1386 1387 1388 1389
    AS_CASE(["${enableval}"],
      [yes],[cfitsio=true],
      [no],[cfitsio=false],
      AC_MSG_ERROR([bad value ${enableval} for --enable-cfitsio])
    ),
1390
    [cfitsio=true]
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
  )
  # end $0
])

AC_DEFUN([LALSUITE_USE_CFITSIO],[
  # $0: check for cfitsio library
  AS_IF([test "x${cfitsio}" = xtrue],[
    LALSUITE_PUSH_UVARS
    PKG_CHECK_MODULES([CFITSIO],[cfitsio],[true],[false])
    LALSUITE_ADD_FLAGS([C],[${CFITSIO_CFLAGS}],[${CFITSIO_LIBS}])
    AC_CHECK_LIB([cfitsio],[ffopen],[],[cfitsio=false])
    AC_CHECK_HEADER([fitsio.h],[],[cfitsio=false])
    AC_CHECK_FUNCS([fffree])
    AC_CHECK_DECLS([fffree],[],[],[AC_INCLUDES_DEFAULT
#include <fitsio.h>
])
    LALSUITE_POP_UVARS
  ])
  AS_IF([test "x${cfitsio}" = xtrue],[
    LALSUITE_ADD_FLAGS([C],[${CFITSIO_CFLAGS}],[${CFITSIO_LIBS}])
  ])
  LALSUITE_ENABLE_MODULE([CFITSIO])
  # end $0
])
1415 1416

AC_DEFUN([LALSUITE_CHECK_PAGER],[
1417
  # $0: check for pager programs and required functions
1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444
  AC_ARG_WITH(
    [pager],
    AC_HELP_STRING([--with-pager=PAGER],[specify pager program [default: less/more]]),
    [
      AS_CASE([${with_pager}],
        [no],[pager="false"],
        [yes],[pager="less -F -R -S -X more"],
        [pager="${with_pager}"]
      )
    ],[
      pager="less -F -R -S -X more"
    ]
  )
  AC_SUBST([PAGER],[])
  AC_SUBST([PAGER_CPPFLAGS],[])
  AS_IF([test "x${pager}" != xfalse],[
    for pager_arg in ${pager}; do
      AS_CASE([${pager_arg}],
        [-*],[
          AS_IF([test "x${PAGER}" != x],[
            AC_MSG_CHECKING([if option ${pager_arg} works with ${PAGER}])
            AS_IF([echo | ${PAGER} ${pager_arg} >/dev/null 2>&1],[
              AC_MSG_RESULT([yes])
              PAGER="${PAGER} ${pager_arg}"
            ],[
              AC_MSG_RESULT([no])
            ])
1445
          ])
1446 1447 1448 1449 1450 1451 1452 1453 1454
        ],[
          AS_IF([test "x${PAGER}" != x],[
            break
          ],[
            AC_PATH_PROGS([PAGER],[${pager_arg}],[])
          ])
        ]
      )
    done
1455 1456
  ])
  AS_IF([test "x${PAGER}" != x],[
1457
      PAGER_CPPFLAGS="-DPAGER='\"\$(PAGER)\"'"
1458 1459
    AC_CHECK_FUNCS([popen pclose])
  ])
1460 1461
  # end $0
])
1462 1463 1464 1465

AC_DEFUN([LALSUITE_ENABLE_HELP2MAN],[
  # $0: check for help2man utility
  AC_PATH_PROG([HELP2MAN], [help2man])
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
  # Require a minimum version of help2man to support the
  # --version-string and --no-discard-stderr flags.
  AS_IF(
    [test -n "${HELP2MAN}"],
    [
      HELP2MAN_MIN_VERSION="1.37"
      AC_MSG_CHECKING([for help2man >= ${HELP2MAN_MIN_VERSION}])
      HELP2MAN_VERSION=`${HELP2MAN} --version --version | head -n 1 | cut -d ' ' -f 3`
      AX_COMPARE_VERSION(
        [${HELP2MAN_VERSION}], [ge], [${HELP2MAN_MIN_VERSION}],
        [AC_MSG_RESULT([yes])],
        [
          AC_MSG_RESULT([no])
          HELP2MAN=
        ]
      )
    ]
  )
1484 1485 1486 1487 1488 1489 1490 1491 1492
  AC_ARG_ENABLE(
    [help2man],
    AC_HELP_STRING([--enable-help2man],[automatically generate man pages with help2man @<:@default=yes@:>@]),
    AS_CASE([${enableval}],
      [yes], [],
      [no], [HELP2MAN=],
      AC_MSG_ERROR([bad value ${enableval} for --enable-help2man])
    )
  )
1493 1494 1495 1496 1497
  AC_SUBST([HELP2MAN], ["${HELP2MAN}"])
  AS_IF([test -n "${HELP2MAN}"], [help2man=true], [help2man=false])
  LALSUITE_ENABLE_MODULE([HELP2MAN])
  # end $0
])
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550

AC_DEFUN([LALSUITE_ENABLE_OPENMP],[
  # $0: check for OpenMP support
  # check for OpenMP
  AC_OPENMP

  # check that compiler supports C99 variable length arrays in OpenMP for loops.
  # Apple's llvm-gcc-4.2 is buggy and does not.
  AS_IF([test "x$OPENMP_CFLAGS" != "x"],
    [
      AC_MSG_CHECKING([if compiler supports C99 VLAs in OpenMP for loops])
      LALSUITE_PUSH_UVARS
      CFLAGS="$OPENMP_CFLAGS"
      AC_LINK_IFELSE([
          AC_LANG_PROGRAM(, [
            int i, n = 10;
            #pragma omp parallel for
            for (i = 0; i < 10; i ++)
            { int a@<:@n@:>@; }
          ])
        ],
        [AC_MSG_RESULT([yes])],
        [
          AC_MSG_RESULT([no, disabling OpenMP])
          OPENMP_CFLAGS=
        ]
      )
      LALSUITE_POP_UVARS
    ]
  )

  # Disable OpenMP by default.
  # FIXME: OpenMP should be on by default, but it breaks condor_compiling lalapps.
  AS_IF(
    [test "x$enable_openmp" = "x"],
    [OPENMP_CFLAGS=]
  )
  # add compiler flags for OpenMP
  AS_IF(
    [test "x$OPENMP_CFLAGS" = "x" -a "x$ac_cv_prog_[]_AC_LANG_ABBREV[]_openmp" != "xnone needed"],
    [
      openmp="false"
      LALSUITE_ADD_FLAGS([C],[-Wno-unknown-pragmas],[])
    ],
    [
      openmp="true"
      LALSUITE_ADD_FLAGS([C],[${OPENMP_CFLAGS}],[])
    ]
  )

  LALSUITE_ENABLE_MODULE([OPENMP])
  # end $0
])