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