1#!/usr/bin/perl 2# Copyright (C) 2006 Jelmer Vernooij 3use strict; 4use File::Basename; 5 6my $includedir = shift; 7 8 9sub read_headermap($) 10{ 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; 22 } 23 $map{$1} = $2; 24 } 25 26 close(MAP); 27 28 return %map; 29} 30 31my %map = read_headermap("headermap.txt"); 32 33sub findmap($) 34{ 35 $_ = shift; 36 s/^\.\///g; 37 38 if (! -f $_ && -f "lib/$_") { $_ = "lib/$_"; } 39 40 return $map{$_}; 41} 42 43sub rewrite_include($$) 44{ 45 my ($pos,$d) = @_; 46 47 my $n = findmap($d); 48 return $n if $n; 49 return $d; 50} 51 52sub install_header($$) 53{ 54 my ($src,$dst) = @_; 55 56 my $lineno = 0; 57 58 open(IN, "<$src"); 59 open(OUT, ">$dst"); 60 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/); 64 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 $_; 71 } 72 } 73 74 close(OUT); 75 close(IN); 76} 77 78foreach my $p (@ARGV) 79{ 80 my $p2 = findmap($p); 81 unless ($p2) { 82 die("Unable to map $p"); 83 } 84 print "Installing $p as $includedir/$p2\n"; 85 86 my $dirname = dirname($p2); 87 88 if (! -d "$includedir/$dirname") { 89 mkdir("$includedir/$dirname", 0777); 90 } 91 92 if ( -f "$includedir/$p2" ) { 93 unlink("$includedir/$p2.old"); 94 rename("$includedir/$p2", "$includedir/$p2.old"); 95 } 96 97 install_header($p,"$includedir/$p2"); 98} 99 100print <<EOF; 101====================================================================== 102The headers are installed. You may restore the old headers (if there 103were any) using the command "make revert". You may uninstall the headers 104using the command "make uninstallheader" or "make uninstall" to uninstall 105binaries, man pages and shell scripts. 106====================================================================== 107EOF 108 109exit 0; 110