Blame src/hwloc/config/hwloc_check_visibility.m4

Packit Service c5cf8c
# This macro set originally copied from Open MPI:
Packit Service c5cf8c
# Copyright © 2004-2005 The Trustees of Indiana University and Indiana
Packit Service c5cf8c
#                         University Research and Technology
Packit Service c5cf8c
#                         Corporation.  All rights reserved.
Packit Service c5cf8c
# Copyright © 2004-2005 The University of Tennessee and The University
Packit Service c5cf8c
#                         of Tennessee Research Foundation.  All rights
Packit Service c5cf8c
#                         reserved.
Packit Service c5cf8c
# Copyright © 2004-2007 High Performance Computing Center Stuttgart,
Packit Service c5cf8c
#                         University of Stuttgart.  All rights reserved.
Packit Service c5cf8c
# Copyright © 2004-2005 The Regents of the University of California.
Packit Service c5cf8c
#                         All rights reserved.
Packit Service c5cf8c
# Copyright © 2006-2007 Cisco Systems, Inc.  All rights reserved.
Packit Service c5cf8c
# and renamed/modified for hwloc:
Packit Service c5cf8c
# Copyright © 2009 Inria.  All rights reserved.
Packit Service c5cf8c
# Copyright © 2009-2010 Université Bordeaux
Packit Service c5cf8c
# Copyright © 2010-2012 Cisco Systems, Inc.  All rights reserved.
Packit Service c5cf8c
# See COPYING in top-level directory.
Packit Service c5cf8c
#
Packit Service c5cf8c
# Redistribution and use in source and binary forms, with or without
Packit Service c5cf8c
# modification, are permitted provided that the following conditions are
Packit Service c5cf8c
# met:
Packit Service c5cf8c
#
Packit Service c5cf8c
# - Redistributions of source code must retain the above copyright
Packit Service c5cf8c
#   notice, this list of conditions and the following disclaimer.
Packit Service c5cf8c
#
Packit Service c5cf8c
# - Redistributions in binary form must reproduce the above copyright
Packit Service c5cf8c
#   notice, this list of conditions and the following disclaimer listed
Packit Service c5cf8c
#   in this license in the documentation and/or other materials
Packit Service c5cf8c
#   provided with the distribution.
Packit Service c5cf8c
#
Packit Service c5cf8c
# - Neither the name of the copyright holders nor the names of its
Packit Service c5cf8c
#   contributors may be used to endorse or promote products derived from
Packit Service c5cf8c
#   this software without specific prior written permission.
Packit Service c5cf8c
#
Packit Service c5cf8c
# The copyright holders provide no reassurances that the source code
Packit Service c5cf8c
# provided does not infringe any patent, copyright, or any other
Packit Service c5cf8c
# intellectual property rights of third parties.  The copyright holders
Packit Service c5cf8c
# disclaim any liability to any recipient for claims brought against
Packit Service c5cf8c
# recipient by any third party for infringement of that parties
Packit Service c5cf8c
# intellectual property rights.
Packit Service c5cf8c
#
Packit Service c5cf8c
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit Service c5cf8c
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit Service c5cf8c
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit Service c5cf8c
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit Service c5cf8c
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit Service c5cf8c
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit Service c5cf8c
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit Service c5cf8c
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit Service c5cf8c
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit Service c5cf8c
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit Service c5cf8c
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service c5cf8c
#
Packit Service c5cf8c
Packit Service c5cf8c
# _HWLOC_CHECK_VISIBILITY
Packit Service c5cf8c
# --------------------------------------------------------
Packit Service c5cf8c
AC_DEFUN([_HWLOC_CHECK_VISIBILITY],[
Packit Service c5cf8c
    # Be safe for systems that have ancient Autoconf's (e.g., RHEL5)
Packit Service c5cf8c
    m4_ifdef([AC_PROG_GREP],
Packit Service c5cf8c
             [AC_REQUIRE([AC_PROG_GREP])],
Packit Service c5cf8c
             [GREP=grep])
Packit Service c5cf8c
Packit Service c5cf8c
    # Check if the compiler has support for visibility, like some
Packit Service c5cf8c
    # versions of gcc, icc, Sun Studio cc.
Packit Service c5cf8c
    AC_ARG_ENABLE(visibility,
Packit Service c5cf8c
        AC_HELP_STRING([--enable-visibility],
Packit Service c5cf8c
            [enable visibility feature of certain compilers/linkers (default: enabled on platforms that support it)]))
Packit Service c5cf8c
Packit Service c5cf8c
    case ${target} in
Packit Service c5cf8c
        *-*-aix*|*-*-mingw*|*-*-cygwin*|*-*-hpux*)
Packit Service c5cf8c
            enable_visibility=no
Packit Service c5cf8c
            ;;
Packit Service c5cf8c
    esac
Packit Service c5cf8c
Packit Service c5cf8c
    hwloc_visibility_define=0
Packit Service c5cf8c
    hwloc_msg="whether to enable symbol visibility"
Packit Service c5cf8c
    if test "$enable_visibility" = "no"; then
Packit Service c5cf8c
        AC_MSG_CHECKING([$hwloc_msg])
Packit Service c5cf8c
        AC_MSG_RESULT([no (disabled)])
Packit Service c5cf8c
    else
Packit Service c5cf8c
        CFLAGS_orig=$CFLAGS
Packit Service c5cf8c
Packit Service c5cf8c
        hwloc_add=
Packit Service c5cf8c
        case "$hwloc_c_vendor" in
Packit Service c5cf8c
        sun)
Packit Service c5cf8c
            # Check using Sun Studio -xldscope=hidden flag
Packit Service c5cf8c
            hwloc_add=-xldscope=hidden
Packit Service c5cf8c
            CFLAGS="$CFLAGS_orig $hwloc_add -errwarn=%all"
Packit Service c5cf8c
            ;;
Packit Service c5cf8c
Packit Service c5cf8c
        *)
Packit Service c5cf8c
            # Check using -fvisibility=hidden
Packit Service c5cf8c
            hwloc_add=-fvisibility=hidden
Packit Service c5cf8c
            CFLAGS="$CFLAGS_orig $hwloc_add -Werror"
Packit Service c5cf8c
            ;;
Packit Service c5cf8c
        esac
Packit Service c5cf8c
Packit Service c5cf8c
        AC_MSG_CHECKING([if $CC supports $hwloc_add])
Packit Service c5cf8c
        AC_LINK_IFELSE([AC_LANG_PROGRAM([[
Packit Service c5cf8c
            #include <stdio.h>
Packit Service c5cf8c
            __attribute__((visibility("default"))) int foo;
Packit Service c5cf8c
            ]],[[fprintf(stderr, "Hello, world\n");]])],
Packit Service c5cf8c
            [AS_IF([test -s conftest.err],
Packit Service c5cf8c
                   [$GREP -iq visibility conftest.err
Packit Service c5cf8c
                    # If we find "visibility" in the stderr, then
Packit Service c5cf8c
                    # assume it doesn't work
Packit Service c5cf8c
                    AS_IF([test "$?" = "0"], [hwloc_add=])])
Packit Service c5cf8c
            ], [hwloc_add=])
Packit Service c5cf8c
        AS_IF([test "$hwloc_add" = ""],
Packit Service c5cf8c
              [AC_MSG_RESULT([no])],
Packit Service c5cf8c
              [AC_MSG_RESULT([yes])])
Packit Service c5cf8c
Packit Service c5cf8c
        CFLAGS=$CFLAGS_orig
Packit Service c5cf8c
        HWLOC_VISIBILITY_CFLAGS=$hwloc_add
Packit Service c5cf8c
Packit Service c5cf8c
        if test "$hwloc_add" != "" ; then
Packit Service c5cf8c
            hwloc_visibility_define=1
Packit Service c5cf8c
            AC_MSG_CHECKING([$hwloc_msg])
Packit Service c5cf8c
            AC_MSG_RESULT([yes (via $hwloc_add)])
Packit Service c5cf8c
        elif test "$enable_visibility" = "yes"; then
Packit Service c5cf8c
            AC_MSG_ERROR([Symbol visibility support requested but compiler does not seem to support it.  Aborting])
Packit Service c5cf8c
        else
Packit Service c5cf8c
            AC_MSG_CHECKING([$hwloc_msg])
Packit Service c5cf8c
            AC_MSG_RESULT([no (unsupported)])
Packit Service c5cf8c
        fi
Packit Service c5cf8c
        unset hwloc_add
Packit Service c5cf8c
    fi
Packit Service c5cf8c
Packit Service c5cf8c
    AC_DEFINE_UNQUOTED([HWLOC_C_HAVE_VISIBILITY], [$hwloc_visibility_define],
Packit Service c5cf8c
            [Whether C compiler supports symbol visibility or not])
Packit Service c5cf8c
])