Blame m4/lib-prefix.m4

Packit 7e555f
# lib-prefix.m4 serial 5 (gettext-0.15)
Packit 7e555f
dnl Copyright (C) 2001-2005 Free Software Foundation, Inc.
Packit 7e555f
dnl This file is free software; the Free Software Foundation
Packit 7e555f
dnl gives unlimited permission to copy and/or distribute it,
Packit 7e555f
dnl with or without modifications, as long as this notice is preserved.
Packit 7e555f
Packit 7e555f
dnl From Bruno Haible.
Packit 7e555f
Packit 7e555f
dnl AC_LIB_ARG_WITH is synonymous to AC_ARG_WITH in autoconf-2.13, and
Packit 7e555f
dnl similar to AC_ARG_WITH in autoconf 2.52...2.57 except that is doesn't
Packit 7e555f
dnl require excessive bracketing.
Packit 7e555f
ifdef([AC_HELP_STRING],
Packit 7e555f
[AC_DEFUN([AC_LIB_ARG_WITH], [AC_ARG_WITH([$1],[[$2]],[$3],[$4])])],
Packit 7e555f
[AC_DEFUN([AC_][LIB_ARG_WITH], [AC_ARG_WITH([$1],[$2],[$3],[$4])])])
Packit 7e555f
Packit 7e555f
dnl AC_LIB_PREFIX adds to the CPPFLAGS and LDFLAGS the flags that are needed
Packit 7e555f
dnl to access previously installed libraries. The basic assumption is that
Packit 7e555f
dnl a user will want packages to use other packages he previously installed
Packit 7e555f
dnl with the same --prefix option.
Packit 7e555f
dnl This macro is not needed if only AC_LIB_LINKFLAGS is used to locate
Packit 7e555f
dnl libraries, but is otherwise very convenient.
Packit 7e555f
AC_DEFUN([AC_LIB_PREFIX],
Packit 7e555f
[
Packit 7e555f
  AC_BEFORE([$0], [AC_LIB_LINKFLAGS])
Packit 7e555f
  AC_REQUIRE([AC_PROG_CC])
Packit 7e555f
  AC_REQUIRE([AC_CANONICAL_HOST])
Packit 7e555f
  AC_REQUIRE([AC_LIB_PREPARE_MULTILIB])
Packit 7e555f
  AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
Packit 7e555f
  dnl By default, look in $includedir and $libdir.
Packit 7e555f
  use_additional=yes
Packit 7e555f
  AC_LIB_WITH_FINAL_PREFIX([
Packit 7e555f
    eval additional_includedir=\"$includedir\"
Packit 7e555f
    eval additional_libdir=\"$libdir\"
Packit 7e555f
  ])
Packit 7e555f
  AC_LIB_ARG_WITH([lib-prefix],
Packit 7e555f
[  --with-lib-prefix[=DIR] search for libraries in DIR/include and DIR/lib
Packit 7e555f
  --without-lib-prefix    don't search for libraries in includedir and libdir],
Packit 7e555f
[
Packit 7e555f
    if test "X$withval" = "Xno"; then
Packit 7e555f
      use_additional=no
Packit 7e555f
    else
Packit 7e555f
      if test "X$withval" = "X"; then
Packit 7e555f
        AC_LIB_WITH_FINAL_PREFIX([
Packit 7e555f
          eval additional_includedir=\"$includedir\"
Packit 7e555f
          eval additional_libdir=\"$libdir\"
Packit 7e555f
        ])
Packit 7e555f
      else
Packit 7e555f
        additional_includedir="$withval/include"
Packit 7e555f
        additional_libdir="$withval/$acl_libdirstem"
Packit 7e555f
      fi
Packit 7e555f
    fi
Packit 7e555f
])
Packit 7e555f
  if test $use_additional = yes; then
Packit 7e555f
    dnl Potentially add $additional_includedir to $CPPFLAGS.
Packit 7e555f
    dnl But don't add it
Packit 7e555f
    dnl   1. if it's the standard /usr/include,
Packit 7e555f
    dnl   2. if it's already present in $CPPFLAGS,
Packit 7e555f
    dnl   3. if it's /usr/local/include and we are using GCC on Linux,
Packit 7e555f
    dnl   4. if it doesn't exist as a directory.
Packit 7e555f
    if test "X$additional_includedir" != "X/usr/include"; then
Packit 7e555f
      haveit=
Packit 7e555f
      for x in $CPPFLAGS; do
Packit 7e555f
        AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
Packit 7e555f
        if test "X$x" = "X-I$additional_includedir"; then
Packit 7e555f
          haveit=yes
Packit 7e555f
          break
Packit 7e555f
        fi
Packit 7e555f
      done
Packit 7e555f
      if test -z "$haveit"; then
Packit 7e555f
        if test "X$additional_includedir" = "X/usr/local/include"; then
Packit 7e555f
          if test -n "$GCC"; then
Packit 7e555f
            case $host_os in
Packit 7e555f
              linux* | gnu* | k*bsd*-gnu) haveit=yes;;
Packit 7e555f
            esac
Packit 7e555f
          fi
Packit 7e555f
        fi
Packit 7e555f
        if test -z "$haveit"; then
Packit 7e555f
          if test -d "$additional_includedir"; then
Packit 7e555f
            dnl Really add $additional_includedir to $CPPFLAGS.
Packit 7e555f
            CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }-I$additional_includedir"
Packit 7e555f
          fi
Packit 7e555f
        fi
Packit 7e555f
      fi
Packit 7e555f
    fi
Packit 7e555f
    dnl Potentially add $additional_libdir to $LDFLAGS.
Packit 7e555f
    dnl But don't add it
Packit 7e555f
    dnl   1. if it's the standard /usr/lib,
Packit 7e555f
    dnl   2. if it's already present in $LDFLAGS,
Packit 7e555f
    dnl   3. if it's /usr/local/lib and we are using GCC on Linux,
Packit 7e555f
    dnl   4. if it doesn't exist as a directory.
Packit 7e555f
    if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
Packit 7e555f
      haveit=
Packit 7e555f
      for x in $LDFLAGS; do
Packit 7e555f
        AC_LIB_WITH_FINAL_PREFIX([eval x=\"$x\"])
Packit 7e555f
        if test "X$x" = "X-L$additional_libdir"; then
Packit 7e555f
          haveit=yes
Packit 7e555f
          break
Packit 7e555f
        fi
Packit 7e555f
      done
Packit 7e555f
      if test -z "$haveit"; then
Packit 7e555f
        if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
Packit 7e555f
          if test -n "$GCC"; then
Packit 7e555f
            case $host_os in
Packit 7e555f
              linux*) haveit=yes;;
Packit 7e555f
            esac
Packit 7e555f
          fi
Packit 7e555f
        fi
Packit 7e555f
        if test -z "$haveit"; then
Packit 7e555f
          if test -d "$additional_libdir"; then
Packit 7e555f
            dnl Really add $additional_libdir to $LDFLAGS.
Packit 7e555f
            LDFLAGS="${LDFLAGS}${LDFLAGS:+ }-L$additional_libdir"
Packit 7e555f
          fi
Packit 7e555f
        fi
Packit 7e555f
      fi
Packit 7e555f
    fi
Packit 7e555f
  fi
Packit 7e555f
])
Packit 7e555f
Packit 7e555f
dnl AC_LIB_PREPARE_PREFIX creates variables acl_final_prefix,
Packit 7e555f
dnl acl_final_exec_prefix, containing the values to which $prefix and
Packit 7e555f
dnl $exec_prefix will expand at the end of the configure script.
Packit 7e555f
AC_DEFUN([AC_LIB_PREPARE_PREFIX],
Packit 7e555f
[
Packit 7e555f
  dnl Unfortunately, prefix and exec_prefix get only finally determined
Packit 7e555f
  dnl at the end of configure.
Packit 7e555f
  if test "X$prefix" = "XNONE"; then
Packit 7e555f
    acl_final_prefix="$ac_default_prefix"
Packit 7e555f
  else
Packit 7e555f
    acl_final_prefix="$prefix"
Packit 7e555f
  fi
Packit 7e555f
  if test "X$exec_prefix" = "XNONE"; then
Packit 7e555f
    acl_final_exec_prefix='${prefix}'
Packit 7e555f
  else
Packit 7e555f
    acl_final_exec_prefix="$exec_prefix"
Packit 7e555f
  fi
Packit 7e555f
  acl_save_prefix="$prefix"
Packit 7e555f
  prefix="$acl_final_prefix"
Packit 7e555f
  eval acl_final_exec_prefix=\"$acl_final_exec_prefix\"
Packit 7e555f
  prefix="$acl_save_prefix"
Packit 7e555f
])
Packit 7e555f
Packit 7e555f
dnl AC_LIB_WITH_FINAL_PREFIX([statement]) evaluates statement, with the
Packit 7e555f
dnl variables prefix and exec_prefix bound to the values they will have
Packit 7e555f
dnl at the end of the configure script.
Packit 7e555f
AC_DEFUN([AC_LIB_WITH_FINAL_PREFIX],
Packit 7e555f
[
Packit 7e555f
  acl_save_prefix="$prefix"
Packit 7e555f
  prefix="$acl_final_prefix"
Packit 7e555f
  acl_save_exec_prefix="$exec_prefix"
Packit 7e555f
  exec_prefix="$acl_final_exec_prefix"
Packit 7e555f
  $1
Packit 7e555f
  exec_prefix="$acl_save_exec_prefix"
Packit 7e555f
  prefix="$acl_save_prefix"
Packit 7e555f
])
Packit 7e555f
Packit 7e555f
dnl AC_LIB_PREPARE_MULTILIB creates a variable acl_libdirstem, containing
Packit 7e555f
dnl the basename of the libdir, either "lib" or "lib64".
Packit 7e555f
AC_DEFUN([AC_LIB_PREPARE_MULTILIB],
Packit 7e555f
[
Packit 7e555f
  dnl There is no formal standard regarding lib and lib64. The current
Packit 7e555f
  dnl practice is that on a system supporting 32-bit and 64-bit instruction
Packit 7e555f
  dnl sets or ABIs, 64-bit libraries go under $prefix/lib64 and 32-bit
Packit 7e555f
  dnl libraries go under $prefix/lib. We determine the compiler's default
Packit 7e555f
  dnl mode by looking at the compiler's library search path. If at least
Packit 7e555f
  dnl of its elements ends in /lib64 or points to a directory whose absolute
Packit 7e555f
  dnl pathname ends in /lib64, we assume a 64-bit ABI. Otherwise we use the
Packit 7e555f
  dnl default, namely "lib".
Packit 7e555f
  acl_libdirstem=lib
Packit 7e555f
  searchpath=`(LC_ALL=C $CC -print-search-dirs) 2>/dev/null | sed -n -e 's,^libraries: ,,p' | sed -e 's,^=,,'`
Packit 7e555f
  if test -n "$searchpath"; then
Packit 7e555f
    acl_save_IFS="${IFS= 	}"; IFS=":"
Packit 7e555f
    for searchdir in $searchpath; do
Packit 7e555f
      if test -d "$searchdir"; then
Packit 7e555f
        case "$searchdir" in
Packit 7e555f
          */lib64/ | */lib64 ) acl_libdirstem=lib64 ;;
Packit 7e555f
          *) searchdir=`cd "$searchdir" && pwd`
Packit 7e555f
             case "$searchdir" in
Packit 7e555f
               */lib64 ) acl_libdirstem=lib64 ;;
Packit 7e555f
             esac ;;
Packit 7e555f
        esac
Packit 7e555f
      fi
Packit 7e555f
    done
Packit 7e555f
    IFS="$acl_save_IFS"
Packit 7e555f
  fi
Packit 7e555f
])