Commit | Line | Data |
---|---|---|
253687a9 MB |
1 | #!/usr/bin/perl |
2 | ||
3 | # This script reorders config_h.SH after metaconfig | |
4 | # Changing metaconfig is too complicated | |
5 | # | |
5b46e172 MB |
6 | # This script is run just after metaconfig, and it |
7 | # is run ONLY ONCE. Not to be used afterwards | |
8 | # | |
9 | # Copyright (C) 2005-2012 by H.Merijn Brand (m)'12 [22-09-2012] | |
253687a9 MB |
10 | # |
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. | |
13 | ||
14 | use strict; | |
15 | use warnings; | |
16 | ||
17 | my ($cSH, $ch, @ch, %ch) = ("config_h.SH"); | |
18 | open $ch, "<$cSH" or die "Cannot open $cSH: $!\n"; | |
19 | { local $/ = "\n\n"; | |
20 | @ch = <$ch>; | |
21 | close $ch; | |
22 | } | |
23 | ||
24 | sub ch_index () | |
25 | { | |
26 | %ch = (); | |
27 | foreach my $ch (0 .. $#ch) { | |
28 | while ($ch[$ch] =~ m{^/\* ([A-Z]\w+)}gm) { | |
29 | $ch{$1} = $ch; | |
30 | } | |
31 | } | |
32 | } # ch_index | |
33 | ||
34 | my %dep = ( | |
35 | # This symbol must be defined BEFORE ... | |
9b70c55f | 36 | BYTEORDER => [ qw( UVSIZE ) ], |
253687a9 MB |
37 | LONGSIZE => [ qw( BYTEORDER ) ], |
38 | MULTIARCH => [ qw( BYTEORDER MEM_ALIGNBYTES ) ], | |
39 | HAS_QUAD => [ qw( I64TYPE ) ], | |
9b70c55f MB |
40 | HAS_GETGROUPS => [ qw( Groups_t ) ], |
41 | HAS_SETGROUPS => [ qw( Groups_t ) ], | |
253687a9 MB |
42 | ); |
43 | ||
44 | my $changed; | |
45 | do { | |
46 | $changed = 0; | |
47 | foreach my $sym (keys %dep) { | |
48 | ch_index; | |
49 | foreach my $dep (@{$dep{$sym}}) { | |
50 | print STDERR "Check if $sym\t($ch{$sym}) precedes $dep\t($ch{$dep})\n"; | |
51 | $ch{$sym} < $ch{$dep} and next; | |
52 | my $ch = splice @ch, $ch{$sym}, 1; | |
53 | splice @ch, $ch{$dep}, 0, $ch; | |
54 | $changed++; | |
55 | ch_index; | |
56 | } | |
57 | } | |
58 | } while ($changed); | |
59 | ||
43dddb59 MB |
60 | # 30327 |
61 | for (grep m{echo .Extracting \$CONFIG_H} => @ch) { | |
62 | my $case = join "\n", | |
63 | qq{case "\$CONFIG_H" in}, | |
64 | qq{already-done) echo "Not re-extracting config.h" ;;}, | |
65 | qq{*)}, ""; | |
66 | s{^(?=echo .Extracting)}{$case}m; | |
67 | } | |
68 | push @ch, ";;\nesac\n"; | |
69 | ||
70 | ||
253687a9 | 71 | open $ch, "> $cSH" or die "Cannot write $cSH: $!\n"; |
43dddb59 | 72 | print $ch <<EOW; |
5b46e172 MB |
73 | #!/bin/sh |
74 | # | |
43dddb59 MB |
75 | # THIS IS A GENERATED FILE |
76 | # DO NOT HAND-EDIT | |
77 | # | |
78 | # See Porting/config_h.pl | |
79 | ||
80 | EOW | |
81 | ||
253687a9 MB |
82 | print $ch @ch; |
83 | close $ch; |