This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Cleanup program in 'perl' directory is actually Porting/config_h.pl.
[metaconfig.git] / bin / find_config_h_deps.pl
CommitLineData
6092c506 1#!/usr/bin/perl
459d3fb5
MBT
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
21my @ref;
22sub ch_index ()
23{
24 %ch = ();
25 foreach my $ch (0 .. $#ch) {
26 while ($ch[$ch] =~ m{^/\* ([A-Z]\w+)}gm) {
27 $ch{$1} = $ch;
28 push @{$ref[$ch]}, $1;
29 }
30 }
31 } # ch_index
32
33ch_index;
34my @CH = @ch;
35my %RF;
36foreach my $ch (0 .. $#CH) {
37 $CH[$ch] =~ s{/\*.*?\*/\s*}{}gis;
38 while ($CH[$ch] =~ m{\b([A-Z]\w+)}g) {
39 exists $ch{$1} or next;
40 $ch{$1} == $ch and next;
41 #print STDERR "$ref[$ch][0] ($ch) ref to $1 ($ch{$1})\n";
42 $RF{$1}{$ref[$ch][0]}++;
43 }
44 }
45foreach my $r (sort keys %RF) {
46 my $R = sprintf "%-20s", $r;
47 print " $r => [ qw ( @{[sort keys %{$RF{$r}}]}\t) ],\n";
48 }
49
50my %dep = (
51 # This symbol must be defined BEFORE ...
52 BYTEORDER => [ qw( UVSIZE ) ],
53 LONGSIZE => [ qw( BYTEORDER ) ],
54 MULTIARCH => [ qw( BYTEORDER MEM_ALIGNBYTES ) ],
55 USE_CROSS_COMPILE => [ qw( BYTEORDER MEM_ALIGNBYTES ) ],
56 HAS_QUAD => [ qw( I64TYPE ) ],
57 HAS_GETGROUPS => [ qw( Groups_t ) ],
58 HAS_SETGROUPS => [ qw( Groups_t ) ],
59 );
60
61my $CHANGED = 0;
62my $changed;
63do {
64 $changed = 0;
65 foreach my $sym (keys %dep) {
66 ch_index;
67 foreach my $dep (@{$dep{$sym}}) {
68 print STDERR "Check if $sym\t($ch{$sym}) precedes $dep\t($ch{$dep})\n";
69 $ch{$sym} < $ch{$dep} and next;
70 my $ch = splice @ch, $ch{$sym}, 1;
71 splice @ch, $ch{$dep}, 0, $ch;
72 $changed++;
73 $CHANGED++;
74 ch_index;
75 }
76 }
77 } while ($changed);