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