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