|
Packit Service |
c5cf8c |
#!/usr/bin/perl
|
|
Packit Service |
c5cf8c |
use strict;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# This script is to be run by AC_CONFIG_COMMANDS in configure.ac.
|
|
Packit Service |
c5cf8c |
# USAGE:
|
|
Packit Service |
c5cf8c |
# AC_CONFIG_COMMANDS([prefix-config],[perl cmd_prefix_config_h.pl PREFIX input_config.h output_config.h])
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# The script will read "input_config.h", and write "output_config.h", adding prefix to every defined macros. This script is a replacement to AX_PREFIX_CONFIG_H.
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
sub add_prefix {
|
|
Packit Service |
c5cf8c |
my ($name, $prefix) = @_;
|
|
Packit Service |
c5cf8c |
if($name=~/^(inline|const|restrict)/){
|
|
Packit Service |
c5cf8c |
# leave c99 keywords alone
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif($name=~/^_/){
|
|
Packit Service |
c5cf8c |
# leave underscore keywords alone, e.g _MINIX
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif($name=~/^$prefix\_/i){
|
|
Packit Service |
c5cf8c |
# avoid double prefix
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif($name=~/^[A-Z0-9_]+$/){
|
|
Packit Service |
c5cf8c |
$name = uc($prefix)."_$name";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else{
|
|
Packit Service |
c5cf8c |
$name = "_".lc($prefix)."_$name";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
return $name;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
my ($prefix, $config_in, $config_out)=@ARGV;
|
|
Packit Service |
c5cf8c |
if(!$prefix){
|
|
Packit Service |
c5cf8c |
die "missing prefix!\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if(!$config_in){
|
|
Packit Service |
c5cf8c |
$config_in = "config.h";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if(!$config_out){
|
|
Packit Service |
c5cf8c |
$config_out = $config_in;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
my @lines;
|
|
Packit Service |
c5cf8c |
open In, "$config_in" or die "Can't open $config_in.\n";
|
|
Packit Service |
c5cf8c |
while(<In>){
|
|
Packit Service |
c5cf8c |
if(/^#define\s+(\w+)\s*(.+)/){
|
|
Packit Service |
c5cf8c |
my $name = add_prefix($1, $prefix);
|
|
Packit Service |
c5cf8c |
push @lines, "#ifndef $name\n";
|
|
Packit Service |
c5cf8c |
push @lines, "#define $name $2\n";
|
|
Packit Service |
c5cf8c |
push @lines, "#endif\n";
|
|
Packit Service |
c5cf8c |
next;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif(/^\/\*\s*#undef (\w+)/){
|
|
Packit Service |
c5cf8c |
my $name = add_prefix($1, $prefix);
|
|
Packit Service |
c5cf8c |
push @lines, "/* #undef $name */\n";
|
|
Packit Service |
c5cf8c |
next;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
push @lines, $_;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
close In;
|
|
Packit Service |
c5cf8c |
my $DEFH=uc($config_out);
|
|
Packit Service |
c5cf8c |
$DEFH=~s/\W/_/g;
|
|
Packit Service |
c5cf8c |
open Out, ">$config_out" or die "Can't write $config_out.\n";
|
|
Packit Service |
c5cf8c |
print Out "#ifndef $DEFH\n";
|
|
Packit Service |
c5cf8c |
print Out "#define $DEFH 1\n\n";
|
|
Packit Service |
c5cf8c |
print Out "\x2f* $config_out. Generated automatically at end of configure. *\x2f\n";
|
|
Packit Service |
c5cf8c |
print Out @lines;
|
|
Packit Service |
c5cf8c |
print Out "\x2f* once: $DEFH *\x2f\n";
|
|
Packit Service |
c5cf8c |
print Out "#endif\n";
|
|
Packit Service |
c5cf8c |
close Out;
|