Rewrite make_h_tree.pl in shell script
authorAndrew Deason <adeason@sinenomine.net>
Fri, 24 Feb 2012 00:28:21 +0000 (18:28 -0600)
committerDerrick Brashear <shadow@dementix.org>
Sat, 25 Feb 2012 13:10:32 +0000 (05:10 -0800)
The current usage of make_h_tree.pl adds a build requirement of
/usr/bin/perl that we did not have prior to commit
1d6593e952ce82c778b1cd6e40c6e22ec756daf1. Do the same thing in a
bourne shell script instead, so we don't need perl.

Note that this is not as generalized as make_h_tree.pl, but it doesn't
need to be. Specifically, this does not strip a leading ../ from found
include directives (nothing in the tree that includes h/* files uses
this), and header filenames containing whitespace almost certainly do
not work correctly.

The h => sys mapping is also much more hardcoded, but that's all we
were using this for anyway.

Reviewed-on: http://gerrit.openafs.org/6790
Reviewed-by: Russ Allbery <rra@stanford.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>
(cherry picked from commit fb03b1380f82a6bdc8a78ad92069da38b4e98c26)

Change-Id: If6bfedea0b563dce6135fbf2f4554ee602ee822c
Reviewed-on: http://gerrit.openafs.org/6793
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>

src/libuafs/Makefile.common.in
src/libuafs/make_h_tree [new file with mode: 0755]
src/libuafs/make_h_tree.pl [deleted file]

index ee6e2eb..c39d131 100644 (file)
@@ -1532,7 +1532,7 @@ AFSWEB:
 
 h: $(TOP_SRC_AFS)/*.c $(TOP_SRC_VNOPS)/*.c $(TOP_SRC_RX)/*.c
        -$(RM) -rf h
-       @TOP_SRCDIR@/libuafs/make_h_tree.pl $(TOP_SRC_AFS) $(TOP_SRC_VNOPS) \
+       @TOP_SRCDIR@/libuafs/make_h_tree $(TOP_SRC_AFS) $(TOP_SRC_VNOPS) \
                $(TOP_SRC_RX)
 
 setup_common: h
diff --git a/src/libuafs/make_h_tree b/src/libuafs/make_h_tree
new file mode 100755 (executable)
index 0000000..2b89973
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh -e
+
+# make_h_tree
+# Generate an h tree that includes the appropriate sys headers
+#
+# Usage: make_h_tree ${SRC} ...
+#
+# The source files in the specified directories will be scanned for include
+# directives. 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. Since this script is
+# for userspace only, this effectively just makes a file called h/foo.h that
+# contains:
+#    #include <sys/foo.h>
+# For every include directive that is found that looks like #include <h/foo.h>
+# This is an ugly hack to work around the naming of header files using h
+# instead of their proper names elsewhere in the code.
+
+mkdir h
+
+for dir in "$@" ; do
+  for hsrc in `cat "$dir"/*.c | \
+    sed -n -e 's|^[    ]*#[    ]*include[      ]*[<"]h/\([^>"/]*\)[>"].*$|\1|p' | \
+      sort | uniq` ; do
+
+    echo "#include <sys/$hsrc>" > h/"$hsrc"
+  done
+done
diff --git a/src/libuafs/make_h_tree.pl b/src/libuafs/make_h_tree.pl
deleted file mode 100755 (executable)
index d877be0..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/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;
-       }
-      }
-    }
-  }
-}