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