6 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
7 # 2002, 2003, 2004, 2005, 2006, 2007 Larry Wall and others.
10 # Regenerate the files
17 # from the contents of the static files
22 # and from the contents of the Configure-generated file
27 # It will only update Config.pm and Config_heavy.pl if the contents of
28 # either file would be different. Note that *both* files are updated in
29 # this case, since for example an extension makefile that has a dependency
30 # on Config.pm should trigger even if only Config_heavy.pl has changed.
32 sub usage { die <<EOF }
34 --no-glossary don't include Porting/Glossary in lib/Config.pod
35 --chdir=dir change directory before writing files
39 our (%Config, $Config_SH_expanded);
41 my $how_many_common = 22;
43 # commonly used names to precache (and hence lookup fastest)
46 while ($how_many_common--) {
49 /^(\S+):\s*(\d+)$/ or die "Malformed line '$_'";
53 # Post 37589e1eefb1bd62 DynaLoader defaults to reading these at runtime.
54 # Ideally we're redo the data below, but Fotango's build system made it
55 # wonderfully easy to instrument, and no longer exists.
56 $Common{$_} = $_ foreach qw(dlext so);
58 # names of things which may need to have slashes changed to double-colons
59 my %Extensions = map {($_,$_)}
60 qw(dynamic_ext static_ext extensions known_extensions);
62 # The plan is that this information is used by ExtUtils::MakeMaker to generate
63 # Makefile dependencies, rather than hardcoding a list, which has become out
64 # of date. However, currently, MM_Unix.pm and MM_VMS.pm have *different* lists,
65 # *and* descrip_mms.template doesn't actually install all the headers.
66 # The "Unix" list seems to (attempt to) avoid the generated headers, which I'm
67 # not sure is the right thing to do. Also, not certain whether it would be
68 # easier to parse MANIFEST to get these (adding config.h, and potentially
69 # removing others), but for now, stick to a hard coded list.
71 # Could use a map to add ".h", but I suspect that it's easier to use literals,
72 # so that anyone using grep will find them
73 # This is the list from MM_VMS, plus pad.h, parser.h, utf8.h
74 # which it installs. It *doesn't* install perliol.h - FIXME.
75 my @header_files = qw(EXTERN.h INTERN.h XSUB.h av.h config.h cop.h cv.h
76 embed.h embedvar.h form.h gv.h handy.h hv.h hv_func.h intrpvar.h
77 iperlsys.h keywords.h mg.h nostdio.h op.h opcode.h
78 pad.h parser.h patchlevel.h perl.h perlio.h perlsdio.h
79 perlvars.h perly.h pp.h pp_proto.h proto.h
80 regcomp.h regexp.h regnodes.h scope.h sv.h thread.h utf8.h
84 $^O eq 'VMS' ? 'vmsish.h' : qw(dosish.h perliol.h time64.h unixish.h);
86 my $header_files = ' return qw(' . join(' ', sort @header_files) . ');';
87 $header_files =~ s/(?=.{64}) # If line is still overlength
88 (.{1,64})\ # Split at the last convenient space
91 # allowed opts as well as specifies default and initial values
93 'glossary' => 1, # --no-glossary - no glossary file inclusion,
95 'chdir' => '', # --chdir=dir - change directory before writing files
99 # user specified options
102 (map {/^--([\-_\w]+)=(.*)$/} @ARGV),
103 # --opt --no-opt --noopt
104 (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV),
107 my %opts = (%Allowed_Opts, %given_opts);
109 for my $opt (grep {!exists $Allowed_Opts{$_}} keys %given_opts) {
110 warn "option '$opt' is not recognized";
113 @ARGV = grep {!/^--/} @ARGV;
122 chdir $Opts{chdir} or die "$0: could not chdir $Opts{chdir}: $!"
125 my ($Config_SH, $Config_PM, $Config_heavy, $Config_POD);
126 my $Glossary = 'Porting/Glossary';
128 $Config_PM = "lib/Config.pm";
129 $Config_POD = "lib/Config.pod";
130 $Config_SH = "config.sh";
132 ($Config_heavy = $Config_PM) =~ s/\.pm$/_heavy.pl/;
133 die "Can't automatically determine name for Config_heavy.pl from '$Config_PM'"
134 if $Config_heavy eq $Config_PM;
139 my $export_funcs = <<'EOT';
140 my %Export_Cache = (myconfig => 1, config_sh => 1, config_vars => 1,
141 config_re => 1, compile_date => 1, local_patches => 1,
142 bincompat_options => 1, non_bincompat_options => 1,
146 my %export_ok = eval $export_funcs or die;
148 $config_txt .= sprintf << 'EOT', $], $export_funcs;
149 # This file was created by configpm when Perl was built. Any changes
150 # made to this file will be lost the next time perl is built.
152 # for a description of the variables, please have a look at the
153 # Glossary file, as written in the Porting folder, or use the url:
154 # https://github.com/Perl/perl5/blob/blead/Porting/Glossary
159 our ( %%Config, $VERSION );
163 # Skip @Config::EXPORT because it only contains %%Config, which we special
164 # case below as it's not a function. @Config::EXPORT won't change in the
165 # lifetime of Perl 5.
167 @Config::EXPORT = qw(%%Config);
168 @Config::EXPORT_OK = keys %%Export_Cache;
170 # Need to stub all the functions to make code such as print Config::config_sh
175 $config_txt .= "sub $_;\n" foreach sort keys %export_ok;
177 my $myver = sprintf "%vd", $^V;
179 $config_txt .= sprintf <<'ENDOFBEG', ($myver) x 3;
181 # Define our own import method to avoid pulling in the full Exporter:
184 @_ = @Config::EXPORT unless @_;
186 my @funcs = grep $_ ne '%%Config', @_;
187 my $export_Config = @funcs < @_ ? 1 : 0;
190 my $callpkg = caller(0);
191 foreach my $func (@funcs) {
192 die qq{"$func" is not exported by the Config module\n}
193 unless $Export_Cache{$func};
194 *{$callpkg.'::'.$func} = \&{$func};
197 *{"$callpkg\::Config"} = \%%Config if $export_Config;
201 die "$0: Perl lib version (%s) doesn't match executable '$^X' version ($])"
205 or die sprintf "%%s: Perl lib version (%s) doesn't match executable '$^X' version (%%vd)", $0, $^V;
216 # These variables were set in older versions of Perl, but are no longer needed
217 # by the core. However, some CPAN modules may rely on them; in particular, Tk
218 # (at least up to version 804.034) fails to build without them. We force them
219 # to be emitted to Config_heavy.pl for backcompat with such modules (and we may
220 # find that this set needs to be extended in future). See RT#132347.
221 my @v_forced = map "$_\n", split /\n+/, <<'EOT';
233 open(CONFIG_SH, '<', $Config_SH) || die "Can't open $Config_SH: $!";
234 while (<CONFIG_SH>) {
235 next if m:^#!/bin/sh:;
237 # Catch PERL_CONFIG_SH=true and PERL_VERSION=n line from Configure.
238 s/^(\w+)=(true|\d+)\s*$/$1='$2'\n/ or m/^(\w+)='(.*)'$/;
239 my($k, $v) = ($1, $2);
241 # grandfather PATCHLEVEL and SUBVERSION and CONFIG
243 if ($k eq 'PERL_VERSION') {
244 push @v_others, "PATCHLEVEL='$v'\n";
246 elsif ($k eq 'PERL_SUBVERSION') {
247 push @v_others, "SUBVERSION='$v'\n";
249 elsif ($k eq 'PERL_CONFIG_SH') {
250 push @v_others, "CONFIG='$v'\n";
254 # We can delimit things in config.sh with either ' or ".
255 unless ($in_v or m/^(\w+)=(['"])(.*\n)/){
256 push(@non_v, "#$_"); # not a name='value' line
264 ($name,$val) = ($1,$3);
266 $val =~ s{^(['"]?+).*\bccache\s+}{$1};
269 $in_v = $val !~ /$quote\n/;
272 s,/,::,g if $Extensions{$name};
274 $val =~ s/$quote\n?\z//;
276 my $line = "$name=$quote$val$quote\n";
277 push(@v_others, $line);
278 $seen_quotes{$quote}++;
283 # This is somewhat grim, but I want the code for parsing config.sh here and
284 # now so that I can expand $Config{ivsize} and $Config{ivtype}
286 my $fetch_string = <<'EOT';
288 # Search for it in the big string
290 my($self, $key) = @_;
294 if ($seen_quotes{'"'}) {
295 # We need the full ' and " code
297 $fetch_string .= <<'EOT';
298 return undef unless my ($quote_type, $value) = $Config_SH_expanded =~ /\n$key=(['"])(.*?)\1\n/s;
300 # If we had a double-quote, we'd better eval it so escape
301 # sequences and such can be interpolated. Since the incoming
302 # value is supposed to follow shell rules and not perl rules,
303 # we escape any perl variable markers
305 # Historically, since " 'support' was added in change 1409, the
306 # interpolation was done before the undef. Stick to this arguably buggy
307 # behaviour as we're refactoring.
308 if ($quote_type eq '"') {
309 $value =~ s/\$/\\\$/g;
310 $value =~ s/\@/\\\@/g;
311 eval "\$value = \"$value\"";
314 # So we can say "if $Config{'foo'}".
315 $self->{$key} = $value eq 'undef' ? undef : $value; # cache it
320 # We only have ' delimited.
322 $fetch_string .= <<'EOT';
323 return undef unless $Config_SH_expanded =~ /\n$key=\'(.*?)\'\n/s;
324 # So we can say "if $Config{'foo'}".
325 $self->{$key} = $1 eq 'undef' ? undef : $1;
334 # Calculation for the keys for byteorder
335 # This is somewhat grim, but I need to run fetch_string here.
336 $Config_SH_expanded = join "\n", '', @v_others;
338 my $t = fetch_string ({}, 'ivtype');
339 my $s = fetch_string ({}, 'ivsize');
341 # byteorder does exist on its own but we overlay a virtual
342 # dynamically recomputed value.
344 # However, ivtype and ivsize will not vary for sane fat binaries
346 my $f = $t eq 'long' ? 'L!' : $s == 8 ? 'Q': 'I';
349 if ($s == 4 || $s == 8) {
350 my $list = join ',', reverse(1..$s-1);
352 $byteorder_code = <<"EOT";
355 foreach my \$c ($list) { \$i <<= 8; \$i |= ord(\$c); }
356 our \$byteorder = join('', unpack('$format', pack('$f', \$i)));
359 $byteorder_code = "our \$byteorder = '?'x$s;\n";
364 if (fetch_string({},'userelocatableinc')) {
365 foreach my $what (qw(prefixexp
414 installvendorhtml1dir
415 installvendorhtml3dir
421 push @need_relocation, $what if fetch_string({}, $what) =~ m!^\.\.\./!;
426 @need_relocation{@need_relocation} = @need_relocation;
428 # This can have .../ anywhere:
429 if (fetch_string({}, 'otherlibdirs') =~ m!\.\.\./!) {
430 $need_relocation{otherlibdirs} = 'otherlibdirs';
433 my $relocation_code = <<'EOT';
437 return $libdir unless $libdir =~ s!^\.\.\./!!;
439 if ($prefix =~ s!/[^/]*$!!) {
440 while ($libdir =~ m!^\.\./!) {
441 # Loop while $libdir starts "../" and $prefix still has a trailing
443 last unless $prefix =~ s!/([^/]+)$!!;
444 # but bail out if the directory we picked off the end of $prefix is .
446 if ($1 eq '.' or $1 eq '..') {
447 # Undo! This should be rare, hence code it this way rather than a
448 # check each time before the s!!! above.
449 $prefix = "$prefix/$1";
452 # Remove that leading ../ and loop again
453 substr ($libdir, 0, 3, '');
455 $libdir = "$prefix/$libdir";
461 my $osname = fetch_string({}, 'osname');
462 my $from = $osname eq 'VMS' ? 'PERLSHR image' : 'binary (from libperl)';
463 my $env_cygwin = $osname eq 'cygwin'
464 ? 'push @env, "CYGWIN=\"$ENV{CYGWIN}\"" if $ENV{CYGWIN};' . "\n" : "";
466 $heavy_txt .= sprintf <<'ENDOFBEG', $osname, $osname, $from, $osname, $env_cygwin;
467 # This file was created by configpm when Perl was built. Any changes
468 # made to this file will be lost the next time perl is built.
475 sub bincompat_options {
476 return split ' ', (Internals::V())[0];
479 sub non_bincompat_options {
480 return split ' ', (Internals::V())[1];
484 return (Internals::V())[2]
488 my (undef, undef, undef, @patches) = Internals::V();
493 die "Perl lib was built for '%s' but is being run on '$^O'"
496 my ($bincompat, $non_bincompat, $date, @patches) = Internals::V();
498 my @opts = sort split ' ', "$bincompat $non_bincompat";
500 print Config::myconfig();
501 print "\nCharacteristics of this %s: \n";
503 print " Compile-time options:\n";
504 print " $_\n" for @opts;
507 print " Locally applied patches:\n";
508 print " $_\n" foreach @patches;
511 print " Built under %s\n";
513 print " $date\n" if defined $date;
515 my @env = map { "$_=\"$ENV{$_}\"" } sort grep {/^PERL/} keys %%ENV;
519 print " $_\n" foreach @env;
522 print " $_\n" foreach @INC;
528 $heavy_txt .= $header_files . "\n}\n\n";
530 if (%need_relocation) {
531 my $relocations_in_common;
532 # otherlibdirs only features in the hash
533 foreach (keys %need_relocation) {
534 $relocations_in_common++ if $Common{$_};
536 if ($relocations_in_common) {
537 $config_txt .= $relocation_code;
539 $heavy_txt .= $relocation_code;
543 $heavy_txt .= join('', @non_v) . "\n";
545 # copy config summary format from the myconfig.SH script
546 $heavy_txt .= "our \$summary = <<'!END!';\n";
547 open(MYCONFIG,'<','myconfig.SH') || die "open myconfig.SH failed: $!";
548 1 while defined($_ = <MYCONFIG>) && !/^Summary of/;
549 do { $heavy_txt .= $_ } until !defined($_ = <MYCONFIG>) || /^\s*$/;
552 $heavy_txt .= "\n!END!\n" . <<'EOT';
553 my $summary_expanded;
556 return $summary_expanded if $summary_expanded;
557 ($summary_expanded = $summary) =~ s{\$(\w+)}
560 if ($1 eq 'git_ancestor_line') {
561 if ($Config::Config{git_ancestor}) {
562 $c= "\n Ancestor: $Config::Config{git_ancestor}";
567 $c = $Config::Config{$1};
569 defined($c) ? $c : 'undef'
577 #proper lexicographical order of the keys
579 $heavy_txt .= join('',
581 sort {$a->[0] cmp $b->[0] }
582 grep { !$seen_var{ $_->[0] }++ }
584 /^([^=]+)/ ? [ $1, $_ ]
585 : [ $_, $_ ] # shouldnt happen
586 } @v_others, @v_forced
589 # Only need the dynamic byteorder code in Config.pm if 'byteorder' is one of
591 if ($Common{byteorder}) {
592 $config_txt .= $byteorder_code;
594 $heavy_txt .= $byteorder_code;
597 if (@need_relocation) {
598 $heavy_txt .= 'foreach my $what (qw(' . join (' ', @need_relocation) .
600 s/^($what=)(['"])(.*?)\2/$1 . $2 . relocate_inc($3) . $2/me;
603 # Currently it only makes sense to do the ... relocation on Unix, so there's
604 # no need to emulate the "which separator for this platform" logic in perl.c -
605 # ':' will always be applicable
606 if ($need_relocation{otherlibdirs}) {
607 $heavy_txt .= << 'EOT';
608 s{^(otherlibdirs=)(['"])(.*?)\2}
609 {$1 . $2 . join ':', map {relocate_inc($_)} split ':', $3 . $2}me;
614 $heavy_txt .= <<'EOT';
615 s/(byteorder=)(['"]).*?\2/$1$2$Config::byteorder$2/m;
617 my $config_sh_len = length $_;
619 our $Config_SH_expanded = "\n$_" . << 'EOVIRTUAL';
622 foreach my $prefix (qw(ccflags ldflags)) {
623 my $value = fetch_string ({}, $prefix);
624 my $withlargefiles = fetch_string ({}, $prefix . "_uselargefiles");
625 if (defined $withlargefiles) {
626 $value =~ s/\Q$withlargefiles\E\b//;
627 $heavy_txt .= "${prefix}_nolargefiles='$value'\n";
631 foreach my $prefix (qw(libs libswanted)) {
632 my $value = fetch_string ({}, $prefix);
633 my $withlf = fetch_string ({}, 'libswanted_uselargefiles');
634 next unless defined $withlf;
636 = split(' ', fetch_string ({}, 'libswanted_uselargefiles'));
639 @lflibswanted{@lflibswanted} = ();
640 if ($prefix eq 'libs') {
641 my @libs = grep { /^-l(.+)/ &&
642 not exists $lflibswanted{$1} }
643 split(' ', fetch_string ({}, 'libs'));
644 $value = join(' ', @libs);
646 my @libswanted = grep { not exists $lflibswanted{$_} }
647 split(' ', fetch_string ({}, 'libswanted'));
648 $value = join(' ', @libswanted);
651 $heavy_txt .= "${prefix}_nolargefiles='$value'\n";
654 if (open(my $fh, '<', 'cflags')) {
658 if (/^warn="(.+)"$/) {
660 } elsif (/^stdflags="(.+)"$/) {
664 if (defined $ccwarnflags) {
665 $heavy_txt .= "ccwarnflags='$ccwarnflags'\n";
667 if (defined $ccstdflags) {
668 $heavy_txt .= "ccstdflags='$ccstdflags'\n";
672 $heavy_txt .= "EOVIRTUAL\n";
674 $heavy_txt .= <<'ENDOFGIT';
676 # do not have hairy conniptions if this isnt available
677 require 'Config_git.pl';
678 $Config_SH_expanded .= $Config::Git_Data;
680 } or warn "Warning: failed to load Config_git.pl, something strange about this perl...\n";
683 $heavy_txt .= $fetch_string;
685 $config_txt .= <<'ENDOFEND';
688 my($self, $key) = @_;
690 # check for cached value (which may be undef so we use exists not defined)
691 return exists $self->{$key} ? $self->{$key} : $self->fetch_string($key);
696 $heavy_txt .= <<'ENDOFEND';
702 substr($Config_SH_expanded, 1, index($Config_SH_expanded, '=') - 1 );
707 if ($seen_quotes{'"'}) {
708 $heavy_txt .= <<'ENDOFEND';
709 # Find out how the current key's quoted so we can skip to its end.
710 my $quote = substr($Config_SH_expanded,
711 index($Config_SH_expanded, "=", $prevpos)+1, 1);
712 my $pos = index($Config_SH_expanded, qq($quote\n), $prevpos) + 2;
715 # Just ' quotes, so it's much easier.
716 $heavy_txt .= <<'ENDOFEND';
717 my $pos = index($Config_SH_expanded, qq('\n), $prevpos) + 2;
720 $heavy_txt .= <<'ENDOFEND';
721 my $len = index($Config_SH_expanded, "=", $pos) - $pos;
723 $len > 0 ? substr($Config_SH_expanded, $pos, $len) : undef;
727 return 1 if exists($_[0]->{$_[1]});
729 return(index($Config_SH_expanded, "\n$_[1]='") != -1
731 if ($seen_quotes{'"'}) {
732 $heavy_txt .= <<'ENDOFEND';
733 or index($Config_SH_expanded, "\n$_[1]=\"") != -1
736 $heavy_txt .= <<'ENDOFEND';
740 sub STORE { die "\%Config::Config is read-only\n" }
741 *DELETE = *CLEAR = \*STORE; # Typeglob aliasing uses less space
744 substr $Config_SH_expanded, 1, $config_sh_len;
749 return map { chomp; $_ } grep eval{ /^(?:$re)=/ }, split /^/,
754 # implements -V:cfgvar option (see perlrun -V:)
756 # find optional leading, trailing colons; and query-spec
757 my ($notag,$qry,$lncont) = m/^(:)?(.*?)(:)?$/; # flags fore and aft,
758 # map colon-flags to print decorations
759 my $prfx = $notag ? '': "$qry="; # tag-prefix for print
760 my $lnend = $lncont ? ' ' : ";\n"; # line ending for print
762 # all config-vars are by definition \w only, any \W means regex
764 my @matches = config_re($qry);
765 print map "$_$lnend", @matches ? @matches : "$qry: not found" if !$notag;
766 print map { s/\w+=//; "$_$lnend" } @matches ? @matches : "$qry: not found" if $notag;
768 my $v = (exists $Config::Config{$qry}) ? $Config::Config{$qry}
770 $v = 'undef' unless defined $v;
771 print "${prfx}'${v}'$lnend";
776 # Called by the real AUTOLOAD
779 goto \&$Config::AUTOLOAD;
786 $config_txt .= <<'ENDOFSET';
789 my ($value, $v) = $Config_SH_expanded =~ m/^used_aout='(.*)'\s*$/m;
790 for (split ' ', $value) {
791 ($v) = $Config_SH_expanded =~ m/^aout_$_='(.*)'\s*$/m;
792 $preconfig{$_} = $v eq 'undef' ? undef : $v;
795 $preconfig{d_fork} = undef unless $OS2::can_fork; # Some funny cases can't
796 sub TIEHASH { bless {%preconfig} }
798 # Extract the name of the DLL from the makefile to avoid duplication
799 my ($f) = grep -r, qw(GNUMakefile Makefile);
801 if (open my $fh, '<', $f) {
803 $dll = $1, last if /^PERL_DLL_BASE\s*=\s*(\S*)\s*$/;
806 $config_txt .= <<ENDOFSET if $dll;
807 \$preconfig{dll_name} = '$dll';
810 $config_txt .= <<'ENDOFSET';
817 foreach my $key (keys %Common) {
818 my $value = fetch_string ({}, $key);
819 # Is it safe on the LHS of => ?
820 my $qkey = $key =~ /^[A-Za-z_][A-Za-z0-9_]*$/ ? $key : "'$key'";
821 if (defined $value) {
822 # Quote things for a '' string
823 $value =~ s!\\!\\\\!g;
826 if ($key eq 'otherlibdirs') {
827 $value = "join (':', map {relocate_inc(\$_)} split (':', $value))";
828 } elsif ($need_relocation{$key}) {
829 $value = "relocate_inc($value)";
834 $Common{$key} = "$qkey => $value";
837 if ($Common{byteorder}) {
838 $Common{byteorder} = 'byteorder => $byteorder';
840 my $fast_config = join '', map { " $_,\n" } sort values %Common;
842 # Sanity check needed to stop an infinite loop if Config_heavy.pl fails to
843 # define &launcher for some reason (eg it got truncated)
844 $config_txt .= sprintf <<'ENDOFTIE', $fast_config;
849 require 'Config_heavy.pl';
850 goto \&launcher unless $Config::AUTOLOAD =~ /launcher$/;
851 die "&Config::AUTOLOAD failed on $Config::AUTOLOAD";
854 # tie returns the object, so the value returned to require will be true.
855 tie %%Config, 'Config', {
860 open(CONFIG_POD, '>:raw', $Config_POD) or die "Can't open $Config_POD: $!";
861 print CONFIG_POD <<'ENDOFTAIL';
864 =for comment Generated by configpm. Any changes made here will be lost!
866 Config - access Perl configuration information
871 if ($Config{usethreads}) {
872 print "has thread support\n"
875 use Config qw(myconfig config_sh config_vars config_re);
883 config_vars(qw(osname archname));
888 The Config module contains all the information that was available to
889 the F<Configure> program at Perl build time (over 900 values).
891 Shell variables from the F<config.sh> file (written by Configure) are
892 stored in the readonly-variable C<%Config>, indexed by their names.
894 Values stored in config.sh as 'undef' are returned as undefined
895 values. The perl C<exists> function can be used to check if a
896 named variable exists.
898 For a description of the variables, please have a look at the
899 Glossary file, as written in the Porting folder, or use the url:
900 https://github.com/Perl/perl5/blob/blead/Porting/Glossary
906 Returns a textual summary of the major perl configuration values.
907 See also C<-V> in L<perlrun/Command Switches>.
911 Returns the entire perl configuration information in the form of the
912 original config.sh shell variable assignment script.
914 =item config_re($regex)
916 Like config_sh() but returns, as a list, only the config entries who's
917 names match the $regex.
919 =item config_vars(@names)
921 Prints to STDOUT the values of the named configuration variable. Each is
922 printed on a separate line in the form:
926 Names which are unknown are output as C<name='UNKNOWN';>.
927 See also C<-V:name> in L<perlrun/Command Switches>.
929 =item bincompat_options()
931 Returns a list of C pre-processor options used when compiling this F<perl>
932 binary, which affect its binary compatibility with extensions.
933 C<bincompat_options()> and C<non_bincompat_options()> are shown together in
934 the output of C<perl -V> as I<Compile-time options>.
936 =item non_bincompat_options()
938 Returns a list of C pre-processor options used when compiling this F<perl>
939 binary, which do not affect binary compatibility with extensions.
943 Returns the compile date (as a string), equivalent to what is shown by
946 =item local_patches()
948 Returns a list of the names of locally applied patches, equivalent to what
949 is shown by C<perl -V>.
953 Returns a list of the header files that should be used as dependencies for
954 XS code, for this version of Perl on this platform.
960 Here's a more sophisticated example of using %Config:
967 unless($Config{sig_name} && $Config{sig_num}) {
970 my @names = split ' ', $Config{sig_name};
971 @sig_num{@names} = split ' ', $Config{sig_num};
973 $sig_name[$sig_num{$_}] ||= $_;
977 print "signal #17 = $sig_name[17]\n";
978 if ($sig_num{ALRM}) {
979 print "SIGALRM is $sig_num{ALRM}\n";
984 Because this information is not stored within the perl executable
985 itself it is possible (but unlikely) that the information does not
986 relate to the actual perl binary which is being used to access it.
988 The Config module is installed into the architecture and version
989 specific library directory ($Config{installarchlib}) and it checks the
990 perl version number when loaded.
992 The values stored in config.sh may be either single-quoted or
993 double-quoted. Double-quoted strings are handy for those cases where you
994 need to include escape sequences in the strings. To avoid runtime variable
995 interpolation, any C<$> and C<@> characters are replaced by C<\$> and
996 C<\@>, respectively. This isn't foolproof, of course, so don't embed C<\$>
997 or C<\@> in double-quoted strings unless you're willing to deal with the
998 consequences. (The slashes will end up escaped and the C<$> or C<@> will
999 trigger variable interpolation)
1003 Most C<Config> variables are determined by the C<Configure> script
1004 on platforms supported by it (which is most UNIX platforms). Some
1005 platforms have custom-made C<Config> variables, and may thus not have
1006 some of the variables described below, or may have extraneous variables
1007 specific to that particular port. See the port specific documentation
1014 if ($Opts{glossary}) {
1015 open(GLOS, '<', $Glossary) or die "Can't open $Glossary: $!";
1023 if (s/\A(\w*)\s+\(([\w.]+)\):\s*\n(\t?)/=item C<$1>\n\nFrom F<$2>:\n\n/m) {
1024 my $c = substr $1, 0, 1;
1025 unless ($seen{$c}++) {
1026 print CONFIG_POD <<EOF if $text;
1030 print CONFIG_POD <<EOF;
1039 elsif (!$text || !/\A\t/) {
1040 warn "Expected a Configure variable header",
1041 ($text ? " or another paragraph of description" : () ),
1042 ", instead we got:\n$_";
1045 s/n't/n\00t/g; # leave can't, won't etc untouched
1046 s/^\t\s+(.*)/\n$1/gm; # Indented lines ===> new paragraph
1047 s/^(?<!\n\n)\t(.*)/$1/gm; # Not indented lines ===> text
1048 s{([\'\"])(?=[^\'\"\s]*[./][^\'\"\s]*\1)([^\'\"\s]+)\1}(F<$2>)g; # '.o'
1049 s{([\'\"])([^\'\"\s]+)\1}(C<$2>)g; # "date" command
1050 s{\'([A-Za-z_\- *=/]+)\'}(C<$1>)g; # 'ln -s'
1052 (?<! [\w./<\'\"\$] ) # Only standalone file names
1053 (?! e \. g \. ) # Not e.g.
1054 (?! \. \. \. ) # Not ...
1055 (?! \d ) # Not 5.004
1056 (?! read/ ) # Not read/write
1057 (?! etc\. ) # Not etc.
1060 \$ ? # Allow leading $
1061 [\w./]* [./] [\w./]* # Require . or / inside
1063 (?<! \. (?= [\s)] ) ) # Do not include trailing dot
1064 (?! [\w/] ) # Include all of it
1066 (F<$1>)xg; # /usr/local
1067 s/((?<=\s)~\w*)/F<$1>/g; # ~name
1068 s/(?<![.<\'\"])\b([A-Z_]{2,})\b(?![\'\"])/C<$1>/g; # UNISTD
1069 s/(?<![.<\'\"])\b(?!the\b)(\w+)\s+macro\b/C<$1> macro/g; # FILE_cnt macro
1070 s/n[\0]t/n't/g; # undo can't, won't damage
1073 if ($Opts{glossary}) {
1074 <GLOS>; # Skip the "DO NOT EDIT"
1075 <GLOS>; # Skip the preamble
1081 die "Errors encountered while processing $Glossary. ",
1082 "Header lines are expected to be of the form:\n",
1084 "Maybe there is a malformed header?\n",
1089 print CONFIG_POD <<'ENDOFTAIL';
1095 Information on the git commit from which the current perl binary was compiled
1096 can be found in the variable C<$Config::Git_Data>. The variable is a
1097 structured string that looks something like this:
1099 git_commit_id='ea0c2dbd5f5ac6845ecc7ec6696415bf8e27bd52'
1100 git_describe='GitLive-blead-1076-gea0c2db'
1101 git_branch='smartmatch'
1102 git_uncommitted_changes=''
1103 git_commit_id_title='Commit id:'
1104 git_commit_date='2009-05-09 17:47:31 +0200'
1106 Its format is not guaranteed not to change over time.
1110 This module contains a good example of how to use tie to implement a
1111 cache and an example of how to make a tied variable readonly to those
1118 close(GLOS) if $Opts{glossary};
1120 print "written $Config_POD\n";
1122 my $orig_config_txt = "";
1123 my $orig_heavy_txt = "";
1127 $orig_config_txt = <$fh> if open $fh, "<", $Config_PM;
1128 $orig_heavy_txt = <$fh> if open $fh, "<", $Config_heavy;
1131 if ($orig_config_txt ne $config_txt or $orig_heavy_txt ne $heavy_txt) {
1132 open CONFIG, ">", $Config_PM or die "Can't open $Config_PM: $!\n";
1133 open CONFIG_HEAVY, ">", $Config_heavy or die "Can't open $Config_heavy: $!\n";
1134 print CONFIG $config_txt;
1135 print CONFIG_HEAVY $heavy_txt;
1136 close(CONFIG_HEAVY);
1138 print "updated $Config_PM\n";
1139 print "updated $Config_heavy\n";
1142 # Now do some simple tests on the Config.pm file we have created
1143 unshift(@INC,'lib');
1145 require $Config_heavy;
1148 die "$0: $Config_PM not valid"
1149 unless $Config{'PERL_CONFIG_SH'} eq 'true';
1151 die "$0: error processing $Config_PM"
1152 if defined($Config{'an impossible name'})
1153 or $Config{'PERL_CONFIG_SH'} ne 'true' # test cache
1156 die "$0: error processing $Config_PM"
1157 if eval '$Config{"cc"} = 1'
1158 or eval 'delete $Config{"cc"}'
1163 # Popularity of various entries in %Config, based on a large build and test
1164 # run of code in the Fotango build system:
1182 inc_version_list: 783
1185 usevendorprefix: 642
1206 installsiteman1dir: 489
1207 installsiteman3dir: 489
1208 installvendorman1dir: 489
1209 installvendorman3dir: 489
1213 installsitearch: 344
1218 installprefixexp: 336
1221 installvendorarch: 336
1222 installvendorbin: 336
1223 installvendorlib: 336