1a32e9e42Smrg# lib-prefix.m4 serial 7 (gettext-0.18) 2a32e9e42Smrgdnl Copyright (C) 2001-2005, 2008-2016 Free Software Foundation, Inc. 3a32e9e42Smrgdnl This file is free software; the Free Software Foundation 4a32e9e42Smrgdnl gives unlimited permission to copy and/or distribute it, 5a32e9e42Smrgdnl with or without modifications, as long as this notice is preserved. 6a32e9e42Smrg 7a32e9e42Smrgdnl From Bruno Haible. 8a32e9e42Smrg 9a32e9e42Smrgdnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and 10a32e9e42Smrgdnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't 11a32e9e42Smrgdnl require excessive bracketing. 12a32e9e42Smrgifdef([AC_HELP_STRING], 13a32e9e42Smrg[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])], 14a32e9e42Smrg[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])]) 15a32e9e42Smrg 16a32e9e42Smrgdnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed 17a32e9e42Smrgdnl to access previously installed libraries. The basic assumption is that 18a32e9e42Smrgdnl a user will want packages to use other packages he previously installed 19a32e9e42Smrgdnl with the same --prefix option. 20a32e9e42Smrgdnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate 21a32e9e42Smrgdnl libraries, but is otherwise very convenient. 22a32e9e42SmrgAC_DEFUN([AC_LIB_PREFIX], 23a32e9e42Smrg[ 24a32e9e42Smrg AC_BEFORE([$0], [AC_LIB_LINKFLAGS]) 25a32e9e42Smrg AC_REQUIRE([AC_PROG_CC]) 26a32e9e42Smrg AC_REQUIRE([AC_CANONICAL_HOST]) 27a32e9e42Smrg AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) 28a32e9e42Smrg AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 29a32e9e42Smrg dnl By default, look in $includedir and $libdir. 30a32e9e42Smrg use_additional=yes 31a32e9e42Smrg AC_LIB_WITH_FINAL_PREFIX([ 32a32e9e42Smrg eval additional_includedir=\"$includedir\" 33a32e9e42Smrg eval additional_libdir=\"$libdir\" 34a32e9e42Smrg ]) 35a32e9e42Smrg AC_LIB_ARG_WITH([lib-prefix], 36a32e9e42Smrg[ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib 37a32e9e42Smrg --without-lib-prefix don't search for libraries in includedir and libdir], 38a32e9e42Smrg[ 39a32e9e42Smrg if test "X$withval" = "Xno"; then 40a32e9e42Smrg use_additional=no 41a32e9e42Smrg else 42a32e9e42Smrg if test "X$withval" = "X"; then 43a32e9e42Smrg AC_LIB_WITH_FINAL_PREFIX([ 44a32e9e42Smrg eval additional_includedir=\"$includedir\" 45a32e9e42Smrg eval additional_libdir=\"$libdir\" 46a32e9e42Smrg ]) 47a32e9e42Smrg else 48a32e9e42Smrg additional_includedir="$withval/include" 49a32e9e42Smrg additional_libdir="$withval/$acl_libdirstem" 50a32e9e42Smrg fi 51a32e9e42Smrg fi 52a32e9e42Smrg]) 53a32e9e42Smrg if test $use_additional = yes; then 54a32e9e42Smrg dnl Potentially add $additional_includedir to $CPPFLAGS. 55a32e9e42Smrg dnl But don't add it 56a32e9e42Smrg dnl 1. if it's the standard /usr/include, 57a32e9e42Smrg dnl 2. if it's already present in $CPPFLAGS, 58a32e9e42Smrg dnl 3. if it's /usr/local/include and we are using GCC on Linux, 59a32e9e42Smrg dnl 4. if it doesn't exist as a directory. 60a32e9e42Smrg if test "X$additional_includedir" != "X/usr/include"; then 61a32e9e42Smrg haveit= 62a32e9e42Smrg for x in $CPPFLAGS; do 63a32e9e42Smrg AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 64a32e9e42Smrg if test "X$x" = "X-I$additional_includedir"; then 65a32e9e42Smrg haveit=yes 66a32e9e42Smrg break 67a32e9e42Smrg fi 68a32e9e42Smrg done 69a32e9e42Smrg if test -z "$haveit"; then 70a32e9e42Smrg if test "X$additional_includedir" = "X/usr/local/include"; then 71a32e9e42Smrg if test -n "$GCC"; then 72a32e9e42Smrg case $host_os in 73a32e9e42Smrg linux* | gnu* | k*bsd*-gnu) haveit=yes;; 74a32e9e42Smrg esac 75a32e9e42Smrg fi 76a32e9e42Smrg fi 77a32e9e42Smrg if test -z "$haveit"; then 78a32e9e42Smrg if test -d "$additional_includedir"; then 79a32e9e42Smrg dnl Really add $additional_includedir to $CPPFLAGS. 80a32e9e42Smrg CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir" 81a32e9e42Smrg fi 82a32e9e42Smrg fi 83a32e9e42Smrg fi 84a32e9e42Smrg fi 85a32e9e42Smrg dnl Potentially add $additional_libdir to $LDFLAGS. 86a32e9e42Smrg dnl But don't add it 87a32e9e42Smrg dnl 1. if it's the standard /usr/lib, 88a32e9e42Smrg dnl 2. if it's already present in $LDFLAGS, 89a32e9e42Smrg dnl 3. if it's /usr/local/lib and we are using GCC on Linux, 90a32e9e42Smrg dnl 4. if it doesn't exist as a directory. 91a32e9e42Smrg if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then 92a32e9e42Smrg haveit= 93a32e9e42Smrg for x in $LDFLAGS; do 94a32e9e42Smrg AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 95a32e9e42Smrg if test "X$x" = "X-L$additional_libdir"; then 96a32e9e42Smrg haveit=yes 97a32e9e42Smrg break 98a32e9e42Smrg fi 99a32e9e42Smrg done 100a32e9e42Smrg if test -z "$haveit"; then 101a32e9e42Smrg if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then 102a32e9e42Smrg if test -n "$GCC"; then 103a32e9e42Smrg case $host_os in 104a32e9e42Smrg linux*) haveit=yes;; 105a32e9e42Smrg esac 106a32e9e42Smrg fi 107a32e9e42Smrg fi 108a32e9e42Smrg if test -z "$haveit"; then 109a32e9e42Smrg if test -d "$additional_libdir"; then 110a32e9e42Smrg dnl Really add $additional_libdir to $LDFLAGS. 111a32e9e42Smrg LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir" 112a32e9e42Smrg fi 113a32e9e42Smrg fi 114a32e9e42Smrg fi 115a32e9e42Smrg fi 116a32e9e42Smrg fi 117a32e9e42Smrg]) 118a32e9e42Smrg 119a32e9e42Smrgdnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix, 120a32e9e42Smrgdnl acl_final_exec_prefix, containing the values to which $prefix and 121a32e9e42Smrgdnl $exec_prefix will expand at the end of the configure script. 122a32e9e42SmrgAC_DEFUN([AC_LIB_PREPARE_PREFIX], 123a32e9e42Smrg[ 124a32e9e42Smrg dnl Unfortunately, prefix and exec_prefix get only finally determined 125a32e9e42Smrg dnl at the end of configure. 126a32e9e42Smrg if test "X$prefix" = "XNONE"; then 127a32e9e42Smrg acl_final_prefix="$ac_default_prefix" 128a32e9e42Smrg else 129a32e9e42Smrg acl_final_prefix="$prefix" 130a32e9e42Smrg fi 131a32e9e42Smrg if test "X$exec_prefix" = "XNONE"; then 132a32e9e42Smrg acl_final_exec_prefix='${prefix}' 133a32e9e42Smrg else 134a32e9e42Smrg acl_final_exec_prefix="$exec_prefix" 135a32e9e42Smrg fi 136a32e9e42Smrg acl_save_prefix="$prefix" 137a32e9e42Smrg prefix="$acl_final_prefix" 138a32e9e42Smrg eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" 139a32e9e42Smrg prefix="$acl_save_prefix" 140a32e9e42Smrg]) 141a32e9e42Smrg 142a32e9e42Smrgdnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the 143a32e9e42Smrgdnl variables prefix and exec_prefix bound to the values they will have 144a32e9e42Smrgdnl at the end of the configure script. 145a32e9e42SmrgAC_DEFUN([AC_LIB_WITH_FINAL_PREFIX], 146a32e9e42Smrg[ 147a32e9e42Smrg acl_save_prefix="$prefix" 148a32e9e42Smrg prefix="$acl_final_prefix" 149a32e9e42Smrg acl_save_exec_prefix="$exec_prefix" 150a32e9e42Smrg exec_prefix="$acl_final_exec_prefix" 151a32e9e42Smrg $1 152a32e9e42Smrg exec_prefix="$acl_save_exec_prefix" 153a32e9e42Smrg prefix="$acl_save_prefix" 154a32e9e42Smrg]) 155a32e9e42Smrg 156a32e9e42Smrgdnl AC_LIB_PREPARE_MULTILIB creates 157a32e9e42Smrgdnl - a variable acl_libdirstem, containing the basename of the libdir, either 158a32e9e42Smrgdnl "lib" or "lib64" or "lib/64", 159a32e9e42Smrgdnl - a variable acl_libdirstem2, as a secondary possible value for 160a32e9e42Smrgdnl acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or 161a32e9e42Smrgdnl "lib/amd64". 162a32e9e42SmrgAC_DEFUN([AC_LIB_PREPARE_MULTILIB], 163a32e9e42Smrg[ 164a32e9e42Smrg dnl There is no formal standard regarding lib and lib64. 165a32e9e42Smrg dnl On glibc systems, the current practice is that on a system supporting 166a32e9e42Smrg dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under 167a32e9e42Smrg dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. We determine 168a32e9e42Smrg dnl the compiler's default mode by looking at the compiler's library search 169a32e9e42Smrg dnl path. If at least one of its elements ends in /lib64 or points to a 170a32e9e42Smrg dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI. 171a32e9e42Smrg dnl Otherwise we use the default, namely "lib". 172a32e9e42Smrg dnl On Solaris systems, the current practice is that on a system supporting 173a32e9e42Smrg dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under 174a32e9e42Smrg dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or 175a32e9e42Smrg dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib. 176a32e9e42Smrg AC_REQUIRE([AC_CANONICAL_HOST]) 177a32e9e42Smrg acl_libdirstem=lib 178a32e9e42Smrg acl_libdirstem2= 179a32e9e42Smrg case "$host_os" in 180a32e9e42Smrg solaris*) 181a32e9e42Smrg dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment 182a32e9e42Smrg dnl <http://docs.sun.com/app/docs/doc/816-5138/dev-env?l=en&a=view>. 183a32e9e42Smrg dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link." 184a32e9e42Smrg dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the 185a32e9e42Smrg dnl symlink is missing, so we set acl_libdirstem2 too. 186a32e9e42Smrg AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit], 187a32e9e42Smrg [AC_EGREP_CPP([sixtyfour bits], [ 188a32e9e42Smrg#ifdef _LP64 189a32e9e42Smrgsixtyfour bits 190a32e9e42Smrg#endif 191a32e9e42Smrg ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no]) 192a32e9e42Smrg ]) 193a32e9e42Smrg if test $gl_cv_solaris_64bit = yes; then 194a32e9e42Smrg acl_libdirstem=lib/64 195a32e9e42Smrg case "$host_cpu" in 196a32e9e42Smrg sparc*) acl_libdirstem2=lib/sparcv9 ;; 197a32e9e42Smrg i*86 | x86_64) acl_libdirstem2=lib/amd64 ;; 198a32e9e42Smrg esac 199a32e9e42Smrg fi 200a32e9e42Smrg ;; 201a32e9e42Smrg *) 202a32e9e42Smrg searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` 203a32e9e42Smrg if test -n "$searchpath"; then 204a32e9e42Smrg acl_save_IFS="${IFS= }"; IFS=":" 205a32e9e42Smrg for searchdir in $searchpath; do 206a32e9e42Smrg if test -d "$searchdir"; then 207a32e9e42Smrg case "$searchdir" in 208a32e9e42Smrg */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; 209a32e9e42Smrg */../ | */.. ) 210a32e9e42Smrg # Better ignore directories of this form. They are misleading. 211a32e9e42Smrg ;; 212a32e9e42Smrg *) searchdir=`cd "$searchdir" && pwd` 213a32e9e42Smrg case "$searchdir" in 214a32e9e42Smrg */lib64 ) acl_libdirstem=lib64 ;; 215a32e9e42Smrg esac ;; 216a32e9e42Smrg esac 217a32e9e42Smrg fi 218a32e9e42Smrg done 219a32e9e42Smrg IFS="$acl_save_IFS" 220a32e9e42Smrg fi 221a32e9e42Smrg ;; 222a32e9e42Smrg esac 223a32e9e42Smrg test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem" 224a32e9e42Smrg]) 225