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