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