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