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