lib-prefix.m4 revision 1.1 1 1.1 christos # lib-prefix.m4 serial 6 (gettext-0.18)
2 1.1 christos dnl Copyright (C) 2001-2005, 2008 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
157 1.1 christos dnl - a variable acl_libdirstem, containing the basename of the libdir, either
158 1.1 christos dnl "lib" or "lib64" or "lib/64",
159 1.1 christos dnl - a variable acl_libdirstem2, as a secondary possible value for
160 1.1 christos dnl acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or
161 1.1 christos dnl "lib/amd64".
162 1.1 christos AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
163 1.1 christos [
164 1.1 christos dnl There is no formal standard regarding lib and lib64.
165 1.1 christos dnl On glibc systems, the current practice is that on a system supporting
166 1.1 christos dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
167 1.1 christos dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. We determine
168 1.1 christos dnl the compiler's default mode by looking at the compiler's library search
169 1.1 christos dnl path. If at least one of its elements ends in /lib64 or points to a
170 1.1 christos dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI.
171 1.1 christos dnl Otherwise we use the default, namely "lib".
172 1.1 christos dnl On Solaris systems, the current practice is that on a system supporting
173 1.1 christos dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
174 1.1 christos dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or
175 1.1 christos dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib.
176 1.1 christos AC_REQUIRE([AC_CANONICAL_HOST])
177 1.1 christos acl_libdirstem=lib
178 1.1 christos acl_libdirstem2=
179 1.1 christos case "$host_os" in
180 1.1 christos solaris*)
181 1.1 christos dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment
182 1.1 christos dnl <http://docs.sun.com/app/docs/doc/816-5138/dev-env?l=en&a=view>.
183 1.1 christos dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link."
184 1.1 christos dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the
185 1.1 christos dnl symlink is missing, so we set acl_libdirstem2 too.
186 1.1 christos AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit],
187 1.1 christos [AC_EGREP_CPP([sixtyfour bits], [
188 1.1 christos #ifdef _LP64
189 1.1 christos sixtyfour bits
190 1.1 christos #endif
191 1.1 christos ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no])
192 1.1 christos ])
193 1.1 christos if test $gl_cv_solaris_64bit = yes; then
194 1.1 christos acl_libdirstem=lib/64
195 1.1 christos case "$host_cpu" in
196 1.1 christos sparc*) acl_libdirstem2=lib/sparcv9 ;;
197 1.1 christos i*86 | x86_64) acl_libdirstem2=lib/amd64 ;;
198 1.1 christos esac
199 1.1 christos fi
200 1.1 christos ;;
201 1.1 christos *)
202 1.1 christos searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
203 1.1 christos if test -n "$searchpath"; then
204 1.1 christos acl_save_IFS="${IFS= }"; IFS=":"
205 1.1 christos for searchdir in $searchpath; do
206 1.1 christos if test -d "$searchdir"; then
207 1.1 christos case "$searchdir" in
208 1.1 christos */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
209 1.1 christos *) searchdir=`cd "$searchdir" && pwd`
210 1.1 christos case "$searchdir" in
211 1.1 christos */lib64 ) acl_libdirstem=lib64 ;;
212 1.1 christos esac ;;
213 1.1 christos esac
214 1.1 christos fi
215 1.1 christos done
216 1.1 christos IFS="$acl_save_IFS"
217 1.1 christos fi
218 1.1 christos ;;
219 1.1 christos esac
220 1.1 christos test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem"
221 1.1 christos ])
222