Skip to content

Commit

Permalink
config: further tuning of ax_prefix_config_h
Browse files Browse the repository at this point in the history
* avoid double prefix
* add prefix to the #undef inside comments
* direct define, matches AC_CONFIG_HEADER, deviates from AX_PREFIX_CONFIG_H
  • Loading branch information
hzhou committed Jun 18, 2019
1 parent d9e4e88 commit d860eeb
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions confdb/cmd_prefix_config_h.pl
Expand Up @@ -7,6 +7,20 @@
#
# 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.

sub add_prefix {
my ($name, $prefix) = @_;
if($name=~/^$prefix\_/i){
# avoid double prefix
}
elsif($name=~/^[A-Z_]+$/){
$name = uc($prefix)."_$name";
}
else{
$name = "_".lc($prefix)."_$name";
}
return $name;
}

my ($prefix, $config_in, $config_out)=@ARGV;
if(!$prefix){
die "missing prefix!\n";
Expand All @@ -21,16 +35,13 @@
open In, "$config_in" or die "Can't open $config_in.\n";
while(<In>){
if(/^#define\s+(\w+)\s*(.+)/){
my ($name, $val) = ($1, $2);
if($name=~/^[A-Z]/){
$name = uc($prefix)."_$name";
}
else{
$name = "_".lc($prefix)."_$name";
}
push @lines, "#ifndef $name \n";
push @lines, "#define $name $val \n";
push @lines, "#endif\n";
my $name = add_prefix($1, $prefix);
push @lines, "#define $name $2\n";
next;
}
elsif(/^\/\*\s*#undef (\w+)/){
my $name = add_prefix($1, $prefix);
push @lines, "/* #undef $name */\n";
next;
}
push @lines, $_;
Expand Down

0 comments on commit d860eeb

Please sign in to comment.