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