1# This macro set originally copied from Open MPI:
2# Copyright © 2004-2005 The Trustees of Indiana University and Indiana
3#                         University Research and Technology
4#                         Corporation.  All rights reserved.
5# Copyright © 2004-2005 The University of Tennessee and The University
6#                         of Tennessee Research Foundation.  All rights
7#                         reserved.
8# Copyright © 2004-2007 High Performance Computing Center Stuttgart,
9#                         University of Stuttgart.  All rights reserved.
10# Copyright © 2004-2005 The Regents of the University of California.
11#                         All rights reserved.
12# Copyright © 2006-2007 Cisco Systems, Inc.  All rights reserved.
13# and renamed/modified for hwloc:
14# Copyright © 2009 Inria.  All rights reserved.
15# Copyright © 2009-2010 Université Bordeaux
16# Copyright © 2010-2012 Cisco Systems, Inc.  All rights reserved.
17# See COPYING in top-level directory.
18#
19# Redistribution and use in source and binary forms, with or without
20# modification, are permitted provided that the following conditions are
21# met:
22#
23# - Redistributions of source code must retain the above copyright
24#   notice, this list of conditions and the following disclaimer.
25#
26# - Redistributions in binary form must reproduce the above copyright
27#   notice, this list of conditions and the following disclaimer listed
28#   in this license in the documentation and/or other materials
29#   provided with the distribution.
30#
31# - Neither the name of the copyright holders nor the names of its
32#   contributors may be used to endorse or promote products derived from
33#   this software without specific prior written permission.
34#
35# The copyright holders provide no reassurances that the source code
36# provided does not infringe any patent, copyright, or any other
37# intellectual property rights of third parties.  The copyright holders
38# disclaim any liability to any recipient for claims brought against
39# recipient by any third party for infringement of that parties
40# intellectual property rights.
41#
42# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
45# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
46# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
48# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
52# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53#
54
55# _HWLOC_CHECK_VISIBILITY
56# --------------------------------------------------------
57AC_DEFUN([_HWLOC_CHECK_VISIBILITY],[
58    # Be safe for systems that have ancient Autoconf's (e.g., RHEL5)
59    m4_ifdef([AC_PROG_GREP],
60             [AC_REQUIRE([AC_PROG_GREP])],
61             [GREP=grep])
62
63    # Check if the compiler has support for visibility, like some
64    # versions of gcc, icc, Sun Studio cc.
65    AC_ARG_ENABLE(visibility,
66        AC_HELP_STRING([--enable-visibility],
67            [enable visibility feature of certain compilers/linkers (default: enabled on platforms that support it)]))
68
69    case ${target} in
70        *-*-aix*|*-*-mingw*|*-*-cygwin*|*-*-hpux*)
71            enable_visibility=no
72            ;;
73    esac
74
75    hwloc_visibility_define=0
76    hwloc_msg="whether to enable symbol visibility"
77    if test "$enable_visibility" = "no"; then
78        AC_MSG_CHECKING([$hwloc_msg])
79        AC_MSG_RESULT([no (disabled)])
80    else
81        CFLAGS_orig=$CFLAGS
82
83        hwloc_add=
84        case "$hwloc_c_vendor" in
85        sun)
86            # Check using Sun Studio -xldscope=hidden flag
87            hwloc_add=-xldscope=hidden
88            CFLAGS="$CFLAGS_orig $hwloc_add -errwarn=%all"
89            ;;
90
91        *)
92            # Check using -fvisibility=hidden
93            hwloc_add=-fvisibility=hidden
94            CFLAGS="$CFLAGS_orig $hwloc_add -Werror"
95            ;;
96        esac
97
98        AC_MSG_CHECKING([if $CC supports $hwloc_add])
99        AC_LINK_IFELSE([AC_LANG_PROGRAM([[
100            #include <stdio.h>
101            __attribute__((visibility("default"))) int foo;
102            ]],[[fprintf(stderr, "Hello, world\n");]])],
103            [AS_IF([test -s conftest.err],
104                   [$GREP -iq visibility conftest.err
105                    # If we find "visibility" in the stderr, then
106                    # assume it doesn't work
107                    AS_IF([test "$?" = "0"], [hwloc_add=])])
108            ], [hwloc_add=])
109        AS_IF([test "$hwloc_add" = ""],
110              [AC_MSG_RESULT([no])],
111              [AC_MSG_RESULT([yes])])
112
113        CFLAGS=$CFLAGS_orig
114        HWLOC_VISIBILITY_CFLAGS=$hwloc_add
115
116        if test "$hwloc_add" != "" ; then
117            hwloc_visibility_define=1
118            AC_MSG_CHECKING([$hwloc_msg])
119            AC_MSG_RESULT([yes (via $hwloc_add)])
120        elif test "$enable_visibility" = "yes"; then
121            AC_MSG_ERROR([Symbol visibility support requested but compiler does not seem to support it.  Aborting])
122        else
123            AC_MSG_CHECKING([$hwloc_msg])
124            AC_MSG_RESULT([no (unsupported)])
125        fi
126        unset hwloc_add
127    fi
128
129    AC_DEFINE_UNQUOTED([HWLOC_C_HAVE_VISIBILITY], [$hwloc_visibility_define],
130            [Whether C compiler supports symbol visibility or not])
131])
132