1 2 3 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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
dnl -*- Autoconf -*-
dnl autoconf macros for the cernlib libraries
dnl Copyright (C) 2004 Patrice Dumas
dnl
dnl This program is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2 of the License, or
dnl (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl A basic axample of the macros usage:
dnl AC_CERNLIB
dnl AC_LIB_CERNLIB(kernlib,CLTOU)
dnl AC_LIB_CERNLIB(mathlib,GAUSS)
dnl The macro AC_CERNLIB tries to determine the cernlib location and
dnl whether the linking should be static or not. It should be called once and
dnl before a particular cernlib library is detected with the second macro.
dnl --with-static-cernlib forces the static or dynamic linking.
dnl --with-cernlib gives the location of cernlib.
dnl
dnl If the type of linking isn't forced it is detected as follow:
dnl - if the environment variable CERNLIB exists it is assumed to be the
dnl location of the static library.
dnl - otherwise if the environment variable CERN_ROOT exists it is assumed
dnl that CERN_ROOT/lib is the location of the static library.
dnl - otherwise if the binary program 'cernlib' is in the path it is assumed
dnl that a static linking using the information reported by that binary is
dnl wanted.
dnl - otherwise a dynamic linking is performed.
dnl
dnl AC_LIB_CERNLIB ([LIBRARY = kernlib], [FUNCTION = CLTOU], [ACTION-IF-FOUND],
dnl [ACTION-IF-NOT-FOUND])
dnl should be called afterwards for each of the cernlib library needed.
dnl Based on the information collected by AC_CERNLIB the needed flags are
dnl added to the linking flags and a test of linking is performed.
# AC_CERNLIB check for cernlib location and whether it should be
# statically linked or not.
AC_DEFUN([AC_CERNLIB], [
CERNLIB_LIB_PATH=
CERNLIB_STATIC=
AC_ARG_WITH(static_cernlib,
[ --with-static-cernlib link statically with the cernlib],
[ CERNLIB_STATIC=$withval ])
AC_ARG_WITH(cernlib,
[ --with-cernlib cernlib location],
[ CERNLIB_LIB_PATH=$withval ])
if test "z$CERNLIB_STATIC" != "zno"; then
CERNLIB_BIN=no
if test "z$CERNLIB_LIB_PATH" = z; then
if test "z$CERNLIB" != z -a -d "$CERNLIB"; then
CERNLIB_LIB_PATH=$CERNLIB
CERNLIB_STATIC="yes"
AC_MSG_NOTICE([using the CERNLIB environment variable for cernlib location])
elif test "z$CERN_ROOT" != z -a -d "$CERN_ROOT/lib"; then
CERNLIB_LIB_PATH=$CERN_ROOT/lib
CERNLIB_STATIC="yes"
AC_MSG_NOTICE([using the CERN_ROOT environment variable for cernlib location])
fi
if test "z$CERNLIB_LIB_PATH" = "z"; then
AC_PATH_PROG(CERNLIB_BIN, cernlib, no)
if test $CERNLIB_BIN != no; then
CERNLIB_STATIC="yes"
fi
fi
fi
fi
if test "z$CERNLIB_STATIC" != "zyes"; then
if test "z$CERNLIB_LIB_PATH" != z; then
LDFLAGS="$LDFLAGS -L$CERNLIB_LIB_PATH"
fi
fi
])
# AC_LIB_CERNLIB ([LIBRARY = kernlib], [FUNCTION = CLTOU], [ACTION-IF-FOUND],
# [ACTION-IF-NOT-FOUND])
# check for a function in a library of the cernlib
AC_DEFUN([AC_LIB_CERNLIB], [
cernlib_lib_ok="no"
if test "z$1" = z; then
cern_library=kernlib
else
cern_library=$1
fi
if test "z$2" = z; then
cern_func=CLTOU
else
cern_func=$2
fi
if test "z$CERNLIB_STATIC" = "zyes"; then
cernlib_lib_static_found=no
AC_MSG_NOTICE([cernlib: linking with a static $cern_library])
save_CERNLIB_LIBS="$CERNLIB_LIBS"
if test "z$CERNLIB_BIN" != "zno"; then
cernlib_bin_out=`$CERNLIB_BIN $cern_library`
CERNLIB_LIBS="$cernlib_bin_out $CERNLIB_LIBS"
cernlib_lib_static_found=yes
elif test "z$CERNLIB_LIB_PATH" != z; then
dnl .a for UNIX libraries only ?
if test -f "$CERNLIB_LIB_PATH/lib${cern_library}.a"; then
CERNLIB_LIBS="$CERNLIB_LIB_PATH/lib${cern_library}.a $CERNLIB_LIBS"
cernlib_lib_static_found=yes
fi
fi
if test "z$cernlib_lib_static_found" = zno; then
AC_MSG_WARN([cannot determine the cernlib location for static linking])
else
dnl now try the link
save_LIBS="$LIBS"; LIBS="$CERNLIB_LIBS $LIBS"
AC_LINK_IFELSE([ program main
call $cern_func
end
],
[
cernlib_lib_ok=yes
],
[
CERNLIB_LIBS="$save_CERNLIB_LIBS"
])
LIBS="$save_LIBS"
fi
else
AC_MSG_NOTICE([trying a dynamical link with $cern_library])
dnl FIXME ther could also be something like
dnl save_LIBS="$LIBS"; LIBS="$CERNLIB_LIBS $LIBS"
dnl CERNLIB_LIBS="-l$cern_library $CERNLIB_LIBS"
dnl LIBS="$save_LIBS"
AC_CHECK_LIB([$cern_library], [$cern_func],
[
AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_LIB$1))
LIBS="-l$1 $LIBS"
cernlib_lib_ok=yes
])
fi
AS_IF([test x"$cernlib_lib_ok" = xyes],
[m4_default([$3], [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_CERNLIB_${cern_library}_${cern_func}))
])],
[
AC_MSG_WARN([cannot link $cern_func in lib$cern_library ])
$4
])
])
|