xref: /minix3/external/bsd/flex/dist/m4/lib-prefix.m4 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc# lib-prefix.m4 serial 7 (gettext-0.18)
2*0a6a1f1dSLionel Sambucdnl Copyright (C) 2001-2005, 2008-2010 Free Software Foundation, Inc.
3*0a6a1f1dSLionel Sambucdnl This file is free software; the Free Software Foundation
4*0a6a1f1dSLionel Sambucdnl gives unlimited permission to copy and/or distribute it,
5*0a6a1f1dSLionel Sambucdnl with or without modifications, as long as this notice is preserved.
6357f1050SThomas Veerman
7357f1050SThomas Veermandnl From Bruno Haible.
8357f1050SThomas Veerman
9357f1050SThomas Veermandnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and
10357f1050SThomas Veermandnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't
11357f1050SThomas Veermandnl require excessive bracketing.
12357f1050SThomas Veermanifdef([AC_HELP_STRING],
13357f1050SThomas Veerman[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])],
14*0a6a1f1dSLionel Sambuc[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])])
15357f1050SThomas Veerman
16357f1050SThomas Veermandnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed
17357f1050SThomas Veermandnl to access previously installed libraries. The basic assumption is that
18357f1050SThomas Veermandnl a user will want packages to use other packages he previously installed
19357f1050SThomas Veermandnl with the same --prefix option.
20357f1050SThomas Veermandnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate
21357f1050SThomas Veermandnl libraries, but is otherwise very convenient.
22357f1050SThomas VeermanAC_DEFUN([AC_LIB_PREFIX],
23357f1050SThomas Veerman[
24357f1050SThomas Veerman  AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
25357f1050SThomas Veerman  AC_REQUIRE([AC_PROG_CC])
26357f1050SThomas Veerman  AC_REQUIRE([AC_CANONICAL_HOST])
27*0a6a1f1dSLionel Sambuc  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
28357f1050SThomas Veerman  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
29357f1050SThomas Veerman  dnl By default, look in $includedir and $libdir.
30357f1050SThomas Veerman  use_additional=yes
31357f1050SThomas Veerman  AC_LIB_WITH_FINAL_PREFIX([
32357f1050SThomas Veerman    eval additional_includedir=\"$includedir\"
33357f1050SThomas Veerman    eval additional_libdir=\"$libdir\"
34357f1050SThomas Veerman  ])
35357f1050SThomas Veerman  AC_LIB_ARG_WITH([lib-prefix],
36357f1050SThomas Veerman[  --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
37357f1050SThomas Veerman  --without-lib-prefix    don't search for libraries in includedir and libdir],
38357f1050SThomas Veerman[
39357f1050SThomas Veerman    if test "X$withval" = "Xno"; then
40357f1050SThomas Veerman      use_additional=no
41357f1050SThomas Veerman    else
42357f1050SThomas Veerman      if test "X$withval" = "X"; then
43357f1050SThomas Veerman        AC_LIB_WITH_FINAL_PREFIX([
44357f1050SThomas Veerman          eval additional_includedir=\"$includedir\"
45357f1050SThomas Veerman          eval additional_libdir=\"$libdir\"
46357f1050SThomas Veerman        ])
47357f1050SThomas Veerman      else
48357f1050SThomas Veerman        additional_includedir="$withval/include"
49*0a6a1f1dSLionel Sambuc        additional_libdir="$withval/$acl_libdirstem"
50357f1050SThomas Veerman      fi
51357f1050SThomas Veerman    fi
52357f1050SThomas Veerman])
53357f1050SThomas Veerman  if test $use_additional = yes; then
54357f1050SThomas Veerman    dnl Potentially add $additional_includedir to $CPPFLAGS.
55357f1050SThomas Veerman    dnl But don't add it
56357f1050SThomas Veerman    dnl   1. if it's the standard /usr/include,
57357f1050SThomas Veerman    dnl   2. if it's already present in $CPPFLAGS,
58357f1050SThomas Veerman    dnl   3. if it's /usr/local/include and we are using GCC on Linux,
59357f1050SThomas Veerman    dnl   4. if it doesn't exist as a directory.
60357f1050SThomas Veerman    if test "X$additional_includedir" != "X/usr/include"; then
61357f1050SThomas Veerman      haveit=
62357f1050SThomas Veerman      for x in $CPPFLAGS; do
63357f1050SThomas Veerman        AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
64357f1050SThomas Veerman        if test "X$x" = "X-I$additional_includedir"; then
65357f1050SThomas Veerman          haveit=yes
66357f1050SThomas Veerman          break
67357f1050SThomas Veerman        fi
68357f1050SThomas Veerman      done
69357f1050SThomas Veerman      if test -z "$haveit"; then
70357f1050SThomas Veerman        if test "X$additional_includedir" = "X/usr/local/include"; then
71357f1050SThomas Veerman          if test -n "$GCC"; then
72357f1050SThomas Veerman            case $host_os in
73*0a6a1f1dSLionel Sambuc              linux* | gnu* | k*bsd*-gnu) haveit=yes;;
74357f1050SThomas Veerman            esac
75357f1050SThomas Veerman          fi
76357f1050SThomas Veerman        fi
77357f1050SThomas Veerman        if test -z "$haveit"; then
78357f1050SThomas Veerman          if test -d "$additional_includedir"; then
79357f1050SThomas Veerman            dnl Really add $additional_includedir to $CPPFLAGS.
80357f1050SThomas Veerman            CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir"
81357f1050SThomas Veerman          fi
82357f1050SThomas Veerman        fi
83357f1050SThomas Veerman      fi
84357f1050SThomas Veerman    fi
85357f1050SThomas Veerman    dnl Potentially add $additional_libdir to $LDFLAGS.
86357f1050SThomas Veerman    dnl But don't add it
87357f1050SThomas Veerman    dnl   1. if it's the standard /usr/lib,
88357f1050SThomas Veerman    dnl   2. if it's already present in $LDFLAGS,
89357f1050SThomas Veerman    dnl   3. if it's /usr/local/lib and we are using GCC on Linux,
90357f1050SThomas Veerman    dnl   4. if it doesn't exist as a directory.
91*0a6a1f1dSLionel Sambuc    if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
92357f1050SThomas Veerman      haveit=
93357f1050SThomas Veerman      for x in $LDFLAGS; do
94357f1050SThomas Veerman        AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
95357f1050SThomas Veerman        if test "X$x" = "X-L$additional_libdir"; then
96357f1050SThomas Veerman          haveit=yes
97357f1050SThomas Veerman          break
98357f1050SThomas Veerman        fi
99357f1050SThomas Veerman      done
100357f1050SThomas Veerman      if test -z "$haveit"; then
101*0a6a1f1dSLionel Sambuc        if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
102357f1050SThomas Veerman          if test -n "$GCC"; then
103357f1050SThomas Veerman            case $host_os in
104357f1050SThomas Veerman              linux*) haveit=yes;;
105357f1050SThomas Veerman            esac
106357f1050SThomas Veerman          fi
107357f1050SThomas Veerman        fi
108357f1050SThomas Veerman        if test -z "$haveit"; then
109357f1050SThomas Veerman          if test -d "$additional_libdir"; then
110357f1050SThomas Veerman            dnl Really add $additional_libdir to $LDFLAGS.
111357f1050SThomas Veerman            LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir"
112357f1050SThomas Veerman          fi
113357f1050SThomas Veerman        fi
114357f1050SThomas Veerman      fi
115357f1050SThomas Veerman    fi
116357f1050SThomas Veerman  fi
117357f1050SThomas Veerman])
118357f1050SThomas Veerman
119357f1050SThomas Veermandnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix,
120357f1050SThomas Veermandnl acl_final_exec_prefix, containing the values to which $prefix and
121357f1050SThomas Veermandnl $exec_prefix will expand at the end of the configure script.
122357f1050SThomas VeermanAC_DEFUN([AC_LIB_PREPARE_PREFIX],
123357f1050SThomas Veerman[
124357f1050SThomas Veerman  dnl Unfortunately, prefix and exec_prefix get only finally determined
125357f1050SThomas Veerman  dnl at the end of configure.
126357f1050SThomas Veerman  if test "X$prefix" = "XNONE"; then
127357f1050SThomas Veerman    acl_final_prefix="$ac_default_prefix"
128357f1050SThomas Veerman  else
129357f1050SThomas Veerman    acl_final_prefix="$prefix"
130357f1050SThomas Veerman  fi
131357f1050SThomas Veerman  if test "X$exec_prefix" = "XNONE"; then
132357f1050SThomas Veerman    acl_final_exec_prefix='${prefix}'
133357f1050SThomas Veerman  else
134357f1050SThomas Veerman    acl_final_exec_prefix="$exec_prefix"
135357f1050SThomas Veerman  fi
136357f1050SThomas Veerman  acl_save_prefix="$prefix"
137357f1050SThomas Veerman  prefix="$acl_final_prefix"
138357f1050SThomas Veerman  eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
139357f1050SThomas Veerman  prefix="$acl_save_prefix"
140357f1050SThomas Veerman])
141357f1050SThomas Veerman
142357f1050SThomas Veermandnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the
143357f1050SThomas Veermandnl variables prefix and exec_prefix bound to the values they will have
144357f1050SThomas Veermandnl at the end of the configure script.
145357f1050SThomas VeermanAC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
146357f1050SThomas Veerman[
147357f1050SThomas Veerman  acl_save_prefix="$prefix"
148357f1050SThomas Veerman  prefix="$acl_final_prefix"
149357f1050SThomas Veerman  acl_save_exec_prefix="$exec_prefix"
150357f1050SThomas Veerman  exec_prefix="$acl_final_exec_prefix"
151357f1050SThomas Veerman  $1
152357f1050SThomas Veerman  exec_prefix="$acl_save_exec_prefix"
153357f1050SThomas Veerman  prefix="$acl_save_prefix"
154357f1050SThomas Veerman])
155*0a6a1f1dSLionel Sambuc
156*0a6a1f1dSLionel Sambucdnl AC_LIB_PREPARE_MULTILIB creates
157*0a6a1f1dSLionel Sambucdnl - a variable acl_libdirstem, containing the basename of the libdir, either
158*0a6a1f1dSLionel Sambucdnl   "lib" or "lib64" or "lib/64",
159*0a6a1f1dSLionel Sambucdnl - a variable acl_libdirstem2, as a secondary possible value for
160*0a6a1f1dSLionel Sambucdnl   acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or
161*0a6a1f1dSLionel Sambucdnl   "lib/amd64".
162*0a6a1f1dSLionel SambucAC_DEFUN([AC_LIB_PREPARE_MULTILIB],
163*0a6a1f1dSLionel Sambuc[
164*0a6a1f1dSLionel Sambuc  dnl There is no formal standard regarding lib and lib64.
165*0a6a1f1dSLionel Sambuc  dnl On glibc systems, the current practice is that on a system supporting
166*0a6a1f1dSLionel Sambuc  dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
167*0a6a1f1dSLionel Sambuc  dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. We determine
168*0a6a1f1dSLionel Sambuc  dnl the compiler's default mode by looking at the compiler's library search
169*0a6a1f1dSLionel Sambuc  dnl path. If at least one of its elements ends in /lib64 or points to a
170*0a6a1f1dSLionel Sambuc  dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI.
171*0a6a1f1dSLionel Sambuc  dnl Otherwise we use the default, namely "lib".
172*0a6a1f1dSLionel Sambuc  dnl On Solaris systems, the current practice is that on a system supporting
173*0a6a1f1dSLionel Sambuc  dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
174*0a6a1f1dSLionel Sambuc  dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or
175*0a6a1f1dSLionel Sambuc  dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib.
176*0a6a1f1dSLionel Sambuc  AC_REQUIRE([AC_CANONICAL_HOST])
177*0a6a1f1dSLionel Sambuc  acl_libdirstem=lib
178*0a6a1f1dSLionel Sambuc  acl_libdirstem2=
179*0a6a1f1dSLionel Sambuc  case "$host_os" in
180*0a6a1f1dSLionel Sambuc    solaris*)
181*0a6a1f1dSLionel Sambuc      dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment
182*0a6a1f1dSLionel Sambuc      dnl <http://docs.sun.com/app/docs/doc/816-5138/dev-env?l=en&a=view>.
183*0a6a1f1dSLionel Sambuc      dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link."
184*0a6a1f1dSLionel Sambuc      dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the
185*0a6a1f1dSLionel Sambuc      dnl symlink is missing, so we set acl_libdirstem2 too.
186*0a6a1f1dSLionel Sambuc      AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit],
187*0a6a1f1dSLionel Sambuc        [AC_EGREP_CPP([sixtyfour bits], [
188*0a6a1f1dSLionel Sambuc#ifdef _LP64
189*0a6a1f1dSLionel Sambucsixtyfour bits
190*0a6a1f1dSLionel Sambuc#endif
191*0a6a1f1dSLionel Sambuc           ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no])
192*0a6a1f1dSLionel Sambuc        ])
193*0a6a1f1dSLionel Sambuc      if test $gl_cv_solaris_64bit = yes; then
194*0a6a1f1dSLionel Sambuc        acl_libdirstem=lib/64
195*0a6a1f1dSLionel Sambuc        case "$host_cpu" in
196*0a6a1f1dSLionel Sambuc          sparc*)        acl_libdirstem2=lib/sparcv9 ;;
197*0a6a1f1dSLionel Sambuc          i*86 | x86_64) acl_libdirstem2=lib/amd64 ;;
198*0a6a1f1dSLionel Sambuc        esac
199*0a6a1f1dSLionel Sambuc      fi
200*0a6a1f1dSLionel Sambuc      ;;
201*0a6a1f1dSLionel Sambuc    *)
202*0a6a1f1dSLionel Sambuc      searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
203*0a6a1f1dSLionel Sambuc      if test -n "$searchpath"; then
204*0a6a1f1dSLionel Sambuc        acl_save_IFS="${IFS= 	}"; IFS=":"
205*0a6a1f1dSLionel Sambuc        for searchdir in $searchpath; do
206*0a6a1f1dSLionel Sambuc          if test -d "$searchdir"; then
207*0a6a1f1dSLionel Sambuc            case "$searchdir" in
208*0a6a1f1dSLionel Sambuc              */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
209*0a6a1f1dSLionel Sambuc              */../ | */.. )
210*0a6a1f1dSLionel Sambuc                # Better ignore directories of this form. They are misleading.
211*0a6a1f1dSLionel Sambuc                ;;
212*0a6a1f1dSLionel Sambuc              *) searchdir=`cd "$searchdir" && pwd`
213*0a6a1f1dSLionel Sambuc                 case "$searchdir" in
214*0a6a1f1dSLionel Sambuc                   */lib64 ) acl_libdirstem=lib64 ;;
215*0a6a1f1dSLionel Sambuc                 esac ;;
216*0a6a1f1dSLionel Sambuc            esac
217*0a6a1f1dSLionel Sambuc          fi
218*0a6a1f1dSLionel Sambuc        done
219*0a6a1f1dSLionel Sambuc        IFS="$acl_save_IFS"
220*0a6a1f1dSLionel Sambuc      fi
221*0a6a1f1dSLionel Sambuc      ;;
222*0a6a1f1dSLionel Sambuc  esac
223*0a6a1f1dSLionel Sambuc  test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem"
224*0a6a1f1dSLionel Sambuc])
225