Commit | Line | Data |
5129552c |
1 | use 5.7.2; |
2 | use strict; |
3 | use ExtUtils::MakeMaker; |
f0a41339 |
4 | use File::Spec::Functions; |
5129552c |
5 | |
6 | my $name = 'Byte'; |
7 | my %tables = ( |
a999c27c |
8 | byte_t => |
5129552c |
9 | [ |
a999c27c |
10 | # misc. vendors |
64ffdd5e |
11 | 'gsm0338.ucm', |
12 | 'nextstep.ucm', |
67d7b5ef |
13 | 'hp-roman8.ucm', |
5129552c |
14 | 'viscii.ucm', |
a999c27c |
15 | 'adobeStdenc.ucm', |
16 | # koi8 |
17 | 'koi8-f.ucm', 'koi8-r.ucm', 'koi8-u.ucm', |
18 | # Mac |
64ffdd5e |
19 | qw( |
a999c27c |
20 | macArabic.ucm |
21 | macCentEuro.ucm |
64ffdd5e |
22 | macCroatian.ucm |
a999c27c |
23 | macCyrillic.ucm |
24 | macFarsi.ucm |
64ffdd5e |
25 | macGreek.ucm |
a999c27c |
26 | macHebrew.ucm |
27 | macIceland.ucm |
64ffdd5e |
28 | macRoman.ucm |
a999c27c |
29 | macROMnn.ucm |
30 | macRUMnn.ucm |
31 | macSami.ucm |
64ffdd5e |
32 | macThai.ucm |
64ffdd5e |
33 | macTurkish.ucm |
a999c27c |
34 | macUkraine.ucm |
64ffdd5e |
35 | ), |
5129552c |
36 | ], |
5129552c |
37 | ); |
38 | |
a999c27c |
39 | my %not_here = |
40 | map {$_ => 1} |
41 | ( |
42 | '8859-1.ucm', # default |
43 | qw(cp037.ucm cp1026.ucm cp1047.ucm cp500.ucm cp875.ucm), # EBCDIC |
44 | qw(cp932.ucm cp936.ucm cp949.ucm cp950.ucm), # CJK |
45 | ); |
46 | |
f0a41339 |
47 | opendir(ENC,catdir(updir(),'ucm')) or die $!; |
5129552c |
48 | while (defined(my $file = readdir(ENC))) |
49 | { |
a999c27c |
50 | $file =~ /^(8859|cp).*\.ucm$/io or next; |
51 | $not_here{$file} and next; |
52 | push(@{$tables{byte_t}},$file); |
5129552c |
53 | } |
54 | closedir(ENC); |
55 | |
56 | WriteMakefile( |
67d7b5ef |
57 | INC => "-I../Encode", |
5129552c |
58 | NAME => 'Encode::'.$name, |
59 | VERSION_FROM => "$name.pm", |
60 | OBJECT => '$(O_FILES)', |
61 | 'dist' => { |
62 | COMPRESS => 'gzip -9f', |
63 | SUFFIX => 'gz', |
64 | DIST_DEFAULT => 'all tardist', |
65 | }, |
66 | MAN3PODS => {}, |
67 | # OS 390 winges about line numbers > 64K ??? |
68 | XSOPT => '-nolinenumbers', |
69 | ); |
70 | |
71 | package MY; |
72 | |
73 | sub post_initialize |
74 | { |
75 | my ($self) = @_; |
76 | my %o; |
77 | my $x = $self->{'OBJ_EXT'}; |
78 | # Add the table O_FILES |
79 | foreach my $e (keys %tables) |
80 | { |
81 | $o{$e.$x} = 1; |
82 | } |
83 | $o{"$name$x"} = 1; |
84 | $self->{'O_FILES'} = [sort keys %o]; |
85 | my @files = ("$name.xs"); |
86 | $self->{'C'} = ["$name.c"]; |
f0a41339 |
87 | $self->{SOURCE} .= " $name.c" |
88 | if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$name\.c\b/; |
67d7b5ef |
89 | $self->{'H'} = [$self->catfile($self->updir,'Encode', 'encode.h')]; |
5129552c |
90 | my %xs; |
91 | foreach my $table (keys %tables) { |
92 | push (@{$self->{'C'}},"$table.c"); |
93 | # Do NOT add $table.h etc. to H_FILES unless we own up as to how they |
94 | # get built. |
e7cbefb8 |
95 | foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm)) { |
5129552c |
96 | push (@files,$table.$ext); |
97 | } |
f0a41339 |
98 | $self->{SOURCE} .= " $table.c" |
99 | if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$table\.c\b/; |
5129552c |
100 | } |
101 | $self->{'XS'} = { "$name.xs" => "$name.c" }; |
102 | $self->{'clean'}{'FILES'} .= join(' ',@files); |
103 | open(XS,">$name.xs") || die "Cannot open $name.xs:$!"; |
104 | print XS <<'END'; |
105 | #include <EXTERN.h> |
106 | #include <perl.h> |
107 | #include <XSUB.h> |
108 | #define U8 U8 |
67d7b5ef |
109 | #include "encode.h" |
5129552c |
110 | END |
111 | foreach my $table (keys %tables) { |
112 | print XS qq[#include "${table}.h"\n]; |
113 | } |
114 | print XS <<"END"; |
115 | |
116 | static void |
117 | Encode_XSEncoding(pTHX_ encode_t *enc) |
118 | { |
119 | dSP; |
120 | HV *stash = gv_stashpv("Encode::XS", TRUE); |
121 | SV *sv = sv_bless(newRV_noinc(newSViv(PTR2IV(enc))),stash); |
122 | int i = 0; |
123 | PUSHMARK(sp); |
124 | XPUSHs(sv); |
125 | while (enc->name[i]) |
126 | { |
127 | const char *name = enc->name[i++]; |
128 | XPUSHs(sv_2mortal(newSVpvn(name,strlen(name)))); |
129 | } |
130 | PUTBACK; |
131 | call_pv("Encode::define_encoding",G_DISCARD); |
132 | SvREFCNT_dec(sv); |
133 | } |
134 | |
135 | MODULE = Encode::$name PACKAGE = Encode::$name |
136 | PROTOTYPES: DISABLE |
137 | BOOT: |
138 | { |
139 | END |
140 | foreach my $table (keys %tables) { |
e7cbefb8 |
141 | print XS qq[#include "${table}.exh"\n]; |
5129552c |
142 | } |
143 | print XS "}\n"; |
144 | close(XS); |
145 | return "# Built $name.xs\n\n"; |
146 | } |
147 | |
148 | sub postamble |
149 | { |
150 | my $self = shift; |
3ef515df |
151 | my $dir = $self->catdir($self->updir,'ucm'); |
e7cbefb8 |
152 | my $str = "# $name\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n"; |
5129552c |
153 | $str .= "$name.c : $name.xs "; |
154 | foreach my $table (keys %tables) |
155 | { |
156 | $str .= " $table.c"; |
157 | } |
158 | $str .= "\n\n"; |
159 | $str .= "$name\$(OBJ_EXT) : $name.c\n\n"; |
160 | |
67d7b5ef |
161 | my $enc2xs = $self->catfile($self->updir,'bin', 'enc2xs'); |
5129552c |
162 | foreach my $table (keys %tables) |
163 | { |
164 | my $numlines = 1; |
165 | my $lengthsofar = length($str); |
166 | my $continuator = ''; |
67d7b5ef |
167 | $str .= "$table.c : $enc2xs Makefile.PL"; |
5129552c |
168 | foreach my $file (@{$tables{$table}}) |
169 | { |
170 | $str .= $continuator.' '.$self->catfile($dir,$file); |
171 | if ( length($str)-$lengthsofar > 128*$numlines ) |
172 | { |
173 | $continuator .= " \\\n\t"; |
174 | $numlines++; |
175 | } else { |
176 | $continuator = ''; |
177 | } |
178 | } |
46fc212f |
179 | my $plib = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : ''; |
fefd7080 |
180 | $plib .= " -MCross=$::Cross::platform" if defined $::Cross::platform; |
46fc212f |
181 | my $ucopts = '-"Q" -"O"'; |
a999c27c |
182 | $str .= |
183 | qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n}; |
5129552c |
184 | open (FILELIST, ">$table.fnm") |
185 | || die "Could not open $table.fnm: $!"; |
186 | foreach my $file (@{$tables{$table}}) |
187 | { |
188 | print FILELIST $self->catfile($dir,$file) . "\n"; |
189 | } |
190 | close(FILELIST); |
191 | } |
192 | return $str; |
193 | } |
194 | |