From 0892826aa94d87f7313dc83b6d934776a149c14b Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 21 Sep 2011 00:51:17 -0400 Subject: [PATCH] Rewrite Gnulib symbols to be in libcdecl's namespace. The gnulib symbols are not properly prefixed for libcdecl internal symbols (e.g. cdecl__blah). This *will* cause problems when statically linking against both libcdecl and another library that uses the same gnulib modules. Unfortunately, there's no simple way to determine what symbols need prefixing without compiling all the gnulib objects. The results can't be distributed either, because they depend on the configuration. So, limited to simple tools and portable make rules, we hack together a "new" config.h at build time that defines object-like macros to rewrite the symbols, carefully ensuring that header dependencies are correct. --- .gitignore | 1 + Makefile.am | 5 ++- configure.ac | 6 +++- exported.sh.in | 44 +++++++++++++++++++++++++++ fix-gnulib.pl | 17 +++++++++-- glconfig.mk | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 150 insertions(+), 5 deletions(-) create mode 100644 exported.sh.in create mode 100644 glconfig.mk diff --git a/.gitignore b/.gitignore index cfb9fa6..462670e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ Makefile.in /lib /cdecl99 /ABOUT-NLS +/exported.sh diff --git a/Makefile.am b/Makefile.am index f42b95c..9579834 100644 --- a/Makefile.am +++ b/Makefile.am @@ -5,6 +5,7 @@ # There is NO WARRANTY, to the extent permitted by law. ACLOCAL_AMFLAGS = -I m4 +AUTOMAKE_OPTIONS = nostdinc # For Gnulib MOSTLYCLEANFILES = @@ -12,6 +13,7 @@ noinst_LTLIBRARIES = AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src \ -I$(top_builddir)/lib -I$(top_srcdir)/lib \ + -I$(top_builddir) -I$(top_srcdir) \ -DBISON_LOCALEDIR=\"$(BISON_LOCALEDIR)\" \ -DLOCALEDIR=\"$(localedir)\" @@ -35,7 +37,7 @@ lib_LTLIBRARIES = libcdecl.la libcdecl_la_LDFLAGS = -export-symbols-regex '^cdecl_[[:lower:]]' libcdecl_la_SOURCES = src/scan.c src/parse.c src/parse-decl.c src/typemap.c \ src/output.c src/explain.c src/declare.c src/i18n.c -libcdecl_la_LIBADD = $(LTLIBINTL) $(LTLIBTHREAD) +libcdecl_la_LIBADD = $(LTLIBINTL) $(LTLIBTHREAD) libgnu.la $(libcdecl_la_OBJECTS): $(gnulib_headers) bin_PROGRAMS = cdecl99 @@ -139,3 +141,4 @@ FLEX_V_0 = @echo " FLEX " $<; fi include $(top_srcdir)/lib/gnulib.mk +include $(top_srcdir)/glconfig.mk diff --git a/configure.ac b/configure.ac index 50eaf75..8576628 100644 --- a/configure.ac +++ b/configure.ac @@ -18,7 +18,7 @@ gl_EARLY LT_INIT gl_INIT -DX_FIX_GNULIB +DX_FIX_GNULIB([cdecl__]) dnl We provide our own makefile rules for gettext. Disable tracing of dnl AM_GNU_GETTEXT to prevent autoreconf from running autopoint, and to @@ -36,7 +36,11 @@ AC_ARG_VAR([BISONFLAGS], [Additional options to pass to Bison.]) AC_CHECK_PROGS([BISON], [bison], [bison]) BISON_I18N +GLOBAL_SYMBOL_PIPE=$lt_cv_sys_global_symbol_pipe +AC_SUBST([GLOBAL_SYMBOL_PIPE]) + AC_CONFIG_FILES([ + exported.sh Makefile ]) AC_OUTPUT diff --git a/exported.sh.in b/exported.sh.in new file mode 100644 index 0000000..762600a --- /dev/null +++ b/exported.sh.in @@ -0,0 +1,44 @@ +#!@SHELL@ +# +# Copyright © 2011 Nick Bowler +# +# Determine the list of exported symbols from archives or (libtool) object +# files. +# +# License WTFPL2: Do What The Fuck You Want To Public License, version 2. +# This is free software: you are free to do what the fuck you want to. +# There is NO WARRANTY, to the extent permitted by law. + +OBJS= + +while test $# -gt 0 +do + case $1 in + /*) arg=$1 ;; + *) arg=./$1 ;; + esac + + if expr "$arg" : '.*\.lo' >/dev/null; then + non_pic_object= + pic_object= + . "$arg" + + dir=`expr "$arg" : '\(.*\)/'` + if test x"$pic_object" != x"none"; then + OBJS="$OBJS $dir/$pic_object" + fi + if test x"$non_pic_object" != x"none"; then + OBJS="$OBJS $dir/$non_pic_object" + fi + else + OBJS="$OBJS $arg" + fi + + shift +done + +set x $OBJS; shift +case $# in +0) : ;; +*) @NM@ $OBJS | @GLOBAL_SYMBOL_PIPE@ | @SED@ 's/^.* //' | sort | uniq ;; +esac diff --git a/fix-gnulib.pl b/fix-gnulib.pl index 17163c7..b8185fa 100755 --- a/fix-gnulib.pl +++ b/fix-gnulib.pl @@ -174,9 +174,21 @@ if (defined $m4output) { open(M4OUT, '>', $m4output) or die "$m4output: $!\n"; - print M4OUT "dnl This file was generated by fix-gnulib.pl\n"; - print M4OUT "AC_DEFUN([$m4macro], [dnl\n"; + print M4OUT < $(@D)/.syms/$(*F).sym +$(gnulib_symfiles): $(gnulib_core_headers) + +clean-local: clean-glconfig +clean-glconfig: + @for sym in $(libgnu_la_SOURCES) $(EXTRA_libgnu_la_SOURCES); do \ + symdir=`expr "$$sym" : '\(.*/\)'`.syms; \ + if test -d "$$symdir"; then \ + echo "rm -rf $$symdir"; rm -rf "$$symdir"; \ + fi; \ + done +.PHONY: clean-glconfig + +# The config header requires compilation of all gnulib object files via the +# .glsym rule above. However, it cannot depend on those build products +# directly because those compilations will include this header if it exists, +# which is (by definition) out of date when this rule gets triggered. +# +# Thus, we delete the header, then perform a recursive make call to regenerate +# the header, which can in turn parallelize the required compilation. +# +# Also delete the phony symbol files so the build doesn't fail badly if they +# got created somehow (for instance by make -t). +$(GLCONFIG): $(top_builddir)/config.h $(gnulib_core_headers) + -$(AM_V_at) rm -f $(gnulib_symfiles) $@.tmp $@ + $(AM_V_at) $(MAKE) $(AM_MAKEFLAGS) glconfig-gen + $(AM_V_GEN) cat $(top_builddir)/config.h >> $@.tmp + $(AM_V_at) mv -f $@.tmp $@ +CLEANFILES += $(GLCONFIG) + +# The glconfig-gen target is intended only for use in recursive make +# invocations. +glconfig-gen: $(gnulib_symfiles) + $(AM_V_at) depfiles=; symfiles=; \ + for sym in $(gnulib_symfiles); do \ + symdir=`expr "$$sym" : '\(.*/\)'`; \ + symfile=`expr "$$sym" : '.*/\(.*\)' || printf '%s\n' "$$sym"`; \ + symbase=$$symdir.syms/`expr "$$symfile" : '\(.*\)\..*'`; \ + test -f "$$symbase.deps" && \ + depfiles="$$depfiles $$symbase.deps"; \ + symfiles="$$symfiles $$symbase.sym"; \ + done; \ + $(GLCAT) $$depfiles > @GLSRC@/$(DEPDIR)/glconfig.Ph && \ + $(GLCAT) $$symfiles | sed 's/.*/#define & $(GLSYM_PREFIX)&/' \ + > $(GLCONFIG).tmp +.PHONY: glconfig-gen + +@AMDEP_TRUE@@am__include@ @am__quote@@GLSRC@/$(DEPDIR)/glconfig.Ph@am__quote@ -- 2.43.2