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