Blame m4/lib-prefix.m4

Packit 3ff1e7
# lib-prefix.m4 serial 7 (gettext-0.18)
Packit 3ff1e7
dnl Copyright (C) 2001-2005, 2008-2010 Free Software Foundation, Inc.
Packit 3ff1e7
dnl This file is free software; the Free Software Foundation
Packit 3ff1e7
dnl gives unlimited permission to copy and/or distribute it,
Packit 3ff1e7
dnl with or without modifications, as long as this notice is preserved.
Packit 3ff1e7
Packit 3ff1e7
dnl From Bruno Haible.
Packit 3ff1e7
Packit 3ff1e7
dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and
Packit 3ff1e7
dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't
Packit 3ff1e7
dnl require excessive bracketing.
Packit 3ff1e7
ifdef([AC_HELP_STRING],
Packit 3ff1e7
[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])],
Packit 3ff1e7
[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])])
Packit 3ff1e7
Packit 3ff1e7
dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed
Packit 3ff1e7
dnl to access previously installed libraries. The basic assumption is that
Packit 3ff1e7
dnl a user will want packages to use other packages he previously installed
Packit 3ff1e7
dnl with the same --prefix option.
Packit 3ff1e7
dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate
Packit 3ff1e7
dnl libraries, but is otherwise very convenient.
Packit 3ff1e7
AC_DEFUN([AC_LIB_PREFIX],
Packit 3ff1e7
[
Packit 3ff1e7
  AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
Packit 3ff1e7
  AC_REQUIRE([AC_PROG_CC])
Packit 3ff1e7
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit 3ff1e7
  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
Packit 3ff1e7
  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
Packit 3ff1e7
  dnl By default, look in $includedir and $libdir.
Packit 3ff1e7
  use_additional=yes
Packit 3ff1e7
  AC_LIB_WITH_FINAL_PREFIX([
Packit 3ff1e7
    eval additional_includedir=\"$includedir\"
Packit 3ff1e7
    eval additional_libdir=\"$libdir\"
Packit 3ff1e7
  ])
Packit 3ff1e7
  AC_LIB_ARG_WITH([lib-prefix],
Packit 3ff1e7
[  --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
Packit 3ff1e7
  --without-lib-prefix    don't search for libraries in includedir and libdir],
Packit 3ff1e7
[
Packit 3ff1e7
    if test "X$withval" = "Xno"; then
Packit 3ff1e7
      use_additional=no
Packit 3ff1e7
    else
Packit 3ff1e7
      if test "X$withval" = "X"; then
Packit 3ff1e7
        AC_LIB_WITH_FINAL_PREFIX([
Packit 3ff1e7
          eval additional_includedir=\"$includedir\"
Packit 3ff1e7
          eval additional_libdir=\"$libdir\"
Packit 3ff1e7
        ])
Packit 3ff1e7
      else
Packit 3ff1e7
        additional_includedir="$withval/include"
Packit 3ff1e7
        additional_libdir="$withval/$acl_libdirstem"
Packit 3ff1e7
      fi
Packit 3ff1e7
    fi
Packit 3ff1e7
])
Packit 3ff1e7
  if test $use_additional = yes; then
Packit 3ff1e7
    dnl Potentially add $additional_includedir to $CPPFLAGS.
Packit 3ff1e7
    dnl But don't add it
Packit 3ff1e7
    dnl   1. if it's the standard /usr/include,
Packit 3ff1e7
    dnl   2. if it's already present in $CPPFLAGS,
Packit 3ff1e7
    dnl   3. if it's /usr/local/include and we are using GCC on Linux,
Packit 3ff1e7
    dnl   4. if it doesn't exist as a directory.
Packit 3ff1e7
    if test "X$additional_includedir" != "X/usr/include"; then
Packit 3ff1e7
      haveit=
Packit 3ff1e7
      for x in $CPPFLAGS; do
Packit 3ff1e7
        AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
Packit 3ff1e7
        if test "X$x" = "X-I$additional_includedir"; then
Packit 3ff1e7
          haveit=yes
Packit 3ff1e7
          break
Packit 3ff1e7
        fi
Packit 3ff1e7
      done
Packit 3ff1e7
      if test -z "$haveit"; then
Packit 3ff1e7
        if test "X$additional_includedir" = "X/usr/local/include"; then
Packit 3ff1e7
          if test -n "$GCC"; then
Packit 3ff1e7
            case $host_os in
Packit 3ff1e7
              linux* | gnu* | k*bsd*-gnu) haveit=yes;;
Packit 3ff1e7
            esac
Packit 3ff1e7
          fi
Packit 3ff1e7
        fi
Packit 3ff1e7
        if test -z "$haveit"; then
Packit 3ff1e7
          if test -d "$additional_includedir"; then
Packit 3ff1e7
            dnl Really add $additional_includedir to $CPPFLAGS.
Packit 3ff1e7
            CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir"
Packit 3ff1e7
          fi
Packit 3ff1e7
        fi
Packit 3ff1e7
      fi
Packit 3ff1e7
    fi
Packit 3ff1e7
    dnl Potentially add $additional_libdir to $LDFLAGS.
Packit 3ff1e7
    dnl But don't add it
Packit 3ff1e7
    dnl   1. if it's the standard /usr/lib,
Packit 3ff1e7
    dnl   2. if it's already present in $LDFLAGS,
Packit 3ff1e7
    dnl   3. if it's /usr/local/lib and we are using GCC on Linux,
Packit 3ff1e7
    dnl   4. if it doesn't exist as a directory.
Packit 3ff1e7
    if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
Packit 3ff1e7
      haveit=
Packit 3ff1e7
      for x in $LDFLAGS; do
Packit 3ff1e7
        AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
Packit 3ff1e7
        if test "X$x" = "X-L$additional_libdir"; then
Packit 3ff1e7
          haveit=yes
Packit 3ff1e7
          break
Packit 3ff1e7
        fi
Packit 3ff1e7
      done
Packit 3ff1e7
      if test -z "$haveit"; then
Packit 3ff1e7
        if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
Packit 3ff1e7
          if test -n "$GCC"; then
Packit 3ff1e7
            case $host_os in
Packit 3ff1e7
              linux*) haveit=yes;;
Packit 3ff1e7
            esac
Packit 3ff1e7
          fi
Packit 3ff1e7
        fi
Packit 3ff1e7
        if test -z "$haveit"; then
Packit 3ff1e7
          if test -d "$additional_libdir"; then
Packit 3ff1e7
            dnl Really add $additional_libdir to $LDFLAGS.
Packit 3ff1e7
            LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir"
Packit 3ff1e7
          fi
Packit 3ff1e7
        fi
Packit 3ff1e7
      fi
Packit 3ff1e7
    fi
Packit 3ff1e7
  fi
Packit 3ff1e7
])
Packit 3ff1e7
Packit 3ff1e7
dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix,
Packit 3ff1e7
dnl acl_final_exec_prefix, containing the values to which $prefix and
Packit 3ff1e7
dnl $exec_prefix will expand at the end of the configure script.
Packit 3ff1e7
AC_DEFUN([AC_LIB_PREPARE_PREFIX],
Packit 3ff1e7
[
Packit 3ff1e7
  dnl Unfortunately, prefix and exec_prefix get only finally determined
Packit 3ff1e7
  dnl at the end of configure.
Packit 3ff1e7
  if test "X$prefix" = "XNONE"; then
Packit 3ff1e7
    acl_final_prefix="$ac_default_prefix"
Packit 3ff1e7
  else
Packit 3ff1e7
    acl_final_prefix="$prefix"
Packit 3ff1e7
  fi
Packit 3ff1e7
  if test "X$exec_prefix" = "XNONE"; then
Packit 3ff1e7
    acl_final_exec_prefix='${prefix}'
Packit 3ff1e7
  else
Packit 3ff1e7
    acl_final_exec_prefix="$exec_prefix"
Packit 3ff1e7
  fi
Packit 3ff1e7
  acl_save_prefix="$prefix"
Packit 3ff1e7
  prefix="$acl_final_prefix"
Packit 3ff1e7
  eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
Packit 3ff1e7
  prefix="$acl_save_prefix"
Packit 3ff1e7
])
Packit 3ff1e7
Packit 3ff1e7
dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the
Packit 3ff1e7
dnl variables prefix and exec_prefix bound to the values they will have
Packit 3ff1e7
dnl at the end of the configure script.
Packit 3ff1e7
AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
Packit 3ff1e7
[
Packit 3ff1e7
  acl_save_prefix="$prefix"
Packit 3ff1e7
  prefix="$acl_final_prefix"
Packit 3ff1e7
  acl_save_exec_prefix="$exec_prefix"
Packit 3ff1e7
  exec_prefix="$acl_final_exec_prefix"
Packit 3ff1e7
  $1
Packit 3ff1e7
  exec_prefix="$acl_save_exec_prefix"
Packit 3ff1e7
  prefix="$acl_save_prefix"
Packit 3ff1e7
])
Packit 3ff1e7
Packit 3ff1e7
dnl AC_LIB_PREPARE_MULTILIB creates
Packit 3ff1e7
dnl - a variable acl_libdirstem, containing the basename of the libdir, either
Packit 3ff1e7
dnl   "lib" or "lib64" or "lib/64",
Packit 3ff1e7
dnl - a variable acl_libdirstem2, as a secondary possible value for
Packit 3ff1e7
dnl   acl_libdirstem, either the same as acl_libdirstem or "lib/sparcv9" or
Packit 3ff1e7
dnl   "lib/amd64".
Packit 3ff1e7
AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
Packit 3ff1e7
[
Packit 3ff1e7
  dnl There is no formal standard regarding lib and lib64.
Packit 3ff1e7
  dnl On glibc systems, the current practice is that on a system supporting
Packit 3ff1e7
  dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
Packit 3ff1e7
  dnl $prefix/lib64 and 32-bit libraries go under $prefix/lib. We determine
Packit 3ff1e7
  dnl the compiler's default mode by looking at the compiler's library search
Packit 3ff1e7
  dnl path. If at least one of its elements ends in /lib64 or points to a
Packit 3ff1e7
  dnl directory whose absolute pathname ends in /lib64, we assume a 64-bit ABI.
Packit 3ff1e7
  dnl Otherwise we use the default, namely "lib".
Packit 3ff1e7
  dnl On Solaris systems, the current practice is that on a system supporting
Packit 3ff1e7
  dnl 32-bit and 64-bit instruction sets or ABIs, 64-bit libraries go under
Packit 3ff1e7
  dnl $prefix/lib/64 (which is a symlink to either $prefix/lib/sparcv9 or
Packit 3ff1e7
  dnl $prefix/lib/amd64) and 32-bit libraries go under $prefix/lib.
Packit 3ff1e7
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit 3ff1e7
  acl_libdirstem=lib
Packit 3ff1e7
  acl_libdirstem2=
Packit 3ff1e7
  case "$host_os" in
Packit 3ff1e7
    solaris*)
Packit 3ff1e7
      dnl See Solaris 10 Software Developer Collection > Solaris 64-bit Developer's Guide > The Development Environment
Packit 3ff1e7
      dnl <http://docs.sun.com/app/docs/doc/816-5138/dev-env?l=en&a=view>.
Packit 3ff1e7
      dnl "Portable Makefiles should refer to any library directories using the 64 symbolic link."
Packit 3ff1e7
      dnl But we want to recognize the sparcv9 or amd64 subdirectory also if the
Packit 3ff1e7
      dnl symlink is missing, so we set acl_libdirstem2 too.
Packit 3ff1e7
      AC_CACHE_CHECK([for 64-bit host], [gl_cv_solaris_64bit],
Packit 3ff1e7
        [AC_EGREP_CPP([sixtyfour bits], [
Packit 3ff1e7
#ifdef _LP64
Packit 3ff1e7
sixtyfour bits
Packit 3ff1e7
#endif
Packit 3ff1e7
           ], [gl_cv_solaris_64bit=yes], [gl_cv_solaris_64bit=no])
Packit 3ff1e7
        ])
Packit 3ff1e7
      if test $gl_cv_solaris_64bit = yes; then
Packit 3ff1e7
        acl_libdirstem=lib/64
Packit 3ff1e7
        case "$host_cpu" in
Packit 3ff1e7
          sparc*)        acl_libdirstem2=lib/sparcv9 ;;
Packit 3ff1e7
          i*86 | x86_64) acl_libdirstem2=lib/amd64 ;;
Packit 3ff1e7
        esac
Packit 3ff1e7
      fi
Packit 3ff1e7
      ;;
Packit 3ff1e7
    *)
Packit 3ff1e7
      searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
Packit 3ff1e7
      if test -n "$searchpath"; then
Packit 3ff1e7
        acl_save_IFS="${IFS= 	}"; IFS=":"
Packit 3ff1e7
        for searchdir in $searchpath; do
Packit 3ff1e7
          if test -d "$searchdir"; then
Packit 3ff1e7
            case "$searchdir" in
Packit 3ff1e7
              */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
Packit 3ff1e7
              */../ | */.. )
Packit 3ff1e7
                # Better ignore directories of this form. They are misleading.
Packit 3ff1e7
                ;;
Packit 3ff1e7
              *) searchdir=`cd "$searchdir" && pwd`
Packit 3ff1e7
                 case "$searchdir" in
Packit 3ff1e7
                   */lib64 ) acl_libdirstem=lib64 ;;
Packit 3ff1e7
                 esac ;;
Packit 3ff1e7
            esac
Packit 3ff1e7
          fi
Packit 3ff1e7
        done
Packit 3ff1e7
        IFS="$acl_save_IFS"
Packit 3ff1e7
      fi
Packit 3ff1e7
      ;;
Packit 3ff1e7
  esac
Packit 3ff1e7
  test -n "$acl_libdirstem2" || acl_libdirstem2="$acl_libdirstem"
Packit 3ff1e7
])