xref: /openbsd-src/gnu/usr.bin/perl/cpan/Encode/CN/Makefile.PL (revision b8851fcc53cbe24fd20b090f26dd149e353f6174)
1use 5.7.2;
2use strict;
3use ExtUtils::MakeMaker;
4use strict;
5
6my %tables = (euc_cn_t   => ['euc-cn.ucm',
7                 'cp936.ucm',
8                 'macChinsimp.ucm',
9                 ],
10          '2312_t'    => ['gb2312.ucm'],
11          '12345_t'  => ['gb12345.ucm'],
12          ir_165_t   => ['ir-165.ucm'],
13             );
14
15unless ($ENV{AGGREGATE_TABLES}){
16    my @ucm;
17    for my $k (keys %tables){
18    push @ucm, @{$tables{$k}};
19    }
20    %tables = ();
21    my $seq = 0;
22    for my $ucm (sort @ucm){
23    # 8.3 compliance !
24    my $t = sprintf ("%s_%02d_t", substr($ucm, 0, 2), $seq++);
25    $tables{$t} = [ $ucm ];
26    }
27}
28
29my $name = 'CN';
30
31WriteMakefile(
32              INC		=> "-I../Encode",
33          NAME		=> 'Encode::'.$name,
34          VERSION_FROM	=> "$name.pm",
35          OBJECT		=> '$(O_FILES)',
36          'dist'		=> {
37          COMPRESS	=> 'gzip -9f',
38          SUFFIX	=> 'gz',
39          DIST_DEFAULT => 'all tardist',
40          },
41          MAN3PODS	=> {},
42          # OS 390 winges about line numbers > 64K ???
43          XSOPT => '-nolinenumbers',
44              XSPROTOARG => '-noprototypes',
45          );
46
47package MY;
48
49sub post_initialize
50{
51    my ($self) = @_;
52    my %o;
53    my $x = $self->{'OBJ_EXT'};
54    # Add the table O_FILES
55    foreach my $e (keys %tables)
56    {
57    $o{$e.$x} = 1;
58    }
59    $o{"$name$x"} = 1;
60    $self->{'O_FILES'} = [sort keys %o];
61    my @files = ("$name.xs");
62    $self->{'C'} = ["$name.c"];
63    $self->{SOURCE} .= " $name.c"
64        if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$name\.c\b/;
65    $self->{'H'} = [$self->catfile($self->updir,'Encode', 'encode.h')];
66    my %xs;
67    foreach my $table (sort keys %tables) {
68    push (@{$self->{'C'}},"$table.c");
69    # Do NOT add $table.h etc. to H_FILES unless we own up as to how they
70    # get built.
71    foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) {
72        push (@files,$table.$ext);
73    }
74    $self->{SOURCE} .= " $table.c"
75        if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$table\.c\b/;
76    }
77    $self->{'XS'} = { "$name.xs" => "$name.c" };
78    $self->{'clean'}{'FILES'} .= join(' ',@files);
79    open(XS,">$name.xs") || die "Cannot open $name.xs:$!";
80    print XS <<'END';
81#define PERL_NO_GET_CONTEXT
82#include <EXTERN.h>
83#include <perl.h>
84#include <XSUB.h>
85#include "encode.h"
86END
87    foreach my $table (sort keys %tables) {
88    print XS qq[#include "${table}.h"\n];
89    }
90    print XS <<"END";
91
92static void
93Encode_XSEncoding(pTHX_ encode_t *enc)
94{
95 dSP;
96 HV *stash = gv_stashpv("Encode::XS", TRUE);
97 SV *iv    = newSViv(PTR2IV(enc));
98 SV *sv    = sv_bless(newRV_noinc(iv),stash);
99 int i = 0;
100 /* with the SvLEN() == 0 hack, PVX won't be freed. We cast away name's
101 constness, in the hope that perl won't mess with it. */
102 assert(SvTYPE(iv) >= SVt_PV); assert(SvLEN(iv) == 0);
103 SvFLAGS(iv) |= SVp_POK;
104 SvPVX(iv) = (char*) enc->name[0];
105 PUSHMARK(sp);
106 XPUSHs(sv);
107 while (enc->name[i])
108  {
109   const char *name = enc->name[i++];
110   XPUSHs(sv_2mortal(newSVpvn(name,strlen(name))));
111  }
112 PUTBACK;
113 call_pv("Encode::define_encoding",G_DISCARD);
114 SvREFCNT_dec(sv);
115}
116
117MODULE = Encode::$name	PACKAGE = Encode::$name
118PROTOTYPES: DISABLE
119BOOT:
120{
121END
122    foreach my $table (sort keys %tables) {
123    print XS qq[#include "${table}.exh"\n];
124    }
125    print XS "}\n";
126    close(XS);
127    return "# Built $name.xs\n\n";
128}
129
130sub postamble
131{
132    my $self = shift;
133    my $dir  = $self->catdir($self->updir,'ucm');
134    my $str  = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n";
135    $str    .= "$name.c : $name.xs ";
136    foreach my $table (sort keys %tables)
137    {
138    $str .= " $table.c";
139    }
140    $str .= "\n\n";
141    $str .= "$name\$(OBJ_EXT) : $name.c\n\n";
142
143    my $enc2xs = $self->catfile($self->updir,'bin', 'enc2xs');
144    foreach my $table (sort keys %tables)
145    {
146    my $numlines = 1;
147    my $lengthsofar = length($str);
148    my $continuator = '';
149    $str .= "$table.c : $enc2xs Makefile.PL";
150    foreach my $file (@{$tables{$table}})
151    {
152        $str .= $continuator.' '.$self->catfile($dir,$file);
153        if ( length($str)-$lengthsofar > 128*$numlines )
154        {
155        $continuator .= " \\\n\t";
156        $numlines++;
157        } else {
158        $continuator = '';
159        }
160    }
161    my $plib   = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : '';
162    $plib .= " -MCross=$::Cross::platform" if defined $::Cross::platform;
163    my $ucopts = '-"Q"';
164    $str .=
165        qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n};
166    open (FILELIST, ">$table.fnm")
167        || die "Could not open $table.fnm: $!";
168    foreach my $file (@{$tables{$table}})
169    {
170        print FILELIST $self->catfile($dir,$file) . "\n";
171    }
172    close(FILELIST);
173    }
174    return $str;
175}
176
177