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