1use 5.7.2; 2use strict; 3use ExtUtils::MakeMaker; 4use strict; 5 6my %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 14unless ($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 28my $name = 'KR'; 29 30WriteMakefile( 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 45package MY; 46 47sub 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 (sort 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#define PERL_NO_GET_CONTEXT 80#include <EXTERN.h> 81#include <perl.h> 82#include <XSUB.h> 83#include "encode.h" 84END 85 foreach my $table (sort keys %tables) { 86 print XS qq[#include "${table}.h"\n]; 87 } 88 print XS <<"END"; 89 90static void 91Encode_XSEncoding(pTHX_ encode_t *enc) 92{ 93 dSP; 94 HV *stash = gv_stashpv("Encode::XS", TRUE); 95 SV *iv = newSViv(PTR2IV(enc)); 96 SV *sv = sv_bless(newRV_noinc(iv),stash); 97 int i = 0; 98 /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's 99 constness, in the hope that perl won't mess with it. */ 100 assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0); 101 SvFLAGS(iv) |= SVp_POK; 102 SvPVX(iv) = (char*) enc->name[0]; 103 PUSHMARK(sp); 104 XPUSHs(sv); 105 while (enc->name[i]) 106 { 107 const char *name = enc->name[i++]; 108 XPUSHs(sv_2mortal(newSVpvn(name,strlen(name)))); 109 } 110 PUTBACK; 111 call_pv("Encode::define_encoding",G_DISCARD); 112 SvREFCNT_dec(sv); 113} 114 115MODULE = Encode::$name PACKAGE = Encode::$name 116PROTOTYPES: DISABLE 117BOOT: 118{ 119END 120 foreach my $table (sort keys %tables) { 121 print XS qq[#include "${table}.exh"\n]; 122 } 123 print XS "}\n"; 124 close(XS); 125 return "# Built $name.xs\n\n"; 126} 127 128sub postamble 129{ 130 my $self = shift; 131 my $dir = $self->catdir($self->updir,'ucm'); 132 my $str = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n"; 133 $str .= "$name.c : $name.xs "; 134 foreach my $table (sort keys %tables) 135 { 136 $str .= " $table.c"; 137 } 138 $str .= "\n\n"; 139 $str .= "$name\$(OBJ_EXT) : $name.c\n\n"; 140 141 my $enc2xs = $self->catfile($self->updir,'bin', 'enc2xs'); 142 foreach my $table (sort keys %tables) 143 { 144 my $numlines = 1; 145 my $lengthsofar = length($str); 146 my $continuator = ''; 147 $str .= "$table.c : $enc2xs Makefile.PL"; 148 foreach my $file (@{$tables{$table}}) 149 { 150 $str .= $continuator.' '.$self->catfile($dir,$file); 151 if ( length($str)-$lengthsofar > 128*$numlines ) 152 { 153 $continuator .= " \\\n\t"; 154 $numlines++; 155 } else { 156 $continuator = ''; 157 } 158 } 159 my $plib = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : ''; 160 $plib .= " -MCross=$::Cross::platform" if defined $::Cross::platform; 161 my $ucopts = '-"Q"'; 162 $str .= 163 qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n}; 164 open (FILELIST, ">$table.fnm") 165 || die "Could not open $table.fnm: $!"; 166 foreach my $file (@{$tables{$table}}) 167 { 168 print FILELIST $self->catfile($dir,$file) . "\n"; 169 } 170 close(FILELIST); 171 } 172 return $str; 173} 174 175