This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Revert "Upgrade to Encode-2.60"
[perl5.git] / cpan / Encode / Encode / Makefile_PL.e2x
CommitLineData
3ef515df
JH
1#
2# This file is auto-generated by:
3# enc2xs version $_Version_
4# $_Now_
5#
6use 5.7.2;
7use strict;
8use ExtUtils::MakeMaker;
9a473428 9use Config;
3ef515df
JH
10
11# Please edit the following to the taste!
12my $name = '$_Name_';
13my %tables = (
d1256cb1
RGS
14 $_Name__t => [ $_TableFiles_ ],
15 );
3ef515df
JH
16
17#### DO NOT EDIT BEYOND THIS POINT!
85982a32
JH
18require File::Spec;
19my ($enc2xs, $encode_h) = ();
64a9a3c0
CBW
20my @path_ext = ('');
21@path_ext = split(';', $ENV{PATHEXT}) if $^O eq 'MSWin32';
85982a32 22PATHLOOP:
11067275 23for my $d (@Config{qw/bin sitebin vendorbin/},
d1256cb1 24 (split /$Config{path_sep}/o, $ENV{PATH})){
85982a32
JH
25 for my $f (qw/enc2xs enc2xs5.7.3/){
26 my $path = File::Spec->catfile($d, $f);
64a9a3c0
CBW
27 for my $ext (@path_ext) {
28 my $bin = "$path$ext";
29 -r "$bin" and $enc2xs = $bin and last PATHLOOP;
30 }
85982a32
JH
31 }
32}
33$enc2xs or die "enc2xs not found!";
34print "enc2xs is $enc2xs\n";
35my %encode_h = ();
36for my $d (@INC){
37 my $dir = File::Spec->catfile($d, "Encode");
38 my $file = File::Spec->catfile($dir, "encode.h");
39 -f $file and $encode_h{$dir} = -M $file;
40}
41%encode_h or die "encode.h not found!";
42# find the latest one
43($encode_h) = sort {$encode_h{$b} <=> $encode_h{$a}} keys %encode_h;
44print "encode.h is at $encode_h\n";
45
3ef515df 46WriteMakefile(
85982a32 47 INC => "-I$encode_h",
3ef515df 48#### END_OF_HEADER -- DO NOT EDIT THIS LINE BY HAND! ####
d1256cb1
RGS
49 NAME => 'Encode::'.$name,
50 VERSION_FROM => "$name.pm",
51 OBJECT => '$(O_FILES)',
52 'dist' => {
53 COMPRESS => 'gzip -9f',
54 SUFFIX => 'gz',
55 DIST_DEFAULT => 'all tardist',
56 },
57 MAN3PODS => {},
58 PREREQ_PM => {
59 'Encode' => "1.41",
85982a32 60 },
d1256cb1
RGS
61 # OS 390 winges about line numbers > 64K ???
62 XSOPT => '-nolinenumbers',
63 );
3ef515df
JH
64
65package MY;
66
67sub post_initialize
68{
69 my ($self) = @_;
70 my %o;
71 my $x = $self->{'OBJ_EXT'};
72 # Add the table O_FILES
73 foreach my $e (keys %tables)
74 {
d1256cb1 75 $o{$e.$x} = 1;
3ef515df
JH
76 }
77 $o{"$name$x"} = 1;
78 $self->{'O_FILES'} = [sort keys %o];
79 my @files = ("$name.xs");
80 $self->{'C'} = ["$name.c"];
f0a41339
DK
81 # The next two lines to make MacPerl Happy -- dankogai via pudge
82 $self->{SOURCE} .= " $name.c"
83 if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$name\.c\b/;
3ef515df
JH
84 # $self->{'H'} = [$self->catfile($self->updir,'encode.h')];
85 my %xs;
0a225b3c 86 foreach my $table (sort keys %tables) {
d1256cb1
RGS
87 push (@{$self->{'C'}},"$table.c");
88 # Do NOT add $table.h etc. to H_FILES unless we own up as to how they
89 # get built.
90 foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) {
91 push (@files,$table.$ext);
92 }
3ef515df
JH
93 }
94 $self->{'XS'} = { "$name.xs" => "$name.c" };
95 $self->{'clean'}{'FILES'} .= join(' ',@files);
96 open(XS,">$name.xs") || die "Cannot open $name.xs:$!";
97 print XS <<'END';
98#include <EXTERN.h>
99#include <perl.h>
100#include <XSUB.h>
3ef515df
JH
101#include "encode.h"
102END
0a225b3c 103 foreach my $table (sort keys %tables) {
d1256cb1 104 print XS qq[#include "${table}.h"\n];
3ef515df
JH
105 }
106 print XS <<"END";
107
108static void
109Encode_XSEncoding(pTHX_ encode_t *enc)
110{
111 dSP;
112 HV *stash = gv_stashpv("Encode::XS", TRUE);
54724570 113 SV *sv = sv_bless(newRV_noinc(newSViv(PTR2IV(enc))),stash);
3ef515df
JH
114 int i = 0;
115 PUSHMARK(sp);
116 XPUSHs(sv);
117 while (enc->name[i])
118 {
119 const char *name = enc->name[i++];
120 XPUSHs(sv_2mortal(newSVpvn(name,strlen(name))));
121 }
122 PUTBACK;
123 call_pv("Encode::define_encoding",G_DISCARD);
124 SvREFCNT_dec(sv);
125}
126
127MODULE = Encode::$name PACKAGE = Encode::$name
128PROTOTYPES: DISABLE
129BOOT:
130{
131END
0a225b3c 132 foreach my $table (sort keys %tables) {
d1256cb1 133 print XS qq[#include "${table}.exh"\n];
3ef515df
JH
134 }
135 print XS "}\n";
136 close(XS);
137 return "# Built $name.xs\n\n";
138}
139
140sub postamble
141{
142 my $self = shift;
143 my $dir = "."; # $self->catdir('Encode');
e7cbefb8 144 my $str = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n";
3ef515df 145 $str .= "$name.c : $name.xs ";
0a225b3c 146 foreach my $table (sort keys %tables)
3ef515df 147 {
d1256cb1 148 $str .= " $table.c";
3ef515df
JH
149 }
150 $str .= "\n\n";
151 $str .= "$name\$(OBJ_EXT) : $name.c\n\n";
152
0a225b3c 153 foreach my $table (sort keys %tables)
3ef515df 154 {
d1256cb1
RGS
155 my $numlines = 1;
156 my $lengthsofar = length($str);
157 my $continuator = '';
158 $str .= "$table.c : Makefile.PL";
159 foreach my $file (@{$tables{$table}})
160 {
161 $str .= $continuator.' '.$self->catfile($dir,$file);
162 if ( length($str)-$lengthsofar > 128*$numlines )
163 {
164 $continuator .= " \\\n\t";
165 $numlines++;
166 } else {
167 $continuator = '';
168 }
169 }
170 my $plib = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : '';
171 my $ucopts = '-"Q"';
172 $str .=
173 qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n};
174 open (FILELIST, ">$table.fnm")
175 || die "Could not open $table.fnm: $!";
176 foreach my $file (@{$tables{$table}})
177 {
178 print FILELIST $self->catfile($dir,$file) . "\n";
179 }
180 close(FILELIST);
3ef515df
JH
181 }
182 return $str;
183}
184