Upgrade to Encode 1.26, from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / Encode / JP / Makefile.PL
1 use 5.7.2;
2 use strict;
3 use ExtUtils::MakeMaker;
4
5 my %tables = (
6               euc_jp_t   => ['euc-jp.ucm'],
7               sjis_t     => ['shiftjis.ucm',
8                              'macJapanese.ucm',
9                              'cp932.ucm'],
10               raw_t      => [
11                              qw(jis0201.ucm jis0208.ucm jis0212.ucm)
12                              ],
13              );
14
15 my $name = 'JP';
16
17 WriteMakefile(
18               INC               => "-I../Encode",
19               NAME              => 'Encode::'.$name,
20               VERSION_FROM      => "$name.pm",
21               OBJECT            => '$(O_FILES)',
22               'dist'            => {
23                   COMPRESS      => 'gzip -9f',
24                   SUFFIX        => 'gz',
25                   DIST_DEFAULT => 'all tardist',
26               },
27               MAN3PODS  => {},
28               # OS 390 winges about line numbers > 64K ???
29               XSOPT => '-nolinenumbers',
30               );
31
32 package MY;
33
34 sub 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     }
44     $o{"$name$x"} = 1;
45     $self->{'O_FILES'} = [sort keys %o];
46     my @files = ("$name.xs");
47     $self->{'C'} = ["$name.c"];
48     $self->{'H'} = [$self->catfile($self->updir,'Encode', 'encode.h')];
49     my %xs;
50     foreach my $table (keys %tables) {
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.
54         foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) {
55             push (@files,$table.$ext);
56         }
57     }
58     $self->{'XS'} = { "$name.xs" => "$name.c" };
59     $self->{'clean'}{'FILES'} .= join(' ',@files);
60     open(XS,">$name.xs") || die "Cannot open $name.xs:$!";
61     print XS <<'END';
62 #include <EXTERN.h>
63 #include <perl.h>
64 #include <XSUB.h>
65 #define U8 U8
66 #include "encode.h"
67 END
68     foreach my $table (keys %tables) {
69         print XS qq[#include "${table}.h"\n];
70     }
71     print XS <<"END";
72
73 static void
74 Encode_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
92 MODULE = Encode::$name  PACKAGE = Encode::$name
93 PROTOTYPES: DISABLE
94 BOOT:
95 {
96 END
97     foreach my $table (keys %tables) {
98         print XS qq[#include "${table}.exh"\n];
99     }
100     print XS "}\n";
101     close(XS);
102     return "# Built $name.xs\n\n";
103 }
104
105 sub postamble
106 {
107     my $self = shift;
108     my $dir  = $self->catdir($self->updir,'ucm');
109     my $str  = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n";
110     $str    .= "$name.c : $name.xs ";
111     foreach my $table (keys %tables)
112     {
113         $str .= " $table.c";
114     }
115     $str .= "\n\n";
116     $str .= "$name\$(OBJ_EXT) : $name.c\n\n";
117
118     my $enc2xs = $self->catfile($self->updir,'bin', 'enc2xs');
119     foreach my $table (keys %tables)
120     {
121         my $numlines = 1;
122         my $lengthsofar = length($str);
123         my $continuator = '';
124         $str .= "$table.c : $enc2xs Makefile.PL";
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         }
136         my $plib   = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : '';
137         my $ucopts = '-"Q"';
138         $str .=  
139             qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n};
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