[glib/wip/symbol-visibility: 1/6] build: Make .symbols file canonical on all platforms



commit a2a81273386fd59f54dd648b740c8afedc14ab8f
Author: Colin Walters <walters verbum org>
Date:   Mon Nov 19 16:51:51 2012 -0500

    build: Make .symbols file canonical on all platforms
    
    Previously:
    * On Unix, an -export-symbol-regex (g_)|(glib_) was used, and the .symbols
      files were used in "make check"
    * On Windows, the .symbols files are massaged into a format which MSVC
      expects as an export list
    
    Now:
    
    * On both Unix and Windows, the .symbols file is used as the list of
      symbols to export, and code to generate the exported list per
      platform is unified.  Even symbols starting with g_ are not exported
      unless they are in the file.  The abicheck.sh tools are deleted.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688681

 configure.ac                |   10 ---------
 gio/Makefile.am             |   24 +++++-----------------
 gio/abicheck.sh             |   13 ------------
 glib/Makefile.am            |   23 ++++-----------------
 glib/abicheck.sh            |   13 ------------
 glib/process-symbol-file.sh |   44 +++++++++++++++++++++++++++++++++++++++++++
 gmodule/Makefile.am         |   13 +++++------
 gobject/Makefile.am         |   22 ++++----------------
 gobject/abicheck.sh         |   13 ------------
 gthread/Makefile.am         |   12 +++++-----
 gthread/gthread.def         |    5 +--
 gthread/gthread.symbols     |    2 +
 12 files changed, 76 insertions(+), 118 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 27b33d1..9a834bb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -209,16 +209,6 @@ AS_IF([test "$glib_native_win32" = "yes"], [
 ])
 AM_CONDITIONAL(MS_LIB_AVAILABLE, [test x$ms_librarian = xyes])
 
-if test "$glib_native_win32" != yes; then
-    # libtool option to control which symbols are exported
-    # right now, symbols starting with _ are not exported
-    LIBTOOL_EXPORT_OPTIONS='-export-symbols-regex "^g.*"'
-else
-    # We currently use .def files on Windows
-    LIBTOOL_EXPORT_OPTIONS=
-fi
-AC_SUBST(LIBTOOL_EXPORT_OPTIONS)
-
 AS_IF([test "x$glib_have_carbon" = "xyes"], [
   AC_DEFINE(HAVE_CARBON, 1, [define to 1 if Carbon is available])
   LDFLAGS="$LDFLAGS -Wl,-framework,Carbon"
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 683ff07..e8f4865 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -1,6 +1,7 @@
 include $(top_srcdir)/Makefile.decl
 
 NULL =
+BUILT_SOURCES =
 
 SUBDIRS = gdbus-2.0/codegen
 
@@ -23,15 +24,8 @@ install-ms-lib:
 uninstall-ms-lib:
 	$(uninstall_ms_lib_cmd)
 
-gio.def: gio.symbols
-	$(AM_V_GEN) (echo EXPORTS; $(CPP) -P -DINCLUDE_VARIABLES -DINCLUDE_INTERNAL_SYMBOLS -DG_OS_WIN32 -DALL_FILES - <$(srcdir)/gio.symbols | sed -e '/^$$/d' -e 's/^/	/' -e 's/G_GNUC_[^ ]*//g' | sort) > $(builddir)/gio.def.tmp && \
-	  mv $(builddir)/gio.def.tmp $(builddir)/gio.def
-
-if OS_LINUX
-if HAVE_GNUC_VISIBILITY
-TESTS = abicheck.sh
-endif
-endif
+gio.def: gio.symbols $(top_builddir)/glib/glibconfig.h $(top_srcdir)/glib/process-symbol-file.sh Makefile
+	$(AM_V_GEN) env GLIB_DEBUG_FLAGS="$(GLIB_DEBUG_FLAGS)" $(top_srcdir)/glib/process-symbol-file.sh $< $@
 
 AM_CPPFLAGS = \
 	-DG_LOG_DOMAIN=\"GLib-GIO\"			\
@@ -493,9 +487,6 @@ no_undefined = -no-undefined
 endif
 
 if OS_WIN32_AND_DLL_COMPILATION
-export_symbols = -export-symbols $(builddir)/gio.def
-gio_def = gio.def
-
 gio_win32_res = gio-win32-res.o
 gio_win32_res_ldflag = -Wl,$(gio_win32_res)
 
@@ -507,8 +498,6 @@ uninstall-def-file:
 else
 install-def-file:
 uninstall-def-file:
-
-export_symbols = $(LIBTOOL_EXPORT_OPTIONS)
 endif
 
 install-data-local: install-ms-lib install-def-file
@@ -519,7 +508,7 @@ uninstall-local: uninstall-ms-lib uninstall-def-file
 libgio_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	$(gio_win32_res_ldflag) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-	-export-dynamic $(no_undefined) $(export_symbols)
+	-export-dynamic $(no_undefined) -export-symbols gio.def
 
 if OS_COCOA
 # This is dumb.  The ObjC source file should be properly named .m
@@ -527,7 +516,7 @@ libgio_2_0_la_CFLAGS = -xobjective-c
 libgio_2_0_la_LDFLAGS += -Wl,-framework,Foundation
 endif
 
-libgio_2_0_la_DEPENDENCIES = $(gio_win32_res) $(gio_def) $(platform_deps)
+libgio_2_0_la_DEPENDENCIES = $(gio_win32_res) gio.def $(platform_deps)
 
 gio-win32-res.o: gio.rc
 	$(WINDRES) gio.rc $@
@@ -637,7 +626,7 @@ gioinclude_HEADERS = 		\
 	gioenumtypes.h
 
 # these sources (also mentioned above) are generated.
-BUILT_SOURCES = 		\
+BUILT_SOURCES += 		\
 	gconstructor_as_data.h	\
 	gioenumtypes.h		\
 	gioenumtypes.c		\
@@ -651,7 +640,6 @@ EXTRA_DIST += 			\
 	gioenumtypes.h.template	\
 	gioenumtypes.c.template	\
 	makefile.msc		\
-	abicheck.sh		\
 	gio.rc.in		\
 	gschema.dtd		\
 	gconstructor_as_data.h	\
diff --git a/glib/Makefile.am b/glib/Makefile.am
index 3168b1a..e3d50b3 100644
--- a/glib/Makefile.am
+++ b/glib/Makefile.am
@@ -49,15 +49,8 @@ AM_CPPFLAGS = 				\
 	-DGLIB_COMPILATION 		\
 	-DPCRE_STATIC
 
-glib.def: glib.symbols
-	$(AM_V_GEN) (echo EXPORTS; $(CPP) -P -DG_OS_WIN32 - <$(srcdir)/glib.symbols | sed -e '/^$$/d' -e 's/^/	/') > $(builddir)/glib.def
-
-if OS_LINUX
-if HAVE_GNUC_VISIBILITY
-TESTS_ENVIRONMENT = GLIB_DEBUG_FLAGS="$(GLIB_DEBUG_FLAGS)"
-TESTS = abicheck.sh
-endif
-endif
+glib.def: glib.symbols $(top_builddir)/glib/glibconfig.h $(top_srcdir)/glib/process-symbol-file.sh Makefile
+	$(AM_V_GEN) env GLIB_DEBUG_FLAGS="$(GLIB_DEBUG_FLAGS)" $(top_srcdir)/glib/process-symbol-file.sh $< $@
 
 MIRRORING_TAB_SOURCE = 				\
 	glib-mirroring-tab/Makefile 		\
@@ -74,7 +67,7 @@ EXTRA_DIST += 			\
 	gen-unicode-tables.pl	\
 	gen-script-table.pl	\
 	glibconfig.h.win32.in	\
-	abicheck.sh		\
+	process-symbol-file.sh	\
 	glib.symbols		\
 	gregex.c		\
 	gregex.h		\
@@ -349,13 +342,9 @@ no_undefined = -no-undefined
 endif
 
 if OS_WIN32_AND_DLL_COMPILATION
-export_symbols = -export-symbols $(builddir)/glib.def
-
 glib_win32_res = glib-win32-res.o
 glib_win32_res_ldflag = -Wl,$(glib_win32_res)
 
-glib_def = glib.def
-
 install-def-file:
 	$(INSTALL) $(builddir)/glib.def $(DESTDIR)$(libdir)/glib-2.0.def
 
@@ -364,8 +353,6 @@ uninstall-def-file:
 else
 install-def-file:
 uninstall-def-file:
-
-export_symbols = $(LIBTOOL_EXPORT_OPTIONS)
 endif
 
 if USE_SYSTEM_PCRE
@@ -377,12 +364,12 @@ pcre_inc =
 endif
 
 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)
+libglib_2_0_la_DEPENDENCIES = libcharset/libcharset.la $(printf_la) @GIO@ @GSPAWN@ @PLATFORMDEP@ $(glib_win32_res) glib.def
 
 libglib_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	 $(glib_win32_res_ldflag) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-	-export-dynamic $(no_undefined) $(export_symbols)
+	-export-dynamic $(no_undefined) -export-symbols glib.def
 
 INSTALL_PROGS=
 
diff --git a/glib/process-symbol-file.sh b/glib/process-symbol-file.sh
new file mode 100755
index 0000000..1a81f38
--- /dev/null
+++ b/glib/process-symbol-file.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+# Process a .symbol file which is a list of symbols, one per line,
+# with C preprocessor conditionals.  Some symbols maybe suffixed
+# PRIVATE, which is ignored on Unix.
+
+set -e
+
+SYMBOLFILE=$1
+OUTPUT=$2
+
+usage () {
+    echo "$0: usage: [--win32] SYMBOLFILE OUTPUT"
+    exit 1
+}
+
+test -n "$SYMBOLFILE" || usage
+test -n "$OUTPUT" || usage
+
+egrep '^#([^i]|if).*[^\]$' "${top_builddir:-..}/glib/glibconfig.h" > glibconfig.cpp
+
+if egrep '^#define G_OS_WIN32' glibconfig.cpp; then
+    win32_mode=true
+else
+    win32_mode=false
+fi
+
+INCLUDES="-include ${top_builddir:-..}/config.h"
+INCLUDES="$INCLUDES -include glibconfig.cpp $GLIB_DEBUG_FLAGS"
+
+rm -f $OUTPUT.tmp
+touch $OUTPUT.tmp
+if $win32_mode; then
+    INCLUDES="$INCLUDES -DG_OS_WIN32"
+    SED_ARG='s/^/	/'
+    echo EXPORTS >> $OUTPUT.tmp
+else
+    INCLUDES="$INCLUDES -DG_STDIO_NO_WRAP_ON_UNIX"
+    SED_ARG='s/ PRIVATE$//'
+fi
+    
+cpp -P  $INCLUDES $SYMBOLFILE | sed -e '/^$/d' -e "$SED_ARG" >> $OUTPUT.tmp && mv $OUTPUT.tmp $OUTPUT
+
+rm -f glibconfig.cpp
+
diff --git a/gmodule/Makefile.am b/gmodule/Makefile.am
index 5e08c11..c797414 100644
--- a/gmodule/Makefile.am
+++ b/gmodule/Makefile.am
@@ -1,6 +1,8 @@
 ## Process this file with automake to produce Makefile.in
 include $(top_srcdir)/Makefile.decl
 
+BUILT_SOURCES =
+
 AM_CPPFLAGS = 				\
 	$(glib_INCLUDES) 		\
 	-DG_LOG_DOMAIN=\"GModule\" 	\
@@ -8,7 +10,7 @@ AM_CPPFLAGS = 				\
 	-DG_DISABLE_DEPRECATED
 
 gmodule.def: gmodule.symbols
-	$(AM_V_GEN) (echo EXPORTS; $(CPP) -P - <$(srcdir)/gmodule.symbols | sed -e '/^$$/d' -e 's/^/	/') > $(builddir)/gmodule.def
+	$(AM_V_GEN) env GLIB_DEBUG_FLAGS="$(GLIB_DEBUG_FLAGS)" $(top_srcdir)/glib/process-symbol-file.sh $< $@
 
 EXTRA_DIST +=				\
 		makefile.msc.in 	\
@@ -28,7 +30,7 @@ BUILT_EXTRA_DIST = \
 		makefile.msc	\
 		gmodule.rc
 
-BUILT_SOURCES = gmoduleconf.h
+BUILT_SOURCES += gmoduleconf.h
 gmoduleconf.h:	gmoduleconf.h.in
 
 glibincludedir=$(includedir)/glib-2.0
@@ -61,9 +63,6 @@ no_undefined = -no-undefined
 endif
 
 if OS_WIN32_AND_DLL_COMPILATION
-export_symbols = -export-symbols $(builddir)/gmodule.def
-gmodule_def = gmodule.def
-
 gmodule_win32_res = gmodule-win32-res.o
 gmodule_win32_res_ldflag = -Wl,$(gmodule_win32_res)
 
@@ -82,11 +81,11 @@ libgmodule_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	$(gmodule_win32_res_ldflag) \
 	$(G_MODULE_LDFLAGS) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-	-export-dynamic $(no_undefined) $(export_symbols)
+	-export-dynamic $(no_undefined) -export-symbols gmodule.def
 
 libgmodule_2_0_la_LIBADD = $(G_MODULE_LIBS_EXTRA) $(G_MODULE_LIBS) $(libglib)
 
-libgmodule_2_0_la_DEPENDENCIES = $(gmodule_win32_res) $(gmodule_def)
+libgmodule_2_0_la_DEPENDENCIES = $(gmodule_win32_res) gmodule.def
 
 gmodule-win32-res.o: gmodule.rc
 	$(AM_V_GEN) $(WINDRES) gmodule.rc $@
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index d7c15d1..9c6eb09 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -18,14 +18,8 @@ AM_CPPFLAGS = 					\
 	$(GLIB_DEBUG_FLAGS)			\
 	-DGOBJECT_COMPILATION
 
-gobject.def: gobject.symbols
-	$(AM_V_GEN) (echo EXPORTS; $(CPP) -P -DINCLUDE_VARIABLES -DINCLUDE_INTERNAL_SYMBOLS -DG_OS_WIN32 -DALL_FILES - <$(srcdir)/gobject.symbols | $(SED) -e '/^$$/d' -e 's/^/	/' -e 's/G_GNUC_[^ ]*//g' | sort) > $(builddir)/gobject.def
-
-if OS_LINUX
-if HAVE_GNUC_VISIBILITY
-TESTS = abicheck.sh
-endif
-endif
+gobject.def: gobject.symbols $(top_builddir)/glib/glibconfig.h $(top_srcdir)/glib/process-symbol-file.sh Makefile
+	$(AM_V_GEN) env GLIB_DEBUG_FLAGS="$(GLIB_DEBUG_FLAGS)" $(top_srcdir)/glib/process-symbol-file.sh $< $@
 
 libglib = $(top_builddir)/glib/libglib-2.0.la
 
@@ -52,9 +46,6 @@ no_undefined = -no-undefined
 endif
 
 if OS_WIN32_AND_DLL_COMPILATION
-export_symbols = -export-symbols $(builddir)/gobject.def
-gobject_def = gobject.def
-
 gobject_win32_res = gobject-win32-res.o
 gobject_win32_res_ldflag = -Wl,$(gobject_win32_res)
 
@@ -66,8 +57,6 @@ uninstall-def-file:
 else
 install-def-file:
 uninstall-def-file:
-
-export_symbols = $(LIBTOOL_EXPORT_OPTIONS)
 endif
 
 # libtool stuff: set version and export symbols for resolving
@@ -75,13 +64,13 @@ libgobjectincludedir = $(includedir)/glib-2.0/gobject
 libgobject_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
   $(gobject_win32_res_ldflag) \
   -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-  -export-dynamic $(no_undefined) $(export_symbols)
+  -export-dynamic $(no_undefined) -export-symbols gobject.def
 
 libgobject_2_0_la_CFLAGS = $(LIBFFI_CFLAGS)
 
 libgobject_2_0_la_LIBADD = $(libglib) $(LIBFFI_LIBS)
 
-libgobject_2_0_la_DEPENDENCIES = $(gobject_win32_res) $(gobject_def)
+libgobject_2_0_la_DEPENDENCIES = $(gobject_win32_res) gobject.def
 
 #
 # setup source file variables
@@ -232,8 +221,7 @@ EXTRA_DIST += 			\
 	makefile.msc.in 	\
 	gobject.rc.in		\
 	libgobject-gdb.py.in	\
-	glib-mkenums.in		\
-	abicheck.sh
+	glib-mkenums.in
 
 CLEANFILES += libgobject-gdb.py
 
diff --git a/gthread/Makefile.am b/gthread/Makefile.am
index 325fec4..73859d0 100644
--- a/gthread/Makefile.am
+++ b/gthread/Makefile.am
@@ -7,9 +7,12 @@ AM_CPPFLAGS = 				\
 	@GTHREAD_COMPILE_IMPL_DEFINES@ 	\
 	@GLIB_DEBUG_FLAGS@
 
+gthread.def: gthread.symbols $(top_builddir)/glib/glibconfig.h $(top_srcdir)/glib/process-symbol-file.sh Makefile
+	$(AM_V_GEN) env GLIB_DEBUG_FLAGS="$(GLIB_DEBUG_FLAGS)" $(top_srcdir)/glib/process-symbol-file.sh $< $@
+
 EXTRA_DIST +=				\
 		makefile.msc.in		\
-		gthread.def		\
+		gthread.symbols		\
 		gthread.rc.in
 
 BUILT_EXTRA_DIST = 			\
@@ -42,9 +45,6 @@ no_undefined = -no-undefined
 endif
 
 if OS_WIN32_AND_DLL_COMPILATION
-export_symbols = -export-symbols $(srcdir)/gthread.def
-gthread_def = gthread.def
-
 install-def-file:
 	$(INSTALL) $(srcdir)/gthread.def $(DESTDIR)$(libdir)/gthread-2.0.def
 
@@ -64,11 +64,11 @@ libgthread_2_0_la_SOURCES = gthread-impl.c
 libgthread_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \
 	$(gthread_win32_res_ldflag) \
 	-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-	-export-dynamic $(no_undefined) $(export_symbols)
+	-export-dynamic $(no_undefined) -export-symbols gthread.def
 
 libgthread_2_0_la_LIBADD = $(G_THREAD_LIBS_EXTRA) $(G_THREAD_LIBS_FOR_GTHREAD) $(libglib)
 
-libgthread_2_0_la_DEPENDENCIES = $(gthread_win32_res) $(gthread_def)
+libgthread_2_0_la_DEPENDENCIES = $(gthread_win32_res) gthread.def
 
 gthread-win32-res.o: gthread.rc
 	$(AM_V_GEN) $(WINDRES) gthread.rc $@
diff --git a/gthread/gthread.def b/gthread/gthread.def
index 200b043..99864ba 100644
--- a/gthread/gthread.def
+++ b/gthread/gthread.def
@@ -1,3 +1,2 @@
-EXPORTS
-	g_thread_init
-	g_thread_init_with_errorcheck_mutexes
+g_thread_init
+g_thread_init_with_errorcheck_mutexes
diff --git a/gthread/gthread.symbols b/gthread/gthread.symbols
new file mode 100644
index 0000000..99864ba
--- /dev/null
+++ b/gthread/gthread.symbols
@@ -0,0 +1,2 @@
+g_thread_init
+g_thread_init_with_errorcheck_mutexes



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