Commit | Line | Data |
d811239c |
1 | use 5.7.2; |
2 | use strict; |
3 | use ExtUtils::MakeMaker; |
4 | |
3de3d21f |
5 | my %tables = (EUC_JP => ['euc-jp.ucm'], |
6 | JIS0208 => ['jis0208.enc'], |
7 | JIS0212 => ['jis0212.enc'], |
8 | SHIFTJIS => ['shiftjis.enc'], |
9 | ); |
d811239c |
10 | |
11 | |
12 | WriteMakefile( |
13 | INC => "-I..", |
3de3d21f |
14 | NAME => "Encode::Japanese", |
15 | VERSION_FROM => 'Japanese.pm', |
d811239c |
16 | OBJECT => '$(O_FILES)', |
17 | 'dist' => { |
18 | COMPRESS => 'gzip -9f', |
19 | SUFFIX => 'gz', |
20 | DIST_DEFAULT => 'all tardist', |
21 | }, |
22 | MAN3PODS => {}, |
1604a540 |
23 | # OS 390 winges about line numbers > 64K ??? |
24 | XSOPT => '-nolinenumbers', |
d811239c |
25 | ); |
26 | |
27 | package MY; |
28 | |
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 | { |
38 | $o{$e.$x} = 1; |
39 | } |
b90c9a30 |
40 | $o{"Japanese$x"} = 1; |
d811239c |
41 | $self->{'O_FILES'} = [sort keys %o]; |
b90c9a30 |
42 | my @files = ('Japanese.xs'); |
d811239c |
43 | my %xs; |
44 | foreach my $table (keys %tables) { |
b90c9a30 |
45 | foreach my $ext (qw($(OBJ_EXT) .c .h _def.h .fnm)) { |
d811239c |
46 | push (@files,$table.$ext); |
47 | } |
48 | } |
b90c9a30 |
49 | $self->{'XS_FILES'} = { 'Japanese.xs' => 'Japanese.c' }; |
d811239c |
50 | $self->{'clean'}{'FILES'} .= join(' ',@files); |
b90c9a30 |
51 | open(XS,">Japanese.xs") || die "Cannot open Japanese.xs:$!"; |
52 | print XS <<'END'; |
53 | #include <EXTERN.h> |
54 | #include <perl.h> |
55 | #include <XSUB.h> |
56 | #define U8 U8 |
57 | #include "../encode.h" |
58 | END |
59 | foreach my $table (keys %tables) { |
60 | print XS qq[#include "${table}.h"\n]; |
61 | } |
62 | print XS <<'END'; |
63 | |
64 | static void |
65 | Encode_XSEncoding(pTHX_ encode_t *enc) |
66 | { |
67 | dSP; |
68 | HV *stash = gv_stashpv("Encode::XS", TRUE); |
69 | SV *sv = sv_bless(newRV_noinc(newSViv(PTR2IV(enc))),stash); |
70 | int i = 0; |
71 | PUSHMARK(sp); |
72 | XPUSHs(sv); |
73 | while (enc->name[i]) |
74 | { |
75 | const char *name = enc->name[i++]; |
76 | XPUSHs(sv_2mortal(newSVpvn(name,strlen(name)))); |
77 | } |
78 | PUTBACK; |
79 | call_pv("Encode::define_encoding",G_DISCARD); |
80 | SvREFCNT_dec(sv); |
81 | } |
82 | |
83 | MODULE = Encode::Japanese PACKAGE = Encode::Japanese |
84 | BOOT: |
85 | { |
86 | END |
87 | foreach my $table (keys %tables) { |
88 | print XS qq[#include "${table}_def.h"\n]; |
89 | } |
90 | print XS "}\n"; |
91 | close(XS); |
d811239c |
92 | return ''; |
93 | } |
94 | |
95 | sub postamble |
96 | { |
97 | my $self = shift; |
98 | my $dir = $self->catdir($self->updir,'Encode'); |
b90c9a30 |
99 | my $str = "# Japanese\$(OBJ_EXT) depends on .h and _def.h files not .c files - but all written by compile\n"; |
100 | $str .= 'Japanese$(OBJ_EXT) :'; |
101 | $str .= ' Japanese.xs'; |
d811239c |
102 | foreach my $table (keys %tables) |
103 | { |
104 | $str .= " $table.c"; |
105 | } |
106 | $str .= "\n\n"; |
107 | my $compile = $self->catfile($self->updir,'compile'); |
108 | foreach my $table (keys %tables) |
109 | { |
110 | my $numlines = 1; |
111 | my $lengthsofar = length($str); |
112 | my $continuator = ''; |
b90c9a30 |
113 | $str .= "$table.c : $compile Makefile.PL"; |
d811239c |
114 | foreach my $file (@{$tables{$table}}) |
115 | { |
116 | $str .= $continuator.' '.$self->catfile($dir,$file); |
117 | if ( length($str)-$lengthsofar > 128*$numlines ) |
118 | { |
119 | $continuator .= " \\\n\t"; |
120 | $numlines++; |
121 | } else { |
122 | $continuator = ''; |
123 | } |
124 | } |
125 | $str .= "\n\t\$(PERL) $compile -o \$\@ -f $table.fnm\n\n"; |
126 | open (FILELIST, ">$table.fnm") |
127 | || die "Could not open $table.fnm: $!"; |
128 | foreach my $file (@{$tables{$table}}) |
129 | { |
130 | print FILELIST $self->catfile($dir,$file) . "\n"; |
131 | } |
132 | close(FILELIST); |
133 | } |
134 | return $str; |
135 | } |
136 | |