2006-03-16 16:04:28 +03:00
#!/usr/bin/perl
2006-03-16 19:02:21 +03:00
# Copyright (C) 2006 Jelmer Vernooij
2006-03-16 16:04:28 +03:00
use strict ;
use File::Basename ;
my $ includedir = shift ;
2006-05-01 19:45:26 +04:00
2006-03-16 19:02:21 +03:00
sub read_headermap ($)
{
my ( $ fn ) = @ _ ;
my % map = ( ) ;
my $ ln = 0 ;
2006-05-01 19:45:26 +04:00
open ( MAP , "<headermap.txt" ) ;
2006-03-16 19:02:21 +03:00
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 ;
}
2006-05-01 19:45:26 +04:00
my % map = read_headermap ( "headermap.txt" ) ;
2006-03-16 19:02:21 +03:00
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 ;
}
2006-03-16 16:04:28 +03:00
sub install_header ($$)
{
my ( $ src , $ dst ) = @ _ ;
2006-03-16 19:02:21 +03:00
my $ lineno = 0 ;
2006-05-01 19:45:26 +04:00
open ( IN , "<$src" ) ;
2006-03-16 16:04:28 +03:00
open ( OUT , ">$dst" ) ;
while ( <IN> ) {
2006-03-16 19:02:21 +03:00
$ lineno + + ;
2008-05-21 22:46:16 +04:00
die ( "Will not install autogenerated header $src" ) if ( /This file was automatically generated by mkproto.pl. DO NOT EDIT/ ) ;
2006-03-16 19:02:21 +03:00
if ( /^#include \"(.*)\"/ ) {
print OUT "#include <" . rewrite_include ( "$src:$lineno" , $ 1 ) . ">\n" ;
} else {
print OUT $ _ ;
}
2006-03-16 16:04:28 +03:00
}
close ( OUT ) ;
close ( IN ) ;
}
foreach my $ p ( @ ARGV )
{
2006-03-16 19:02:21 +03:00
my $ p2 = findmap ( $ p ) ;
unless ( $ p2 ) {
2006-11-06 15:05:09 +03:00
die ( "Unable to map $p" ) ;
2006-03-16 19:02:21 +03:00
}
print "Installing $p as $includedir/$p2\n" ;
my $ dirname = dirname ( $ p2 ) ;
2006-03-16 16:04:28 +03:00
2006-03-16 19:02:21 +03:00
if ( ! - d "$includedir/$dirname" ) {
2006-04-26 13:51:02 +04:00
mkdir ( "$includedir/$dirname" , 0777 ) ;
2006-03-16 19:02:21 +03:00
}
if ( - f "$includedir/$p2" ) {
unlink ( "$includedir/$p2.old" ) ;
rename ( "$includedir/$p2" , "$includedir/$p2.old" ) ;
}
2006-03-16 16:04:28 +03:00
2006-03-16 19:02:21 +03:00
install_header ( $ p , "$includedir/$p2" ) ;
2006-03-16 16:04:28 +03:00
}
print << EOF ;
=== === === === === === === === === === === === === === === === === === === === === === === =
The headers are installed . You may restore the old headers ( if there
were any ) using the command "make revert" . You may uninstall the headers
using the command "make uninstallheader" or "make uninstall" to uninstall
binaries , man pages and shell scripts .
=== === === === === === === === === === === === === === === === === === === === === === === =
EOF
exit 0 ;