summaryrefslogtreecommitdiff
path: root/configure.ac
diff options
context:
space:
mode:
authorSam Thursfield <sam@afuera.me.uk>2017-07-21 12:33:49 +0100
committerCarlos Garnacho <carlosg@gnome.org>2017-08-09 17:12:02 +0200
commit213a8c015b0d233dc32ca3b2699da71c706958a7 (patch)
tree79fee0065119184dbc1edd3d9c55fb13c1b94f5b /configure.ac
parent9c2091d67d581fed07dae8dc4b0e0541bc6be3f8 (diff)
downloadlibmediaart-213a8c015b0d233dc32ca3b2699da71c706958a7.tar.gz
Use compiler symbol visiblity features to hide internal functions
Previously we relied on libtool's -export-symbols-regex feature, but we are hoping to drop GNU Autotools and GNU Libtool in soon in favour of Meson. Meson doesn't have an equivalent feature, instead the advice is to control symbol visibility at compile time. The approach taken in this patch is based on Pango's build system. Pango tells the compiler to hide symbols by default (if possible), and then defines a _PANGO_EXTERN variable at compile time which marks a single symbol as public. In Pango's case there is then further machinary to hide symbols based on deprecation policies but I have not copied that here, instead I used _LIBMEDIAART_EXTERN directly. If a compiler doesn't support hiding symbols then the library we build makes all symbols available, which is exactly what would happen before on platforms where the libtool didn't have an implementation for -export-symbols-regex. See also: http://mesonbuild.com/FAQ.html#how-do-i-do-the-equivalent-of-libtools-exportsymbol-and-exportregex https://git.gnome.org/browse/pango/ https://git.gnome.org/browse/pango/tree/pango/pango-version-macros.h https://gcc.gnu.org/wiki/Visibility https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options (-fvisibility) https://bugzilla.gnome.org/show_bug.cgi?id=783562
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac34
1 files changed, 34 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 9993b4e..74f0408 100644
--- a/configure.ac
+++ b/configure.ac
@@ -328,6 +328,40 @@ fi
AM_CONDITIONAL(HAVE_UNIT_TESTS, test "x$have_unit_tests" = "xyes")
+dnl *********************************************************************
+dnl * Check for -fvisibility=hidden to determine if we can do GNU-style *
+dnl * visibility attributes for symbol export control *
+dnl *********************************************************************
+
+LIBMEDIAART_HIDDEN_VISIBILITY_CFLAGS=""
+case "$host" in
+ *-*-mingw*)
+ dnl on mingw32 we do -fvisibility=hidden and __declspec(dllexport)
+ AC_DEFINE([_LIBMEDIAART_EXTERN], [__attribute__((visibility("default"))) __declspec(dllexport) extern],
+ [defines how to decorate public symbols while building])
+ CFLAGS="${CFLAGS} -fvisibility=hidden"
+ ;;
+ *)
+ dnl on other compilers, check if we can do -fvisibility=hidden
+ SAVED_CFLAGS="${CFLAGS}"
+ CFLAGS="-fvisibility=hidden"
+ AC_MSG_CHECKING([for -fvisibility=hidden compiler flag])
+ AC_TRY_COMPILE([], [return 0],
+ AC_MSG_RESULT(yes)
+ enable_fvisibility_hidden=yes,
+ AC_MSG_RESULT(no)
+ enable_fvisibility_hidden=no)
+ CFLAGS="${SAVED_CFLAGS}"
+
+ AS_IF([test "${enable_fvisibility_hidden}" = "yes"], [
+ AC_DEFINE([_LIBMEDIAART_EXTERN], [__attribute__((visibility("default"))) extern],
+ [defines how to decorate public symbols while building])
+ LIBMEDIAART_HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden"
+ ])
+ ;;
+esac
+AC_SUBST(LIBMEDIAART_HIDDEN_VISIBILITY_CFLAGS)
+
##################################################################
# Write generated files
##################################################################