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