[glib] visibility: Use a separate CFLAGS variable



commit 5d42fdd068bddaaf7e42b7aaca2c15e931ebf3c5
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Jan 14 23:24:53 2013 -0500

    visibility: Use a separate CFLAGS variable
    
    We only want to control the default visibility for our five main
    installable libraries: libglib, libgthread, libgmodule, libgobject,
    libgio.  We should therefore only set -fvisibility=hidden when building
    those.
    
    Use a separate substitution variable for this purpose.
    
    Using CFLAGS directly leads to some modules built in testcases not
    exporting their symbols (and then the tests fail).  It also affects the
    fam file monitoring module.
    
    Colin had originally done it this way in his visibility patch series but
    I failed to understand why so I didn't copy it.  Now I do.
    
    Also: revert changes made to two testcases in an attempt to work around
    this issue.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=691756

 configure.ac                  |    4 +++-
 gio/Makefile.am               |    3 ++-
 gio/tests/resourceplugin.c    |    8 +++-----
 glib/Makefile.am              |    1 +
 gmodule/Makefile.am           |    1 +
 gobject/Makefile.am           |    2 +-
 gthread/Makefile.am           |    1 +
 tests/libmoduletestplugin_a.c |   20 ++++++++------------
 tests/libmoduletestplugin_b.c |   19 ++++++++-----------
 tests/module-test.c           |    6 ++----
 10 files changed, 30 insertions(+), 35 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9e48f90..eb9a505 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3570,6 +3570,7 @@ dnl
 dnl Check for -fvisibility=hidden to determine if we can do GNU-style
 dnl visibility attributes for symbol export control
 dnl
+GLIB_HIDDEN_VISIBILITY_CFLAGS=""
 case "$host" in
   *-*-mingw*)
     dnl on mingw32 we do -fvisibility=hidden and __declspec(dllexport)
@@ -3592,10 +3593,11 @@ case "$host" in
     AS_IF([test "${enable_fvisibility_hidden}" = "yes"], [
       AC_DEFINE([_GLIB_EXTERN], [__attribute__((visibility("default"))) extern],
                 [defines how to decorate public symbols while building])
-      CFLAGS="${CFLAGS} -fvisibility=hidden"
+      GLIB_HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden"
     ])
     ;;
 esac
+AC_SUBST(GLIB_HIDDEN_VISIBILITY_CFLAGS)
 
 dnl Compiler flags; macro originates from systemd
 dnl See https://bugzilla.gnome.org/show_bug.cgi?id=608953
diff --git a/gio/Makefile.am b/gio/Makefile.am
index b4edecf..7d6f915 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -501,6 +501,7 @@ install-data-local: install-ms-lib
 
 uninstall-local: uninstall-ms-lib
 
+libgio_2_0_la_CFLAGS = $(AM_CFLAGS) $(GLIB_HIDDEN_VISIBILITY_CFLAGS)
 libgio_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	$(gio_win32_res_ldflag) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
@@ -508,7 +509,7 @@ libgio_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 
 if OS_COCOA
 # This is dumb.  The ObjC source file should be properly named .m
-libgio_2_0_la_CFLAGS = -xobjective-c
+libgio_2_0_la_CFLAGS += -xobjective-c
 libgio_2_0_la_LDFLAGS += -Wl,-framework,Foundation
 endif
 
diff --git a/gio/tests/resourceplugin.c b/gio/tests/resourceplugin.c
index 9e3b704..b66d541 100644
--- a/gio/tests/resourceplugin.c
+++ b/gio/tests/resourceplugin.c
@@ -1,18 +1,16 @@
-#include "config.h"
-
 #include <gio/gio.h>
 
-_GLIB_EXTERN void
+void
 g_io_module_load (GIOModule *module)
 {
 }
 
-_GLIB_EXTERN void
+void
 g_io_module_unload (GIOModule   *module)
 {
 }
 
-_GLIB_EXTERN char **
+char **
 g_io_module_query (void)
 {
   return NULL;
diff --git a/glib/Makefile.am b/glib/Makefile.am
index 951d102..98c5978 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -360,6 +360,7 @@ pcre_lib = pcre/libpcre.la
 pcre_inc =
 endif
 
+libglib_2_0_la_CFLAGS = $(AM_CFLAGS) $(GLIB_HIDDEN_VISIBILITY_CFLAGS)
 libglib_2_0_la_LIBADD = libcharset/libcharset.la $(printf_la) @GIO@ @GSPAWN@ @PLATFORMDEP@ @ICONV_LIBS@ @G_LIBS_EXTRA@ $(pcre_lib) $(G_THREAD_LIBS_EXTRA) $(G_THREAD_LIBS_FOR_GTHREAD)
 libglib_2_0_la_DEPENDENCIES = libcharset/libcharset.la $(printf_la) @GIO@ @GSPAWN@ @PLATFORMDEP@ $(glib_win32_res) $(glib_def)
 
diff --git a/gmodule/Makefile.am b/gmodule/Makefile.am
index 19737fa..92b844a 100644
--- a/gmodule/Makefile.am
+++ b/gmodule/Makefile.am
@@ -62,6 +62,7 @@ gmodule_win32_res = gmodule-win32-res.o
 gmodule_win32_res_ldflag = -Wl,$(gmodule_win32_res)
 endif
 
+libgmodule_2_0_la_CFLAGS = $(AM_CFLAGS) $(GLIB_HIDDEN_VISIBILITY_CFLAGS)
 libgmodule_2_0_la_SOURCES = gmodule.c
 libgmodule_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	$(gmodule_win32_res_ldflag) \
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index 24143f7..615a780 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -62,7 +62,7 @@ libgobject_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
   -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
   -export-dynamic $(no_undefined) $(export_symbols)
 
-libgobject_2_0_la_CFLAGS = $(LIBFFI_CFLAGS)
+libgobject_2_0_la_CFLAGS = $(AM_CFLAGS) $(LIBFFI_CFLAGS) $(GLIB_HIDDEN_VISIBILITY_CFLAGS)
 
 libgobject_2_0_la_LIBADD = $(libglib) $(LIBFFI_LIBS)
 
diff --git a/gthread/Makefile.am b/gthread/Makefile.am
index 325fec4..2aa5078 100644
--- a/gthread/Makefile.am
+++ b/gthread/Makefile.am
@@ -60,6 +60,7 @@ gthread_win32_res = gthread-win32-res.o
 gthread_win32_res_ldflag = -Wl,$(gthread_win32_res)
 endif
 
+libgthread_2_0_la_CFLAGS = $(AM_CFLAGS) $(GLIB_HIDDEN_VISIBILITY_CFLAGS)
 libgthread_2_0_la_SOURCES = gthread-impl.c
 libgthread_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	$(gthread_win32_res_ldflag) \
diff --git a/tests/libmoduletestplugin_a.c b/tests/libmoduletestplugin_a.c
index 3ce43da..69fdd0f 100644
--- a/tests/libmoduletestplugin_a.c
+++ b/tests/libmoduletestplugin_a.c
@@ -27,11 +27,8 @@
 #undef G_DISABLE_ASSERT
 #undef G_LOG_DOMAIN
 
-#include "config.h"
-
-#include <glib.h>
-#include <gmodule.h>
-#include <stdlib.h>
+#include	<gmodule.h>
+#include	<stdlib.h>
 
 void gplugin_a_func (void);
 void gplugin_clash_func (void);
@@ -39,34 +36,33 @@ void g_clash_func (void);
 void gplugin_say_boo_func (void);
 void gplugin_a_module_func (GModule *module);
 
-_GLIB_EXTERN gchar* gplugin_a_state;
-gchar* gplugin_a_state;
+G_MODULE_EXPORT gchar* gplugin_a_state;
 
-_GLIB_EXTERN void
+G_MODULE_EXPORT void
 gplugin_a_func (void)
 {
   gplugin_a_state = "Hello world";
 }
 
-_GLIB_EXTERN void
+G_MODULE_EXPORT void
 gplugin_clash_func (void)
 {
   gplugin_a_state = "plugin clash";
 }
 
-_GLIB_EXTERN void
+G_MODULE_EXPORT void
 g_clash_func (void)
 {
   gplugin_a_state = "global clash";
 }
 
-_GLIB_EXTERN void
+G_MODULE_EXPORT void
 gplugin_say_boo_func (void)
 {
   gplugin_a_state = "BOOH";
 }
 
-_GLIB_EXTERN void
+G_MODULE_EXPORT void
 gplugin_a_module_func (GModule *module)
 {
   void *f = NULL;
diff --git a/tests/libmoduletestplugin_b.c b/tests/libmoduletestplugin_b.c
index 11e3ccf..26cc33f 100644
--- a/tests/libmoduletestplugin_b.c
+++ b/tests/libmoduletestplugin_b.c
@@ -27,12 +27,9 @@
 #undef G_DISABLE_ASSERT
 #undef G_LOG_DOMAIN
 
-#include "config.h"
+#include        <gmodule.h>
 
-#include <gmodule.h>
-
-_GLIB_EXTERN gchar* gplugin_b_state;
-gchar* gplugin_b_state;
+G_MODULE_EXPORT gchar* gplugin_b_state;
 
 const gchar* g_module_check_init (GModule *module);
 void   g_module_unload (GModule *module);
@@ -42,7 +39,7 @@ void gplugin_clash_func (void);
 void g_clash_func (void);
 void gplugin_say_boo_func (void);
 
-_GLIB_EXTERN const gchar*
+G_MODULE_EXPORT const gchar*
 g_module_check_init (GModule *module)
 {
   gplugin_b_state = "check-init";
@@ -50,31 +47,31 @@ g_module_check_init (GModule *module)
   return NULL;
 }
 
-_GLIB_EXTERN void
+G_MODULE_EXPORT void
 g_module_unload (GModule *module)
 {
   gplugin_b_state = "unloaded";
 }
 
-_GLIB_EXTERN void
+G_MODULE_EXPORT void
 gplugin_b_func (void)
 {
   gplugin_b_state = "Hello world";
 }
 
-_GLIB_EXTERN void
+G_MODULE_EXPORT void
 gplugin_clash_func (void)
 {
   gplugin_b_state = "plugin clash";
 }
 
-_GLIB_EXTERN void
+G_MODULE_EXPORT void
 g_clash_func (void)
 {
   gplugin_b_state = "global clash";
 }
 
-_GLIB_EXTERN void
+G_MODULE_EXPORT void
 gplugin_say_boo_func (void)
 {
   gplugin_b_state = "BOOH";
diff --git a/tests/module-test.c b/tests/module-test.c
index 4b195d3..dd99b71 100644
--- a/tests/module-test.c
+++ b/tests/module-test.c
@@ -27,16 +27,14 @@
 #undef G_DISABLE_ASSERT
 #undef G_LOG_DOMAIN
 
-#include "config.h"
-
 #include <gmodule.h>
 #include <string.h>
 
 gchar* global_state;
 
-_GLIB_EXTERN void g_clash_func (void);
+G_MODULE_EXPORT void g_clash_func (void);
 
-_GLIB_EXTERN void
+G_MODULE_EXPORT void
 g_clash_func (void)
 {
   global_state = "global clash";



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]