Skip to content
Permalink
Browse files

config: further tuning of ax_prefix_config_h

* 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 b5006469b1bb7d7b68e8c8c2d785b70d8005a057
Showing with 28 additions and 9 deletions.
  1. +28 −9 confdb/cmd_prefix_config_h.pl
@@ -7,6 +7,26 @@
#
# 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=~/^(inline|const|restrict)/){
# leave c99 keywords alone
}
elsif($name=~/^_/){
# leave underscore keywords alone, e.g _MINIX
}
elsif($name=~/^$prefix\_/i){
# avoid double prefix
}
elsif($name=~/^[A-Z0-9_]+$/){
$name = uc($prefix)."_$name";
}
else{
$name = "_".lc($prefix)."_$name";
}
return $name;
}

my ($prefix, $config_in, $config_out)=@ARGV;
if(!$prefix){
die "missing prefix!\n";
@@ -21,18 +41,17 @@
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";
my $name = add_prefix($1, $prefix);
push @lines, "#ifndef $name\n";
push @lines, "#define $name $2\n";
push @lines, "#endif\n";
next;
}
elsif(/^\/\*\s*#undef (\w+)/){
my $name = add_prefix($1, $prefix);
push @lines, "/* #undef $name */\n";
next;
}
push @lines, $_;
}
close In;

0 comments on commit b500646

Please sign in to comment.
You can’t perform that action at this time.