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