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