Create symbols to export in libtdb dynamically from tdb.h.
authorMichael Adam <obnox@samba.org>
Thu, 14 Feb 2008 13:15:07 +0000 (14:15 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 14 Feb 2008 13:17:57 +0000 (14:17 +0100)
This adds a general mechanism to create version-scripts for
linking shared libraries from one or several header files,
similar to mkproto.sh/awk.

Michael
(This used to be commit 65817703c49a7410f4f0c8b46494ede6169d9fa6)

source3/Makefile.in
source3/exports/libtdb.syms [deleted file]
source3/script/mksyms.awk [new file with mode: 0644]
source3/script/mksyms.sh [new file with mode: 0755]

index 9b210cc9e725daf56eb5864147c3d6c8c8d9d6e4..0e2e22ca86ac81cb2af6797e289c16ee81104bb4 100644 (file)
@@ -148,6 +148,8 @@ LIBTALLOC=$(LIBTALLOC_STATIC_TARGET) @LIBTALLOC_SHARED@
 LIBTDB_SHARED_TARGET=@LIBTDB_SHARED_TARGET@
 LIBTDB_STATIC_TARGET=@LIBTDB_STATIC_TARGET@
 LIBTDB=$(LIBTDB_STATIC_TARGET) @LIBTDB_SHARED@
+LIBTDB_SYMS=exports/libtdb.syms
+LIBTDB_HEADERS=@tdbdir@/include/tdb.h
 
 LIBSMBCLIENT=bin/libsmbclient.a @LIBSMBCLIENT_SHARED@
 LIBSMBSHAREMODES=bin/libsmbsharemodes.a @LIBSMBSHAREMODES_SHARED@
@@ -1471,7 +1473,12 @@ $(LIBTALLOC_STATIC_TARGET): $(BINARY_PREREQS) $(LIBTALLOC_OBJ0)
        @echo Linking non-shared library $@
        @-$(AR) -rc $@ $(LIBTALLOC_OBJ0)
 
-$(LIBTDB_SHARED_TARGET): $(BINARY_PREREQS) $(LIBTDB_OBJ)
+MKSYMS_SH = $(srcdir)/script/mksyms.sh
+
+$(LIBTDB_SYMS): $(LIBTDB_HEADERS)
+       @$(MKSYMS_SH) $(AWK) $@ $(LIBTDB_HEADERS)
+
+$(LIBTDB_SHARED_TARGET): $(BINARY_PREREQS) $(LIBTDB_OBJ) $(LIBTDB_SYMS)
        @echo Linking shared library $@
        @$(SHLD_DSO) $(LIBTDB_OBJ) \
                @SONAMEFLAG@`basename $@`.$(SONAME_VER)
@@ -1998,7 +2005,7 @@ installlibtdb: installdirs libtdb
        -$(INSTALLLIBCMD_SH) $(LIBTDB_SHARED_TARGET) $(DESTDIR)$(LIBDIR)
        -$(INSTALLLIBCMD_A) $(LIBTDB_STATIC_TARGET) $(DESTDIR)$(LIBDIR)
        @$(SHELL) $(srcdir)/script/installdirs.sh $(INSTALLPERMS_BIN) $(DESTDIR) ${prefix}/include
-       -$(INSTALLCMD) -m $(INSTALLPERMS_DATA) @tdbdir@/include/tdb.h $(DESTDIR)${prefix}/include
+       -$(INSTALLCMD) -m $(INSTALLPERMS_DATA) $(LIBTDB_HEADERS) $(DESTDIR)${prefix}/include
 
 installlibsmbsharemodes: installdirs libsmbsharemodes
        @$(SHELL) $(srcdir)/script/installdirs.sh $(INSTALLPERMS_BIN) $(DESTDIR) $(LIBDIR)
@@ -2132,7 +2139,8 @@ clean: delheaders
                $(LIBTALLOC) $(LIBSMBCLIENT) $(LIBADDNS) \
                $(LIBSMBSHAREMODES) $(EVERYTHING_PROGS) $(LIBNETAPI) \
                bin/libwbclient.so.0 bin/timelimit \
-               .headers.stamp */src/*.o proto_exists
+               .headers.stamp */src/*.o proto_exists \
+               $(LIBTDB_SYMS)
        -rm -rf t_dir
 
 # Making this target will just make sure that the prototype files
diff --git a/source3/exports/libtdb.syms b/source3/exports/libtdb.syms
deleted file mode 100644 (file)
index 5d24771..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-{
-       global: tdb_*;
-       local: *;
-};
diff --git a/source3/script/mksyms.awk b/source3/script/mksyms.awk
new file mode 100644 (file)
index 0000000..a30bea4
--- /dev/null
@@ -0,0 +1,76 @@
+#
+# mksyms.awk
+#
+# Extract symbols to export from C-header files.
+# output in version-script format for linking shared libraries.
+#
+# Copyright (C) 2008 Micheal Adam <obnox@samba.org>
+#
+BEGIN {
+       inheader=0;
+       current_file="";
+       print "#"
+       print "# This file is automatically generated with \"make symbols\". DO NOT EDIT "
+       print "#"
+       print "{"
+       print "\tglobal:"
+}
+
+END {
+       print""
+       print "\tlocal: *;"
+       print "};"
+}
+
+{
+       if (FILENAME!=current_file) {
+               print "\t\t# The following definitions come from",FILENAME
+               current_file=FILENAME
+       }
+       if (inheader) {
+               if (match($0,"[)][ \t]*[;][ \t]*$")) {
+                       inheader = 0;
+               }
+               next;
+       }
+}
+
+/^static/ || /^[ \t]*typedef/ || !/^[a-zA-Z\_]/ {
+       next;
+}
+
+/^extern[ \t]+[^()]+[;][ \t]*$/ {
+       gsub(/[^ \t]+[ \t]+/, "");
+       sub(/[;][ \t]*$/, "");
+       printf "\t\t%s;\n", $0;
+       next;
+}
+
+# look for function headers:
+{
+       gotstart = 0;
+       if ($0 ~ /^[A-Za-z_][A-Za-z0-9_]+/) {
+       gotstart = 1;
+       }
+       if(!gotstart) {
+               next;
+       }
+}
+
+/[_A-Za-z0-9]+[ \t]*[(].*[)][ \t]*;[ \t]*$/ {
+       sub(/[(].*$/, "");
+       gsub(/[^ \t]+[ \t]+/, "");
+       gsub(/^[*]/, "");
+       printf "\t\t%s;\n",$0;
+       next;
+}
+
+/[_A-Za-z0-9]+[ \t]*[(]/ {
+       inheader=1;
+       sub(/[(].*$/, "");
+       gsub(/[^ \t]+[ \t]+/, "");
+       gsub(/^[*]/, "");
+       printf "\t\t%s;\n",$0;
+       next;
+}
+
diff --git a/source3/script/mksyms.sh b/source3/script/mksyms.sh
new file mode 100755 (executable)
index 0000000..637ec50
--- /dev/null
@@ -0,0 +1,45 @@
+#! /bin/sh
+
+#
+# mksyms.sh
+#
+# Extract symbols to export from C-header files.
+# output in version-script format for linking shared libraries.
+#
+# This is the shell warpper for the mksyms.awk core script.
+#
+# Copyright (C) 2008 Micheal Adam <obnox@samba.org>
+#
+
+LANG=C; export LANG
+LC_ALL=C; export LC_ALL
+LC_COLLATE=C; export LC_COLLATE
+
+if [ $# -lt 2 ]
+then
+  echo "Usage: $0 awk output_file header_files"
+  exit 1
+fi
+
+awk="$1"
+shift
+
+symsfile="$1"
+shift
+symsfile_tmp="$symsfile.$$.tmp~"
+
+proto_src="`echo $@ | tr ' ' '\n' | sort | uniq `"
+
+echo creating $symsfile
+
+mkdir -p `dirname $symsfile`
+
+${awk} -f script/mksyms.awk $proto_src > $symsfile_tmp
+
+if cmp -s $symsfile $symsfile_tmp 2>/dev/null
+then
+  echo "$symsfile unchanged"
+  rm $symsfile_tmp
+else
+  mv $symsfile_tmp $symsfile
+fi