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