1 1.1 christos # lib-prefix.m4 serial 5 (gettext-0.15) 2 1.1 christos dnl Copyright (C) 2001-2005 Free Software Foundation, Inc. 3 1.1 christos dnl This file is free software; the Free Software Foundation 4 1.1 christos dnl gives unlimited permission to copy and/or distribute it, 5 1.1 christos dnl with or without modifications, as long as this notice is preserved. 6 1.1 christos 7 1.1 christos dnl From Bruno Haible. 8 1.1 christos 9 1.1 christos dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and 10 1.1 christos dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't 11 1.1 christos dnl require excessive bracketing. 12 1.1 christos ifdef([AC_HELP_STRING], 13 1.1 christos [AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])], 14 1.1 christos [AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])]) 15 1.1 christos 16 1.1 christos dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed 17 1.1 christos dnl to access previously installed libraries. The basic assumption is that 18 1.1 christos dnl a user will want packages to use other packages he previously installed 19 1.1 christos dnl with the same --prefix option. 20 1.1 christos dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate 21 1.1 christos dnl libraries, but is otherwise very convenient. 22 1.1 christos AC_DEFUN([AC_LIB_PREFIX], 23 1.1 christos [ 24 1.1 christos AC_BEFORE([$0], [AC_LIB_LINKFLAGS]) 25 1.1 christos AC_REQUIRE([AC_PROG_CC]) 26 1.1 christos AC_REQUIRE([AC_CANONICAL_HOST]) 27 1.1 christos AC_REQUIRE([AC_LIB_PREPARE_MULTILIB]) 28 1.1 christos AC_REQUIRE([AC_LIB_PREPARE_PREFIX]) 29 1.1 christos dnl By default, look in $includedir and $libdir. 30 1.1 christos use_additional=yes 31 1.1 christos AC_LIB_WITH_FINAL_PREFIX([ 32 1.1 christos eval additional_includedir=\"$includedir\" 33 1.1 christos eval additional_libdir=\"$libdir\" 34 1.1 christos ]) 35 1.1 christos AC_LIB_ARG_WITH([lib-prefix], 36 1.1 christos [ --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib 37 1.1 christos --without-lib-prefix don't search for libraries in includedir and libdir], 38 1.1 christos [ 39 1.1 christos if test "X$withval" = "Xno"; then 40 1.1 christos use_additional=no 41 1.1 christos else 42 1.1 christos if test "X$withval" = "X"; then 43 1.1 christos AC_LIB_WITH_FINAL_PREFIX([ 44 1.1 christos eval additional_includedir=\"$includedir\" 45 1.1 christos eval additional_libdir=\"$libdir\" 46 1.1 christos ]) 47 1.1 christos else 48 1.1 christos additional_includedir="$withval/include" 49 1.1 christos additional_libdir="$withval/$acl_libdirstem" 50 1.1 christos fi 51 1.1 christos fi 52 1.1 christos ]) 53 1.1 christos if test $use_additional = yes; then 54 1.1 christos dnl Potentially add $additional_includedir to $CPPFLAGS. 55 1.1 christos dnl But don't add it 56 1.1 christos dnl 1. if it's the standard /usr/include, 57 1.1 christos dnl 2. if it's already present in $CPPFLAGS, 58 1.1 christos dnl 3. if it's /usr/local/include and we are using GCC on Linux, 59 1.1 christos dnl 4. if it doesn't exist as a directory. 60 1.1 christos if test "X$additional_includedir" != "X/usr/include"; then 61 1.1 christos haveit= 62 1.1 christos for x in $CPPFLAGS; do 63 1.1 christos AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 64 1.1 christos if test "X$x" = "X-I$additional_includedir"; then 65 1.1 christos haveit=yes 66 1.1 christos break 67 1.1 christos fi 68 1.1 christos done 69 1.1 christos if test -z "$haveit"; then 70 1.1 christos if test "X$additional_includedir" = "X/usr/local/include"; then 71 1.1 christos if test -n "$GCC"; then 72 1.1 christos case $host_os in 73 1.1 christos linux* | gnu* | k*bsd*-gnu) haveit=yes;; 74 1.1 christos esac 75 1.1 christos fi 76 1.1 christos fi 77 1.1 christos if test -z "$haveit"; then 78 1.1 christos if test -d "$additional_includedir"; then 79 1.1 christos dnl Really add $additional_includedir to $CPPFLAGS. 80 1.1 christos CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir" 81 1.1 christos fi 82 1.1 christos fi 83 1.1 christos fi 84 1.1 christos fi 85 1.1 christos dnl Potentially add $additional_libdir to $LDFLAGS. 86 1.1 christos dnl But don't add it 87 1.1 christos dnl 1. if it's the standard /usr/lib, 88 1.1 christos dnl 2. if it's already present in $LDFLAGS, 89 1.1 christos dnl 3. if it's /usr/local/lib and we are using GCC on Linux, 90 1.1 christos dnl 4. if it doesn't exist as a directory. 91 1.1 christos if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then 92 1.1 christos haveit= 93 1.1 christos for x in $LDFLAGS; do 94 1.1 christos AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"]) 95 1.1 christos if test "X$x" = "X-L$additional_libdir"; then 96 1.1 christos haveit=yes 97 1.1 christos break 98 1.1 christos fi 99 1.1 christos done 100 1.1 christos if test -z "$haveit"; then 101 1.1 christos if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then 102 1.1 christos if test -n "$GCC"; then 103 1.1 christos case $host_os in 104 1.1 christos linux*) haveit=yes;; 105 1.1 christos esac 106 1.1 christos fi 107 1.1 christos fi 108 1.1 christos if test -z "$haveit"; then 109 1.1 christos if test -d "$additional_libdir"; then 110 1.1 christos dnl Really add $additional_libdir to $LDFLAGS. 111 1.1 christos LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir" 112 1.1 christos fi 113 1.1 christos fi 114 1.1 christos fi 115 1.1 christos fi 116 1.1 christos fi 117 1.1 christos ]) 118 1.1 christos 119 1.1 christos dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix, 120 1.1 christos dnl acl_final_exec_prefix, containing the values to which $prefix and 121 1.1 christos dnl $exec_prefix will expand at the end of the configure script. 122 1.1 christos AC_DEFUN([AC_LIB_PREPARE_PREFIX], 123 1.1 christos [ 124 1.1 christos dnl Unfortunately, prefix and exec_prefix get only finally determined 125 1.1 christos dnl at the end of configure. 126 1.1 christos if test "X$prefix" = "XNONE"; then 127 1.1 christos acl_final_prefix="$ac_default_prefix" 128 1.1 christos else 129 1.1 christos acl_final_prefix="$prefix" 130 1.1 christos fi 131 1.1 christos if test "X$exec_prefix" = "XNONE"; then 132 1.1 christos acl_final_exec_prefix='${prefix}' 133 1.1 christos else 134 1.1 christos acl_final_exec_prefix="$exec_prefix" 135 1.1 christos fi 136 1.1 christos acl_save_prefix="$prefix" 137 1.1 christos prefix="$acl_final_prefix" 138 1.1 christos eval acl_final_exec_prefix=\"$acl_final_exec_prefix\" 139 1.1 christos prefix="$acl_save_prefix" 140 1.1 christos ]) 141 1.1 christos 142 1.1 christos dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the 143 1.1 christos dnl variables prefix and exec_prefix bound to the values they will have 144 1.1 christos dnl at the end of the configure script. 145 1.1 christos AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX], 146 1.1 christos [ 147 1.1 christos acl_save_prefix="$prefix" 148 1.1 christos prefix="$acl_final_prefix" 149 1.1 christos acl_save_exec_prefix="$exec_prefix" 150 1.1 christos exec_prefix="$acl_final_exec_prefix" 151 1.1 christos $1 152 1.1 christos exec_prefix="$acl_save_exec_prefix" 153 1.1 christos prefix="$acl_save_prefix" 154 1.1 christos ]) 155 1.1 christos 156 1.1 christos dnl AC_LIB_PREPARE_MULTILIB creates a variable acl_libdirstem, containing 157 1.1 christos dnl the basename of the libdir, either "lib" or "lib64". 158 1.1 christos AC_DEFUN([AC_LIB_PREPARE_MULTILIB], 159 1.1 christos [ 160 1.1 christos dnl There is no formal standard regarding lib and lib64. The current 161 1.1 christos dnl practice is that on a system supporting 32-bit and 64-bit instruction 162 1.1 christos dnl sets or ABIs, 64-bit libraries go under $prefix/lib64 and 32-bit 163 1.1 christos dnl libraries go under $prefix/lib. We determine the compiler's default 164 1.1 christos dnl mode by looking at the compiler's library search path. If at least 165 1.1 christos dnl of its elements ends in /lib64 or points to a directory whose absolute 166 1.1 christos dnl pathname ends in /lib64, we assume a 64-bit ABI. Otherwise we use the 167 1.1 christos dnl default, namely "lib". 168 1.1 christos acl_libdirstem=lib 169 1.1 christos searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'` 170 1.1 christos if test -n "$searchpath"; then 171 1.1 christos acl_save_IFS="${IFS= }"; IFS=":" 172 1.1 christos for searchdir in $searchpath; do 173 1.1 christos if test -d "$searchdir"; then 174 1.1 christos case "$searchdir" in 175 1.1 christos */lib64/ | */lib64 ) acl_libdirstem=lib64 ;; 176 1.1 christos *) searchdir=`cd "$searchdir" && pwd` 177 1.1 christos case "$searchdir" in 178 1.1 christos */lib64 ) acl_libdirstem=lib64 ;; 179 1.1 christos esac ;; 180 1.1 christos esac 181 1.1 christos fi 182 1.1 christos done 183 1.1 christos IFS="$acl_save_IFS" 184 1.1 christos fi 185 1.1 christos ]) 186