3 $config_pm = $ARGV[0] || 'lib/Config.pm';
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);
12 # names of things which may need to have slashes changed to double-colons
13 @extensions = qw(dynamic_ext static_ext extensions known_extensions);
16 open CONFIG, ">$config_pm" or die "Can't open $config_pm: $!\n";
17 $myver = sprintf("%.3f", $]);
18 print CONFIG <<"ENDOFBEG";
22 \@EXPORT = qw(%Config);
24 \$] == $myver or die sprintf
25 "Perl lib version ($myver) doesn't match executable version (%.3f)\\n", \$];
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.
32 print CONFIG <<'EndOfPod';
35 Config - access Perl configuration option
40 if ($Config{'cc'} =~ /gcc/) {
41 print "built by gcc\n";
46 The Config module contains everything that was available to the
47 C<Configure> program at Perl build time. Shell variables from
48 F<config.sh> are stored in the readonly-variable C<%Config>, indexed by
53 Here's a more sophisticated example of using %Config:
57 defined $Config{sig_name} || die "No sigs?";
58 foreach $name (split(' ', $Config{sig_name})) {
64 print "signal #17 = $signame[17]\n";
66 print "SIGALRM is $signo{ALRM}\n";
71 This module contains a good example of how to make a variable
72 readonly to those outside of it.
79 @extensions{@extensions} = @extensions;
85 next if m:^#!/bin/sh:;
86 # Catch CONFIG=true and PATCHLEVEL=n line from Configure.
87 s/^(\w+)=(true|\d+)\s*$/$1='$2'\n/;
88 unless (m/^(\w+)='(.*)'\s*$/){
89 push(@non_v, "#$_"); # not a name='value' line
93 if ($extensions{$name}) { s,/,::,g }
94 if (!$fast{$name}){ push(@v_others, $_); next; }
98 foreach(@non_v){ print CONFIG $_ }
101 "\$config_sh=<<'!END!OF!CONFIG!';\n",
102 join("", @v_fast, sort @v_others),
103 "!END!OF!CONFIG!\n\n";
106 print CONFIG <<'ENDOFEND';
109 sub TIEHASH { bless {} }
111 # check for cached value (which maybe undef so we use exists not defined)
112 return $_[0]->{$_[1]} if (exists $_[0]->{$_[1]});
114 my($value); # search for the item in the big $config_sh string
115 return undef unless (($value) = $config_sh =~ m/^$_[1]='(.*)'\s*$/m);
117 $value = undef if $value eq 'undef'; # So we can say "if $Config{'foo'}".
118 $_[0]->{$_[1]} = $value; # cache it
125 ($key) = $config_sh =~ m/^(.*)=/;
132 $pos = index( $config_sh, "\n", $pos) + 1;
134 $len = index( $config_sh, "=", $pos) - $pos;
135 $len > 0 ? substr( $config_sh, $pos, $len) : undef;
139 exists($_[0]->{$_[1]}) or $config_sh =~ m/^$_[1]=/m;
142 sub readonly { die "\%Config::Config is read-only\n" }
148 Summary of my $package (patchlevel $PATCHLEVEL) configuration:
150 osname=$osname, osver=$osvers, archname=$archname
154 cc='$cc', optimize='$optimize'
158 stdchar='$stdchar', d_stdstdio=$d_stdstdio, usevfork=$usevfork
159 voidflags=$voidflags, castflags=$castflags, d_casti32=$d_casti32, d_castneg=$d_castneg
160 intsize=$intsize, alignbytes=$alignbytes, usemymalloc=$usemymalloc, randbits=$randbits
167 dlsrc=$dlsrc, dlext=$dlext, d_dlsymun=$d_dlsymun
168 cccdlflags='$cccdlflags', ccdlflags='$ccdlflags', lddlflags='$lddlflags'
171 $output =~ s/\$(\w+)/$Config{$1}/ge;
175 sub STORE { &readonly }
176 sub DELETE{ &readonly }
177 sub CLEAR { &readonly }
179 sub config_sh { $config_sh }
186 # Now do some simple tests on the Config.pm file we have created
191 die "$0: $config_pm not valid"
192 unless $Config{'CONFIG'} eq 'true';
194 die "$0: error processing $config_pm"
195 if defined($Config{'an impossible name'})
196 or $Config{'CONFIG'} ne 'true' # test cache
199 die "$0: error processing $config_pm"
200 if eval '$Config{"cc"} = 1'
201 or eval 'delete $Config{"cc"}'