Upgrade to Encode 1.20, from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / Encode / Byte / Makefile.PL
CommitLineData
5129552c 1use 5.7.2;
2use strict;
3use ExtUtils::MakeMaker;
4
5my $name = 'Byte';
6my %tables = (
a999c27c 7 byte_t =>
5129552c 8 [
a999c27c 9 # misc. vendors
64ffdd5e 10 'gsm0338.ucm',
11 'nextstep.ucm',
67d7b5ef 12 'hp-roman8.ucm',
5129552c 13 'viscii.ucm',
a999c27c 14 'adobeStdenc.ucm',
15 # koi8
16 'koi8-f.ucm', 'koi8-r.ucm', 'koi8-u.ucm',
17 # Mac
64ffdd5e 18 qw(
a999c27c 19 macArabic.ucm
20 macCentEuro.ucm
64ffdd5e 21 macCroatian.ucm
a999c27c 22 macCyrillic.ucm
23 macFarsi.ucm
64ffdd5e 24 macGreek.ucm
a999c27c 25 macHebrew.ucm
26 macIceland.ucm
64ffdd5e 27 macRoman.ucm
a999c27c 28 macROMnn.ucm
29 macRUMnn.ucm
30 macSami.ucm
64ffdd5e 31 macThai.ucm
64ffdd5e 32 macTurkish.ucm
a999c27c 33 macUkraine.ucm
64ffdd5e 34 ),
5129552c 35 ],
5129552c 36 );
37
a999c27c 38my %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
3ef515df 46opendir(ENC,'../ucm');
5129552c 47while (defined(my $file = readdir(ENC)))
48{
a999c27c 49 $file =~ /^(8859|cp).*\.ucm$/io or next;
50 $not_here{$file} and next;
51 push(@{$tables{byte_t}},$file);
5129552c 52}
53closedir(ENC);
54
55WriteMakefile(
67d7b5ef 56 INC => "-I../Encode",
5129552c 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
70package MY;
71
72sub 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"];
67d7b5ef 86 $self->{'H'} = [$self->catfile($self->updir,'Encode', 'encode.h')];
5129552c 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.
e7cbefb8 92 foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) {
5129552c 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
67d7b5ef 104#include "encode.h"
5129552c 105END
106 foreach my $table (keys %tables) {
107 print XS qq[#include "${table}.h"\n];
108 }
109 print XS <<"END";
110
111static void
112Encode_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
130MODULE = Encode::$name PACKAGE = Encode::$name
131PROTOTYPES: DISABLE
132BOOT:
133{
134END
135 foreach my $table (keys %tables) {
e7cbefb8 136 print XS qq[#include "${table}.exh"\n];
5129552c 137 }
138 print XS "}\n";
139 close(XS);
140 return "# Built $name.xs\n\n";
141}
142
143sub postamble
144{
145 my $self = shift;
3ef515df 146 my $dir = $self->catdir($self->updir,'ucm');
e7cbefb8 147 my $str = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n";
5129552c 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
67d7b5ef 156 my $enc2xs = $self->catfile($self->updir,'bin', 'enc2xs');
5129552c 157 foreach my $table (keys %tables)
158 {
159 my $numlines = 1;
160 my $lengthsofar = length($str);
161 my $continuator = '';
67d7b5ef 162 $str .= "$table.c : $enc2xs Makefile.PL";
5129552c 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 }
a999c27c 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};
5129552c 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