Fix bug 7063 - Samba 3.4.5 on ubuntu 8.04 64 bit - Core dumps.
[Samba/gbeck.git] / source4 / script / installheader.pl
blob5be3434a5c2c1ab664d84df7e3846d9bae3f490a
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 } elsif (/^#if _SAMBA_BUILD_ == 4/) {
68 print OUT "#if 1\n";
69 } else {
70 print OUT $_;
74 close(OUT);
75 close(IN);
78 foreach my $p (@ARGV)
80 my $p2 = findmap($p);
81 unless ($p2) {
82 die("Unable to map $p");
84 print "Installing $p as $includedir/$p2\n";
86 my $dirname = dirname($p2);
88 if (! -d "$includedir/$dirname") {
89 mkdir("$includedir/$dirname", 0777);
92 if ( -f "$includedir/$p2" ) {
93 unlink("$includedir/$p2.old");
94 rename("$includedir/$p2", "$includedir/$p2.old");
97 install_header($p,"$includedir/$p2");
100 print <<EOF;
101 ======================================================================
102 The headers are installed. You may restore the old headers (if there
103 were any) using the command "make revert". You may uninstall the headers
104 using the command "make uninstallheader" or "make uninstall" to uninstall
105 binaries, man pages and shell scripts.
106 ======================================================================
109 exit 0;