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