This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl.h: Add comments
[perl5.git] / utils / splain.PL
1 #!/usr/local/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Config;
7 use File::Basename qw(&basename &dirname);
8 use File::Spec;
9 use Cwd;
10
11 # List explicitly here the variables you want Configure to
12 # generate.  Metaconfig only looks for shell variables, so you
13 # have to mention them as if they were shell variables, not
14 # %Config entries:
15 #  $startperl
16 #  $perlpath
17 #  $eunicefix
18
19 # This forces PL files to create target in same directory as PL file.
20 # This is so that make depend always knows where to find PL derivatives.
21 my $origdir = cwd;
22 chdir dirname($0);
23 my $file = basename($0, '.PL');
24 $file .= '.com' if $^O eq 'VMS';
25
26 # Open input file before creating output file.
27 my $in = File::Spec->catfile(File::Spec->updir, 'lib', 'diagnostics.pm');
28 open IN, '<', $in or die "Can't open $in: $!\n";
29
30 # Create output file.
31 open OUT, '>', $file or die "Can't create $file: $!";
32
33 print "Extracting $file (with variable substitutions)\n";
34
35 # In this section, perl variables will be expanded during extraction.
36 # You can use $Config{...} to use Configure variables.
37
38 print OUT <<"!GROK!THIS!";
39 $Config{startperl}
40     eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
41         if 0; # ^ Run only under a shell
42 !GROK!THIS!
43
44 print OUT <<'!NO!SUBS!';
45
46 BEGIN { pop @INC if $INC[-1] eq '.' }
47
48 !NO!SUBS!
49
50 while (<IN>) {
51     print OUT unless /^package diagnostics/;
52 }
53
54 close IN;
55
56 close OUT or die "Can't close $file: $!";
57 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
58 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
59 chdir $origdir;