Upgrade to Encode 1.20, from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / Encode / Byte / Makefile.PL
1 use 5.7.2;
2 use strict;
3 use ExtUtils::MakeMaker;
4
5 my $name = 'Byte';
6 my %tables = (
7               byte_t => 
8               [
9                # misc. vendors
10                'gsm0338.ucm',
11                'nextstep.ucm',
12                'hp-roman8.ucm',
13                'viscii.ucm',
14                'adobeStdenc.ucm',
15                # koi8
16                'koi8-f.ucm', 'koi8-r.ucm', 'koi8-u.ucm', 
17                # Mac
18                qw(
19                   macArabic.ucm
20                   macCentEuro.ucm
21                   macCroatian.ucm
22                   macCyrillic.ucm
23                   macFarsi.ucm
24                   macGreek.ucm
25                   macHebrew.ucm
26                   macIceland.ucm
27                   macRoman.ucm
28                   macROMnn.ucm
29                   macRUMnn.ucm
30                   macSami.ucm
31                   macThai.ucm
32                   macTurkish.ucm
33                   macUkraine.ucm
34                   ),
35               ],
36              );
37
38 my %not_here = 
39     map {$_ => 1} 
40 (
41  '8859-1.ucm', # default
42  qw(cp037.ucm cp1026.ucm cp1047.ucm cp500.ucm cp875.ucm), # EBCDIC
43  qw(cp932.ucm cp936.ucm cp949.ucm cp950.ucm),  # CJK
44  );
45
46 opendir(ENC,'../ucm');
47 while (defined(my $file = readdir(ENC)))
48 {
49     $file =~ /^(8859|cp).*\.ucm$/io or next;
50     $not_here{$file} and next;
51     push(@{$tables{byte_t}},$file);
52 }
53 closedir(ENC);
54
55 WriteMakefile(
56               INC               => "-I../Encode",
57               NAME              => 'Encode::'.$name,
58               VERSION_FROM      => "$name.pm",
59               OBJECT            => '$(O_FILES)',
60               'dist'            => {
61                   COMPRESS      => 'gzip -9f',
62                   SUFFIX        => 'gz',
63                   DIST_DEFAULT => 'all tardist',
64               },
65               MAN3PODS  => {},
66               # OS 390 winges about line numbers > 64K ???
67               XSOPT => '-nolinenumbers',
68               );
69
70 package MY;
71
72 sub post_initialize
73 {
74     my ($self) = @_;
75     my %o;
76     my $x = $self->{'OBJ_EXT'};
77     # Add the table O_FILES
78     foreach my $e (keys %tables)
79     {
80         $o{$e.$x} = 1;
81     }
82     $o{"$name$x"} = 1;
83     $self->{'O_FILES'} = [sort keys %o];
84     my @files = ("$name.xs");
85     $self->{'C'} = ["$name.c"];
86     $self->{'H'} = [$self->catfile($self->updir,'Encode', 'encode.h')];
87     my %xs;
88     foreach my $table (keys %tables) {
89         push (@{$self->{'C'}},"$table.c");
90         # Do NOT add $table.h etc. to H_FILES unless we own up as to how they
91         # get built.
92         foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) {
93             push (@files,$table.$ext);
94         }
95     }
96     $self->{'XS'} = { "$name.xs" => "$name.c" };
97     $self->{'clean'}{'FILES'} .= join(' ',@files);
98     open(XS,">$name.xs") || die "Cannot open $name.xs:$!";
99     print XS <<'END';
100 #include <EXTERN.h>
101 #include <perl.h>
102 #include <XSUB.h>
103 #define U8 U8
104 #include "encode.h"
105 END
106     foreach my $table (keys %tables) {
107         print XS qq[#include "${table}.h"\n];
108     }
109     print XS <<"END";
110
111 static void
112 Encode_XSEncoding(pTHX_ encode_t *enc)
113 {
114  dSP;
115  HV *stash = gv_stashpv("Encode::XS", TRUE);
116  SV *sv    = sv_bless(newRV_noinc(newSViv(PTR2IV(enc))),stash);
117  int i = 0;
118  PUSHMARK(sp);
119  XPUSHs(sv);
120  while (enc->name[i])
121   {
122    const char *name = enc->name[i++];
123    XPUSHs(sv_2mortal(newSVpvn(name,strlen(name))));
124   }
125  PUTBACK;
126  call_pv("Encode::define_encoding",G_DISCARD);
127  SvREFCNT_dec(sv);
128 }
129
130 MODULE = Encode::$name  PACKAGE = Encode::$name
131 PROTOTYPES: DISABLE
132 BOOT:
133 {
134 END
135     foreach my $table (keys %tables) {
136         print XS qq[#include "${table}.exh"\n];
137     }
138     print XS "}\n";
139     close(XS);
140     return "# Built $name.xs\n\n";
141 }
142
143 sub postamble
144 {
145     my $self = shift;
146     my $dir  = $self->catdir($self->updir,'ucm');
147     my $str  = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n";
148     $str    .= "$name.c : $name.xs ";
149     foreach my $table (keys %tables)
150     {
151         $str .= " $table.c";
152     }
153     $str .= "\n\n";
154     $str .= "$name\$(OBJ_EXT) : $name.c\n\n";
155
156     my $enc2xs = $self->catfile($self->updir,'bin', 'enc2xs');
157     foreach my $table (keys %tables)
158     {
159         my $numlines = 1;
160         my $lengthsofar = length($str);
161         my $continuator = '';
162         $str .= "$table.c : $enc2xs Makefile.PL";
163         foreach my $file (@{$tables{$table}})
164         {
165             $str .= $continuator.' '.$self->catfile($dir,$file);
166             if ( length($str)-$lengthsofar > 128*$numlines )
167             {
168                 $continuator .= " \\\n\t";
169                 $numlines++;
170             } else {
171                 $continuator = '';
172             }
173         }
174         my $plib   = $ENV{PERL_CORE} ? '-I$(PERL_LIB)' : '';
175         my $ucopts = ($^O eq 'VMS')  ? '-"Q" -"O"' : '-Q -O'; 
176         $str .=  
177             qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n};
178         open (FILELIST, ">$table.fnm")
179             || die "Could not open $table.fnm: $!";
180         foreach my $file (@{$tables{$table}})
181         {
182             print FILELIST $self->catfile($dir,$file) . "\n";
183         }
184         close(FILELIST);
185     }
186     return $str;
187 }
188