Commit | Line | Data |
a0d0e21e |
1 | #!./miniperl -w |
8990e307 |
2 | |
75f92628 |
3 | $config_pm = $ARGV[0] || 'lib/Config.pm'; |
8990e307 |
4 | @ARGV = "./config.sh"; |
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 | |
fec02dd3 |
12 | # names of things which may need to have slashes changed to double-colons |
13 | @extensions = qw(dynamic_ext static_ext extensions known_extensions); |
14 | |
a0d0e21e |
15 | |
16 | open CONFIG, ">$config_pm" or die "Can't open $config_pm: $!\n"; |
8990e307 |
17 | $myver = sprintf("%.3f", $]); |
a0d0e21e |
18 | print CONFIG <<"ENDOFBEG"; |
8990e307 |
19 | package Config; |
20 | require Exporter; |
21 | \@ISA = (Exporter); |
22 | \@EXPORT = qw(%Config); |
23 | |
24 | \$] == $myver or die sprintf |
25 | "Perl lib version ($myver) doesn't match executable version (%.3f)\\n", \$]; |
26 | |
a0d0e21e |
27 | # This file was created by configpm when Perl was built. Any changes |
28 | # made to this file will be lost the next time perl is built. |
29 | |
8990e307 |
30 | ENDOFBEG |
31 | |
a0d0e21e |
32 | @fast{@fast} = @fast; |
fec02dd3 |
33 | @extensions{@extensions} = @extensions; |
a0d0e21e |
34 | @non_v=(); |
35 | @v_fast=(); |
36 | @v_others=(); |
37 | |
85e6fe83 |
38 | while (<>) { |
a0d0e21e |
39 | next if m:^#!/bin/sh:; |
40 | # Catch CONFIG=true and PATCHLEVEL=n line from Configure. |
41 | s/^(\w+)=(true|\d+)\s*$/$1='$2'\n/; |
42 | unless (m/^(\w+)='(.*)'\s*$/){ |
43 | push(@non_v, "#$_"); # not a name='value' line |
44 | next; |
45 | } |
fec02dd3 |
46 | $name = $1; |
47 | if ($extensions{$name}) { s,/,::,g } |
48 | if (!$fast{$name}){ push(@v_others, $_); next; } |
a0d0e21e |
49 | push(@v_fast,$_); |
50 | } |
51 | |
52 | foreach(@non_v){ print CONFIG $_ } |
53 | |
54 | print CONFIG "\n", |
55 | "\$config_sh=<<'!END!OF!CONFIG!';\n", |
56 | join("", @v_fast, sort @v_others), |
57 | "!END!OF!CONFIG!\n\n"; |
58 | |
59 | |
60 | print CONFIG <<'ENDOFEND'; |
61 | |
62 | tie %Config, Config; |
63 | sub TIEHASH { bless {} } |
64 | sub FETCH { |
65 | # check for cached value (which maybe undef so we use exists not defined) |
66 | return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]}); |
67 | |
68 | my($value); # search for the item in the big $config_sh string |
69 | return undef unless (($value) = $config_sh =~ m/^$_[1]='(.*)'\s*$/m); |
70 | |
71 | $value = undef if $value eq 'undef'; # So we can say "if $Config{'foo'}". |
72 | $_[0]->{$_[1]} = $value; # cache it |
73 | return $value; |
74 | } |
75 | |
76 | sub FIRSTKEY { |
77 | $prevpos = 0; |
78 | my $key; |
79 | ($key) = $config_sh =~ m/^(.*)=/; |
80 | $key; |
81 | } |
82 | |
83 | sub NEXTKEY { |
84 | my ($pos, $len); |
85 | $pos = $prevpos; |
86 | $pos = index( $config_sh, "\n", $pos) + 1; |
87 | $prevpos = $pos; |
88 | $len = index( $config_sh, "=", $pos) - $pos; |
89 | $len > 0 ? substr( $config_sh, $pos, $len) : undef; |
85e6fe83 |
90 | } |
a0d0e21e |
91 | |
92 | sub EXISTS{ |
93 | exists($_[0]->{$_[1]}) or $config_sh =~ m/^$_[1]=/m; |
94 | } |
95 | |
96 | sub readonly { die "\%Config::Config is read-only\n" } |
97 | |
748a9306 |
98 | sub myconfig { |
99 | my($output); |
100 | |
101 | $output = <<'END'; |
102 | Summary of my $package (patchlevel $PATCHLEVEL) configuration: |
103 | Platform: |
104 | osname=$osname, osver=$osvers, archname=$archname |
105 | uname='$myuname' |
106 | hint=$hint |
107 | Compiler: |
108 | cc='$cc', optimize='$optimize' |
109 | cppflags='$cppflags' |
110 | ccflags ='$ccflags' |
111 | ldflags ='$ldflags' |
112 | stdchar='$stdchar', d_stdstdio=$d_stdstdio, usevfork=$usevfork |
113 | voidflags=$voidflags, castflags=$castflags, d_casti32=$d_casti32, d_castneg=$d_castneg |
114 | intsize=$intsize, alignbytes=$alignbytes, usemymalloc=$usemymalloc, randbits=$randbits |
115 | Libraries: |
116 | so=$so |
117 | libpth=$libpth |
118 | libs=$libs |
119 | libc=$libc |
120 | Dynamic Linking: |
121 | dlsrc=$dlsrc, dlext=$dlext, d_dlsymun=$d_dlsymun |
122 | cccdlflags='$cccdlflags', ccdlflags='$ccdlflags', lddlflags='$lddlflags' |
123 | |
124 | END |
125 | $output =~ s/\$(\w+)/$Config{$1}/ge; |
126 | $output; |
127 | } |
128 | |
a0d0e21e |
129 | sub STORE { &readonly } |
130 | sub DELETE{ &readonly } |
131 | sub CLEAR { &readonly } |
132 | |
133 | |
134 | 1; |
135 | ENDOFEND |
136 | |
137 | close(CONFIG); |
138 | |
139 | # Now do some simple tests on the Config.pm file we have created |
140 | unshift(@INC,'lib'); |
141 | require $config_pm; |
142 | import Config; |
143 | |
144 | die "$0: $config_pm not valid" |
145 | unless $Config{'CONFIG'} eq 'true'; |
146 | |
147 | die "$0: error processing $config_pm" |
148 | if defined($Config{'an impossible name'}) |
149 | or $Config{'CONFIG'} ne 'true' # test cache |
150 | ; |
151 | |
152 | die "$0: error processing $config_pm" |
153 | if eval '$Config{"cc"} = 1' |
154 | or eval 'delete $Config{"cc"}' |
155 | ; |
156 | |
157 | |
85e6fe83 |
158 | exit 0; |