3 # This script reorders config_h.SH after metaconfig
4 # Changing metaconfig is too complicated
6 # This script is run just after metaconfig, and it
7 # is run ONLY ONCE. Not to be used afterwards
9 # Copyright (C) 2005-2020 by H.Merijn Brand (m)'20 [23-08-2020]
11 # You may distribute under the terms of either the GNU General Public
12 # License or the Artistic License, as specified in the README file.
17 my ($cSH, $ch, @ch, %ch) = ("config_h.SH");
18 open $ch, "<", $cSH or die "Cannot open $cSH: $!\n";
26 foreach my $ch (0 .. $#ch) {
27 while ($ch[$ch] =~ m{^/\* ([A-Z]\w+)}gm) {
34 # This symbol must be defined BEFORE ...
35 BYTEORDER => [ qw( UVSIZE ) ],
36 LONGSIZE => [ qw( BYTEORDER ) ],
37 MULTIARCH => [ qw( BYTEORDER MEM_ALIGNBYTES ) ],
38 HAS_QUAD => [ qw( I64TYPE ) ],
39 HAS_GETGROUPS => [ qw( Groups_t ) ],
40 HAS_SETGROUPS => [ qw( Groups_t ) ],
46 foreach my $sym (keys %dep) {
48 foreach my $dep (@{$dep{$sym}}) {
49 print STDERR "Check if $sym\t($ch{$sym}) precedes $dep\t($ch{$dep})\n";
50 $ch{$sym} < $ch{$dep} and next;
51 my $ch = splice @ch, $ch{$sym}, 1;
52 splice @ch, $ch{$dep}, 0, $ch;
60 for (grep m{echo .Extracting \$CONFIG_H} => @ch) {
62 qq{case "\$CONFIG_H" in},
63 qq{already-done) echo "Not re-extracting config.h" ;;},
65 s{^(?=echo .Extracting)}{$case}m;
68 unless ($ch[0] =~ m/THIS IS A GENERATED FILE/) {
69 unshift @ch, join "\n" =>
72 "# THIS IS A GENERATED FILE",
75 "# See Porting/config_h.pl",
78 push @ch, ";;\nesac\n";
81 open $ch, ">", $cSH or die "Cannot write $cSH: $!\n";