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