Make Makefile_PL.e2x happy on MSWin32
[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 use Config;
10
11 # Please edit the following to the taste!
12 my $name = '$_Name_';
13 my %tables = (
14              $_Name__t   => [ $_TableFiles_ ],
15              );
16
17 #### DO NOT EDIT BEYOND THIS POINT!
18 require File::Spec;
19 my ($enc2xs, $encode_h) = ();
20 PATHLOOP:
21 for my $d (@Config{qw/bin sitebin vendorbin/}, 
22            (split /$Config{path_sep}/o, $ENV{PATH})){
23     for my $f (qw/enc2xs enc2xs5.7.3/){
24         my $path = File::Spec->catfile($d, $f);
25         -r $path and $enc2xs = $path and last PATHLOOP;
26     }
27 }
28 $enc2xs or die "enc2xs not found!";
29 print "enc2xs is $enc2xs\n";
30 my %encode_h = ();
31 for my $d (@INC){
32     my $dir = File::Spec->catfile($d, "Encode");
33     my $file =  File::Spec->catfile($dir, "encode.h");
34     -f $file and $encode_h{$dir} = -M $file;
35 }
36 %encode_h or die "encode.h not found!";
37 # find the latest one
38 ($encode_h) = sort {$encode_h{$b} <=> $encode_h{$a}} keys %encode_h;
39 print "encode.h is at $encode_h\n";
40
41 WriteMakefile(
42               INC               => "-I$encode_h",
43 #### END_OF_HEADER -- DO NOT EDIT THIS LINE BY HAND! ####
44               NAME              => 'Encode::'.$name,
45               VERSION_FROM      => "$name.pm",
46               OBJECT            => '$(O_FILES)',
47               'dist'            => {
48                   COMPRESS      => 'gzip -9f',
49                   SUFFIX        => 'gz',
50                   DIST_DEFAULT => 'all tardist',
51               },
52               MAN3PODS  => {},
53               PREREQ_PM => {
54                             'Encode'     => "1.41",
55                            },
56               # OS 390 winges about line numbers > 64K ???
57               XSOPT => '-nolinenumbers',
58               );
59
60 package MY;
61
62 sub post_initialize
63 {
64     my ($self) = @_;
65     my %o;
66     my $x = $self->{'OBJ_EXT'};
67     # Add the table O_FILES
68     foreach my $e (keys %tables)
69     {
70         $o{$e.$x} = 1;
71     }
72     $o{"$name$x"} = 1;
73     $self->{'O_FILES'} = [sort keys %o];
74     my @files = ("$name.xs");
75     $self->{'C'} = ["$name.c"];
76     # $self->{'H'} = [$self->catfile($self->updir,'encode.h')];
77     my %xs;
78     foreach my $table (keys %tables) {
79         push (@{$self->{'C'}},"$table.c");
80         # Do NOT add $table.h etc. to H_FILES unless we own up as to how they
81         # get built.
82         foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) {
83             push (@files,$table.$ext);
84         }
85     }
86     $self->{'XS'} = { "$name.xs" => "$name.c" };
87     $self->{'clean'}{'FILES'} .= join(' ',@files);
88     open(XS,">$name.xs") || die "Cannot open $name.xs:$!";
89     print XS <<'END';
90 #include <EXTERN.h>
91 #include <perl.h>
92 #include <XSUB.h>
93 #define U8 U8
94 #include "encode.h"
95 END
96     foreach my $table (keys %tables) {
97         print XS qq[#include "${table}.h"\n];
98     }
99     print XS <<"END";
100
101 static void
102 Encode_XSEncoding(pTHX_ encode_t *enc)
103 {
104  dSP;
105  HV *stash = gv_stashpv("Encode::XS", TRUE);
106  SV *sv    = sv_bless(newRV_noinc(newSViv(PTR2IV(enc))),stash);
107  int i = 0;
108  PUSHMARK(sp);
109  XPUSHs(sv);
110  while (enc->name[i])
111   {
112    const char *name = enc->name[i++];
113    XPUSHs(sv_2mortal(newSVpvn(name,strlen(name))));
114   }
115  PUTBACK;
116  call_pv("Encode::define_encoding",G_DISCARD);
117  SvREFCNT_dec(sv);
118 }
119
120 MODULE = Encode::$name  PACKAGE = Encode::$name
121 PROTOTYPES: DISABLE
122 BOOT:
123 {
124 END
125     foreach my $table (keys %tables) {
126         print XS qq[#include "${table}.exh"\n];
127     }
128     print XS "}\n";
129     close(XS);
130     return "# Built $name.xs\n\n";
131 }
132
133 sub postamble
134 {
135     my $self = shift;
136     my $dir  = "."; # $self->catdir('Encode');
137     my $str  = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n";
138     $str    .= "$name.c : $name.xs ";
139     foreach my $table (keys %tables)
140     {
141         $str .= " $table.c";
142     }
143     $str .= "\n\n";
144     $str .= "$name\$(OBJ_EXT) : $name.c\n\n";
145
146     foreach my $table (keys %tables)
147     {
148         my $numlines = 1;
149         my $lengthsofar = length($str);
150         my $continuator = '';
151         $str .= "$table.c : Makefile.PL";
152         foreach my $file (@{$tables{$table}})
153         {
154             $str .= $continuator.' '.$self->catfile($dir,$file);
155             if ( length($str)-$lengthsofar > 128*$numlines )
156             {
157                 $continuator .= " \\\n\t";
158                 $numlines++;
159             } else {
160                 $continuator = '';
161             }
162         }
163         my $plib   = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : '';
164         my $ucopts = '-"Q"';
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