Commit | Line | Data |
a0d0e21e |
1 | #!./miniperl -w |
8990e307 |
2 | |
3 | @ARGV = "./config.sh"; |
a0d0e21e |
4 | $config_pm = 'lib/Config.pm'; |
8990e307 |
5 | |
a0d0e21e |
6 | # list names to put first (and hence lookup fastest) |
7 | @fast = qw(osname osvers so libpth archlib |
8 | sharpbang startsh shsharp |
9 | dynamic_ext static_ext extensions dl_src |
10 | sig_name ccflags cppflags intsize); |
11 | |
12 | |
13 | open CONFIG, ">$config_pm" or die "Can't open $config_pm: $!\n"; |
8990e307 |
14 | $myver = sprintf("%.3f", $]); |
a0d0e21e |
15 | print CONFIG <<"ENDOFBEG"; |
8990e307 |
16 | package Config; |
17 | require Exporter; |
18 | \@ISA = (Exporter); |
19 | \@EXPORT = qw(%Config); |
20 | |
21 | \$] == $myver or die sprintf |
22 | "Perl lib version ($myver) doesn't match executable version (%.3f)\\n", \$]; |
23 | |
a0d0e21e |
24 | # This file was created by configpm when Perl was built. Any changes |
25 | # made to this file will be lost the next time perl is built. |
26 | |
8990e307 |
27 | ENDOFBEG |
28 | |
a0d0e21e |
29 | @fast{@fast} = @fast; |
30 | @non_v=(); |
31 | @v_fast=(); |
32 | @v_others=(); |
33 | |
85e6fe83 |
34 | while (<>) { |
a0d0e21e |
35 | next if m:^#!/bin/sh:; |
36 | # Catch CONFIG=true and PATCHLEVEL=n line from Configure. |
37 | s/^(\w+)=(true|\d+)\s*$/$1='$2'\n/; |
38 | unless (m/^(\w+)='(.*)'\s*$/){ |
39 | push(@non_v, "#$_"); # not a name='value' line |
40 | next; |
41 | } |
42 | if (!$fast{$1}){ push(@v_others, $_); next; } |
43 | push(@v_fast,$_); |
44 | } |
45 | |
46 | foreach(@non_v){ print CONFIG $_ } |
47 | |
48 | print CONFIG "\n", |
49 | "\$config_sh=<<'!END!OF!CONFIG!';\n", |
50 | join("", @v_fast, sort @v_others), |
51 | "!END!OF!CONFIG!\n\n"; |
52 | |
53 | |
54 | print CONFIG <<'ENDOFEND'; |
55 | |
56 | tie %Config, Config; |
57 | sub TIEHASH { bless {} } |
58 | sub FETCH { |
59 | # check for cached value (which maybe undef so we use exists not defined) |
60 | return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]}); |
61 | |
62 | my($value); # search for the item in the big $config_sh string |
63 | return undef unless (($value) = $config_sh =~ m/^$_[1]='(.*)'\s*$/m); |
64 | |
65 | $value = undef if $value eq 'undef'; # So we can say "if $Config{'foo'}". |
66 | $_[0]->{$_[1]} = $value; # cache it |
67 | return $value; |
68 | } |
69 | |
70 | sub FIRSTKEY { |
71 | $prevpos = 0; |
72 | my $key; |
73 | ($key) = $config_sh =~ m/^(.*)=/; |
74 | $key; |
75 | } |
76 | |
77 | sub NEXTKEY { |
78 | my ($pos, $len); |
79 | $pos = $prevpos; |
80 | $pos = index( $config_sh, "\n", $pos) + 1; |
81 | $prevpos = $pos; |
82 | $len = index( $config_sh, "=", $pos) - $pos; |
83 | $len > 0 ? substr( $config_sh, $pos, $len) : undef; |
85e6fe83 |
84 | } |
a0d0e21e |
85 | |
86 | sub EXISTS{ |
87 | exists($_[0]->{$_[1]}) or $config_sh =~ m/^$_[1]=/m; |
88 | } |
89 | |
90 | sub readonly { die "\%Config::Config is read-only\n" } |
91 | |
92 | sub STORE { &readonly } |
93 | sub DELETE{ &readonly } |
94 | sub CLEAR { &readonly } |
95 | |
96 | |
97 | 1; |
98 | ENDOFEND |
99 | |
100 | close(CONFIG); |
101 | |
102 | # Now do some simple tests on the Config.pm file we have created |
103 | unshift(@INC,'lib'); |
104 | require $config_pm; |
105 | import Config; |
106 | |
107 | die "$0: $config_pm not valid" |
108 | unless $Config{'CONFIG'} eq 'true'; |
109 | |
110 | die "$0: error processing $config_pm" |
111 | if defined($Config{'an impossible name'}) |
112 | or $Config{'CONFIG'} ne 'true' # test cache |
113 | ; |
114 | |
115 | die "$0: error processing $config_pm" |
116 | if eval '$Config{"cc"} = 1' |
117 | or eval 'delete $Config{"cc"}' |
118 | ; |
119 | |
120 | |
85e6fe83 |
121 | exit 0; |