5 # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
6 # 2002, 2003, 2004, 2005, 2006, 2007 Larry Wall and others.
14 # lib/Cross.pm (optionally)
17 # from the contents of the static files
22 # and from the contents of the Configure-generated file
26 # Note that output directory is xlib/[cross-name]/ for cross-compiling
28 # It will only update Config.pm and Config_heavy.pl if the contents of
29 # either file would be different. Note that *both* files are updated in
30 # this case, since for example an extension makefile that has a dependency
31 # on Config.pm should trigger even if only Config_heavy.pl has changed.
33 sub usage { die <<EOF }
35 --cross=PLATFORM cross-compile for a different platform
36 --no-glossary don't include Porting/Glossary in lib/Config.pod
37 --chdir=dir change directory before writing files
41 use vars qw(%Config $Config_SH_expanded);
43 my $how_many_common = 22;
45 # commonly used names to precache (and hence lookup fastest)
48 while ($how_many_common--) {
51 /^(\S+):\s*(\d+)$/ or die "Malformed line '$_'";
55 # Post 37589e1eefb1bd62 DynaLoader defaults to reading these at runtime.
56 # Ideally we're redo the data below, but Fotango's build system made it
57 # wonderfully easy to instrument, and no longer exists.
58 $Common{$_} = $_ foreach qw(dlext so);
60 # names of things which may need to have slashes changed to double-colons
61 my %Extensions = map {($_,$_)}
62 qw(dynamic_ext static_ext extensions known_extensions);
64 # The plan is that this information is used by ExtUtils::MakeMaker to generate
65 # Makefile dependencies, rather than hardcoding a list, which has become out
66 # of date. However, currently, MM_Unix.pm and MM_VMS.pm have *different* lists,
67 # *and* descrip_mms.template doesn't actually install all the headers.
68 # The "Unix" list seems to (attempt to) avoid the generated headers, which I'm
69 # not sure is the right thing to do. Also, not certain whether it would be
70 # easier to parse MANIFEST to get these (adding config.h, and potentially
71 # removing others), but for now, stick to a hard coded list.
73 # Could use a map to add ".h", but I suspect that it's easier to use literals,
74 # so that anyone using grep will find them
75 # This is the list from MM_VMS, plus pad.h, parser.h, perlsfio.h utf8.h
76 # which it installs. It *doesn't* install perliol.h - FIXME.
77 my @header_files = qw(EXTERN.h INTERN.h XSUB.h av.h config.h cop.h cv.h
78 embed.h embedvar.h form.h gv.h handy.h hv.h intrpvar.h
79 iperlsys.h keywords.h mg.h nostdio.h op.h opcode.h
80 pad.h parser.h patchlevel.h perl.h perlio.h perlsdio.h
81 perlsfio.h perlvars.h perly.h pp.h pp_proto.h proto.h
82 regcomp.h regexp.h regnodes.h scope.h sv.h thread.h utf8.h
85 # No point in adding fakethr.h, as it no longer works
87 $^O eq 'VMS' ? 'vmsish.h' : qw(dosish.h perliol.h time64.h unixish.h);
89 my $header_files = ' return qw(' . join(' ', sort @header_files) . ');';
90 $header_files =~ s/(?=.{64}) # If line is still overlength
91 (.{1,64})\ # Split at the last convenient space
94 # allowed opts as well as specifies default and initial values
96 'cross' => '', # --cross=PLATFORM - crosscompiling for PLATFORM
97 'glossary' => 1, # --no-glossary - no glossary file inclusion,
99 'chdir' => '', # --chdir=dir - change directory before writing files
103 # user specified options
106 (map {/^--([\-_\w]+)=(.*)$/} @ARGV),
107 # --opt --no-opt --noopt
108 (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV),
111 my %opts = (%Allowed_Opts, %given_opts);
113 for my $opt (grep {!exists $Allowed_Opts{$_}} keys %given_opts) {
114 warn "option '$opt' is not recognized";
117 @ARGV = grep {!/^--/} @ARGV;
126 chdir $Opts{chdir} or die "$0: could not chdir $Opts{chdir}: $!"
129 my ($Config_SH, $Config_PM, $Config_heavy, $Config_POD);
130 my $Glossary = 'Porting/Glossary';
133 # creating cross-platform config file
135 mkdir "xlib/$Opts{cross}";
136 $Config_PM = "xlib/$Opts{cross}/Config.pm";
137 $Config_POD = "xlib/$Opts{cross}/Config.pod";
138 $Config_SH = "Cross/config-$Opts{cross}.sh";
141 $Config_PM = "lib/Config.pm";
142 $Config_POD = "lib/Config.pod";
143 $Config_SH = "config.sh";
145 ($Config_heavy = $Config_PM) =~ s/\.pm$/_heavy.pl/;
146 die "Can't automatically determine name for Config_heavy.pl from '$Config_PM'"
147 if $Config_heavy eq $Config_PM;
152 my $from = $^O eq 'VMS' ? 'PERLSHR image' : 'binary (from libperl)';
153 my $env_cygwin = $^O eq 'cygwin'
154 ? 'push @env, "CYGWIN=\"$ENV{CYGWIN}\"" if $ENV{CYGWIN};' . "\n" : "";
155 $heavy_txt .= sprintf <<'ENDOFBEG', $^O, $^O, $from, $^O, $env_cygwin;
156 # This file was created by configpm when Perl was built. Any changes
157 # made to this file will be lost the next time perl is built.
164 sub bincompat_options {
165 return split ' ', (Internals::V())[0];
168 sub non_bincompat_options {
169 return split ' ', (Internals::V())[1];
173 return (Internals::V())[2]
177 my (undef, undef, undef, @patches) = Internals::V();
182 die "Perl lib was built for '%s' but is being run on '$^O'"
185 my ($bincompat, $non_bincompat, $date, @patches) = Internals::V();
187 my $opts = join ' ', sort split ' ', "$bincompat $non_bincompat";
189 # wrap at 76 columns.
191 $opts =~ s/(?=.{53})(.{1,53}) /$1\n /mg;
193 print Config::myconfig();
194 print "\nCharacteristics of this %s: \n";
196 print " Compile-time options: $opts\n";
199 print " Locally applied patches:\n";
200 print "\t$_\n" foreach @patches;
203 print " Built under %s\n";
205 print " $date\n" if defined $date;
207 my @env = map { "$_=\"$ENV{$_}\"" } sort grep {/^PERL/} keys %%ENV;
211 print " $_\n" foreach @env;
214 print " $_\n" foreach @INC;
220 $heavy_txt .= $header_files . "\n}\n\n";
222 my $export_funcs = <<'EOT';
223 my %Export_Cache = (myconfig => 1, config_sh => 1, config_vars => 1,
224 config_re => 1, compile_date => 1, local_patches => 1,
225 bincompat_options => 1, non_bincompat_options => 1,
229 my %export_ok = eval $export_funcs or die;
231 $config_txt .= sprintf << 'EOT', $export_funcs;
232 # This file was created by configpm when Perl was built. Any changes
233 # made to this file will be lost the next time perl is built.
235 # for a description of the variables, please have a look at the
236 # Glossary file, as written in the Porting folder, or use the url:
237 # http://perl5.git.perl.org/perl.git/blob/HEAD:/Porting/Glossary
244 # Skip @Config::EXPORT because it only contains %%Config, which we special
245 # case below as it's not a function. @Config::EXPORT won't change in the
246 # lifetime of Perl 5.
248 @Config::EXPORT = qw(%%Config);
249 @Config::EXPORT_OK = keys %%Export_Cache;
251 # Need to stub all the functions to make code such as print Config::config_sh
256 $config_txt .= "sub $_;\n" foreach sort keys %export_ok;
258 my $myver = sprintf "%vd", $^V;
260 $config_txt .= sprintf <<'ENDOFBEG', ($myver) x 3;
262 # Define our own import method to avoid pulling in the full Exporter:
265 @_ = @Config::EXPORT unless @_;
267 my @funcs = grep $_ ne '%%Config', @_;
268 my $export_Config = @funcs < @_ ? 1 : 0;
271 my $callpkg = caller(0);
272 foreach my $func (@funcs) {
273 die qq{"$func" is not exported by the Config module\n}
274 unless $Export_Cache{$func};
275 *{$callpkg.'::'.$func} = \&{$func};
278 *{"$callpkg\::Config"} = \%%Config if $export_Config;
282 die "Perl lib version (%s) doesn't match executable '$0' version ($])"
286 or die "Perl lib version (%s) doesn't match executable '$0' version (" .
287 sprintf("v%%vd",$^V) . ")";
302 open(CONFIG_SH, $Config_SH) || die "Can't open $Config_SH: $!";
303 while (<CONFIG_SH>) {
304 next if m:^#!/bin/sh:;
306 # Catch PERL_CONFIG_SH=true and PERL_VERSION=n line from Configure.
307 s/^(\w+)=(true|\d+)\s*$/$1='$2'\n/ or m/^(\w+)='(.*)'$/;
308 my($k, $v) = ($1, $2);
310 # grandfather PATCHLEVEL and SUBVERSION and CONFIG
312 if ($k eq 'PERL_VERSION') {
313 push @v_others, "PATCHLEVEL='$v'\n";
315 elsif ($k eq 'PERL_SUBVERSION') {
316 push @v_others, "SUBVERSION='$v'\n";
318 elsif ($k eq 'PERL_CONFIG_SH') {
319 push @v_others, "CONFIG='$v'\n";
323 # We can delimit things in config.sh with either ' or ".
324 unless ($in_v or m/^(\w+)=(['"])(.*\n)/){
325 push(@non_v, "#$_"); # not a name='value' line
333 ($name,$val) = ($1,$3);
335 $in_v = $val !~ /$quote\n/;
338 s,/,::,g if $Extensions{$name};
340 $val =~ s/$quote\n?\z//;
342 my $line = "$name=$quote$val$quote\n";
343 push(@v_others, $line);
344 $seen_quotes{$quote}++;
349 # This is somewhat grim, but I want the code for parsing config.sh here and
350 # now so that I can expand $Config{ivsize} and $Config{ivtype}
352 my $fetch_string = <<'EOT';
354 # Search for it in the big string
356 my($self, $key) = @_;
360 if ($seen_quotes{'"'}) {
361 # We need the full ' and " code
363 $fetch_string .= <<'EOT';
364 return undef unless my ($quote_type, $value) = $Config_SH_expanded =~ /\n$key=(['"])(.*?)\1\n/s;
366 # If we had a double-quote, we'd better eval it so escape
367 # sequences and such can be interpolated. Since the incoming
368 # value is supposed to follow shell rules and not perl rules,
369 # we escape any perl variable markers
371 # Historically, since " 'support' was added in change 1409, the
372 # interpolation was done before the undef. Stick to this arguably buggy
373 # behaviour as we're refactoring.
374 if ($quote_type eq '"') {
375 $value =~ s/\$/\\\$/g;
376 $value =~ s/\@/\\\@/g;
377 eval "\$value = \"$value\"";
380 # So we can say "if $Config{'foo'}".
381 $self->{$key} = $value eq 'undef' ? undef : $value; # cache it
386 # We only have ' delimted.
388 $fetch_string .= <<'EOT';
389 return undef unless $Config_SH_expanded =~ /\n$key=\'(.*?)\'\n/s;
390 # So we can say "if $Config{'foo'}".
391 $self->{$key} = $1 eq 'undef' ? undef : $1;
400 # Calculation for the keys for byteorder
401 # This is somewhat grim, but I need to run fetch_string here.
402 our $Config_SH_expanded = join "\n", '', @v_others;
404 my $t = fetch_string ({}, 'ivtype');
405 my $s = fetch_string ({}, 'ivsize');
407 # byteorder does exist on its own but we overlay a virtual
408 # dynamically recomputed value.
410 # However, ivtype and ivsize will not vary for sane fat binaries
412 my $f = $t eq 'long' ? 'L!' : $s == 8 ? 'Q': 'I';
415 if ($s == 4 || $s == 8) {
416 my $list = join ',', reverse(1..$s-1);
418 $byteorder_code = <<"EOT";
421 foreach my \$c ($list) { \$i <<= 8; \$i |= ord(\$c); }
422 our \$byteorder = join('', unpack('$format', pack('$f', \$i)));
425 $byteorder_code = "our \$byteorder = '?'x$s;\n";
430 if (fetch_string({},'userelocatableinc')) {
431 foreach my $what (qw(prefixexp
480 installvendorhtml1dir
481 installvendorhtml3dir
487 push @need_relocation, $what if fetch_string({}, $what) =~ m!^\.\.\./!;
492 @need_relocation{@need_relocation} = @need_relocation;
494 # This can have .../ anywhere:
495 if (fetch_string({}, 'otherlibdirs') =~ m!\.\.\./!) {
496 $need_relocation{otherlibdirs} = 'otherlibdirs';
499 my $relocation_code = <<'EOT';
503 return $libdir unless $libdir =~ s!^\.\.\./!!;
505 if ($prefix =~ s!/[^/]*$!!) {
506 while ($libdir =~ m!^\.\./!) {
507 # Loop while $libdir starts "../" and $prefix still has a trailing
509 last unless $prefix =~ s!/([^/]+)$!!;
510 # but bail out if the directory we picked off the end of $prefix is .
512 if ($1 eq '.' or $1 eq '..') {
513 # Undo! This should be rare, hence code it this way rather than a
514 # check each time before the s!!! above.
515 $prefix = "$prefix/$1";
518 # Remove that leading ../ and loop again
519 substr ($libdir, 0, 3, '');
521 $libdir = "$prefix/$libdir";
527 if (%need_relocation) {
528 my $relocations_in_common;
529 # otherlibdirs only features in the hash
530 foreach (keys %need_relocation) {
531 $relocations_in_common++ if $Common{$_};
533 if ($relocations_in_common) {
534 $config_txt .= $relocation_code;
536 $heavy_txt .= $relocation_code;
540 $heavy_txt .= join('', @non_v) . "\n";
542 # copy config summary format from the myconfig.SH script
543 $heavy_txt .= "our \$summary = <<'!END!';\n";
544 open(MYCONFIG,"<myconfig.SH") || die "open myconfig.SH failed: $!";
545 1 while defined($_ = <MYCONFIG>) && !/^Summary of/;
546 do { $heavy_txt .= $_ } until !defined($_ = <MYCONFIG>) || /^\s*$/;
549 $heavy_txt .= "\n!END!\n" . <<'EOT';
550 my $summary_expanded;
553 return $summary_expanded if $summary_expanded;
554 ($summary_expanded = $summary) =~ s{\$(\w+)}
557 if ($1 eq 'git_ancestor_line') {
558 if ($Config::Config{git_ancestor}) {
559 $c= "\n Ancestor: $Config::Config{git_ancestor}";
564 $c = $Config::Config{$1};
566 defined($c) ? $c : 'undef'
575 $heavy_txt .= join('', sort @v_others) . "!END!\n";
577 # Only need the dynamic byteorder code in Config.pm if 'byteorder' is one of
579 if ($Common{byteorder}) {
580 $config_txt .= $byteorder_code;
582 $heavy_txt .= $byteorder_code;
585 if (@need_relocation) {
586 $heavy_txt .= 'foreach my $what (qw(' . join (' ', @need_relocation) .
588 s/^($what=)(['"])(.*?)\2/$1 . $2 . relocate_inc($3) . $2/me;
591 # Currently it only makes sense to do the ... relocation on Unix, so there's
592 # no need to emulate the "which separator for this platform" logic in perl.c -
593 # ':' will always be applicable
594 if ($need_relocation{otherlibdirs}) {
595 $heavy_txt .= << 'EOT';
596 s{^(otherlibdirs=)(['"])(.*?)\2}
597 {$1 . $2 . join ':', map {relocate_inc($_)} split ':', $3 . $2}me;
602 $heavy_txt .= <<'EOT';
603 s/(byteorder=)(['"]).*?\2/$1$2$Config::byteorder$2/m;
605 my $config_sh_len = length $_;
607 our $Config_SH_expanded = "\n$_" . << 'EOVIRTUAL';
610 foreach my $prefix (qw(ccflags ldflags)) {
611 my $value = fetch_string ({}, $prefix);
612 my $withlargefiles = fetch_string ({}, $prefix . "_uselargefiles");
613 if (defined $withlargefiles) {
614 $value =~ s/\Q$withlargefiles\E\b//;
615 $heavy_txt .= "${prefix}_nolargefiles='$value'\n";
619 foreach my $prefix (qw(libs libswanted)) {
620 my $value = fetch_string ({}, $prefix);
621 my $withlf = fetch_string ({}, 'libswanted_uselargefiles');
622 next unless defined $withlf;
624 = split(' ', fetch_string ({}, 'libswanted_uselargefiles'));
627 @lflibswanted{@lflibswanted} = ();
628 if ($prefix eq 'libs') {
629 my @libs = grep { /^-l(.+)/ &&
630 not exists $lflibswanted{$1} }
631 split(' ', fetch_string ({}, 'libs'));
632 $value = join(' ', @libs);
634 my @libswanted = grep { not exists $lflibswanted{$_} }
635 split(' ', fetch_string ({}, 'libswanted'));
636 $value = join(' ', @libswanted);
639 $heavy_txt .= "${prefix}_nolargefiles='$value'\n";
642 $heavy_txt .= "EOVIRTUAL\n";
644 $heavy_txt .= <<'ENDOFGIT';
646 # do not have hairy conniptions if this isnt available
647 require 'Config_git.pl';
648 $Config_SH_expanded .= $Config::Git_Data;
650 } or warn "Warning: failed to load Config_git.pl, something strange about this perl...\n";
653 $heavy_txt .= $fetch_string;
655 $config_txt .= <<'ENDOFEND';
658 my($self, $key) = @_;
660 # check for cached value (which may be undef so we use exists not defined)
661 return exists $self->{$key} ? $self->{$key} : $self->fetch_string($key);
666 $heavy_txt .= <<'ENDOFEND';
672 substr($Config_SH_expanded, 1, index($Config_SH_expanded, '=') - 1 );
677 if ($seen_quotes{'"'}) {
678 $heavy_txt .= <<'ENDOFEND';
679 # Find out how the current key's quoted so we can skip to its end.
680 my $quote = substr($Config_SH_expanded,
681 index($Config_SH_expanded, "=", $prevpos)+1, 1);
682 my $pos = index($Config_SH_expanded, qq($quote\n), $prevpos) + 2;
685 # Just ' quotes, so it's much easier.
686 $heavy_txt .= <<'ENDOFEND';
687 my $pos = index($Config_SH_expanded, qq('\n), $prevpos) + 2;
690 $heavy_txt .= <<'ENDOFEND';
691 my $len = index($Config_SH_expanded, "=", $pos) - $pos;
693 $len > 0 ? substr($Config_SH_expanded, $pos, $len) : undef;
697 return 1 if exists($_[0]->{$_[1]});
699 return(index($Config_SH_expanded, "\n$_[1]='") != -1
701 if ($seen_quotes{'"'}) {
702 $heavy_txt .= <<'ENDOFEND';
703 or index($Config_SH_expanded, "\n$_[1]=\"") != -1
706 $heavy_txt .= <<'ENDOFEND';
710 sub STORE { die "\%Config::Config is read-only\n" }
711 *DELETE = *CLEAR = \*STORE; # Typeglob aliasing uses less space
714 substr $Config_SH_expanded, 1, $config_sh_len;
719 return map { chomp; $_ } grep eval{ /^(?:$re)=/ }, split /^/,
724 # implements -V:cfgvar option (see perlrun -V:)
726 # find optional leading, trailing colons; and query-spec
727 my ($notag,$qry,$lncont) = m/^(:)?(.*?)(:)?$/; # flags fore and aft,
728 # map colon-flags to print decorations
729 my $prfx = $notag ? '': "$qry="; # tag-prefix for print
730 my $lnend = $lncont ? ' ' : ";\n"; # line ending for print
732 # all config-vars are by definition \w only, any \W means regex
734 my @matches = config_re($qry);
735 print map "$_$lnend", @matches ? @matches : "$qry: not found" if !$notag;
736 print map { s/\w+=//; "$_$lnend" } @matches ? @matches : "$qry: not found" if $notag;
738 my $v = (exists $Config::Config{$qry}) ? $Config::Config{$qry}
740 $v = 'undef' unless defined $v;
741 print "${prfx}'${v}'$lnend";
746 # Called by the real AUTOLOAD
749 goto \&$Config::AUTOLOAD;
756 $config_txt .= <<'ENDOFSET';
759 my ($value, $v) = $Config_SH_expanded =~ m/^used_aout='(.*)'\s*$/m;
760 for (split ' ', $value) {
761 ($v) = $Config_SH_expanded =~ m/^aout_$_='(.*)'\s*$/m;
762 $preconfig{$_} = $v eq 'undef' ? undef : $v;
765 $preconfig{d_fork} = undef unless $OS2::can_fork; # Some funny cases can't
766 sub TIEHASH { bless {%preconfig} }
768 # Extract the name of the DLL from the makefile to avoid duplication
769 my ($f) = grep -r, qw(GNUMakefile Makefile);
771 if (open my $fh, '<', $f) {
773 $dll = $1, last if /^PERL_DLL_BASE\s*=\s*(\S*)\s*$/;
776 $config_txt .= <<ENDOFSET if $dll;
777 \$preconfig{dll_name} = '$dll';
780 $config_txt .= <<'ENDOFSET';
787 foreach my $key (keys %Common) {
788 my $value = fetch_string ({}, $key);
789 # Is it safe on the LHS of => ?
790 my $qkey = $key =~ /^[A-Za-z_][A-Za-z0-9_]*$/ ? $key : "'$key'";
791 if (defined $value) {
792 # Quote things for a '' string
793 $value =~ s!\\!\\\\!g;
796 if ($key eq 'otherlibdirs') {
797 $value = "join (':', map {relocate_inc(\$_)} split (':', $value))";
798 } elsif ($need_relocation{$key}) {
799 $value = "relocate_inc($value)";
804 $Common{$key} = "$qkey => $value";
807 if ($Common{byteorder}) {
808 $Common{byteorder} = 'byteorder => $byteorder';
810 my $fast_config = join '', map { " $_,\n" } sort values %Common;
812 # Sanity check needed to stop an infinite loop if Config_heavy.pl fails to
813 # define &launcher for some reason (eg it got truncated)
814 $config_txt .= sprintf <<'ENDOFTIE', $fast_config;
819 require 'Config_heavy.pl';
820 goto \&launcher unless $Config::AUTOLOAD =~ /launcher$/;
821 die "&Config::AUTOLOAD failed on $Config::AUTOLOAD";
824 # tie returns the object, so the value returned to require will be true.
825 tie %%Config, 'Config', {
830 open(CONFIG_POD, ">$Config_POD") or die "Can't open $Config_POD: $!";
831 print CONFIG_POD <<'ENDOFTAIL';
834 Config - access Perl configuration information
839 if ($Config{usethreads}) {
840 print "has thread support\n"
843 use Config qw(myconfig config_sh config_vars config_re);
851 config_vars(qw(osname archname));
856 The Config module contains all the information that was available to
857 the C<Configure> program at Perl build time (over 900 values).
859 Shell variables from the F<config.sh> file (written by Configure) are
860 stored in the readonly-variable C<%Config>, indexed by their names.
862 Values stored in config.sh as 'undef' are returned as undefined
863 values. The perl C<exists> function can be used to check if a
864 named variable exists.
866 For a description of the variables, please have a look at the
867 Glossary file, as written in the Porting folder, or use the url:
868 http://perl5.git.perl.org/perl.git/blob/HEAD:/Porting/Glossary
874 Returns a textual summary of the major perl configuration values.
875 See also C<-V> in L<perlrun/Command Switches>.
879 Returns the entire perl configuration information in the form of the
880 original config.sh shell variable assignment script.
882 =item config_re($regex)
884 Like config_sh() but returns, as a list, only the config entries who's
885 names match the $regex.
887 =item config_vars(@names)
889 Prints to STDOUT the values of the named configuration variable. Each is
890 printed on a separate line in the form:
894 Names which are unknown are output as C<name='UNKNOWN';>.
895 See also C<-V:name> in L<perlrun/Command Switches>.
897 =item bincompat_options()
899 Returns a list of C pre-processor options used when compiling this F<perl>
900 binary, which affect its binary compatibility with extensions.
901 C<bincompat_options()> and C<non_bincompat_options()> are shown together in
902 the output of C<perl -V> as I<Compile-time options>.
904 =item non_bincompat_options()
906 Returns a list of C pre-processor options used when compiling this F<perl>
907 binary, which do not affect binary compatibility with extensions.
911 Returns the compile date (as a string), equivalent to what is shown by
914 =item local_patches()
916 Returns a list of the names of locally applied patches, equivalent to what
917 is shown by C<perl -V>.
921 Returns a list of the header files that should be used as dependencies for
922 XS code, for this version of Perl on this platform.
928 Here's a more sophisticated example of using %Config:
935 unless($Config{sig_name} && $Config{sig_num}) {
938 my @names = split ' ', $Config{sig_name};
939 @sig_num{@names} = split ' ', $Config{sig_num};
941 $sig_name[$sig_num{$_}] ||= $_;
945 print "signal #17 = $sig_name[17]\n";
946 if ($sig_num{ALRM}) {
947 print "SIGALRM is $sig_num{ALRM}\n";
952 Because this information is not stored within the perl executable
953 itself it is possible (but unlikely) that the information does not
954 relate to the actual perl binary which is being used to access it.
956 The Config module is installed into the architecture and version
957 specific library directory ($Config{installarchlib}) and it checks the
958 perl version number when loaded.
960 The values stored in config.sh may be either single-quoted or
961 double-quoted. Double-quoted strings are handy for those cases where you
962 need to include escape sequences in the strings. To avoid runtime variable
963 interpolation, any C<$> and C<@> characters are replaced by C<\$> and
964 C<\@>, respectively. This isn't foolproof, of course, so don't embed C<\$>
965 or C<\@> in double-quoted strings unless you're willing to deal with the
966 consequences. (The slashes will end up escaped and the C<$> or C<@> will
967 trigger variable interpolation)
971 Most C<Config> variables are determined by the C<Configure> script
972 on platforms supported by it (which is most UNIX platforms). Some
973 platforms have custom-made C<Config> variables, and may thus not have
974 some of the variables described below, or may have extraneous variables
975 specific to that particular port. See the port specific documentation
982 if ($Opts{glossary}) {
983 open(GLOS, "<$Glossary") or die "Can't open $Glossary: $!";
990 if (s/\A(\w*)\s+\(([\w.]+)\):\s*\n(\t?)/=item C<$1>\n\nFrom F<$2>:\n\n/m) {
991 my $c = substr $1, 0, 1;
992 unless ($seen{$c}++) {
993 print CONFIG_POD <<EOF if $text;
999 print CONFIG_POD <<EOF;
1010 elsif (!$text || !/\A\t/) {
1011 warn "Expected a Configure variable header",
1012 ($text ? " or another paragraph of description" : () );
1014 s/n't/n\00t/g; # leave can't, won't etc untouched
1015 s/^\t\s+(.*)/\n$1/gm; # Indented lines ===> new paragraph
1016 s/^(?<!\n\n)\t(.*)/$1/gm; # Not indented lines ===> text
1017 s{([\'\"])(?=[^\'\"\s]*[./][^\'\"\s]*\1)([^\'\"\s]+)\1}(F<$2>)g; # '.o'
1018 s{([\'\"])([^\'\"\s]+)\1}(C<$2>)g; # "date" command
1019 s{\'([A-Za-z_\- *=/]+)\'}(C<$1>)g; # 'ln -s'
1021 (?<! [\w./<\'\"] ) # Only standalone file names
1022 (?! e \. g \. ) # Not e.g.
1023 (?! \. \. \. ) # Not ...
1024 (?! \d ) # Not 5.004
1025 (?! read/ ) # Not read/write
1026 (?! etc\. ) # Not etc.
1029 \$ ? # Allow leading $
1030 [\w./]* [./] [\w./]* # Require . or / inside
1032 (?<! \. (?= [\s)] ) ) # Do not include trailing dot
1033 (?! [\w/] ) # Include all of it
1035 (F<$1>)xg; # /usr/local
1036 s/((?<=\s)~\w*)/F<$1>/g; # ~name
1037 s/(?<![.<\'\"])\b([A-Z_]{2,})\b(?![\'\"])/C<$1>/g; # UNISTD
1038 s/(?<![.<\'\"])\b(?!the\b)(\w+)\s+macro\b/C<$1> macro/g; # FILE_cnt macro
1039 s/n[\0]t/n't/g; # undo can't, won't damage
1042 if ($Opts{glossary}) {
1043 <GLOS>; # Skip the "DO NOT EDIT"
1044 <GLOS>; # Skip the preamble
1051 print CONFIG_POD <<'ENDOFTAIL';
1057 Information on the git commit from which the current perl binary was compiled
1058 can be found in the variable C<$Config::Git_Data>. The variable is a
1059 structured string that looks something like this:
1061 git_commit_id='ea0c2dbd5f5ac6845ecc7ec6696415bf8e27bd52'
1062 git_describe='GitLive-blead-1076-gea0c2db'
1063 git_branch='smartmatch'
1064 git_uncommitted_changes=''
1065 git_commit_id_title='Commit id:'
1066 git_commit_date='2009-05-09 17:47:31 +0200'
1068 Its format is not guaranteed not to change over time.
1072 This module contains a good example of how to use tie to implement a
1073 cache and an example of how to make a tied variable readonly to those
1080 close(GLOS) if $Opts{glossary};
1082 print "written $Config_POD\n";
1084 my $orig_config_txt = "";
1085 my $orig_heavy_txt = "";
1089 $orig_config_txt = <$fh> if open $fh, "<", $Config_PM;
1090 $orig_heavy_txt = <$fh> if open $fh, "<", $Config_heavy;
1093 if ($orig_config_txt ne $config_txt or $orig_heavy_txt ne $heavy_txt) {
1094 open CONFIG, ">", $Config_PM or die "Can't open $Config_PM: $!\n";
1095 open CONFIG_HEAVY, ">", $Config_heavy or die "Can't open $Config_heavy: $!\n";
1096 print CONFIG $config_txt;
1097 print CONFIG_HEAVY $heavy_txt;
1098 close(CONFIG_HEAVY);
1100 print "updated $Config_PM\n";
1101 print "updated $Config_heavy\n";
1105 # Now create Cross.pm if needed
1107 open CROSS, ">lib/Cross.pm" or die "Can not open >lib/Cross.pm: $!";
1108 my $cross = <<'EOS';
1109 # typical invocation:
1110 # perl -MCross Makefile.PL
1111 # perl -MCross=wince -V:cc
1115 my ($package,$platform) = @_;
1116 unless (defined $platform) {
1117 # if $platform is not specified, then use last one when
1118 # 'configpm; was invoked with --cross option
1119 $platform = '***replace-marker***';
1121 @INC = map {/\blib\b/?(do{local $_=$_;s/\blib\b/xlib\/$platform/;$_},$_):($_)} @INC;
1122 $::Cross::platform = $platform;
1127 $cross =~ s/\*\*\*replace-marker\*\*\*/$Opts{cross}/g;
1130 print "written lib/Cross.pm\n";
1131 unshift(@INC,"xlib/$Opts{cross}");
1134 # Now do some simple tests on the Config.pm file we have created
1135 unshift(@INC,'lib');
1136 unshift(@INC,'xlib/symbian') if $Opts{cross};
1138 require $Config_heavy;
1141 die "$0: $Config_PM not valid"
1142 unless $Config{'PERL_CONFIG_SH'} eq 'true';
1144 die "$0: error processing $Config_PM"
1145 if defined($Config{'an impossible name'})
1146 or $Config{'PERL_CONFIG_SH'} ne 'true' # test cache
1149 die "$0: error processing $Config_PM"
1150 if eval '$Config{"cc"} = 1'
1151 or eval 'delete $Config{"cc"}'
1156 # Popularity of various entries in %Config, based on a large build and test
1157 # run of code in the Fotango build system:
1175 inc_version_list: 783
1178 usevendorprefix: 642
1199 installsiteman1dir: 489
1200 installsiteman3dir: 489
1201 installvendorman1dir: 489
1202 installvendorman3dir: 489
1206 installsitearch: 344
1211 installprefixexp: 336
1214 installvendorarch: 336
1215 installvendorbin: 336
1216 installvendorlib: 336