r14481: Change paths in headers on the fly when installing. Adds a simple text
authorJelmer Vernooij <jelmer@samba.org>
Thu, 16 Mar 2006 16:02:21 +0000 (16:02 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:57:31 +0000 (13:57 -0500)
file that contains the paths where headers need to be installed.

source/headermap.txt [new file with mode: 0644]
source/script/installheader.pl

diff --git a/source/headermap.txt b/source/headermap.txt
new file mode 100644 (file)
index 0000000..646cc00
--- /dev/null
@@ -0,0 +1,47 @@
+# FIXME: This file should be autogenerated by the build system at some 
+# point
+lib/talloc/talloc.h: talloc.h
+lib/util/util.h: util.h
+lib/util/debug.h: util/debug.h
+lib/util/mutex.h: util/mutex.h
+lib/util/util_proto.h: util/proto.h
+nt_status.h: core/nt_status.h
+lib/util/byteorder.h: util/byteorder.h
+lib/util/safe_string.h: util/safe_string.h
+lib/util/xfile.h: util/xfile.h
+lib/tdr/tdr.h: tdr.h
+librpc/rpc/dcerpc.h: dcerpc.h
+lib/socket_wrapper/socket_wrapper.h: socket_wrapper.h
+libnet/libnet.h: libnet.h
+libnet/libnet_join.h: libnet/join.h
+libnet/libnet_lookup.h: libnet/lookup.h
+libnet/libnet_passwd.h: libnet/passwd.h
+libnet/libnet_rpc.h: libnet/rpc.h
+libnet/libnet_share.h: libnet/share.h
+libnet/libnet_time.h: libnet/time.h
+libnet/libnet_user.h: libnet/user.h
+libnet/libnet_site.h: libnet/site.h
+libnet/libnet_vampire.h: libnet/vampire.h
+libnet/userinfo.h: libnet/userinfo.h
+libnet/userman.h: libnet/userman.h
+lib/ldb/include/ldb.h: ldb.h
+ntvfs/ntvfs.h: ntvfs.h
+lib/tdb/include/tdb.h: tdb.h
+auth/gensec/gensec.h: gensec.h
+gtk/common/gtk-smb.h: gtk-smb.h
+gtk/common/select.h: gtk/select.h
+librpc/ndr/libndr.h: ndr.h
+lib/registry/registry.h: registry.h
+libcli/util/nterr.h: core/nterr.h
+libcli/util/doserr.h: core/doserr.h
+libcli/util/nt_status.h: core/ntstatus.h
+libcli/cldap/cldap.h: cldap.h
+lib/samba3/samba3.h: samba3.h
+include/core.h: core.h
+librpc/gen_ndr/dcerpc.h: gen_ndr/dcerpc.h
+librpc/gen_ndr/misc.h: gen_ndr/misc.h
+librpc/ndr/libndr_proto.h: ndr/proto.h
+librpc/rpc/dcerpc_proto.h: dcerpc/proto.h
+lib/tdr/tdr_proto.h: tdr/proto.h
+auth/credentials/credentials.h: credentials.h
+auth/credentials/credentials_proto.h: credentials/proto.h
index 1af05f3fea65d99c1bf174f0626116b6c16ae006..808ab8d4335aab0b6951f673618f4bcf7cfc9398 100755 (executable)
@@ -1,18 +1,70 @@
 #!/usr/bin/perl
+# Copyright (C) 2006 Jelmer Vernooij
 use strict;
 use File::Basename;
 
 my $includedir = shift;
 
+
+sub read_headermap($)
+{
+       my ($fn) = @_;
+       my %map = ();
+       my $ln = 0;
+       open(MAP, "<headermap.txt");
+       while(<MAP>) {
+               $ln++;
+               s/#.*$//g;
+               next if (/^\s*$/);
+               if (! /^(.*): (.*)$/) {
+                       print STDERR "headermap.txt:$ln: Malformed line\n";
+                       next;
+               }
+               $map{$1} = $2;
+       }
+
+       close(MAP);
+
+       return %map;
+}
+
+my %map = read_headermap("headermap.txt");
+
+sub findmap($)
+{
+       $_ = shift;
+       s/^\.\///g;
+
+       if (! -f $_ && -f "lib/$_") { $_ = "lib/$_"; }
+       
+       return $map{$_};
+}
+
+sub rewrite_include($$)
+{
+       my ($pos,$d) = @_;
+
+       my $n = findmap($d);
+       return $n if $n; 
+       return $d;
+}
+
 sub install_header($$)
 {
        my ($src,$dst) = @_;
 
+       my $lineno = 0;
+
        open(IN, "<$src");
        open(OUT, ">$dst");
 
        while (<IN>) {
-               print OUT $_;
+               $lineno++;
+               if (/^#include \"(.*)\"/) {
+                       print OUT "#include <" . rewrite_include("$src:$lineno", $1) . ">\n";
+               } else {
+                       print OUT $_;
+               }
        }
 
        close(OUT);
@@ -21,15 +73,25 @@ sub install_header($$)
 
 foreach my $p (@ARGV)
 {
- my $p2 = basename($p);
- print "Installing $p as $includedir/$p2\n";
+       my $p2 = findmap($p);
+       unless ($p2) {
+               warn("Unable to map $p");
+               next;
+       }
+       print "Installing $p as $includedir/$p2\n";
+
+       my $dirname = dirname($p2);
 
- if ( -f "$includedir/$p2" ) {
-   unlink("$includedir/$p2.old");
-   rename("$includedir/$p2", "$includedir/$p2.old");
- }
+       if (! -d "$includedir/$dirname") {
+               mkdir("$includedir/$dirname");
+       }
+
+       if ( -f "$includedir/$p2" ) {
+               unlink("$includedir/$p2.old");
+               rename("$includedir/$p2", "$includedir/$p2.old");
+       }
 
- install_header($p,"$includedir/$p2");
      install_header($p,"$includedir/$p2");
 }
 
 print <<EOF;