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