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