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 ... |
33 | LONGSIZE => [ qw( BYTEORDER ) ], |
34 | MULTIARCH => [ qw( BYTEORDER MEM_ALIGNBYTES ) ], |
35 | HAS_QUAD => [ qw( I64TYPE ) ], |
36 | ); |
37 | |
38 | my $changed; |
39 | do { |
40 | $changed = 0; |
41 | foreach my $sym (keys %dep) { |
42 | ch_index; |
43 | foreach my $dep (@{$dep{$sym}}) { |
44 | print STDERR "Check if $sym\t($ch{$sym}) precedes $dep\t($ch{$dep})\n"; |
45 | $ch{$sym} < $ch{$dep} and next; |
46 | my $ch = splice @ch, $ch{$sym}, 1; |
47 | splice @ch, $ch{$dep}, 0, $ch; |
48 | $changed++; |
49 | ch_index; |
50 | } |
51 | } |
52 | } while ($changed); |
53 | |
54 | open $ch, "> $cSH" or die "Cannot write $cSH: $!\n"; |
55 | print $ch @ch; |
56 | close $ch; |