#! /bin/sh
# Output a system dependent set of variables, describing how to export
# all global symbols in an executable for use by dynamic loading.
#
#   Copyright 1996-2005 Free Software Foundation, Inc.
#   Taken from GNU libtool, 2001
#   Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful, but
#   WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
#   USA.
#
#   As a special exception to the GNU General Public License, if you
#   distribute this file as part of a program that contains a
#   configuration script generated by Autoconf, you may include it under
#   the same distribution terms that you use for the rest of that program.
#
# The first argument passed to this file is the canonical host specification,
#    CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
# or
#    CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
# The environment variables CC, GCC, LDFLAGS, LD, with_gnu_ld
# should be set by the caller.
#
# The set of defined variables is at the end of this script.

host="$1"
host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`

cc_basename=`echo "$CC" | sed -e 's%^.*/%%'`

# Code taken from libtool.m4's AC_LIBTOOL_PROG_COMPILER_PIC.

wl=
if test "$GCC" = yes; then
  wl='-Wl,'
else
  case "$host_os" in
    aix*)
      wl='-Wl,'
      ;;
    darwin*)
      case "$cc_basename" in
        xlc*)
          wl='-Wl,'
          ;;
      esac
      ;;
    mingw* | pw32* | os2*)
      ;;
    hpux9* | hpux10* | hpux11*)
      wl='-Wl,'
      ;;
    irix5* | irix6* | nonstopux*)
      wl='-Wl,'
      ;;
    newsos6)
      ;;
    linux*)
      case $CC in
        icc* | ecc*)
          wl='-Wl,'
          ;;
        ccc*)
          wl='-Wl,'
          ;;
        como)
          wl='-lopt='
          ;;
      esac
      ;;
    osf3* | osf4* | osf5*)
      wl='-Wl,'
      ;;
    sco3.2v5*)
      ;;
    solaris*)
      wl='-Wl,'
      ;;
    sunos4*)
      wl='-Qoption ld '
      ;;
    sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*)
      wl='-Wl,'
      ;;
    sysv4*MP*)
      ;;
    uts4*)
      ;;
  esac
fi

# Code taken from libtool.m4's AC_LIBTOOL_PROG_LD_SHLIBS.

export_dynamic_flag_spec=

case "$host_os" in
  cygwin* | mingw* | pw32*)
    # FIXME: the MSVC++ port hasn't been tested in a loooong time
    # When not using gcc, we currently assume that we are using
    # Microsoft Visual C++.
    if test "$GCC" != yes; then
      with_gnu_ld=no
    fi
    ;;
  openbsd*)
    with_gnu_ld=no
    ;;
esac

ld_shlibs=yes
if test "$with_gnu_ld" = yes; then
  case "$host_os" in
    aix3* | aix4* | aix5*)
      # On AIX/PPC, the GNU linker is very broken
      if test "$host_cpu" != ia64; then
        ld_shlibs=no
      fi
      ;;
    amigaos*)
      # Samuel A. Falvo II <kc5tja@dolphin.openprojects.net> reports
      # that the semantics of dynamic libraries on AmigaOS, at least up
      # to version 4, is to share data among multiple programs linked
      # with the same dynamic library.  Since this doesn't match the
      # behavior of shared libraries on other platforms, we cannot use
      # them.
      ld_shlibs=no
      ;;
    beos*)
      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
        :
      else
        ld_shlibs=no
      fi
      ;;
    cygwin* | mingw* | pw32*)
      if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
        :
      else
        ld_shlibs=no
      fi
      ;;
    netbsd*)
      ;;
    solaris* | sysv5*)
      if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
        ld_shlibs=no
      elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
        :
      else
        ld_shlibs=no
      fi
      ;;
    sunos4*)
      ;;
    linux*)
      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
        :
      else
        ld_shlibs=no
      fi
      ;;
    *)
      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
        :
      else
        ld_shlibs=no
      fi
      ;;
  esac
  if test "$ld_shlibs" = yes; then
    export_dynamic_flag_spec='${wl}--export-dynamic'
  fi
else
  case "$host_os" in
    aix3*)
      ;;
    aix4* | aix5*)
      ;;
    amigaos*)
      ;;
    bsdi[45]*)
      export_dynamic_flag_spec=-rdynamic
      ;;
    cygwin* | mingw* | pw32*)
      ;;
    darwin* | rhapsody*)
      ;;
    dgux*)
      ;;
    freebsd1*)
      ;;
    freebsd2.2*)
      ;;
    freebsd2*)
      ;;
    freebsd* | kfreebsd*-gnu)
      ;;
    hpux9*)
      export_dynamic_flag_spec='${wl}-E'
      ;;
    hpux10* | hpux11*)
      if test "$with_gnu_ld" = no; then
        case "$host_cpu" in
          hppa*64*)
            ;;
          ia64*)
            ;;
          *)
            export_dynamic_flag_spec='${wl}-E'
            ;;
        esac
      fi
      ;;
    irix5* | irix6* | nonstopux*)
      ;;
    netbsd*)
      ;;
    newsos6)
      ;;
    openbsd*)
      if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
        export_dynamic_flag_spec='${wl}-E'
      fi
      ;;
    os2*)
      ;;
    osf3*)
      ;;
    osf4* | osf5*)
      ;;
    sco3.2v5*)
      export_dynamic_flag_spec='${wl}-Bexport'
      ;;
    solaris*)
      ;;
    sunos4*)
      ;;
    sysv4)
      ;;
    sysv4.3*)
      export_dynamic_flag_spec='-Bexport'
      ;;
    sysv4*MP*)
      ;;
    sysv4.2uw2*)
      ;;
    sysv5OpenUNIX8* | sysv5UnixWare7* |  sysv5uw[78]* | unixware7*)
      ;;
    sysv5*)
      ;;
    uts4*)
      ;;
    *)
      ;;
  esac
fi

sed_quote_subst='s/\(["`$\\]\)/\\\1/g'
escaped_wl=`echo "X$wl" | sed -e 's/^X//' -e "$sed_quote_subst"`
escaped_export_dynamic_flag_spec=`echo "X$export_dynamic_flag_spec" | sed -e 's/^X//' -e "$sed_quote_subst"`

sed -e 's/^\([a-zA-Z0-9_]*\)=/acl_cv_\1=/' <<EOF

# How to pass a linker flag through the compiler.
wl="$escaped_wl"

# Flag to export symbols from an executable.
export_dynamic_flag_spec="$escaped_export_dynamic_flag_spec"

EOF
