This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make Configure abort if both -Duselongdouble and -Dusequadmath are requested
[perl5.git] / configpm
... / ...
CommitLineData
1#!./miniperl -w
2#
3# configpm
4#
5# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
6# 2002, 2003, 2004, 2005, 2006, 2007 Larry Wall and others.
7#
8#
9# Regenerate the files
10#
11# lib/Config.pm
12# lib/Config_heavy.pl
13# lib/Config.pod
14#
15#
16# from the contents of the static files
17#
18# Porting/Glossary
19# myconfig.SH
20#
21# and from the contents of the Configure-generated file
22#
23# config.sh
24#
25#
26# It will only update Config.pm and Config_heavy.pl if the contents of
27# either file would be different. Note that *both* files are updated in
28# this case, since for example an extension makefile that has a dependency
29# on Config.pm should trigger even if only Config_heavy.pl has changed.
30
31sub usage { die <<EOF }
32usage: $0 [ options ]
33 --no-glossary don't include Porting/Glossary in lib/Config.pod
34 --chdir=dir change directory before writing files
35EOF
36
37use strict;
38use vars qw(%Config $Config_SH_expanded);
39
40my $how_many_common = 22;
41
42# commonly used names to precache (and hence lookup fastest)
43my %Common;
44
45while ($how_many_common--) {
46 $_ = <DATA>;
47 chomp;
48 /^(\S+):\s*(\d+)$/ or die "Malformed line '$_'";
49 $Common{$1} = $1;
50}
51
52# Post 37589e1eefb1bd62 DynaLoader defaults to reading these at runtime.
53# Ideally we're redo the data below, but Fotango's build system made it
54# wonderfully easy to instrument, and no longer exists.
55$Common{$_} = $_ foreach qw(dlext so);
56
57# names of things which may need to have slashes changed to double-colons
58my %Extensions = map {($_,$_)}
59 qw(dynamic_ext static_ext extensions known_extensions);
60
61# The plan is that this information is used by ExtUtils::MakeMaker to generate
62# Makefile dependencies, rather than hardcoding a list, which has become out
63# of date. However, currently, MM_Unix.pm and MM_VMS.pm have *different* lists,
64# *and* descrip_mms.template doesn't actually install all the headers.
65# The "Unix" list seems to (attempt to) avoid the generated headers, which I'm
66# not sure is the right thing to do. Also, not certain whether it would be
67# easier to parse MANIFEST to get these (adding config.h, and potentially
68# removing others), but for now, stick to a hard coded list.
69
70# Could use a map to add ".h", but I suspect that it's easier to use literals,
71# so that anyone using grep will find them
72# This is the list from MM_VMS, plus pad.h, parser.h, utf8.h
73# which it installs. It *doesn't* install perliol.h - FIXME.
74my @header_files = qw(EXTERN.h INTERN.h XSUB.h av.h config.h cop.h cv.h
75 embed.h embedvar.h form.h gv.h handy.h hv.h hv_func.h intrpvar.h
76 iperlsys.h keywords.h mg.h nostdio.h op.h opcode.h
77 pad.h parser.h patchlevel.h perl.h perlio.h perlsdio.h
78 perlvars.h perly.h pp.h pp_proto.h proto.h
79 regcomp.h regexp.h regnodes.h scope.h sv.h thread.h utf8.h
80 util.h);
81
82push @header_files,
83 $^O eq 'VMS' ? 'vmsish.h' : qw(dosish.h perliol.h time64.h unixish.h);
84
85my $header_files = ' return qw(' . join(' ', sort @header_files) . ');';
86$header_files =~ s/(?=.{64}) # If line is still overlength
87 (.{1,64})\ # Split at the last convenient space
88 /$1\n /gx;
89
90# allowed opts as well as specifies default and initial values
91my %Allowed_Opts = (
92 'glossary' => 1, # --no-glossary - no glossary file inclusion,
93 # for compactness
94 'chdir' => '', # --chdir=dir - change directory before writing files
95);
96
97sub opts {
98 # user specified options
99 my %given_opts = (
100 # --opt=smth
101 (map {/^--([\-_\w]+)=(.*)$/} @ARGV),
102 # --opt --no-opt --noopt
103 (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV),
104 );
105
106 my %opts = (%Allowed_Opts, %given_opts);
107
108 for my $opt (grep {!exists $Allowed_Opts{$_}} keys %given_opts) {
109 warn "option '$opt' is not recognized";
110 usage;
111 }
112 @ARGV = grep {!/^--/} @ARGV;
113
114 return %opts;
115}
116
117
118my %Opts = opts();
119
120if ($Opts{chdir}) {
121 chdir $Opts{chdir} or die "$0: could not chdir $Opts{chdir}: $!"
122}
123
124my ($Config_SH, $Config_PM, $Config_heavy, $Config_POD);
125my $Glossary = 'Porting/Glossary';
126
127$Config_PM = "lib/Config.pm";
128$Config_POD = "lib/Config.pod";
129$Config_SH = "config.sh";
130
131($Config_heavy = $Config_PM) =~ s/\.pm$/_heavy.pl/;
132die "Can't automatically determine name for Config_heavy.pl from '$Config_PM'"
133 if $Config_heavy eq $Config_PM;
134
135my $config_txt;
136my $heavy_txt;
137
138my $export_funcs = <<'EOT';
139my %Export_Cache = (myconfig => 1, config_sh => 1, config_vars => 1,
140 config_re => 1, compile_date => 1, local_patches => 1,
141 bincompat_options => 1, non_bincompat_options => 1,
142 header_files => 1);
143EOT
144
145my %export_ok = eval $export_funcs or die;
146
147$config_txt .= sprintf << 'EOT', $], $export_funcs;
148# This file was created by configpm when Perl was built. Any changes
149# made to this file will be lost the next time perl is built.
150
151# for a description of the variables, please have a look at the
152# Glossary file, as written in the Porting folder, or use the url:
153# http://perl5.git.perl.org/perl.git/blob/HEAD:/Porting/Glossary
154
155package Config;
156use strict;
157use warnings;
158use vars '%%Config', '$VERSION';
159
160$VERSION = "%s";
161
162# Skip @Config::EXPORT because it only contains %%Config, which we special
163# case below as it's not a function. @Config::EXPORT won't change in the
164# lifetime of Perl 5.
165%s
166@Config::EXPORT = qw(%%Config);
167@Config::EXPORT_OK = keys %%Export_Cache;
168
169# Need to stub all the functions to make code such as print Config::config_sh
170# keep working
171
172EOT
173
174$config_txt .= "sub $_;\n" foreach sort keys %export_ok;
175
176my $myver = sprintf "%vd", $^V;
177
178$config_txt .= sprintf <<'ENDOFBEG', ($myver) x 3;
179
180# Define our own import method to avoid pulling in the full Exporter:
181sub import {
182 shift;
183 @_ = @Config::EXPORT unless @_;
184
185 my @funcs = grep $_ ne '%%Config', @_;
186 my $export_Config = @funcs < @_ ? 1 : 0;
187
188 no strict 'refs';
189 my $callpkg = caller(0);
190 foreach my $func (@funcs) {
191 die qq{"$func" is not exported by the Config module\n}
192 unless $Export_Cache{$func};
193 *{$callpkg.'::'.$func} = \&{$func};
194 }
195
196 *{"$callpkg\::Config"} = \%%Config if $export_Config;
197 return;
198}
199
200die "$0: Perl lib version (%s) doesn't match executable '$^X' version ($])"
201 unless $^V;
202
203$^V eq %s
204 or die sprintf "%%s: Perl lib version (%s) doesn't match executable '$^X' version (%%vd)", $0, $^V;
205
206ENDOFBEG
207
208
209my @non_v = ();
210my @v_others = ();
211my $in_v = 0;
212my %Data = ();
213my $quote;
214
215
216my %seen_quotes;
217{
218 my ($name, $val);
219 open(CONFIG_SH, $Config_SH) || die "Can't open $Config_SH: $!";
220 while (<CONFIG_SH>) {
221 next if m:^#!/bin/sh:;
222
223 # Catch PERL_CONFIG_SH=true and PERL_VERSION=n line from Configure.
224 s/^(\w+)=(true|\d+)\s*$/$1='$2'\n/ or m/^(\w+)='(.*)'$/;
225 my($k, $v) = ($1, $2);
226
227 # grandfather PATCHLEVEL and SUBVERSION and CONFIG
228 if ($k) {
229 if ($k eq 'PERL_VERSION') {
230 push @v_others, "PATCHLEVEL='$v'\n";
231 }
232 elsif ($k eq 'PERL_SUBVERSION') {
233 push @v_others, "SUBVERSION='$v'\n";
234 }
235 elsif ($k eq 'PERL_CONFIG_SH') {
236 push @v_others, "CONFIG='$v'\n";
237 }
238 }
239
240 # We can delimit things in config.sh with either ' or ".
241 unless ($in_v or m/^(\w+)=(['"])(.*\n)/){
242 push(@non_v, "#$_"); # not a name='value' line
243 next;
244 }
245 if ($in_v) {
246 $val .= $_;
247 }
248 else {
249 $quote = $2;
250 ($name,$val) = ($1,$3);
251 }
252 $in_v = $val !~ /$quote\n/;
253 next if $in_v;
254
255 s,/,::,g if $Extensions{$name};
256
257 $val =~ s/$quote\n?\z//;
258
259 my $line = "$name=$quote$val$quote\n";
260 push(@v_others, $line);
261 $seen_quotes{$quote}++;
262 }
263 close CONFIG_SH;
264}
265
266# This is somewhat grim, but I want the code for parsing config.sh here and
267# now so that I can expand $Config{ivsize} and $Config{ivtype}
268
269my $fetch_string = <<'EOT';
270
271# Search for it in the big string
272sub fetch_string {
273 my($self, $key) = @_;
274
275EOT
276
277if ($seen_quotes{'"'}) {
278 # We need the full ' and " code
279
280$fetch_string .= <<'EOT';
281 return undef unless my ($quote_type, $value) = $Config_SH_expanded =~ /\n$key=(['"])(.*?)\1\n/s;
282
283 # If we had a double-quote, we'd better eval it so escape
284 # sequences and such can be interpolated. Since the incoming
285 # value is supposed to follow shell rules and not perl rules,
286 # we escape any perl variable markers
287
288 # Historically, since " 'support' was added in change 1409, the
289 # interpolation was done before the undef. Stick to this arguably buggy
290 # behaviour as we're refactoring.
291 if ($quote_type eq '"') {
292 $value =~ s/\$/\\\$/g;
293 $value =~ s/\@/\\\@/g;
294 eval "\$value = \"$value\"";
295 }
296
297 # So we can say "if $Config{'foo'}".
298 $self->{$key} = $value eq 'undef' ? undef : $value; # cache it
299}
300EOT
301
302} else {
303 # We only have ' delimited.
304
305$fetch_string .= <<'EOT';
306 return undef unless $Config_SH_expanded =~ /\n$key=\'(.*?)\'\n/s;
307 # So we can say "if $Config{'foo'}".
308 $self->{$key} = $1 eq 'undef' ? undef : $1;
309}
310EOT
311
312}
313
314eval $fetch_string;
315die if $@;
316
317# Calculation for the keys for byteorder
318# This is somewhat grim, but I need to run fetch_string here.
319our $Config_SH_expanded = join "\n", '', @v_others;
320
321my $t = fetch_string ({}, 'ivtype');
322my $s = fetch_string ({}, 'ivsize');
323
324# byteorder does exist on its own but we overlay a virtual
325# dynamically recomputed value.
326
327# However, ivtype and ivsize will not vary for sane fat binaries
328
329my $f = $t eq 'long' ? 'L!' : $s == 8 ? 'Q': 'I';
330
331my $byteorder_code;
332if ($s == 4 || $s == 8) {
333 my $list = join ',', reverse(1..$s-1);
334 my $format = 'a'x$s;
335 $byteorder_code = <<"EOT";
336
337my \$i = ord($s);
338foreach my \$c ($list) { \$i <<= 8; \$i |= ord(\$c); }
339our \$byteorder = join('', unpack('$format', pack('$f', \$i)));
340EOT
341} else {
342 $byteorder_code = "our \$byteorder = '?'x$s;\n";
343}
344
345my @need_relocation;
346
347if (fetch_string({},'userelocatableinc')) {
348 foreach my $what (qw(prefixexp
349
350 archlibexp
351 html1direxp
352 html3direxp
353 man1direxp
354 man3direxp
355 privlibexp
356 scriptdirexp
357 sitearchexp
358 sitebinexp
359 sitehtml1direxp
360 sitehtml3direxp
361 sitelibexp
362 siteman1direxp
363 siteman3direxp
364 sitescriptexp
365 vendorarchexp
366 vendorbinexp
367 vendorhtml1direxp
368 vendorhtml3direxp
369 vendorlibexp
370 vendorman1direxp
371 vendorman3direxp
372 vendorscriptexp
373
374 siteprefixexp
375 sitelib_stem
376 vendorlib_stem
377
378 installarchlib
379 installhtml1dir
380 installhtml3dir
381 installman1dir
382 installman3dir
383 installprefix
384 installprefixexp
385 installprivlib
386 installscript
387 installsitearch
388 installsitebin
389 installsitehtml1dir
390 installsitehtml3dir
391 installsitelib
392 installsiteman1dir
393 installsiteman3dir
394 installsitescript
395 installvendorarch
396 installvendorbin
397 installvendorhtml1dir
398 installvendorhtml3dir
399 installvendorlib
400 installvendorman1dir
401 installvendorman3dir
402 installvendorscript
403 )) {
404 push @need_relocation, $what if fetch_string({}, $what) =~ m!^\.\.\./!;
405 }
406}
407
408my %need_relocation;
409@need_relocation{@need_relocation} = @need_relocation;
410
411# This can have .../ anywhere:
412if (fetch_string({}, 'otherlibdirs') =~ m!\.\.\./!) {
413 $need_relocation{otherlibdirs} = 'otherlibdirs';
414}
415
416my $relocation_code = <<'EOT';
417
418sub relocate_inc {
419 my $libdir = shift;
420 return $libdir unless $libdir =~ s!^\.\.\./!!;
421 my $prefix = $^X;
422 if ($prefix =~ s!/[^/]*$!!) {
423 while ($libdir =~ m!^\.\./!) {
424 # Loop while $libdir starts "../" and $prefix still has a trailing
425 # directory
426 last unless $prefix =~ s!/([^/]+)$!!;
427 # but bail out if the directory we picked off the end of $prefix is .
428 # or ..
429 if ($1 eq '.' or $1 eq '..') {
430 # Undo! This should be rare, hence code it this way rather than a
431 # check each time before the s!!! above.
432 $prefix = "$prefix/$1";
433 last;
434 }
435 # Remove that leading ../ and loop again
436 substr ($libdir, 0, 3, '');
437 }
438 $libdir = "$prefix/$libdir";
439 }
440 $libdir;
441}
442EOT
443
444my $osname = fetch_string({}, 'osname');
445my $from = $osname eq 'VMS' ? 'PERLSHR image' : 'binary (from libperl)';
446my $env_cygwin = $osname eq 'cygwin'
447 ? 'push @env, "CYGWIN=\"$ENV{CYGWIN}\"" if $ENV{CYGWIN};' . "\n" : "";
448
449$heavy_txt .= sprintf <<'ENDOFBEG', $osname, $osname, $from, $osname, $env_cygwin;
450# This file was created by configpm when Perl was built. Any changes
451# made to this file will be lost the next time perl is built.
452
453package Config;
454use strict;
455use warnings;
456use vars '%%Config';
457
458sub bincompat_options {
459 return split ' ', (Internals::V())[0];
460}
461
462sub non_bincompat_options {
463 return split ' ', (Internals::V())[1];
464}
465
466sub compile_date {
467 return (Internals::V())[2]
468}
469
470sub local_patches {
471 my (undef, undef, undef, @patches) = Internals::V();
472 return @patches;
473}
474
475sub _V {
476 die "Perl lib was built for '%s' but is being run on '$^O'"
477 unless "%s" eq $^O;
478
479 my ($bincompat, $non_bincompat, $date, @patches) = Internals::V();
480
481 my @opts = sort split ' ', "$bincompat $non_bincompat";
482
483 print Config::myconfig();
484 print "\nCharacteristics of this %s: \n";
485
486 print " Compile-time options:\n";
487 print " $_\n" for @opts;
488
489 if (@patches) {
490 print " Locally applied patches:\n";
491 print " $_\n" foreach @patches;
492 }
493
494 print " Built under %s\n";
495
496 print " $date\n" if defined $date;
497
498 my @env = map { "$_=\"$ENV{$_}\"" } sort grep {/^PERL/} keys %%ENV;
499%s
500 if (@env) {
501 print " \%%ENV:\n";
502 print " $_\n" foreach @env;
503 }
504 print " \@INC:\n";
505 print " $_\n" foreach @INC;
506}
507
508sub header_files {
509ENDOFBEG
510
511$heavy_txt .= $header_files . "\n}\n\n";
512
513if (%need_relocation) {
514 my $relocations_in_common;
515 # otherlibdirs only features in the hash
516 foreach (keys %need_relocation) {
517 $relocations_in_common++ if $Common{$_};
518 }
519 if ($relocations_in_common) {
520 $config_txt .= $relocation_code;
521 } else {
522 $heavy_txt .= $relocation_code;
523 }
524}
525
526$heavy_txt .= join('', @non_v) . "\n";
527
528# copy config summary format from the myconfig.SH script
529$heavy_txt .= "our \$summary = <<'!END!';\n";
530open(MYCONFIG,"<myconfig.SH") || die "open myconfig.SH failed: $!";
5311 while defined($_ = <MYCONFIG>) && !/^Summary of/;
532do { $heavy_txt .= $_ } until !defined($_ = <MYCONFIG>) || /^\s*$/;
533close(MYCONFIG);
534
535$heavy_txt .= "\n!END!\n" . <<'EOT';
536my $summary_expanded;
537
538sub myconfig {
539 return $summary_expanded if $summary_expanded;
540 ($summary_expanded = $summary) =~ s{\$(\w+)}
541 {
542 my $c;
543 if ($1 eq 'git_ancestor_line') {
544 if ($Config::Config{git_ancestor}) {
545 $c= "\n Ancestor: $Config::Config{git_ancestor}";
546 } else {
547 $c= "";
548 }
549 } else {
550 $c = $Config::Config{$1};
551 }
552 defined($c) ? $c : 'undef'
553 }ge;
554 $summary_expanded;
555}
556
557local *_ = \my $a;
558$_ = <<'!END!';
559EOT
560
561$heavy_txt .= join('', sort @v_others) . "!END!\n";
562
563# Only need the dynamic byteorder code in Config.pm if 'byteorder' is one of
564# the precached keys
565if ($Common{byteorder}) {
566 $config_txt .= $byteorder_code;
567} else {
568 $heavy_txt .= $byteorder_code;
569}
570
571if (@need_relocation) {
572$heavy_txt .= 'foreach my $what (qw(' . join (' ', @need_relocation) .
573 ")) {\n" . <<'EOT';
574 s/^($what=)(['"])(.*?)\2/$1 . $2 . relocate_inc($3) . $2/me;
575}
576EOT
577# Currently it only makes sense to do the ... relocation on Unix, so there's
578# no need to emulate the "which separator for this platform" logic in perl.c -
579# ':' will always be applicable
580if ($need_relocation{otherlibdirs}) {
581$heavy_txt .= << 'EOT';
582s{^(otherlibdirs=)(['"])(.*?)\2}
583 {$1 . $2 . join ':', map {relocate_inc($_)} split ':', $3 . $2}me;
584EOT
585}
586}
587
588$heavy_txt .= <<'EOT';
589s/(byteorder=)(['"]).*?\2/$1$2$Config::byteorder$2/m;
590
591my $config_sh_len = length $_;
592
593our $Config_SH_expanded = "\n$_" . << 'EOVIRTUAL';
594EOT
595
596foreach my $prefix (qw(ccflags ldflags)) {
597 my $value = fetch_string ({}, $prefix);
598 my $withlargefiles = fetch_string ({}, $prefix . "_uselargefiles");
599 if (defined $withlargefiles) {
600 $value =~ s/\Q$withlargefiles\E\b//;
601 $heavy_txt .= "${prefix}_nolargefiles='$value'\n";
602 }
603}
604
605foreach my $prefix (qw(libs libswanted)) {
606 my $value = fetch_string ({}, $prefix);
607 my $withlf = fetch_string ({}, 'libswanted_uselargefiles');
608 next unless defined $withlf;
609 my @lflibswanted
610 = split(' ', fetch_string ({}, 'libswanted_uselargefiles'));
611 if (@lflibswanted) {
612 my %lflibswanted;
613 @lflibswanted{@lflibswanted} = ();
614 if ($prefix eq 'libs') {
615 my @libs = grep { /^-l(.+)/ &&
616 not exists $lflibswanted{$1} }
617 split(' ', fetch_string ({}, 'libs'));
618 $value = join(' ', @libs);
619 } else {
620 my @libswanted = grep { not exists $lflibswanted{$_} }
621 split(' ', fetch_string ({}, 'libswanted'));
622 $value = join(' ', @libswanted);
623 }
624 }
625 $heavy_txt .= "${prefix}_nolargefiles='$value'\n";
626}
627
628if (open(my $fh, "cflags")) {
629 my $ccwarnflags;
630 my $ccstdflags;
631 while (<$fh>) {
632 if (/^warn="(.+)"$/) {
633 $ccwarnflags = $1;
634 } elsif (/^stdflags="(.+)"$/) {
635 $ccstdflags = $1;
636 }
637 }
638 if (defined $ccwarnflags) {
639 $heavy_txt .= "ccwarnflags='$ccwarnflags'\n";
640 }
641 if (defined $ccstdflags) {
642 $heavy_txt .= "ccstdflags='$ccstdflags'\n";
643 }
644}
645
646$heavy_txt .= "EOVIRTUAL\n";
647
648$heavy_txt .= <<'ENDOFGIT';
649eval {
650 # do not have hairy conniptions if this isnt available
651 require 'Config_git.pl';
652 $Config_SH_expanded .= $Config::Git_Data;
653 1;
654} or warn "Warning: failed to load Config_git.pl, something strange about this perl...\n";
655ENDOFGIT
656
657$heavy_txt .= $fetch_string;
658
659$config_txt .= <<'ENDOFEND';
660
661sub FETCH {
662 my($self, $key) = @_;
663
664 # check for cached value (which may be undef so we use exists not defined)
665 return exists $self->{$key} ? $self->{$key} : $self->fetch_string($key);
666}
667
668ENDOFEND
669
670$heavy_txt .= <<'ENDOFEND';
671
672my $prevpos = 0;
673
674sub FIRSTKEY {
675 $prevpos = 0;
676 substr($Config_SH_expanded, 1, index($Config_SH_expanded, '=') - 1 );
677}
678
679sub NEXTKEY {
680ENDOFEND
681if ($seen_quotes{'"'}) {
682$heavy_txt .= <<'ENDOFEND';
683 # Find out how the current key's quoted so we can skip to its end.
684 my $quote = substr($Config_SH_expanded,
685 index($Config_SH_expanded, "=", $prevpos)+1, 1);
686 my $pos = index($Config_SH_expanded, qq($quote\n), $prevpos) + 2;
687ENDOFEND
688} else {
689 # Just ' quotes, so it's much easier.
690$heavy_txt .= <<'ENDOFEND';
691 my $pos = index($Config_SH_expanded, qq('\n), $prevpos) + 2;
692ENDOFEND
693}
694$heavy_txt .= <<'ENDOFEND';
695 my $len = index($Config_SH_expanded, "=", $pos) - $pos;
696 $prevpos = $pos;
697 $len > 0 ? substr($Config_SH_expanded, $pos, $len) : undef;
698}
699
700sub EXISTS {
701 return 1 if exists($_[0]->{$_[1]});
702
703 return(index($Config_SH_expanded, "\n$_[1]='") != -1
704ENDOFEND
705if ($seen_quotes{'"'}) {
706$heavy_txt .= <<'ENDOFEND';
707 or index($Config_SH_expanded, "\n$_[1]=\"") != -1
708ENDOFEND
709}
710$heavy_txt .= <<'ENDOFEND';
711 );
712}
713
714sub STORE { die "\%Config::Config is read-only\n" }
715*DELETE = *CLEAR = \*STORE; # Typeglob aliasing uses less space
716
717sub config_sh {
718 substr $Config_SH_expanded, 1, $config_sh_len;
719}
720
721sub config_re {
722 my $re = shift;
723 return map { chomp; $_ } grep eval{ /^(?:$re)=/ }, split /^/,
724 $Config_SH_expanded;
725}
726
727sub config_vars {
728 # implements -V:cfgvar option (see perlrun -V:)
729 foreach (@_) {
730 # find optional leading, trailing colons; and query-spec
731 my ($notag,$qry,$lncont) = m/^(:)?(.*?)(:)?$/; # flags fore and aft,
732 # map colon-flags to print decorations
733 my $prfx = $notag ? '': "$qry="; # tag-prefix for print
734 my $lnend = $lncont ? ' ' : ";\n"; # line ending for print
735
736 # all config-vars are by definition \w only, any \W means regex
737 if ($qry =~ /\W/) {
738 my @matches = config_re($qry);
739 print map "$_$lnend", @matches ? @matches : "$qry: not found" if !$notag;
740 print map { s/\w+=//; "$_$lnend" } @matches ? @matches : "$qry: not found" if $notag;
741 } else {
742 my $v = (exists $Config::Config{$qry}) ? $Config::Config{$qry}
743 : 'UNKNOWN';
744 $v = 'undef' unless defined $v;
745 print "${prfx}'${v}'$lnend";
746 }
747 }
748}
749
750# Called by the real AUTOLOAD
751sub launcher {
752 undef &AUTOLOAD;
753 goto \&$Config::AUTOLOAD;
754}
755
7561;
757ENDOFEND
758
759if ($^O eq 'os2') {
760 $config_txt .= <<'ENDOFSET';
761my %preconfig;
762if ($OS2::is_aout) {
763 my ($value, $v) = $Config_SH_expanded =~ m/^used_aout='(.*)'\s*$/m;
764 for (split ' ', $value) {
765 ($v) = $Config_SH_expanded =~ m/^aout_$_='(.*)'\s*$/m;
766 $preconfig{$_} = $v eq 'undef' ? undef : $v;
767 }
768}
769$preconfig{d_fork} = undef unless $OS2::can_fork; # Some funny cases can't
770sub TIEHASH { bless {%preconfig} }
771ENDOFSET
772 # Extract the name of the DLL from the makefile to avoid duplication
773 my ($f) = grep -r, qw(GNUMakefile Makefile);
774 my $dll;
775 if (open my $fh, '<', $f) {
776 while (<$fh>) {
777 $dll = $1, last if /^PERL_DLL_BASE\s*=\s*(\S*)\s*$/;
778 }
779 }
780 $config_txt .= <<ENDOFSET if $dll;
781\$preconfig{dll_name} = '$dll';
782ENDOFSET
783} else {
784 $config_txt .= <<'ENDOFSET';
785sub TIEHASH {
786 bless $_[1], $_[0];
787}
788ENDOFSET
789}
790
791foreach my $key (keys %Common) {
792 my $value = fetch_string ({}, $key);
793 # Is it safe on the LHS of => ?
794 my $qkey = $key =~ /^[A-Za-z_][A-Za-z0-9_]*$/ ? $key : "'$key'";
795 if (defined $value) {
796 # Quote things for a '' string
797 $value =~ s!\\!\\\\!g;
798 $value =~ s!'!\\'!g;
799 $value = "'$value'";
800 if ($key eq 'otherlibdirs') {
801 $value = "join (':', map {relocate_inc(\$_)} split (':', $value))";
802 } elsif ($need_relocation{$key}) {
803 $value = "relocate_inc($value)";
804 }
805 } else {
806 $value = "undef";
807 }
808 $Common{$key} = "$qkey => $value";
809}
810
811if ($Common{byteorder}) {
812 $Common{byteorder} = 'byteorder => $byteorder';
813}
814my $fast_config = join '', map { " $_,\n" } sort values %Common;
815
816# Sanity check needed to stop an infinite loop if Config_heavy.pl fails to
817# define &launcher for some reason (eg it got truncated)
818$config_txt .= sprintf <<'ENDOFTIE', $fast_config;
819
820sub DESTROY { }
821
822sub AUTOLOAD {
823 require 'Config_heavy.pl';
824 goto \&launcher unless $Config::AUTOLOAD =~ /launcher$/;
825 die "&Config::AUTOLOAD failed on $Config::AUTOLOAD";
826}
827
828# tie returns the object, so the value returned to require will be true.
829tie %%Config, 'Config', {
830%s};
831ENDOFTIE
832
833
834open(CONFIG_POD, ">$Config_POD") or die "Can't open $Config_POD: $!";
835print CONFIG_POD <<'ENDOFTAIL';
836=head1 NAME
837
838Config - access Perl configuration information
839
840=head1 SYNOPSIS
841
842 use Config;
843 if ($Config{usethreads}) {
844 print "has thread support\n"
845 }
846
847 use Config qw(myconfig config_sh config_vars config_re);
848
849 print myconfig();
850
851 print config_sh();
852
853 print config_re();
854
855 config_vars(qw(osname archname));
856
857
858=head1 DESCRIPTION
859
860The Config module contains all the information that was available to
861the C<Configure> program at Perl build time (over 900 values).
862
863Shell variables from the F<config.sh> file (written by Configure) are
864stored in the readonly-variable C<%Config>, indexed by their names.
865
866Values stored in config.sh as 'undef' are returned as undefined
867values. The perl C<exists> function can be used to check if a
868named variable exists.
869
870For a description of the variables, please have a look at the
871Glossary file, as written in the Porting folder, or use the url:
872http://perl5.git.perl.org/perl.git/blob/HEAD:/Porting/Glossary
873
874=over 4
875
876=item myconfig()
877
878Returns a textual summary of the major perl configuration values.
879See also C<-V> in L<perlrun/Command Switches>.
880
881=item config_sh()
882
883Returns the entire perl configuration information in the form of the
884original config.sh shell variable assignment script.
885
886=item config_re($regex)
887
888Like config_sh() but returns, as a list, only the config entries who's
889names match the $regex.
890
891=item config_vars(@names)
892
893Prints to STDOUT the values of the named configuration variable. Each is
894printed on a separate line in the form:
895
896 name='value';
897
898Names which are unknown are output as C<name='UNKNOWN';>.
899See also C<-V:name> in L<perlrun/Command Switches>.
900
901=item bincompat_options()
902
903Returns a list of C pre-processor options used when compiling this F<perl>
904binary, which affect its binary compatibility with extensions.
905C<bincompat_options()> and C<non_bincompat_options()> are shown together in
906the output of C<perl -V> as I<Compile-time options>.
907
908=item non_bincompat_options()
909
910Returns a list of C pre-processor options used when compiling this F<perl>
911binary, which do not affect binary compatibility with extensions.
912
913=item compile_date()
914
915Returns the compile date (as a string), equivalent to what is shown by
916C<perl -V>
917
918=item local_patches()
919
920Returns a list of the names of locally applied patches, equivalent to what
921is shown by C<perl -V>.
922
923=item header_files()
924
925Returns a list of the header files that should be used as dependencies for
926XS code, for this version of Perl on this platform.
927
928=back
929
930=head1 EXAMPLE
931
932Here's a more sophisticated example of using %Config:
933
934 use Config;
935 use strict;
936
937 my %sig_num;
938 my @sig_name;
939 unless($Config{sig_name} && $Config{sig_num}) {
940 die "No sigs?";
941 } else {
942 my @names = split ' ', $Config{sig_name};
943 @sig_num{@names} = split ' ', $Config{sig_num};
944 foreach (@names) {
945 $sig_name[$sig_num{$_}] ||= $_;
946 }
947 }
948
949 print "signal #17 = $sig_name[17]\n";
950 if ($sig_num{ALRM}) {
951 print "SIGALRM is $sig_num{ALRM}\n";
952 }
953
954=head1 WARNING
955
956Because this information is not stored within the perl executable
957itself it is possible (but unlikely) that the information does not
958relate to the actual perl binary which is being used to access it.
959
960The Config module is installed into the architecture and version
961specific library directory ($Config{installarchlib}) and it checks the
962perl version number when loaded.
963
964The values stored in config.sh may be either single-quoted or
965double-quoted. Double-quoted strings are handy for those cases where you
966need to include escape sequences in the strings. To avoid runtime variable
967interpolation, any C<$> and C<@> characters are replaced by C<\$> and
968C<\@>, respectively. This isn't foolproof, of course, so don't embed C<\$>
969or C<\@> in double-quoted strings unless you're willing to deal with the
970consequences. (The slashes will end up escaped and the C<$> or C<@> will
971trigger variable interpolation)
972
973=head1 GLOSSARY
974
975Most C<Config> variables are determined by the C<Configure> script
976on platforms supported by it (which is most UNIX platforms). Some
977platforms have custom-made C<Config> variables, and may thus not have
978some of the variables described below, or may have extraneous variables
979specific to that particular port. See the port specific documentation
980in such cases.
981
982=cut
983
984ENDOFTAIL
985
986if ($Opts{glossary}) {
987 open(GLOS, "<$Glossary") or die "Can't open $Glossary: $!";
988}
989my %seen = ();
990my $text = 0;
991$/ = '';
992my $errors= 0;
993
994sub process {
995 if (s/\A(\w*)\s+\(([\w.]+)\):\s*\n(\t?)/=item C<$1>\n\nFrom F<$2>:\n\n/m) {
996 my $c = substr $1, 0, 1;
997 unless ($seen{$c}++) {
998 print CONFIG_POD <<EOF if $text;
999=back
1000
1001=cut
1002
1003EOF
1004 print CONFIG_POD <<EOF;
1005=head2 $c
1006
1007=over 4
1008
1009=cut
1010
1011EOF
1012 $text = 1;
1013 }
1014 }
1015 elsif (!$text || !/\A\t/) {
1016 warn "Expected a Configure variable header",
1017 ($text ? " or another paragraph of description" : () ),
1018 ", instead we got:\n$_";
1019 $errors++;
1020 }
1021 s/n't/n\00t/g; # leave can't, won't etc untouched
1022 s/^\t\s+(.*)/\n$1/gm; # Indented lines ===> new paragraph
1023 s/^(?<!\n\n)\t(.*)/$1/gm; # Not indented lines ===> text
1024 s{([\'\"])(?=[^\'\"\s]*[./][^\'\"\s]*\1)([^\'\"\s]+)\1}(F<$2>)g; # '.o'
1025 s{([\'\"])([^\'\"\s]+)\1}(C<$2>)g; # "date" command
1026 s{\'([A-Za-z_\- *=/]+)\'}(C<$1>)g; # 'ln -s'
1027 s{
1028 (?<! [\w./<\'\"\$] ) # Only standalone file names
1029 (?! e \. g \. ) # Not e.g.
1030 (?! \. \. \. ) # Not ...
1031 (?! \d ) # Not 5.004
1032 (?! read/ ) # Not read/write
1033 (?! etc\. ) # Not etc.
1034 (?! I/O ) # Not I/O
1035 (
1036 \$ ? # Allow leading $
1037 [\w./]* [./] [\w./]* # Require . or / inside
1038 )
1039 (?<! \. (?= [\s)] ) ) # Do not include trailing dot
1040 (?! [\w/] ) # Include all of it
1041 }
1042 (F<$1>)xg; # /usr/local
1043 s/((?<=\s)~\w*)/F<$1>/g; # ~name
1044 s/(?<![.<\'\"])\b([A-Z_]{2,})\b(?![\'\"])/C<$1>/g; # UNISTD
1045 s/(?<![.<\'\"])\b(?!the\b)(\w+)\s+macro\b/C<$1> macro/g; # FILE_cnt macro
1046 s/n[\0]t/n't/g; # undo can't, won't damage
1047}
1048
1049if ($Opts{glossary}) {
1050 <GLOS>; # Skip the "DO NOT EDIT"
1051 <GLOS>; # Skip the preamble
1052 while (<GLOS>) {
1053 process;
1054 print CONFIG_POD;
1055 }
1056 if ($errors) {
1057 die "Errors encountered while processing $Glossary. ",
1058 "Header lines are expected to be of the form:\n",
1059 "NAME (CLASS):\n",
1060 "Maybe there is a malformed header?\n",
1061 ;
1062 }
1063}
1064
1065print CONFIG_POD <<'ENDOFTAIL';
1066
1067=back
1068
1069=head1 GIT DATA
1070
1071Information on the git commit from which the current perl binary was compiled
1072can be found in the variable C<$Config::Git_Data>. The variable is a
1073structured string that looks something like this:
1074
1075 git_commit_id='ea0c2dbd5f5ac6845ecc7ec6696415bf8e27bd52'
1076 git_describe='GitLive-blead-1076-gea0c2db'
1077 git_branch='smartmatch'
1078 git_uncommitted_changes=''
1079 git_commit_id_title='Commit id:'
1080 git_commit_date='2009-05-09 17:47:31 +0200'
1081
1082Its format is not guaranteed not to change over time.
1083
1084=head1 NOTE
1085
1086This module contains a good example of how to use tie to implement a
1087cache and an example of how to make a tied variable readonly to those
1088outside of it.
1089
1090=cut
1091
1092ENDOFTAIL
1093
1094close(GLOS) if $Opts{glossary};
1095close(CONFIG_POD);
1096print "written $Config_POD\n";
1097
1098my $orig_config_txt = "";
1099my $orig_heavy_txt = "";
1100{
1101 local $/;
1102 my $fh;
1103 $orig_config_txt = <$fh> if open $fh, "<", $Config_PM;
1104 $orig_heavy_txt = <$fh> if open $fh, "<", $Config_heavy;
1105}
1106
1107if ($orig_config_txt ne $config_txt or $orig_heavy_txt ne $heavy_txt) {
1108 open CONFIG, ">", $Config_PM or die "Can't open $Config_PM: $!\n";
1109 open CONFIG_HEAVY, ">", $Config_heavy or die "Can't open $Config_heavy: $!\n";
1110 print CONFIG $config_txt;
1111 print CONFIG_HEAVY $heavy_txt;
1112 close(CONFIG_HEAVY);
1113 close(CONFIG);
1114 print "updated $Config_PM\n";
1115 print "updated $Config_heavy\n";
1116}
1117
1118# Now do some simple tests on the Config.pm file we have created
1119unshift(@INC,'lib');
1120require $Config_PM;
1121require $Config_heavy;
1122import Config;
1123
1124die "$0: $Config_PM not valid"
1125 unless $Config{'PERL_CONFIG_SH'} eq 'true';
1126
1127die "$0: error processing $Config_PM"
1128 if defined($Config{'an impossible name'})
1129 or $Config{'PERL_CONFIG_SH'} ne 'true' # test cache
1130 ;
1131
1132die "$0: error processing $Config_PM"
1133 if eval '$Config{"cc"} = 1'
1134 or eval 'delete $Config{"cc"}'
1135 ;
1136
1137
1138exit 0;
1139# Popularity of various entries in %Config, based on a large build and test
1140# run of code in the Fotango build system:
1141__DATA__
1142path_sep: 8490
1143d_readlink: 7101
1144d_symlink: 7101
1145archlibexp: 4318
1146sitearchexp: 4305
1147sitelibexp: 4305
1148privlibexp: 4163
1149ldlibpthname: 4041
1150libpth: 2134
1151archname: 1591
1152exe_ext: 1256
1153scriptdir: 1155
1154version: 1116
1155useithreads: 1002
1156osvers: 982
1157osname: 851
1158inc_version_list: 783
1159dont_use_nlink: 779
1160intsize: 759
1161usevendorprefix: 642
1162dlsrc: 624
1163cc: 541
1164lib_ext: 520
1165so: 512
1166ld: 501
1167ccdlflags: 500
1168ldflags: 495
1169obj_ext: 495
1170cccdlflags: 493
1171lddlflags: 493
1172ar: 492
1173dlext: 492
1174libc: 492
1175ranlib: 492
1176full_ar: 491
1177vendorarchexp: 491
1178vendorlibexp: 491
1179installman1dir: 489
1180installman3dir: 489
1181installsitebin: 489
1182installsiteman1dir: 489
1183installsiteman3dir: 489
1184installvendorman1dir: 489
1185installvendorman3dir: 489
1186d_flexfnam: 474
1187eunicefix: 360
1188d_link: 347
1189installsitearch: 344
1190installscript: 341
1191installprivlib: 337
1192binexp: 336
1193installarchlib: 336
1194installprefixexp: 336
1195installsitelib: 336
1196installstyle: 336
1197installvendorarch: 336
1198installvendorbin: 336
1199installvendorlib: 336
1200man1ext: 336
1201man3ext: 336
1202sh: 336
1203siteprefixexp: 336
1204installbin: 335
1205usedl: 332
1206ccflags: 285
1207startperl: 232
1208optimize: 231
1209usemymalloc: 229
1210cpprun: 228
1211sharpbang: 228
1212perllibs: 225
1213usesfio: 224
1214usethreads: 220
1215perlpath: 218
1216extensions: 217
1217usesocks: 208
1218shellflags: 198
1219make: 191
1220d_pwage: 189
1221d_pwchange: 189
1222d_pwclass: 189
1223d_pwcomment: 189
1224d_pwexpire: 189
1225d_pwgecos: 189
1226d_pwpasswd: 189
1227d_pwquota: 189
1228gccversion: 189
1229libs: 186
1230useshrplib: 186
1231cppflags: 185
1232ptrsize: 185
1233shrpenv: 185
1234static_ext: 185
1235use5005threads: 185
1236uselargefiles: 185
1237alignbytes: 184
1238byteorder: 184
1239ccversion: 184
1240config_args: 184
1241cppminus: 184