File: cmd_prefix_config_h.pl

package info (click to toggle)
mpich 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 423,384 kB
  • sloc: ansic: 1,088,434; cpp: 71,364; javascript: 40,763; f90: 22,829; sh: 17,463; perl: 14,773; xml: 14,418; python: 10,265; makefile: 9,246; fortran: 8,008; java: 4,355; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (72 lines) | stat: -rw-r--r-- 1,926 bytes parent folder | download | duplicates (37)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#! /usr/bin/env perl
##
## Copyright (C) by Argonne National Laboratory
##     See COPYRIGHT in top-level directory
##

use strict;

# This script is to be run by AC_CONFIG_COMMANDS in configure.ac.
# USAGE:
#     AC_CONFIG_COMMANDS([prefix-config],[perl cmd_prefix_config_h.pl PREFIX input_config.h output_config.h])
#
# 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";
}
if(!$config_in){
    $config_in = "config.h";
}
if(!$config_out){
    $config_out = $config_in;
}
my @lines;
open In, "$config_in" or die "Can't open $config_in.\n";
while(<In>){
    if(/^#define\s+(\w+)\s*(.+)/){
        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;
my $DEFH=uc($config_out);
$DEFH=~s/\W/_/g;
open Out, ">$config_out" or die "Can't write $config_out.\n";
print Out "#ifndef $DEFH\n";
print Out "#define $DEFH 1\n\n";
print Out "\x2f* $config_out. Generated automatically at end of configure. *\x2f\n";
print Out @lines;
print Out "\x2f* once: $DEFH *\x2f\n";
print Out "#endif\n";
close Out;