1# 2# CDDL HEADER START 3# 4# The contents of this file are subject to the terms of the 5# Common Development and Distribution License, Version 1.0 only 6# (the "License"). You may not use this file except in compliance 7# with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22use 5.7.2; 23use strict; 24use ExtUtils::MakeMaker; 25use strict; 26 27my %tables = ( 28 euc_jp_t => ['euc-jp.ucm'], 29 sjis_t => ['shiftjis.ucm', 30 'macJapanese.ucm', 31 'cp932.ucm'], 32 raw_t => [ 33 qw(jis0201.ucm jis0208.ucm jis0212.ucm) 34 ], 35 ); 36 37unless ($ENV{AGGREGATE_TABLES}){ 38 my @ucm; 39 for my $k (keys %tables){ 40 push @ucm, @{$tables{$k}}; 41 } 42 %tables = (); 43 my $seq = 0; 44 for my $ucm (sort @ucm){ 45 # 8.3 compliance ! 46 my $t = sprintf ("%s_%02d_t", substr($ucm, 0, 2), $seq++); 47 $tables{$t} = [ $ucm ]; 48 } 49} 50 51my $name = 'JP'; 52 53WriteMakefile( 54 INC => "-I../Encode", 55 NAME => 'Encode::'.$name, 56 VERSION_FROM => "$name.pm", 57 OBJECT => '$(O_FILES)', 58 'dist' => { 59 COMPRESS => 'gzip -9f', 60 SUFFIX => 'gz', 61 DIST_DEFAULT => 'all tardist', 62 }, 63 MAN3PODS => {}, 64 # OS 390 winges about line numbers > 64K ??? 65 XSOPT => '-nolinenumbers', 66 ); 67 68package MY; 69 70sub post_initialize 71{ 72 my ($self) = @_; 73 my %o; 74 my $x = $self->{'OBJ_EXT'}; 75 # Add the table O_FILES 76 foreach my $e (keys %tables) 77 { 78 $o{$e.$x} = 1; 79 } 80 $o{"$name$x"} = 1; 81 $self->{'O_FILES'} = [sort keys %o]; 82 my @files = ("$name.xs"); 83 $self->{'C'} = ["$name.c"]; 84 $self->{SOURCE} .= " $name.c" 85 if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$name\.c\b/; 86 $self->{'H'} = [$self->catfile($self->updir,'Encode', 'encode.h')]; 87 my %xs; 88 foreach my $table (keys %tables) { 89 push (@{$self->{'C'}},"$table.c"); 90 # Do NOT add $table.h etc. to H_FILES unless we own up as to how they 91 # get built. 92 foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) { 93 push (@files,$table.$ext); 94 } 95 $self->{SOURCE} .= " $table.c" 96 if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$table\.c\b/; 97 } 98 $self->{'XS'} = { "$name.xs" => "$name.c" }; 99 $self->{'clean'}{'FILES'} .= join(' ',@files); 100 open(XS,">$name.xs") || die "Cannot open $name.xs:$!"; 101 print XS <<'END'; 102#include <EXTERN.h> 103#include <perl.h> 104#include <XSUB.h> 105#define U8 U8 106#include "encode.h" 107END 108 foreach my $table (keys %tables) { 109 print XS qq[#include "${table}.h"\n]; 110 } 111 print XS <<"END"; 112 113static void 114Encode_XSEncoding(pTHX_ encode_t *enc) 115{ 116 dSP; 117 HV *stash = gv_stashpv("Encode::XS", TRUE); 118 SV *sv = sv_bless(newRV_noinc(newSViv(PTR2IV(enc))),stash); 119 int i = 0; 120 PUSHMARK(sp); 121 XPUSHs(sv); 122 while (enc->name[i]) 123 { 124 const char *name = enc->name[i++]; 125 XPUSHs(sv_2mortal(newSVpvn(name,strlen(name)))); 126 } 127 PUTBACK; 128 call_pv("Encode::define_encoding",G_DISCARD); 129 SvREFCNT_dec(sv); 130} 131 132MODULE = Encode::$name PACKAGE = Encode::$name 133PROTOTYPES: DISABLE 134BOOT: 135{ 136END 137 foreach my $table (keys %tables) { 138 print XS qq[#include "${table}.exh"\n]; 139 } 140 print XS "}\n"; 141 close(XS); 142 return "# Built $name.xs\n\n"; 143} 144 145sub postamble 146{ 147 my $self = shift; 148 my $dir = $self->catdir($self->updir,'ucm'); 149 my $str = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n"; 150 $str .= "$name.c : $name.xs "; 151 foreach my $table (keys %tables) 152 { 153 $str .= " $table.c"; 154 } 155 $str .= "\n\n"; 156 $str .= "$name\$(OBJ_EXT) : $name.c\n\n"; 157 158 my $enc2xs = $self->catfile($self->updir,'bin', 'enc2xs'); 159 foreach my $table (keys %tables) 160 { 161 my $numlines = 1; 162 my $lengthsofar = length($str); 163 my $continuator = ''; 164 $str .= "$table.c : $enc2xs Makefile.PL"; 165 foreach my $file (@{$tables{$table}}) 166 { 167 $str .= $continuator.' '.$self->catfile($dir,$file); 168 if ( length($str)-$lengthsofar > 128*$numlines ) 169 { 170 $continuator .= " \\\n\t"; 171 $numlines++; 172 } else { 173 $continuator = ''; 174 } 175 } 176 my $plib = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : ''; 177 $plib .= " -MCross=$::Cross::platform" if defined $::Cross::platform; 178 my $ucopts = '-"Q"'; 179 $str .= 180 qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n}; 181 open (FILELIST, ">$table.fnm") 182 || die "Could not open $table.fnm: $!"; 183 foreach my $file (@{$tables{$table}}) 184 { 185 print FILELIST $self->catfile($dir,$file) . "\n"; 186 } 187 close(FILELIST); 188 } 189 return $str; 190} 191 192