Upgrade to Encode 1.60, from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / Encode / Encode / Makefile_PL.e2x
1 #
2 # This file is auto-generated by:
3 # enc2xs version $_Version_
4 # $_Now_
5 #
6 use 5.7.2;
7 use strict;
8 use ExtUtils::MakeMaker;
9
10 # Please edit the following to the taste!
11 my $name = '$_Name_';
12 my %tables = (
13              $_Name__t   => [ $_TableFiles_ ],
14              );
15
16 #### DO NOT EDIT BEYOND THIS POINT!
17 require File::Spec;
18 my ($enc2xs, $encode_h) = ();
19 PATHLOOP:
20 for my $d (split /:/, $ENV{PATH}){
21     for my $f (qw/enc2xs enc2xs5.7.3/){
22         my $path = File::Spec->catfile($d, $f);
23         -x $path and $enc2xs = $path and last PATHLOOP;
24     }
25 }
26 $enc2xs or die "enc2xs not found!";
27 print "enc2xs is $enc2xs\n";
28 my %encode_h = ();
29 for my $d (@INC){
30     my $dir = File::Spec->catfile($d, "Encode");
31     my $file =  File::Spec->catfile($dir, "encode.h");
32     -f $file and $encode_h{$dir} = -M $file;
33 }
34 %encode_h or die "encode.h not found!";
35 # find the latest one
36 ($encode_h) = sort {$encode_h{$b} <=> $encode_h{$a}} keys %encode_h;
37 print "encode.h is at $encode_h\n";
38
39 WriteMakefile(
40               INC               => "-I$encode_h",
41 #### END_OF_HEADER -- DO NOT EDIT THIS LINE BY HAND! ####
42               NAME              => 'Encode::'.$name,
43               VERSION_FROM      => "$name.pm",
44               OBJECT            => '$(O_FILES)',
45               'dist'            => {
46                   COMPRESS      => 'gzip -9f',
47                   SUFFIX        => 'gz',
48                   DIST_DEFAULT => 'all tardist',
49               },
50               MAN3PODS  => {},
51               PREREQ_PM => {
52                             'Encode'     => "1.41",
53                            },
54               # OS 390 winges about line numbers > 64K ???
55               XSOPT => '-nolinenumbers',
56               );
57
58 package MY;
59
60 sub post_initialize
61 {
62     my ($self) = @_;
63     my %o;
64     my $x = $self->{'OBJ_EXT'};
65     # Add the table O_FILES
66     foreach my $e (keys %tables)
67     {
68         $o{$e.$x} = 1;
69     }
70     $o{"$name$x"} = 1;
71     $self->{'O_FILES'} = [sort keys %o];
72     my @files = ("$name.xs");
73     $self->{'C'} = ["$name.c"];
74     # $self->{'H'} = [$self->catfile($self->updir,'encode.h')];
75     my %xs;
76     foreach my $table (keys %tables) {
77         push (@{$self->{'C'}},"$table.c");
78         # Do NOT add $table.h etc. to H_FILES unless we own up as to how they
79         # get built.
80         foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) {
81             push (@files,$table.$ext);
82         }
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"
93 END
94     foreach my $table (keys %tables) {
95         print XS qq[#include "${table}.h"\n];
96     }
97     print XS <<"END";
98
99 static void
100 Encode_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
118 MODULE = Encode::$name  PACKAGE = Encode::$name
119 PROTOTYPES: DISABLE
120 BOOT:
121 {
122 END
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
131 sub postamble
132 {
133     my $self = shift;
134     my $dir  = "."; # $self->catdir('Encode');
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     foreach my $table (keys %tables)
145     {
146         my $numlines = 1;
147         my $lengthsofar = length($str);
148         my $continuator = '';
149         $str .= "$table.c : 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         my $ucopts = '-"Q"';
163         $str .=  
164             qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n};
165         open (FILELIST, ">$table.fnm")
166             || die "Could not open $table.fnm: $!";
167         foreach my $file (@{$tables{$table}})
168         {
169             print FILELIST $self->catfile($dir,$file) . "\n";
170         }
171         close(FILELIST);
172     }
173     return $str;
174 }
175