1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License, Version 1.0 only
6# (the "License").  You may not use this file except in compliance
7# with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# This file is auto-generated by:
24# enc2xs version $_Version_
25# $_Now_
26#
27use 5.7.2;
28use strict;
29use ExtUtils::MakeMaker;
30use Config;
31
32# Please edit the following to the taste!
33my $name = '$_Name_';
34my %tables = (
35	     $_Name__t   => [ $_TableFiles_ ],
36	     );
37
38#### DO NOT EDIT BEYOND THIS POINT!
39require File::Spec;
40my ($enc2xs, $encode_h) = ();
41PATHLOOP:
42for my $d (@Config{qw/bin sitebin vendorbin/},
43	   (split /$Config{path_sep}/o, $ENV{PATH})){
44    for my $f (qw/enc2xs enc2xs5.7.3/){
45        my $path = File::Spec->catfile($d, $f);
46        -r $path and $enc2xs = $path and last PATHLOOP;
47    }
48}
49$enc2xs or die "enc2xs not found!";
50print "enc2xs is $enc2xs\n";
51my %encode_h = ();
52for my $d (@INC){
53    my $dir = File::Spec->catfile($d, "Encode");
54    my $file =  File::Spec->catfile($dir, "encode.h");
55    -f $file and $encode_h{$dir} = -M $file;
56}
57%encode_h or die "encode.h not found!";
58# find the latest one
59($encode_h) = sort {$encode_h{$b} <=> $encode_h{$a}} keys %encode_h;
60print "encode.h is at $encode_h\n";
61
62WriteMakefile(
63              INC		=> "-I$encode_h",
64#### END_OF_HEADER -- DO NOT EDIT THIS LINE BY HAND! ####
65	      NAME		=> 'Encode::'.$name,
66	      VERSION_FROM	=> "$name.pm",
67	      OBJECT		=> '$(O_FILES)',
68	      'dist'		=> {
69		  COMPRESS	=> 'gzip -9f',
70		  SUFFIX	=> 'gz',
71		  DIST_DEFAULT => 'all tardist',
72	      },
73	      MAN3PODS	=> {},
74	      PREREQ_PM => {
75			    'Encode'     => "1.41",
76                           },
77	      # OS 390 winges about line numbers > 64K ???
78	      XSOPT => '-nolinenumbers',
79	      );
80
81package MY;
82
83sub post_initialize
84{
85    my ($self) = @_;
86    my %o;
87    my $x = $self->{'OBJ_EXT'};
88    # Add the table O_FILES
89    foreach my $e (keys %tables)
90    {
91	$o{$e.$x} = 1;
92    }
93    $o{"$name$x"} = 1;
94    $self->{'O_FILES'} = [sort keys %o];
95    my @files = ("$name.xs");
96    $self->{'C'} = ["$name.c"];
97    # The next two lines to make MacPerl Happy -- dankogai via pudge
98    $self->{SOURCE} .= " $name.c"
99        if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$name\.c\b/;
100    # $self->{'H'} = [$self->catfile($self->updir,'encode.h')];
101    my %xs;
102    foreach my $table (keys %tables) {
103	push (@{$self->{'C'}},"$table.c");
104	# Do NOT add $table.h etc. to H_FILES unless we own up as to how they
105	# get built.
106	foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) {
107	    push (@files,$table.$ext);
108	}
109    }
110    $self->{'XS'} = { "$name.xs" => "$name.c" };
111    $self->{'clean'}{'FILES'} .= join(' ',@files);
112    open(XS,">$name.xs") || die "Cannot open $name.xs:$!";
113    print XS <<'END';
114#include <EXTERN.h>
115#include <perl.h>
116#include <XSUB.h>
117#define U8 U8
118#include "encode.h"
119END
120    foreach my $table (keys %tables) {
121	print XS qq[#include "${table}.h"\n];
122    }
123    print XS <<"END";
124
125static void
126Encode_XSEncoding(pTHX_ encode_t *enc)
127{
128 dSP;
129 HV *stash = gv_stashpv("Encode::XS", TRUE);
130 SV *sv    = sv_bless(newRV_noinc(newSViv(PTR2IV(enc))),stash);
131 int i = 0;
132 PUSHMARK(sp);
133 XPUSHs(sv);
134 while (enc->name[i])
135  {
136   const char *name = enc->name[i++];
137   XPUSHs(sv_2mortal(newSVpvn(name,strlen(name))));
138  }
139 PUTBACK;
140 call_pv("Encode::define_encoding",G_DISCARD);
141 SvREFCNT_dec(sv);
142}
143
144MODULE = Encode::$name	PACKAGE = Encode::$name
145PROTOTYPES: DISABLE
146BOOT:
147{
148END
149    foreach my $table (keys %tables) {
150	print XS qq[#include "${table}.exh"\n];
151    }
152    print XS "}\n";
153    close(XS);
154    return "# Built $name.xs\n\n";
155}
156
157sub postamble
158{
159    my $self = shift;
160    my $dir  = "."; # $self->catdir('Encode');
161    my $str  = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n";
162    $str    .= "$name.c : $name.xs ";
163    foreach my $table (keys %tables)
164    {
165	$str .= " $table.c";
166    }
167    $str .= "\n\n";
168    $str .= "$name\$(OBJ_EXT) : $name.c\n\n";
169
170    foreach my $table (keys %tables)
171    {
172	my $numlines = 1;
173	my $lengthsofar = length($str);
174	my $continuator = '';
175	$str .= "$table.c : Makefile.PL";
176	foreach my $file (@{$tables{$table}})
177	{
178	    $str .= $continuator.' '.$self->catfile($dir,$file);
179	    if ( length($str)-$lengthsofar > 128*$numlines )
180	    {
181		$continuator .= " \\\n\t";
182		$numlines++;
183	    } else {
184		$continuator = '';
185	    }
186	}
187	my $plib   = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : '';
188	my $ucopts = '-"Q"';
189	$str .=
190	    qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n};
191	open (FILELIST, ">$table.fnm")
192	    || die "Could not open $table.fnm: $!";
193	foreach my $file (@{$tables{$table}})
194	{
195	    print FILELIST $self->catfile($dir,$file) . "\n";
196	}
197	close(FILELIST);
198    }
199    return $str;
200}
201
202