Upgrade to Encode 0.99, from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / Encode / Byte / Makefile.PL
1 use 5.7.2;
2 use strict;
3 use ExtUtils::MakeMaker;
4
5 my $name = 'Byte';
6 my %tables = (
7               misc_t => 
8               [
9                'gsm0338.ucm',
10                'nextstep.ucm',
11                'roman8.ucm',
12                'viscii.ucm',
13                ],
14               koi8_t => [ 'koi8-f.ucm', 'koi8-r.ucm', 'koi8-u.ucm', ],
15               mac_t => 
16               [
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                   ),
30               ],
31              );
32
33 opendir(ENC,'../Encode');
34 while (defined(my $file = readdir(ENC)))
35 {
36     if ($file =~ /(8859|ibm).*\.ucm/io)
37     {
38         push(@{$tables{$1."_t"}},$file) unless $file eq '8859-1.ucm';
39     }
40 }
41 closedir(ENC);
42
43 WriteMakefile(
44               INC               => "-I..",
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
58 package MY;
59
60 sub 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"];
74     $self->{'H'} = [$self->catfile($self->updir,'encode.h')];
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
92 #include "../encode.h"
93 END
94     foreach my $table (keys %tables) {
95         print XS qq[#include "${table}.h"\n];
96     }
97     print XS <<"END";
98
99 static void
100 Encode_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
118 MODULE = Encode::$name  PACKAGE = Encode::$name
119 PROTOTYPES: DISABLE
120 BOOT:
121 {
122 END
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
131 sub postamble
132 {
133     my $self = shift;
134     my $dir  = $self->catdir($self->updir,'Encode');
135     my $str  = "# $name\$(OBJ_EXT) depends on .h and _def.h files not .c files - but all written by compile\n";
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
144     my $compile = $self->catfile($self->updir,'compile');
145     foreach my $table (keys %tables)
146     {
147         my $numlines = 1;
148         my $lengthsofar = length($str);
149         my $continuator = '';
150         $str .= "$table.c : $compile Makefile.PL";
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
163             ? qq{\n\t\$(PERL) $compile -"Q" -o \$\@ -f $table.fnm\n\n}
164             : qq{\n\t\$(PERL) $compile -Q -o \$\@ -f $table.fnm\n\n};
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