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