Blame m4/lib-prefix.m4

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