From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Reding Subject: [RFC libdrm 1/6] configure: Support symbol visibility when available Date: Wed, 19 Feb 2014 17:04:48 +0100 Message-ID: <1392825893-7380-2-git-send-email-thierry.reding@gmail.com> References: <1392825893-7380-1-git-send-email-thierry.reding@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-bk0-f52.google.com (mail-bk0-f52.google.com [209.85.214.52]) by gabe.freedesktop.org (Postfix) with ESMTP id 9ED65F9D57 for ; Wed, 19 Feb 2014 08:05:00 -0800 (PST) Received: by mail-bk0-f52.google.com with SMTP id e11so270647bkh.11 for ; Wed, 19 Feb 2014 08:04:58 -0800 (PST) In-Reply-To: <1392825893-7380-1-git-send-email-thierry.reding@gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org To: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org From: Thierry Reding Checks whether or not the compiler supports the -fvisibility option. If so it sets the VISIBILITY_CFLAGS variable which can be added to the per directory AM_CFLAGS where appropriate. Libraries can use the HAVE_VISIBILITY preprocessor definition to check for availability and use something like this: #if defined(HAVE_VISIBILITY) # define drm_private __attribute__((visibility("hidden"))) # define drm_public __attribute__((visibility("default"))) #else # define drm_private # define drm_public #endif By default all symbols will be hidden via the VISIBILITY_CFLAGS. Only symbols explicitly marked drm_public will be exported. Signed-off-by: Thierry Reding --- configure.ac | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/configure.ac b/configure.ac index d2d19d66dc17..3f4164238494 100644 --- a/configure.ac +++ b/configure.ac @@ -365,6 +365,26 @@ AC_ARG_WITH([kernel-source], [kernel_source="$with_kernel_source"]) AC_SUBST(kernel_source) +dnl Add flags for gcc and g++ +if test "x$GCC" = xyes; then + # Enable -fvisibility=hidden if using a gcc that supports it + save_CFLAGS="$CFLAGS" + AC_MSG_CHECKING([whether $CC supports -fvisibility=hidden]) + VISIBILITY_CFLAGS="-fvisibility=hidden" + CFLAGS="$CFLAGS $VISIBILITY_CFLAGS" + AC_LINK_IFELSE([AC_LANG_PROGRAM()], AC_MSG_RESULT([yes]), + [VISIBILITY_CFLAGS=""; AC_MSG_RESULT([no])]); + + # Restore CFLAGS; VISIBILITY_CFLAGS are added to it where needed. + CFLAGS=$save_CFLAGS + + if test "x$VISIBILITY_CFLAGS" != x; then + AC_DEFINE(HAVE_VISIBILITY, 1, [Compiler has -fvisibility support]) + fi + + AC_SUBST([VISIBILITY_CFLAGS]) +fi + AC_SUBST(WARN_CFLAGS) AC_CONFIG_FILES([ Makefile -- 1.8.4.2