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