1
0
mirror of http://mpg123.de/trunk/.git synced 2025-04-19 16:02:16 +03:00
mpg123/scripts/fixinc.pl
thor f26bfa5b34 build: relative header includes, dropping -Isrc/compat and -Isrc/common
Only the generated config.h and the API headers in src/include should be
located via search path now.


git-svn-id: svn://scm.orgis.org/mpg123/trunk@5386 35dc7657-300d-0410-a2e5-dc2837fedb53
2023-12-06 22:32:09 +00:00

43 lines
832 B
Perl

#!/usr/bin/perl
use File::Basename qw(dirname);
use File::Spec::Functions qw(abs2rel);
my @incdirs = ('src/common', 'src/compat', 'src');
sub header
{
my ($from, $inc) = @_;
for(dirname($from), @incdirs)
{
my $cand = "$_/$inc";
return $cand if -e $cand;
}
return undef;
}
for my $f (@ARGV)
{
open(my $ih, '<', $f) or die "meh: $!\n";
open(my $oh, '>', "$f.tmp") or die "moh: $!\n";
while(my $line = <$ih>)
{
if($line =~ m,^(\s*\#\s*include\s+)"([^/]+)\"(.*)$,)
{
my ($pre, $inc, $post) = ($1, $2, $3);
my $h = header($f, $inc);
if($inc ne "config.h" and defined $h)
{
if(dirname($h) ne dirname($f))
{
my $rel = abs2rel($h, dirname($f));
print "$f: including $inc ($rel)\n";
$line = $pre.'"'.$rel.'"'.$post."\n";
}
}
}
print $oh "$line";
}
rename("$f.tmp", $f);
}