Commit | Line | Data |
253687a9 |
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 | |
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 ... |
9b70c55f |
33 | BYTEORDER => [ qw( UVSIZE ) ], |
253687a9 |
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 |
38 | HAS_GETGROUPS => [ qw( Groups_t ) ], |
39 | HAS_SETGROUPS => [ qw( Groups_t ) ], |
253687a9 |
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 | open $ch, "> $cSH" or die "Cannot write $cSH: $!\n"; |
59 | print $ch @ch; |
60 | close $ch; |