]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Generate stub header files for h/*.h files included in libuafs
authorRuss Allbery <rra@stanford.edu>
Tue, 23 Aug 2011 19:50:55 +0000 (12:50 -0700)
committerDerrick Brashear <shadow@dementix.org>
Mon, 12 Sep 2011 12:21:52 +0000 (05:21 -0700)
Previously, the libuafs build created a symlink from h to
/usr/include/sys so that files included under h/* by kernel source
files could be found in the normal system header location.  However,
this assumption about the system header location is no longer valid.
Debian and Ubuntu systems with multiarch have arch-specific include
paths so that the same host can be used to build 32-bit and 64-bit
binaries with different system headers, and those include paths are
automatically searched by the compiler.  This means some standard
headers are no longer found directly in /usr/include/sys but are
instead found in /usr/include/<arch>/sys.

Using a stripped-down version of similar code for building the kernel
module on Linux, create an h directory containing stub header files
that just include the relevant system <sys/*.h> header file instead.
This allows the compiler to implement its normal internal header
search algorithm.

Also remove all the other symlinks, such as sys, netinet, etc., that
just pointed to the same directories under /usr/include.  We can assume
the normal compiler search algorithm will find these headers without
requiring this assistance.

Reviewed-on: http://gerrit.openafs.org/5305
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
(cherry picked from commit 1d6593e952ce82c778b1cd6e40c6e22ec756daf1)

Change-Id: I4360eede894846a52c54c29486fa774bde3def5e
Reviewed-on: http://gerrit.openafs.org/5397
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
src/libuafs/Makefile.common.in
src/libuafs/make_h_tree.pl [new file with mode: 0755]

index 5f94679846a87ae01816963c0d0055112300a0b3..fe3acc1c8728c7277ad667ba2d725996b0f6de06 100644 (file)
@@ -1485,8 +1485,8 @@ $(JUAFS)/xdr_len.o: $(TOP_SRC_RX)/xdr_len.c
 
 clean:
        -$(RM) -rf UAFS* JUAFS* AFSWEB* nsapi des afs afsint config rx
-       -$(RM) -f  h net netinet rpc ufs machine inet nfs sys des linktest $(AFS_OS_CLEAN)
-
+       -$(RM) -rf h
+       -$(RM) linktest $(AFS_OS_CLEAN)
 
 install: UAFS/$(LIBUAFS) JUAFS/$(LIBJUAFS)
        ${INSTALL} -d ${DESTDIR}${libdir}
@@ -1531,15 +1531,10 @@ AFSWEB:
        mkdir -p $@
 
 setup_common:
-       -$(RM) -f h net netinet rpc ufs nfs machine sys inet nsapi afsd
-       -ln -s ${ISYSROOT}/usr/include/sys h
-       -ln -s ${ISYSROOT}/usr/include/net net
-       -ln -s ${ISYSROOT}/usr/include/netinet netinet
-       -ln -s ${ISYSROOT}/usr/include/rpc rpc
-       -ln -s ${ISYSROOT}/usr/include/sys sys
-       -ln -s ${ISYSROOT}/usr/include/nfs nfs
-       -ln -s ${ISYSROOT}/usr/include/inet inet
-       -ln -s ${ISYSROOT}/usr/include/ufs ufs
+       -$(RM) -f nsapi afsd
+       -$(RM) -rf h
+       @TOP_SRCDIR@/libuafs/make_h_tree.pl $(TOP_SRC_AFS) $(TOP_SRC_VNOPS) \
+               $(TOP_SRC_RX)
        -ln -s $(TOP_SRCDIR)/afsd afsd
        -ln -s $(NS_INCL) nsapi
 
diff --git a/src/libuafs/make_h_tree.pl b/src/libuafs/make_h_tree.pl
new file mode 100755 (executable)
index 0000000..d877be0
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+# make_h_tree.pl
+# Generate an h tree that includes the appropriate sys headers
+#
+# Usage: make_h_tree.pl ${SRC} ...
+#
+# The specified makefiles will be scanned for variable values.  The h
+# directory will be created under the current directory and populated with
+# stubs that include the actual header file for every header included by any
+# source file in the ${SRC} directories.  This is an ugly hack to work around
+# the naming of header files using h instead of their proper names elsewhere
+# in the code.
+
+use IO::File;
+
+if (@ARGV < 1) {
+  die "Usage: $0 SRC ...\n";
+}
+
+%remap = ('h' => 'sys');
+foreach $src (keys %remap) {
+    mkdir($src, 0777) or die "$src: $!\n";
+%seen = ();
+@q = map { glob ("$_/*.[Sc]") } @ARGV;
+  while (@q) {
+    $src = shift @q;
+    $content = new IO::File($src, O_RDONLY) or die "$src: $!\n";
+  LINE:
+    while (<$content>) {
+      chomp;
+      if (/^\s*\#\s*include\s*[<\"](?:\.\.\/)?([^\/>\"]*)(.*?)[>\"]/) {
+       $inc = "$1$2";
+       if (exists $seen{$inc}) {
+         next;
+       } elsif (exists $remap{$1}  &&  $2 !~ /.\//) {
+         $H = new IO::File("$inc", O_WRONLY|O_CREAT|O_TRUNC, 0666)
+           or die "$inc: $!\n";
+         print $H "#include <sys$2>\n";
+         $H->close() or die "$inc: $!\n";
+          $seen{$inc} = 1;
+       }
+      }
+    }
+  }
+}