This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mktables: Improve \p{xids} defn for early Unicodes
[perl5.git] / Porting / config_h.pl
1 #!/usr/bin/perl
2
3 # This script reorders config_h.SH after metaconfig
4 # Changing metaconfig is too complicated
5 #
6 # Copyright (C) 2005-2007 by H.Merijn Brand (m)'07 [18-04-2007]
7 #
8 # You may distribute under the terms of either the GNU General Public
9 # License or the Artistic License, as specified in the README file.
10
11 use strict;
12 use warnings;
13
14 my ($cSH, $ch, @ch, %ch) = ("config_h.SH");
15 open $ch, "<$cSH" or die "Cannot open $cSH: $!\n";
16 {   local $/ = "\n\n";
17     @ch = <$ch>;
18     close  $ch;
19     }
20
21 sub ch_index ()
22 {
23     %ch = ();
24     foreach my $ch (0 .. $#ch) {
25         while ($ch[$ch] =~ m{^/\* ([A-Z]\w+)}gm) {
26             $ch{$1} = $ch;
27             }
28         }
29     } # ch_index
30
31 my %dep = (
32     # This symbol must be defined BEFORE ...
33     BYTEORDER           => [ qw( UVSIZE                         ) ],
34     LONGSIZE            => [ qw( BYTEORDER                      ) ],
35     MULTIARCH           => [ qw( BYTEORDER MEM_ALIGNBYTES       ) ],
36     USE_CROSS_COMPILE   => [ qw( BYTEORDER MEM_ALIGNBYTES       ) ],
37     HAS_QUAD            => [ qw( I64TYPE                        ) ],
38     HAS_GETGROUPS       => [ qw( Groups_t                       ) ],
39     HAS_SETGROUPS       => [ qw( Groups_t                       ) ],
40     );
41
42 my $changed;
43 do {
44     $changed = 0;
45     foreach my $sym (keys %dep) {
46         ch_index;
47         foreach my $dep (@{$dep{$sym}}) {
48             print STDERR "Check if $sym\t($ch{$sym}) precedes $dep\t($ch{$dep})\n";
49             $ch{$sym} < $ch{$dep} and next;
50             my $ch = splice @ch, $ch{$sym}, 1;
51             splice @ch, $ch{$dep}, 0, $ch;
52             $changed++;
53             ch_index;
54             }
55         }
56     } while ($changed);
57
58 # 30327
59 for (grep m{echo .Extracting \$CONFIG_H} => @ch) {
60     my $case = join "\n",
61         qq{case "\$CONFIG_H" in},
62         qq{already-done) echo "Not re-extracting config.h" ;;},
63         qq{*)}, "";
64     s{^(?=echo .Extracting)}{$case}m;
65     }
66 push @ch, ";;\nesac\n";
67
68
69 open  $ch, "> $cSH" or die "Cannot write $cSH: $!\n";
70 print $ch <<EOW;
71 # THIS IS A GENERATED FILE
72 # DO NOT HAND-EDIT
73 #
74 # See Porting/config_h.pl
75
76 EOW
77
78 print $ch @ch;
79 close $ch;