s4-nbt: use private_data instead of private.
[Samba/gbeck.git] / source4 / script / installheader.pl
blob6b10bde65f33775ec982c19a0cd7b47b60aadddf
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 die("Will not install autogenerated header $src") if (/This file was automatically generated by mkproto.pl. DO NOT EDIT/);
65 if (/^#include \"(.*)\"/) {
66 print OUT "#include <" . rewrite_include("$src:$lineno", $1) . ">\n";
67 } else {
68 print OUT $_;
72 close(OUT);
73 close(IN);
76 foreach my $p (@ARGV)
78 my $p2 = findmap($p);
79 unless ($p2) {
80 die("Unable to map $p");
82 print "Installing $p as $includedir/$p2\n";
84 my $dirname = dirname($p2);
86 if (! -d "$includedir/$dirname") {
87 mkdir("$includedir/$dirname", 0777);
90 if ( -f "$includedir/$p2" ) {
91 unlink("$includedir/$p2.old");
92 rename("$includedir/$p2", "$includedir/$p2.old");
95 install_header($p,"$includedir/$p2");
98 print <<EOF;
99 ======================================================================
100 The headers are installed. You may restore the old headers (if there
101 were any) using the command "make revert". You may uninstall the headers
102 using the command "make uninstallheader" or "make uninstall" to uninstall
103 binaries, man pages and shell scripts.
104 ======================================================================
107 exit 0;