| 1 | #!/usr/local/bin/perl |
| 2 | |
| 3 | # This is for generating the perldoc executable. |
| 4 | # It may eventually be expanded to generate many executables, as |
| 5 | # explained in the preface of /Programming Perl/ 3e. |
| 6 | |
| 7 | require 5; |
| 8 | use strict; |
| 9 | use Config; |
| 10 | use File::Basename qw(&basename &dirname); |
| 11 | use Cwd; |
| 12 | |
| 13 | # List explicitly here the variables you want Configure to |
| 14 | # generate. Metaconfig only looks for shell variables, so you |
| 15 | # have to mention them as if they were shell variables, not |
| 16 | # %Config entries. Thus you write |
| 17 | # $startperl |
| 18 | # to ensure Configure will look for $Config{startperl}. |
| 19 | |
| 20 | # This forces PL files to create target in same directory as PL file. |
| 21 | # This is so that make depend always knows where to find PL derivatives. |
| 22 | |
| 23 | my $origdir = cwd; |
| 24 | chdir dirname($0); |
| 25 | my $file = basename($0, '.PL'); |
| 26 | my $file_shortname = $file; # should be like "perldoc", maybe "perlsyn", etc. |
| 27 | warn "How odd, I'm going to generate $file_shortname?!" |
| 28 | unless $file_shortname =~ m/^\w+$/; |
| 29 | |
| 30 | $file .= '.com' if $^O eq 'VMS'; |
| 31 | |
| 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 0; |
| 43 | |
| 44 | # This "$file" file was generated by "$0" |
| 45 | |
| 46 | require 5; |
| 47 | BEGIN { \$^W = 1 if \$ENV{'PERLDOCDEBUG'} } |
| 48 | use Pod::Perldoc; |
| 49 | exit( Pod::Perldoc->run() ); |
| 50 | |
| 51 | !GROK!THIS! |
| 52 | |
| 53 | |
| 54 | close OUT or die "Can't close $file: $!"; |
| 55 | chmod 0755, $file or die "Can't reset permissions for $file: $!\n"; |
| 56 | exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':'; |
| 57 | chdir $origdir; |
| 58 | |