1dnl 2dnl Definitions for creating shared libraries 3dnl 4dnl The purpose of these definitions is to provide common support for 5dnl shared libraries, with *or without* the use of the GNU Libtool package. 6dnl For many of our important platforms, the Libtool approach is overkill, 7dnl and can be particularly painful for developers. 8dnl 9dnl To use libtool, you need macros that are defined by libtool for libtool 10dnl Don't even think about the consequences of this for updating and for 11dnl using user-versions of libtool :( 12dnl 13dnl !!!!!!!!!!!!!!!!!!!!! 14dnl libtool requires ac 2.50 !!!!!!!!!!!!!!!!! 15dnl 16dnl builtin(include,libtool.m4) 17dnl 18dnl/*D 19dnl PAC_ARG_SHAREDLIBS - Add --enable-sharedlibs=kind to configure. 20dnl 21dnl Synopsis: 22dnl PAC_ARG_SHAREDLIBS 23dnl 24dnl Output effects: 25dnl Adds '--enable-sharedlibs=kind' to the command line. If this is enabled, 26dnl then based on the value of 'kind', programs are selected for the 27dnl names 'CC_SHL' and 'CC_LINK_SHL' that configure will substitute for in 28dnl 'Makefile.in's. These symbols are generated by 'simplemake' when 29dnl shared library support is selected. 30dnl The variable 'C_LINKPATH_SHL' is set to the option to specify the 31dnl path to search at runtime for libraries (-rpath in gcc/GNU ld). 32dnl This can be turned off with --disable-rpath , which is appropriate 33dnl for libraries and for executables that may be installed in different 34dnl locations. 35dnl The variable 'SHLIB_EXT' is set to the extension used by shared 36dnl libraries; under most forms of Unix, this is 'so'; under Mac OS/X, this 37dnl is 'dylib', and under Windows (including cygwin), this is 'dll'. 38dnl 39dnl Supported values of 'kind' include \: 40dnl+ gcc - Use gcc to create both shared objects and libraries 41dnl. osx-gcc - Use gcc on Mac OS/X to create both shared objects and 42dnl libraries 43dnl. solaris-cc - Use native Solaris cc to create shared objects and 44dnl libraries 45dnl. cygwin-gcc - Use gcc on Cygwin to create shared objects and libraries 46dnl- none - The same as '--disable-sharedlibs' 47dnl 48dnl Others will be added as experience dictates. Likely names are 49dnl + libtool - For general GNU libtool 50dnl - linux-pgcc - For Portland group under Linux 51dnl 52dnl Notes: 53dnl Shared libraries are only partially implemented. Additional symbols 54dnl will probably be defined, including symbols to specify how shared library 55dnl search paths are specified and how shared library names are set. 56dnl D*/ 57AC_DEFUN([PAC_ARG_SHAREDLIBS],[ 58 59AC_ARG_ENABLE(shared, 60 AC_HELP_STRING([--enable-shared], [Enable shared library builds]),, 61 enable_shared=no) 62 63AC_ARG_ENABLE(rpath, 64 AC_HELP_STRING([--enable-rpath], 65 [Determine whether the rpath is set when programs are 66 compiled and linked when shared libraries are built. 67 The default is yes; use --disable-rpath to turn this 68 feature off; in that case, shared libraries will be 69 found according to the rules for your system (e.g., in 70 LD_LIBRARY_PATH)]),,enable_rpath=yes) 71 72AC_ARG_ENABLE(sharedlibs, 73[ --enable-sharedlibs=kind - Enable shared libraries. kind may be 74 gcc - Standard gcc and GNU ld options for creating shared libraries 75 osx-gcc - Special options for gcc needed only on OS/X 76 solaris-cc - Solaris native (SPARC) compilers for 32 bit systems 77 cygwin-gcc - Special options for gcc needed only for cygwin 78 none - same as --disable-sharedlibs 79 Only gcc, osx-gcc, and solaris-cc are currently supported 80],,enable_sharedlibs=default) 81 82if test "$enable_sharedlibs" = "default" ; then 83 if test "$enable_shared" = "yes" ; then 84 AS_CASE([$host], 85 [*-*-darwin*], [enable_sharedlibs=gcc-osx], 86 [*-*-cygwin*|*-*-mingw*|*-*-pw32*|*-*-cegcc*], [enable_sharedlibs=cygwin-gcc], 87 [*-*-sunos*], [enable_sharedlibs=solaris-gcc], 88 [enable_sharedlibs=gcc]) 89 else 90 enable_sharedlibs=none 91 fi 92fi 93 94# If --enable-sharedlibs is given, but --enable-shared is not, throw 95# an error 96if test "$enable_sharedlibs" != "no" -a "$enable_sharedlibs" != "none" ; then 97 if test "$enable_shared" = "no" ; then 98 AC_MSG_ERROR([--enable-sharedlibs cannot be used without --enable-shared]) 99 fi 100fi 101 102CC_SHL=true 103C_LINK_SHL=true 104C_LINKPATH_SHL="" 105SHLIB_EXT=unknown 106SHLIB_FROM_LO=no 107SHLIB_INSTALL='$(INSTALL_PROGRAM)' 108case "$enable_sharedlibs" in 109 no|none) 110 ;; 111 gcc-osx|osx-gcc) 112 AC_MSG_RESULT([Creating shared libraries using GNU for Mac OSX]) 113 C_LINK_SHL='${CC} -dynamiclib -undefined suppress -single_module -flat_namespace' 114 CC_SHL='${CC} -fPIC' 115 # No way in osx to specify the location of the shared libraries at link 116 # time (see the code in createshlib in mpich2/src/util) 117 # As of 10.5, -Wl,-rpath,dirname should work . The dirname 118 # must be a single directory, not a colon-separated list (use multiple 119 # -Wl,-rpath,path for each of the paths in the list). However, os x 120 # apparently records the library full path, so rpath isn't as useful 121 # as it is on other systems 122 C_LINKPATH_SHL="" 123 SHLIB_EXT="dylib" 124 enable_sharedlibs="osx-gcc" 125 ;; 126 gcc) 127 AC_MSG_RESULT([Creating shared libraries using GNU]) 128 # Not quite right yet. See mpich/util/makesharedlib 129 # Use syntax that works in both Make and the shell 130 #C_LINK_SHL='${CC} -shared -Wl,-r' 131 C_LINK_SHL='${CC} -shared' 132 # For example, include the libname as ${LIBNAME_SHL} 133 #C_LINK_SHL='${CC} -shared -Wl,-h,<finallibname>' 134 # May need -fPIC . Test to see which one works. 135 for sh_arg in "-fPIC" "-fpic" "-KPIC" ; do 136 PAC_C_CHECK_COMPILER_OPTION($sh_arg,works=yes,works=no) 137 if test "$works" = "yes" ; then 138 CC_SHL="${CC} ${sh_arg}" 139 break 140 fi 141 done 142 if test "$works" != "yes"; then 143 AC_MSG_ERROR([Cannot build shared libraries with this compiler]) 144 fi 145 # This used to have -Wl,-rpath earlier, but that causes problems 146 # on many systems. 147 if test $enable_rpath = "yes" ; then 148 C_LINKPATH_SHL="-Wl,-rpath," 149 fi 150 SHLIB_EXT=so 151 # We need to test that this isn't osx. The following is a 152 # simple hack 153 osname=`uname -s` 154 case $osname in 155 *Darwin*|*darwin*) 156 AC_MSG_ERROR([You must specify --enable-sharedlibs=osx-gcc for Mac OS/X]) 157 ;; 158 *CYGWIN*|*cygwin*) 159 AC_MSG_ERROR([You must specify --enable-sharedlibs=cygwin-gcc for Cygwin]) 160 ;; 161 *SunOS*) 162 AC_MSG_ERROR([You must specify --enable-sharedlibs=solaris-gcc for Solaris with gcc]) 163 ;; 164 esac 165 ;; 166 167 cygwin|cygwin-gcc|gcc-cygwin) 168 AC_MSG_RESULT([Creating shared libraries using GNU under CYGWIN]) 169 C_LINK_SHL='${CC} -shared' 170 CC_SHL='${CC}' 171 # DLL Libraries need to be in the user's path (!) 172 C_LINKPATH_SHL="" 173 SHLIB_EXT="dll" 174 enable_sharedlibs="cygwin-gcc" 175 ;; 176 177 libtool) 178 # set TRY_LIBTOOL to yes to experiment with libtool. You are on your 179 # own - only send fixes, not bug reports. 180 if test "$TRY_LIBTOOL" != yes ; then 181 AC_MSG_ERROR([Creating shared libraries using libtool not yet supported]) 182 else 183 # Using libtool requires a heavy-weight process to test for 184 # various stuff that libtool needs. Without this, you'll get a 185 # bizarre error message about libtool being unable to find 186 # configure.in or configure.ac (!) 187 # Libtool expects to see at least enable-shared. 188 if test "X$enable_shared" = "X" ; then enable_shared=yes ; fi 189 # Initialize libtool 190 # This works, but libtool version 2 places the object files 191 # in a different place, making it harder to integrate with 192 # our base approach. Disabling for now 193 dnl LT_PREREQ([2.2.6]) 194 dnl LT_INIT([disable-shared]) 195 AC_MSG_ERROR([To use this test verison, edit aclocal_shl.m4]) 196 # Likely to be 197 # either CC or CC_SHL is libtool $cc 198 CC_SHL='${LIBTOOL} --mode=compile ${CC}' 199 # CC_LINK_SHL includes the final installation path 200 # For many systems, the link may need to include *all* libraries 201 # (since many systems don't allow any unsatisfied dependencies) 202 # We need to give libtool the .lo file, not the .o files 203 SHLIB_FROM_LO=yes 204 # We also need to add -no-undefined when the compiler is gcc and 205 # we are building under cygwin 206 sysname=`uname -s | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ` 207 isCygwin=no 208 case "$sysname" in 209 *CYGWIN*) isCygwin=yes ;; 210 esac 211 if test "$isCygwin" = yes ; then 212 C_LINK_SHL='${LIBTOOL} --mode=link ${CC} -no-undefined -rpath ${libdir}' 213 else 214 C_LINK_SHL='${LIBTOOL} --mode=link ${CC} -rpath ${libdir}' 215 fi 216 if test $enable_rpath = "yes" ; then 217 C_LINKPATH_SHL="-rpath " 218 fi 219 # We also need a special install process with libtool. Note that this 220 # will also install the static libraries 221 SHLIB_INSTALL='$(LIBTOOL) --mode=install $(INSTALL_PROGRAM)' 222 # Note we may still need to add 223 #'$(LIBTOOL) --mode=finish $(libdir)' 224 fi 225 ;; 226dnl 227dnl Other, such as solaris-cc 228 solaris|solaris-cc) 229 AC_MSG_RESULT([Creating shared libraries using Solaris]) 230 # pic32 is appropriate for both 32 and 64 bit Solaris 231 C_LINK_SHL='${CC} -G -xcode=pic32' 232 CC_SHL='${CC} -xcode=pic32' 233 if test $enable_rpath = "yes" ; then 234 C_LINKPATH_SHL="-R" 235 fi 236 SHLIB_EXT=so 237 enable_sharedlibs="solaris-cc" 238 ;; 239 240 solaris-gcc) 241 # This is the same as gcc, except for the C_LINKPATH_SHL 242 AC_MSG_RESULT([Creating shared libraries using Solaris with gcc]) 243 C_LINK_SHL='${CC} -shared' 244 CC_SHL='${CC} -fPIC' 245 if test $enable_rpath = "yes" ; then 246 C_LINKPATH_SHL="-R" 247 fi 248 SHLIB_EXT=so 249 enable_sharedlibs="solaris-gcc" 250 ;; 251 252 linuxppc-xlc) 253 # This is only the beginning of xlc support, thanks to andy@vpac.org 254 CC_SHL='${CC} -qmkshrobj' 255 # More recent versions allow multiple args, separated by commas 256 if test $enable_rpath = "yes" ; then 257 C_LINKPATH_SHL="-Wl,-rpath," 258 fi 259 #C_LINKPATH_SHL="-Wl,-rpath -Wl," 260 C_LINK_SHL='${CC} -shared -qmkshrobj' 261 SHLIB_EXT=so 262 # Note that the full line should be more like 263 # $CLINKER -shared -qmkshrobj -Wl,-h,$libbase.$slsuffix -o ../shared/$libbase.$slsuffix *.o $OtherLibs 264 # for the appropriate values of $libbase and $slsuffix 265 # The -h name sets the name of the object; this is necessary to 266 # ensure that the dynamic linker can find the proper shared library. 267 ;; 268 269 *) 270 AC_MSG_ERROR([Unknown value $enable_sharedlibs for enable-sharedlibs. Values should be gcc or osx-gcc]) 271 enable_sharedlibs=no 272 ;; 273esac 274# Check for the shared-library extension 275PAC_CC_SHLIB_EXT 276dnl 277AC_SUBST(CC_SHL) 278AC_SUBST(C_LINK_SHL) 279AC_SUBST(C_LINKPATH_SHL) 280AC_SUBST(SHLIB_EXT) 281AC_SUBST(SHLIB_FROM_LO) 282AC_SUBST(SHLIB_INSTALL) 283]) 284 285dnl /*D 286dnl PAC_xx_SHAREDLIBS - Get compiler and linker for shared libraries 287dnl These routines may be used to determine the compiler and the 288dnl linker to be used in creating shared libraries 289dnl Rather than set predefined variable names, they set an argument 290dnl (if provided) 291dnl 292dnl Synopsis 293dnl PAC_CC_SHAREDLIBS(type,CCvar,CLINKvar) 294dnl D*/ 295AC_DEFUN([PAC_CC_SHAREDLIBS], 296[ 297pac_kinds=$1 298ifelse($1,,[ 299 pac_prog="" 300 AC_CHECK_PROG(pac_prog,gcc,yes,no) 301 # If we are gcc but OS X, set the special type 302 # We need a similar setting for cygwin 303 if test "$pac_prog" = yes ; then 304 osname=`uname -s` 305 case $osname in 306 *Darwin*|*darwin*) pac_kinds=gcc-osx 307 ;; 308 *) pac_kinds=gcc 309 ;; 310 esac 311 fi 312 pac_prog="" 313 AC_CHECK_PROG(pac_prog,libtool,yes,no) 314 if test "$pac_prog" = yes ; then pac_kinds="$pac_kinds libtool" ; fi 315]) 316for pac_arg in $pac_kinds ; do 317 case $pac_arg in 318 gcc) 319 # For example, include the libname as ${LIBNAME_SHL} 320 #C_LINK_SHL='${CC} -shared -Wl,-h,<finallibname>' 321 pac_cc_sharedlibs='gcc -shared' 322 # Make sure we select the correct fpic option 323 PAC_C_CHECK_COMPILER_OPTION(-fPIC,fPIC_OK=yes,fPIC_OK=no) 324 if test "$fPIC_OK" != yes ; then 325 PAC_C_CHECK_COMPILER_OPTION(-fpic,fpic_ok=yes,fpic_ok=no) 326 if test "$fpic_ok" != yes ; then 327 AC_MSG_ERROR([Neither -fpic nor -fPIC accepted by $CC]) 328 else 329 pac_cc_sharedlibs="$pac_cc_sharedlibs -fpic" 330 fi 331 else 332 pac_cc_sharedlibs="$pac_cc_sharedlibs -fPIC" 333 fi 334 pac_clink_sharedlibs='gcc -shared' 335 pac_type_sharedlibs=gcc 336 ;; 337 gcc-osx|osx-gcc) 338 pac_clink_sharedlibs='${CC} -dynamiclib -undefined suppress -single_module -flat_namespace' 339 pac_cc_sharedlibs='${CC} -fPIC' 340 pac_type_sharedlibs=gcc-osx 341 ;; 342 libtool) 343 AC_CHECK_PROGS(LIBTOOL,libtool,false) 344 if test "$LIBTOOL" = "false" ; then 345 AC_MSG_WARN([Could not find libtool]) 346 else 347 # Likely to be 348 # either CC or CC_SHL is libtool $cc 349 pac_cc_sharedlibs'${LIBTOOL} -mode=compile ${CC}' 350 pac_clink_sharedlibs='${LIBTOOL} -mode=link ${CC} -rpath ${libdir}' 351 pac_type_sharedlibs=libtool 352 fi 353 ;; 354 *) 355 ;; 356 esac 357 if test -n "$pac_cc_sharedlibs" ; then break ; fi 358done 359if test -z "$pac_cc_sharedlibs" ; then pac_cc_sharedlibs=true ; fi 360if test -z "$pac_clink_sharedlibs" ; then pac_clink_sharedlibs=true ; fi 361ifelse($2,,CC_SHL=$pac_cc_sharedlibs,$2=$pac_cc_sharedlibs) 362ifelse($3,,C_LINK_SHL=$pac_clink_sharedlibs,$3=$pac_clink_sharedlibs) 363ifelse($4,,SHAREDLIB_TYPE=$pac_type_sharedlibs,$4=$pac_type_sharedlibs) 364]) 365 366dnl This macro ensures that all of the necessary substitutions are 367dnl made by any subdirectory configure (which may simply SUBST the 368dnl necessary values rather than trying to determine them from scratch) 369dnl This is a more robust (and, in the case of libtool, only 370dnl managable) method. 371AC_DEFUN([PAC_CC_SUBDIR_SHLIBS],[ 372 AC_SUBST(CC_SHL) 373 AC_SUBST(C_LINK_SHL) 374 AC_SUBST(LIBTOOL) 375 AC_SUBST(ENABLE_SHLIB) 376 AC_SUBST(SHLIB_EXT) 377 if test "$ENABLE_SHLIB" = "libtool" ; then 378 if test -z "$LIBTOOL" ; then 379 AC_MSG_WARN([libtool selected for shared library support but LIBTOOL is not defined]) 380 fi 381 # Libtool needs master_top_builddir 382 if test "X$master_top_builddir" = "X" ; then 383 AC_MSG_ERROR([Libtool requires master_top_builddir - check configure.ac sources]) 384 fi 385 AC_SUBST(master_top_builddir) 386 fi 387]) 388 389dnl PAC_CC_SHLIB_EXT - get the extension for shared libraries 390dnl Set the variable SHLIB_EXT if it is other than unknown. 391AC_DEFUN([PAC_CC_SHLIB_EXT],[ 392# Not all systems use .so as the extension for shared libraries (cygwin 393# and OSX are two important examples). If we did not set the SHLIB_EXT, 394# then try and determine it. We need this to properly implement 395# clean steps that look for libfoo.$SHLIB_EXT . 396if test "$SHLIB_EXT" = "unknown" ; then 397 osname=`uname -s` 398 case $osname in 399 *Darwin*|*darwin*) SHLIB_EXT=dylib 400 ;; 401 *CYGWIN*|*cygwin*) SHLIB_EXT=dll 402 ;; 403 *Linux*|*LINUX*|*SunOS*) SHLIB_EXT=so 404 ;; 405 esac 406fi 407]) 408 409dnl PAC_COMPILER_SHLIB_FLAGS(compiler-var,output-file) 410dnl 411dnl Uses confdb/config.rpath to determine important linking flags and 412dnl information. This is mainly intended to support the compiler wrapper 413dnl scripts in MPICH2 ("mpicc" and friends) which cannot directly use libtool to 414dnl handle linking. MPICH2's compiler wrappers attempt to link executables with 415dnl an rpath by default. The resulting variable assignment statements will be 416dnl placed into "output-file", which is then suitable for AC_SUBST_FILE or 417dnl sourcing in a shell script (including configure itself). 418dnl 419dnl This macro assumes that the basic tests associated with "compiler-var" have 420dnl been run already, but does not AC_REQUIRE them in order to prevent problems 421dnl with "expanded before required" when requiring the AC_PROG_{CC,F77,FC,CXX} 422dnl macros. 423dnl 424dnl Example usage: 425dnl 426dnl ----8<---- 427dnl # compute flags for linking executables against shared libraries when using 428dnl # the modern Fortran compiler ($FC). 429dnl PAC_COMPILER_SHLIB_FLAGS([FC],[src/env/fc_shlib.conf]) 430dnl ----8<---- 431AC_DEFUN([PAC_COMPILER_SHLIB_FLAGS],[ 432AC_REQUIRE_AUX_FILE([config.rpath]) 433AC_REQUIRE([AC_CANONICAL_HOST]) 434 435# It appears that the libtool dynamic linking strategy on Darwin is this: 436# 1. Link all shared libs with "-install_name /full/path/to/libfoo.dylib" 437# 2. Don't do anything special when linking programs, since it seems that the 438# darwin dynamic linker will always use the "install_name" field from the lib 439# that was found at program link-time. (CONFIRMED) This is in opposition to 440# the way that Linux does it, where specifying a "-rpath" argument at program 441# link-time is important. 442# 443# There is an alternative darwin strategy for versions 444# >= 10.5, see this: http://www.cmake.org/pipermail/cmake/2010-August/038970.html 445# (goodell@ 2011-06-17) 446 447AC_MSG_CHECKING([for shared library (esp. rpath) characteristics of $1]) 448 449# unfortunately, config.rpath expects the compiler in question is always CC and 450# uses several other environment variables as input 451PAC_PUSH_FLAG([CC]) 452PAC_PUSH_FLAG([GCC]) 453PAC_PUSH_FLAG([LD]) 454# these two don't currently get overridden, but we push/pop them for safety in 455# case they do in the future 456PAC_PUSH_FLAG([LDFLAGS]) 457PAC_PUSH_FLAG([with_gnu_ld]) 458 459# set the temporary override values (if any) 460m4_case([$1], 461[CC], 462 [:], dnl do nothing special for CC, values are already correct 463[F77], 464 [CC="$$1" 465 GCC="$G77" 466 LD="$LD_F77"], 467[FC], 468 [CC="$$1" 469 GCC="$GCC_FC" 470 LD="$LD_FC"], 471[CXX], 472 [CC="$$1" 473 GCC="$GXX" 474 LD="$LD_CXX"], 475[m4_fatal([unknown compiler argument "$1"])]) 476 477# ensure the values are available to the script 478export CC 479export GCC 480export LDFLAGS 481export LD 482export with_gnu_ld 483 484# FIXME these variables refer to each other and prefixing breaks that, so we 485# will disable the prefixing for now 486## force all variables set in $2 to be prefixed with the compiler name instead of "acl_cv_" 487#PAC_CC_PREFIX=$1_ 488PAC_CC_PREFIX= 489export PAC_CC_PREFIX 490 491AS_IF([$ac_aux_dir/config.rpath "$host" > $2],[:],[AC_MSG_ERROR([unable to execute $ac_aux_dir/config.rpath])]) 492 493C_LINKPATH_SHL="" 494AC_SUBST([C_LINKPATH_SHL]) 495 496AS_UNSET([PAC_CC_PREFIX]) 497rm -f conftest.out 498 499# restore the old values 500PAC_POP_FLAG([with_gnu_ld]) 501PAC_POP_FLAG([LD]) 502PAC_POP_FLAG([LDFLAGS]) 503PAC_POP_FLAG([GCC]) 504PAC_POP_FLAG([CC]) 505 506AC_MSG_RESULT([done (results in $2)]) 507]) 508 509