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