r21497: Pass more of the RPC-CRACKNAMES test by using the new search_options control.
[Samba.git] / source / script / installheader.pl
blobd1f96b2592fb8cbd7831ba237968546032e0bdf3
1 #!/usr/bin/perl
2 # Copyright (C) 2006 Jelmer Vernooij
3 use strict;
4 use File::Basename;
6 my $includedir = shift;
9 sub read_headermap($)
11 my ($fn) = @_;
12 my %map = ();
13 my $ln = 0;
14 open(MAP, "<headermap.txt");
15 while(<MAP>) {
16 $ln++;
17 s/#.*$//g;
18 next if (/^\s*$/);
19 if (! /^(.*): (.*)$/) {
20 print STDERR "headermap.txt:$ln: Malformed line\n";
21 next;
23 $map{$1} = $2;
26 close(MAP);
28 return %map;
31 my %map = read_headermap("headermap.txt");
33 sub findmap($)
35 $_ = shift;
36 s/^\.\///g;
38 if (! -f $_ && -f "lib/$_") { $_ = "lib/$_"; }
40 return $map{$_};
43 sub rewrite_include($$)
45 my ($pos,$d) = @_;
47 my $n = findmap($d);
48 return $n if $n;
49 return $d;
52 sub install_header($$)
54 my ($src,$dst) = @_;
56 my $lineno = 0;
58 open(IN, "<$src");
59 open(OUT, ">$dst");
61 while (<IN>) {
62 $lineno++;
63 if (/^#include \"(.*)\"/) {
64 print OUT "#include <" . rewrite_include("$src:$lineno", $1) . ">\n";
65 } else {
66 print OUT $_;
70 close(OUT);
71 close(IN);
74 foreach my $p (@ARGV)
76 my $p2 = findmap($p);
77 unless ($p2) {
78 die("Unable to map $p");
80 print "Installing $p as $includedir/$p2\n";
82 my $dirname = dirname($p2);
84 if (! -d "$includedir/$dirname") {
85 mkdir("$includedir/$dirname", 0777);
88 if ( -f "$includedir/$p2" ) {
89 unlink("$includedir/$p2.old");
90 rename("$includedir/$p2", "$includedir/$p2.old");
93 install_header($p,"$includedir/$p2");
96 print <<EOF;
97 ======================================================================
98 The headers are installed. You may restore the old headers (if there
99 were any) using the command "make revert". You may uninstall the headers
100 using the command "make uninstallheader" or "make uninstall" to uninstall
101 binaries, man pages and shell scripts.
102 ======================================================================
105 exit 0;