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