enc2xs template -- searches script more sensibly
[p5sagit/p5-mst-13.2.git] / ext / Encode / Encode / Makefile_PL.e2x
CommitLineData
3ef515df 1#
2# This file is auto-generated by:
3# enc2xs version $_Version_
4# $_Now_
5#
6use 5.7.2;
7use strict;
8use ExtUtils::MakeMaker;
9a473428 9use Config;
3ef515df 10
11# Please edit the following to the taste!
12my $name = '$_Name_';
13my %tables = (
14 $_Name__t => [ $_TableFiles_ ],
15 );
16
17#### DO NOT EDIT BEYOND THIS POINT!
85982a32 18require File::Spec;
19my ($enc2xs, $encode_h) = ();
20PATHLOOP:
9a473428 21for my $d (@Config{qw/bin sitebin vendorbin/},
22 (split /:/, $ENV{PATH})){
85982a32 23 for my $f (qw/enc2xs enc2xs5.7.3/){
24 my $path = File::Spec->catfile($d, $f);
25 -x $path and $enc2xs = $path and last PATHLOOP;
26 }
27}
28$enc2xs or die "enc2xs not found!";
29print "enc2xs is $enc2xs\n";
30my %encode_h = ();
31for 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;
39print "encode.h is at $encode_h\n";
40
3ef515df 41WriteMakefile(
85982a32 42 INC => "-I$encode_h",
3ef515df 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 => {},
85982a32 53 PREREQ_PM => {
54 'Encode' => "1.41",
55 },
3ef515df 56 # OS 390 winges about line numbers > 64K ???
57 XSOPT => '-nolinenumbers',
58 );
59
60package MY;
61
62sub 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.
e7cbefb8 82 foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) {
3ef515df 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"
95END
96 foreach my $table (keys %tables) {
97 print XS qq[#include "${table}.h"\n];
98 }
99 print XS <<"END";
100
101static void
102Encode_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
120MODULE = Encode::$name PACKAGE = Encode::$name
121PROTOTYPES: DISABLE
122BOOT:
123{
124END
125 foreach my $table (keys %tables) {
e7cbefb8 126 print XS qq[#include "${table}.exh"\n];
3ef515df 127 }
128 print XS "}\n";
129 close(XS);
130 return "# Built $name.xs\n\n";
131}
132
133sub postamble
134{
135 my $self = shift;
136 my $dir = "."; # $self->catdir('Encode');
e7cbefb8 137 my $str = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n";
3ef515df 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 }
f2a2953c 163 my $plib = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : '';
164 my $ucopts = '-"Q"';
a999c27c 165 $str .=
166 qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n};
3ef515df 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