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 File::Spec::Functions; 26 27my $name = 'Byte'; 28my %tables = ( 29 byte_t => 30 [ 31 # misc. vendors 32 'gsm0338.ucm', 33 'nextstep.ucm', 34 'hp-roman8.ucm', 35 'viscii.ucm', 36 'adobeStdenc.ucm', 37 # koi8 38 'koi8-f.ucm', 'koi8-r.ucm', 'koi8-u.ucm', 39 # Mac 40 qw( 41 macArabic.ucm 42 macCentEuro.ucm 43 macCroatian.ucm 44 macCyrillic.ucm 45 macFarsi.ucm 46 macGreek.ucm 47 macHebrew.ucm 48 macIceland.ucm 49 macRoman.ucm 50 macROMnn.ucm 51 macRUMnn.ucm 52 macSami.ucm 53 macThai.ucm 54 macTurkish.ucm 55 macUkraine.ucm 56 ), 57 ], 58 ); 59 60my %not_here = 61 map {$_ => 1} 62( 63 '8859-1.ucm', # default 64 qw(cp037.ucm cp1026.ucm cp1047.ucm cp500.ucm cp875.ucm), # EBCDIC 65 qw(cp932.ucm cp936.ucm cp949.ucm cp950.ucm), # CJK 66 ); 67 68opendir(ENC,catdir(updir(),'ucm')) or die $!; 69while (defined(my $file = readdir(ENC))) 70{ 71 $file =~ /^(8859|cp).*\.ucm$/io or next; 72 $not_here{$file} and next; 73 push(@{$tables{byte_t}},$file); 74} 75closedir(ENC); 76 77WriteMakefile( 78 INC => "-I../Encode", 79 NAME => 'Encode::'.$name, 80 VERSION_FROM => "$name.pm", 81 OBJECT => '$(O_FILES)', 82 'dist' => { 83 COMPRESS => 'gzip -9f', 84 SUFFIX => 'gz', 85 DIST_DEFAULT => 'all tardist', 86 }, 87 MAN3PODS => {}, 88 # OS 390 winges about line numbers > 64K ??? 89 XSOPT => '-nolinenumbers', 90 ); 91 92package MY; 93 94sub post_initialize 95{ 96 my ($self) = @_; 97 my %o; 98 my $x = $self->{'OBJ_EXT'}; 99 # Add the table O_FILES 100 foreach my $e (keys %tables) 101 { 102 $o{$e.$x} = 1; 103 } 104 $o{"$name$x"} = 1; 105 $self->{'O_FILES'} = [sort keys %o]; 106 my @files = ("$name.xs"); 107 $self->{'C'} = ["$name.c"]; 108 $self->{SOURCE} .= " $name.c" 109 if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$name\.c\b/; 110 $self->{'H'} = [$self->catfile($self->updir,'Encode', 'encode.h')]; 111 my %xs; 112 foreach my $table (keys %tables) { 113 push (@{$self->{'C'}},"$table.c"); 114 # Do NOT add $table.h etc. to H_FILES unless we own up as to how they 115 # get built. 116 foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) { 117 push (@files,$table.$ext); 118 } 119 $self->{SOURCE} .= " $table.c" 120 if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$table\.c\b/; 121 } 122 $self->{'XS'} = { "$name.xs" => "$name.c" }; 123 $self->{'clean'}{'FILES'} .= join(' ',@files); 124 open(XS,">$name.xs") || die "Cannot open $name.xs:$!"; 125 print XS <<'END'; 126#include <EXTERN.h> 127#include <perl.h> 128#include <XSUB.h> 129#define U8 U8 130#include "encode.h" 131END 132 foreach my $table (keys %tables) { 133 print XS qq[#include "${table}.h"\n]; 134 } 135 print XS <<"END"; 136 137static void 138Encode_XSEncoding(pTHX_ encode_t *enc) 139{ 140 dSP; 141 HV *stash = gv_stashpv("Encode::XS", TRUE); 142 SV *sv = sv_bless(newRV_noinc(newSViv(PTR2IV(enc))),stash); 143 int i = 0; 144 PUSHMARK(sp); 145 XPUSHs(sv); 146 while (enc->name[i]) 147 { 148 const char *name = enc->name[i++]; 149 XPUSHs(sv_2mortal(newSVpvn(name,strlen(name)))); 150 } 151 PUTBACK; 152 call_pv("Encode::define_encoding",G_DISCARD); 153 SvREFCNT_dec(sv); 154} 155 156MODULE = Encode::$name PACKAGE = Encode::$name 157PROTOTYPES: DISABLE 158BOOT: 159{ 160END 161 foreach my $table (keys %tables) { 162 print XS qq[#include "${table}.exh"\n]; 163 } 164 print XS "}\n"; 165 close(XS); 166 return "# Built $name.xs\n\n"; 167} 168 169sub postamble 170{ 171 my $self = shift; 172 my $dir = $self->catdir($self->updir,'ucm'); 173 my $str = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n"; 174 $str .= "$name.c : $name.xs "; 175 foreach my $table (keys %tables) 176 { 177 $str .= " $table.c"; 178 } 179 $str .= "\n\n"; 180 $str .= "$name\$(OBJ_EXT) : $name.c\n\n"; 181 182 my $enc2xs = $self->catfile($self->updir,'bin', 'enc2xs'); 183 foreach my $table (keys %tables) 184 { 185 my $numlines = 1; 186 my $lengthsofar = length($str); 187 my $continuator = ''; 188 $str .= "$table.c : $enc2xs Makefile.PL"; 189 foreach my $file (@{$tables{$table}}) 190 { 191 $str .= $continuator.' '.$self->catfile($dir,$file); 192 if ( length($str)-$lengthsofar > 128*$numlines ) 193 { 194 $continuator .= " \\\n\t"; 195 $numlines++; 196 } else { 197 $continuator = ''; 198 } 199 } 200 my $plib = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : ''; 201 $plib .= " -MCross=$::Cross::platform" if defined $::Cross::platform; 202 my $ucopts = '-"Q" -"O"'; 203 $str .= 204 qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n}; 205 open (FILELIST, ">$table.fnm") 206 || die "Could not open $table.fnm: $!"; 207 foreach my $file (@{$tables{$table}}) 208 { 209 print FILELIST $self->catfile($dir,$file) . "\n"; 210 } 211 close(FILELIST); 212 } 213 return $str; 214} 215 216