This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Extract _cmd_l_calc_initial_end_and_i .
[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#
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
14use strict;
15use warnings;
16
17my ($cSH, $ch, @ch, %ch) = ("config_h.SH");
18open $ch, "<$cSH" or die "Cannot open $cSH: $!\n";
19{ local $/ = "\n\n";
20 @ch = <$ch>;
21 close $ch;
22 }
23
24sub 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
34my %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 ) ],
9b70c55f 39 USE_CROSS_COMPILE => [ qw( BYTEORDER MEM_ALIGNBYTES ) ],
253687a9 40 HAS_QUAD => [ qw( I64TYPE ) ],
9b70c55f
MB
41 HAS_GETGROUPS => [ qw( Groups_t ) ],
42 HAS_SETGROUPS => [ qw( Groups_t ) ],
253687a9
MB
43 );
44
45my $changed;
46do {
47 $changed = 0;
48 foreach my $sym (keys %dep) {
49 ch_index;
50 foreach my $dep (@{$dep{$sym}}) {
51 print STDERR "Check if $sym\t($ch{$sym}) precedes $dep\t($ch{$dep})\n";
52 $ch{$sym} < $ch{$dep} and next;
53 my $ch = splice @ch, $ch{$sym}, 1;
54 splice @ch, $ch{$dep}, 0, $ch;
55 $changed++;
56 ch_index;
57 }
58 }
59 } while ($changed);
60
43dddb59
MB
61# 30327
62for (grep m{echo .Extracting \$CONFIG_H} => @ch) {
63 my $case = join "\n",
64 qq{case "\$CONFIG_H" in},
65 qq{already-done) echo "Not re-extracting config.h" ;;},
66 qq{*)}, "";
67 s{^(?=echo .Extracting)}{$case}m;
68 }
69push @ch, ";;\nesac\n";
70
71
253687a9 72open $ch, "> $cSH" or die "Cannot write $cSH: $!\n";
43dddb59 73print $ch <<EOW;
5b46e172
MB
74#!/bin/sh
75#
43dddb59
MB
76# THIS IS A GENERATED FILE
77# DO NOT HAND-EDIT
78#
79# See Porting/config_h.pl
80
81EOW
82
253687a9
MB
83print $ch @ch;
84close $ch;