Upgrade to Encode 1.26, from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / Encode / JP / Makefile.PL
CommitLineData
d811239c 1use 5.7.2;
2use strict;
3use ExtUtils::MakeMaker;
4
ee981de6 5my %tables = (
071db25d 6 euc_jp_t => ['euc-jp.ucm'],
64ffdd5e 7 sjis_t => ['shiftjis.ucm',
a999c27c 8 'macJapanese.ucm',
64ffdd5e 9 'cp932.ucm'],
f2a2953c 10 raw_t => [
11 qw(jis0201.ucm jis0208.ucm jis0212.ucm)
12 ],
3de3d21f 13 );
d811239c 14
0e567a6c 15my $name = 'JP';
d811239c 16
17WriteMakefile(
67d7b5ef 18 INC => "-I../Encode",
6d4ed59b 19 NAME => 'Encode::'.$name,
20 VERSION_FROM => "$name.pm",
d811239c 21 OBJECT => '$(O_FILES)',
22 'dist' => {
23 COMPRESS => 'gzip -9f',
24 SUFFIX => 'gz',
25 DIST_DEFAULT => 'all tardist',
26 },
27 MAN3PODS => {},
1604a540 28 # OS 390 winges about line numbers > 64K ???
29 XSOPT => '-nolinenumbers',
d811239c 30 );
31
32package MY;
33
d811239c 34sub post_initialize
35{
36 my ($self) = @_;
37 my %o;
38 my $x = $self->{'OBJ_EXT'};
39 # Add the table O_FILES
40 foreach my $e (keys %tables)
41 {
42 $o{$e.$x} = 1;
43 }
6d4ed59b 44 $o{"$name$x"} = 1;
d811239c 45 $self->{'O_FILES'} = [sort keys %o];
6d4ed59b 46 my @files = ("$name.xs");
47 $self->{'C'} = ["$name.c"];
67d7b5ef 48 $self->{'H'} = [$self->catfile($self->updir,'Encode', 'encode.h')];
d811239c 49 my %xs;
50 foreach my $table (keys %tables) {
6d4ed59b 51 push (@{$self->{'C'}},"$table.c");
52 # Do NOT add $table.h etc. to H_FILES unless we own up as to how they
53 # get built.
e7cbefb8 54 foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) {
d811239c 55 push (@files,$table.$ext);
56 }
57 }
6d4ed59b 58 $self->{'XS'} = { "$name.xs" => "$name.c" };
d811239c 59 $self->{'clean'}{'FILES'} .= join(' ',@files);
6d4ed59b 60 open(XS,">$name.xs") || die "Cannot open $name.xs:$!";
b90c9a30 61 print XS <<'END';
62#include <EXTERN.h>
63#include <perl.h>
64#include <XSUB.h>
65#define U8 U8
67d7b5ef 66#include "encode.h"
b90c9a30 67END
68 foreach my $table (keys %tables) {
69 print XS qq[#include "${table}.h"\n];
70 }
6d4ed59b 71 print XS <<"END";
b90c9a30 72
73static void
74Encode_XSEncoding(pTHX_ encode_t *enc)
75{
76 dSP;
77 HV *stash = gv_stashpv("Encode::XS", TRUE);
78 SV *sv = sv_bless(newRV_noinc(newSViv(PTR2IV(enc))),stash);
79 int i = 0;
80 PUSHMARK(sp);
81 XPUSHs(sv);
82 while (enc->name[i])
83 {
84 const char *name = enc->name[i++];
85 XPUSHs(sv_2mortal(newSVpvn(name,strlen(name))));
86 }
87 PUTBACK;
88 call_pv("Encode::define_encoding",G_DISCARD);
89 SvREFCNT_dec(sv);
90}
91
6d4ed59b 92MODULE = Encode::$name PACKAGE = Encode::$name
1aebe30a 93PROTOTYPES: DISABLE
b90c9a30 94BOOT:
95{
96END
97 foreach my $table (keys %tables) {
e7cbefb8 98 print XS qq[#include "${table}.exh"\n];
b90c9a30 99 }
100 print XS "}\n";
101 close(XS);
6d4ed59b 102 return "# Built $name.xs\n\n";
d811239c 103}
104
105sub postamble
106{
107 my $self = shift;
3ef515df 108 my $dir = $self->catdir($self->updir,'ucm');
e7cbefb8 109 my $str = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n";
6d4ed59b 110 $str .= "$name.c : $name.xs ";
d811239c 111 foreach my $table (keys %tables)
112 {
113 $str .= " $table.c";
114 }
115 $str .= "\n\n";
6d4ed59b 116 $str .= "$name\$(OBJ_EXT) : $name.c\n\n";
117
67d7b5ef 118 my $enc2xs = $self->catfile($self->updir,'bin', 'enc2xs');
d811239c 119 foreach my $table (keys %tables)
120 {
121 my $numlines = 1;
122 my $lengthsofar = length($str);
123 my $continuator = '';
67d7b5ef 124 $str .= "$table.c : $enc2xs Makefile.PL";
d811239c 125 foreach my $file (@{$tables{$table}})
126 {
127 $str .= $continuator.' '.$self->catfile($dir,$file);
128 if ( length($str)-$lengthsofar > 128*$numlines )
129 {
130 $continuator .= " \\\n\t";
131 $numlines++;
132 } else {
133 $continuator = '';
134 }
135 }
46fc212f 136 my $plib = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : '';
137 my $ucopts = '-"Q"';
a999c27c 138 $str .=
139 qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n};
d811239c 140 open (FILELIST, ">$table.fnm")
141 || die "Could not open $table.fnm: $!";
142 foreach my $file (@{$tables{$table}})
143 {
144 print FILELIST $self->catfile($dir,$file) . "\n";
145 }
146 close(FILELIST);
147 }
148 return $str;
149}
150