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