This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to CPAN-1.88_53.
[perl5.git] / Porting / config_h.pl
CommitLineData
253687a9
MB
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-2005 by H.Merijn Brand (m)'05 [25-05-2005]
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
11use strict;
12use warnings;
13
14my ($cSH, $ch, @ch, %ch) = ("config_h.SH");
15open $ch, "<$cSH" or die "Cannot open $cSH: $!\n";
16{ local $/ = "\n\n";
17 @ch = <$ch>;
18 close $ch;
19 }
20
21sub 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
31my %dep = (
32 # This symbol must be defined BEFORE ...
9b70c55f 33 BYTEORDER => [ qw( UVSIZE ) ],
253687a9
MB
34 LONGSIZE => [ qw( BYTEORDER ) ],
35 MULTIARCH => [ qw( BYTEORDER MEM_ALIGNBYTES ) ],
9b70c55f 36 USE_CROSS_COMPILE => [ qw( BYTEORDER MEM_ALIGNBYTES ) ],
253687a9 37 HAS_QUAD => [ qw( I64TYPE ) ],
9b70c55f
MB
38 HAS_GETGROUPS => [ qw( Groups_t ) ],
39 HAS_SETGROUPS => [ qw( Groups_t ) ],
253687a9
MB
40 );
41
42my $changed;
43do {
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
58open $ch, "> $cSH" or die "Cannot write $cSH: $!\n";
59print $ch @ch;
60close $ch;