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