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