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