17f71b389Schristos# lib-prefix.m4 serial 7 (gettext-0.18) 2*463ae347Schristosdnl Copyright (C) 2001-2005, 2008-2010 Free Software Foundation, Inc. 37f71b389Schristosdnl This file is free software; the Free Software Foundation 47f71b389Schristosdnl gives unlimited permission to copy and/or distribute it, 57f71b389Schristosdnl with or without modifications, as long as this notice is preserved. 63c3a7b76Schristos 73c3a7b76Schristosdnl From Bruno Haible. 83c3a7b76Schristos 93c3a7b76Schristosdnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and 103c3a7b76Schristosdnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't 113c3a7b76Schristosdnl require excessive bracketing. 123c3a7b76Schristosifdef([AC_HELP_STRING], 133c3a7b76Schristos[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])], 147f71b389Schristos[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])]) 153c3a7b76Schristos 163c3a7b76Schristosdnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed 173c3a7b76Schristosdnl to access previously installed libraries. The basic assumption is that 183c3a7b76Schristosdnl a user will want packages to use other packages he previously installed 193c3a7b76Schristosdnl with the same --prefix option. 203c3a7b76Schristosdnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate 213c3a7b76Schristosdnl libraries, but is otherwise very convenient. 223c3a7b76SchristosAC_DEFUN([AC_LIB_PREFIX], 233c3a7b76Schristos[ 243c3a7b76Schristos AC_BEFORE([$0], [AC_LIB_LINKFLAGS]) 253c3a7b76Schristos AC_REQUIRE([AC_PROG_CC]) 263c3a7b76Schristos AC_REQUIRE([AC_CANONICAL_HOST]) 277f71b389Schristos AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) 283c3a7b76Schristos AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 293c3a7b76Schristos dnl By default, look in $includedir and $libdir. 303c3a7b76Schristos use_additional=yes 313c3a7b76Schristos AC_LIB_WITH_FINAL_PREFIX([ 323c3a7b76Schristos eval additional_includedir=\"$includedir\" 333c3a7b76Schristos eval additional_libdir=\"$libdir\" 343c3a7b76Schristos ]) 353c3a7b76Schristos AC_LIB_ARG_WITH([lib-prefix], 363c3a7b76Schristos[ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib 373c3a7b76Schristos --without-lib-prefix don't search for libraries in includedir and libdir], 383c3a7b76Schristos[ 393c3a7b76Schristos if test "X$withval" = "Xno"; then 403c3a7b76Schristos use_additional=no 413c3a7b76Schristos else 423c3a7b76Schristos if test "X$withval" = "X"; then 433c3a7b76Schristos AC_LIB_WITH_FINAL_PREFIX([ 443c3a7b76Schristos eval additional_includedir=\"$includedir\" 453c3a7b76Schristos eval additional_libdir=\"$libdir\" 463c3a7b76Schristos ]) 473c3a7b76Schristos else 483c3a7b76Schristos additional_includedir="$withval/include" 497f71b389Schristos additional_libdir="$withval/$acl_libdirstem" 503c3a7b76Schristos fi 513c3a7b76Schristos fi 523c3a7b76Schristos]) 533c3a7b76Schristos if test $use_additional = yes; then 543c3a7b76Schristos dnl Potentially add $additional_includedir to $CPPFLAGS. 553c3a7b76Schristos dnl But don't add it 563c3a7b76Schristos dnl 1. if it's the standard /usr/include, 573c3a7b76Schristos dnl 2. if it's already present in $CPPFLAGS, 583c3a7b76Schristos dnl 3. if it's /usr/local/include and we are using GCC on Linux, 593c3a7b76Schristos dnl 4. if it doesn't exist as a directory. 603c3a7b76Schristos if test "X$additional_includedir" != "X/usr/include"; then 613c3a7b76Schristos haveit= 623c3a7b76Schristos for x in $CPPFLAGS; do 633c3a7b76Schristos AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 643c3a7b76Schristos if test "X$x" = "X-I$additional_includedir"; then 653c3a7b76Schristos haveit=yes 663c3a7b76Schristos break 673c3a7b76Schristos fi 683c3a7b76Schristos done 693c3a7b76Schristos if test -z "$haveit"; then 703c3a7b76Schristos if test "X$additional_includedir" = "X/usr/local/include"; then 713c3a7b76Schristos if test -n "$GCC"; then 723c3a7b76Schristos case $host_os in 737f71b389Schristos linux* | gnu* | k*bsd*-gnu) haveit=yes;; 743c3a7b76Schristos esac 753c3a7b76Schristos fi 763c3a7b76Schristos fi 773c3a7b76Schristos if test -z "$haveit"; then 783c3a7b76Schristos if test -d "$additional_includedir"; then 793c3a7b76Schristos dnl Really add $additional_includedir to $CPPFLAGS. 803c3a7b76Schristos CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir" 813c3a7b76Schristos fi 823c3a7b76Schristos fi 833c3a7b76Schristos fi 843c3a7b76Schristos fi 853c3a7b76Schristos dnl Potentially add $additional_libdir to $LDFLAGS. 863c3a7b76Schristos dnl But don't add it 873c3a7b76Schristos dnl 1. if it's the standard /usr/lib, 883c3a7b76Schristos dnl 2. if it's already present in $LDFLAGS, 893c3a7b76Schristos dnl 3. if it's /usr/local/lib and we are using GCC on Linux, 903c3a7b76Schristos dnl 4. if it doesn't exist as a directory. 917f71b389Schristos if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then 923c3a7b76Schristos haveit= 933c3a7b76Schristos for x in $LDFLAGS; do 943c3a7b76Schristos AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 953c3a7b76Schristos if test "X$x" = "X-L$additional_libdir"; then 963c3a7b76Schristos haveit=yes 973c3a7b76Schristos break 983c3a7b76Schristos fi 993c3a7b76Schristos done 1003c3a7b76Schristos if test -z "$haveit"; then 1017f71b389Schristos if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then 1023c3a7b76Schristos if test -n "$GCC"; then 1033c3a7b76Schristos case $host_os in 1043c3a7b76Schristos linux*) haveit=yes;; 1053c3a7b76Schristos esac 1063c3a7b76Schristos fi 1073c3a7b76Schristos fi 1083c3a7b76Schristos if test -z "$haveit"; then 1093c3a7b76Schristos if test -d "$additional_libdir"; then 1103c3a7b76Schristos dnl Really add $additional_libdir to $LDFLAGS. 1113c3a7b76Schristos LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir" 1123c3a7b76Schristos fi 1133c3a7b76Schristos fi 1143c3a7b76Schristos fi 1153c3a7b76Schristos fi 1163c3a7b76Schristos fi 1173c3a7b76Schristos]) 1183c3a7b76Schristos 1193c3a7b76Schristosdnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix, 1203c3a7b76Schristosdnl acl_final_exec_prefix, containing the values to which $prefix and 1213c3a7b76Schristosdnl $exec_prefix will expand at the end of the configure script. 1223c3a7b76SchristosAC_DEFUN([AC_LIB_PREPARE_PREFIX], 1233c3a7b76Schristos[ 1243c3a7b76Schristos dnl Unfortunately, prefix and exec_prefix get only finally determined 1253c3a7b76Schristos dnl at the end of configure. 1263c3a7b76Schristos if test "X$prefix" = "XNONE"; then 1273c3a7b76Schristos acl_final_prefix="$ac_default_prefix" 1283c3a7b76Schristos else 1293c3a7b76Schristos acl_final_prefix="$prefix" 1303c3a7b76Schristos fi 1313c3a7b76Schristos if test "X$exec_prefix" = "XNONE"; then 1323c3a7b76Schristos acl_final_exec_prefix='${prefix}' 1333c3a7b76Schristos else 1343c3a7b76Schristos acl_final_exec_prefix="$exec_prefix" 1353c3a7b76Schristos fi 1363c3a7b76Schristos acl_save_prefix="$prefix" 1373c3a7b76Schristos prefix="$acl_final_prefix" 1383c3a7b76Schristos eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" 1393c3a7b76Schristos prefix="$acl_save_prefix" 1403c3a7b76Schristos]) 1413c3a7b76Schristos 1423c3a7b76Schristosdnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the 1433c3a7b76Schristosdnl variables prefix and exec_prefix bound to the values they will have 1443c3a7b76Schristosdnl at the end of the configure script. 1453c3a7b76SchristosAC_DEFUN([AC_LIB_WITH_FINAL_PREFIX], 1463c3a7b76Schristos[ 1473c3a7b76Schristos acl_save_prefix="$prefix" 1483c3a7b76Schristos prefix="$acl_final_prefix" 1493c3a7b76Schristos acl_save_exec_prefix="$exec_prefix" 1503c3a7b76Schristos exec_prefix="$acl_final_exec_prefix" 1513c3a7b76Schristos $1 1523c3a7b76Schristos exec_prefix="$acl_save_exec_prefix" 1533c3a7b76Schristos prefix="$acl_save_prefix" 1543c3a7b76Schristos]) 1557f71b389Schristos 1567f71b389Schristosdnl AC_LIB_PREPARE_MULTILIB creates 1577f71b389Schristosdnl - a variable acl_libdirstem, containing the basename of the libdir, either 1587f71b389Schristosdnl "lib" or "lib64" or "lib/64", 1597f71b389Schristosdnl - a variable acl_libdirstem2, as a secondary possible value for 1607f71b389Schristosdnl acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or 1617f71b389Schristosdnl "lib/amd64". 1627f71b389SchristosAC_DEFUN([AC_LIB_PREPARE_MULTILIB], 1637f71b389Schristos[ 1647f71b389Schristos dnl There is no formal standard regarding lib and lib64. 1657f71b389Schristos dnl On glibc systems, the current practice is that on a system supporting 1667f71b389Schristos dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under 1677f71b389Schristos dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. We determine 1687f71b389Schristos dnl the compiler's default mode by looking at the compiler's library search 1697f71b389Schristos dnl path. If at least one of its elements ends in /lib64 or points to a 1707f71b389Schristos dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI. 1717f71b389Schristos dnl Otherwise we use the default, namely "lib". 1727f71b389Schristos dnl On Solaris systems, the current practice is that on a system supporting 1737f71b389Schristos dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under 1747f71b389Schristos dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or 1757f71b389Schristos dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib. 1767f71b389Schristos AC_REQUIRE([AC_CANONICAL_HOST]) 1777f71b389Schristos acl_libdirstem=lib 1787f71b389Schristos acl_libdirstem2= 1797f71b389Schristos case "$host_os" in 1807f71b389Schristos solaris*) 1817f71b389Schristos dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment 1827f71b389Schristos dnl <http://docs.sun.com/app/docs/doc/816-5138/dev-env?l=en&a=view>. 1837f71b389Schristos dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link." 1847f71b389Schristos dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the 1857f71b389Schristos dnl symlink is missing, so we set acl_libdirstem2 too. 1867f71b389Schristos AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit], 1877f71b389Schristos [AC_EGREP_CPP([sixtyfour bits], [ 1887f71b389Schristos#ifdef _LP64 1897f71b389Schristossixtyfour bits 1907f71b389Schristos#endif 1917f71b389Schristos ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no]) 1927f71b389Schristos ]) 1937f71b389Schristos if test $gl_cv_solaris_64bit = yes; then 1947f71b389Schristos acl_libdirstem=lib/64 1957f71b389Schristos case "$host_cpu" in 1967f71b389Schristos sparc*) acl_libdirstem2=lib/sparcv9 ;; 1977f71b389Schristos i*86 | x86_64) acl_libdirstem2=lib/amd64 ;; 1987f71b389Schristos esac 1997f71b389Schristos fi 2007f71b389Schristos ;; 2017f71b389Schristos *) 2027f71b389Schristos searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` 2037f71b389Schristos if test -n "$searchpath"; then 2047f71b389Schristos acl_save_IFS="${IFS= }"; IFS=":" 2057f71b389Schristos for searchdir in $searchpath; do 2067f71b389Schristos if test -d "$searchdir"; then 2077f71b389Schristos case "$searchdir" in 2087f71b389Schristos */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; 2097f71b389Schristos */../ | */.. ) 2107f71b389Schristos # Better ignore directories of this form. They are misleading. 2117f71b389Schristos ;; 2127f71b389Schristos *) searchdir=`cd "$searchdir" && pwd` 2137f71b389Schristos case "$searchdir" in 2147f71b389Schristos */lib64 ) acl_libdirstem=lib64 ;; 2157f71b389Schristos esac ;; 2167f71b389Schristos esac 2177f71b389Schristos fi 2187f71b389Schristos done 2197f71b389Schristos IFS="$acl_save_IFS" 2207f71b389Schristos fi 2217f71b389Schristos ;; 2227f71b389Schristos esac 2237f71b389Schristos test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem" 2247f71b389Schristos]) 225