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
CommitLineData
5d437a65
JH
1#!/usr/local/bin/perl
2
822cd0f2
DM
3# Copy the cpan/Encode/bin/enc2xs script to utils/, while
4# prepending a suitable #! invocation.
5
5d437a65
JH
6use Config;
7use File::Basename qw(&basename &dirname);
8use 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.
19my $origdir = cwd;
20chdir dirname($0);
21my $file = basename($0, '.PL');
22$file .= '.com' if $^O eq 'VMS';
23
1ae6ead9 24open OUT, '>', $file or die "Can't create $file: $!";
5d437a65
JH
25
26print "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
31print OUT <<"!GROK!THIS!";
32$Config{startperl}
33 eval 'exec $Config{perlpath} -S \$0 \${1+"\$@"}'
188e64dd 34 if 0; # ^ Run only under a shell
5d437a65
JH
35!GROK!THIS!
36
37use File::Spec;
38
fafe5ad5 39my $enc2xs = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "cpan", "Encode", "bin"), "enc2xs");
5d437a65 40
1ae6ead9 41if (open(ENC2XS, '<', $enc2xs)) {
5d437a65
JH
42 print OUT <ENC2XS>;
43 close ENC2XS;
44} else {
45 die "$0: cannot find '$enc2xs'\n";
46}
47
48close OUT or die "Can't close $file: $!";
49chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
50exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
51chdir $origdir;