Commit | Line | Data |
5129552c |
1 | use 5.7.2; |
2 | use strict; |
3 | use ExtUtils::MakeMaker; |
4 | |
5 | my $name = 'Byte'; |
6 | my %tables = ( |
071db25d |
7 | byte_t => |
5129552c |
8 | [ |
071db25d |
9 | # 'ascii.ucm', |
5129552c |
10 | 'koi8-r.ucm', |
11 | 'viscii.ucm', |
12 | ], |
071db25d |
13 | mac_t => |
5129552c |
14 | [ |
15 | qw(macCentEuro.enc macCroatian.enc |
16 | macCyrillic.enc macDingbats.enc |
17 | macGreek.enc macIceland.enc |
18 | macRoman.enc macRumanian.enc |
19 | macSami.enc macThai.enc |
20 | macTurkish.enc macUkraine.enc), |
21 | ], |
5129552c |
22 | ); |
23 | |
24 | opendir(ENC,'../Encode'); |
25 | while (defined(my $file = readdir(ENC))) |
26 | { |
27 | if ($file =~ /(8859|ibm).*\.ucm/io) |
28 | { |
071db25d |
29 | push(@{$tables{$1."_t"}},$file) unless $file eq '8859-1.ucm'; |
5129552c |
30 | } |
31 | } |
32 | closedir(ENC); |
33 | |
34 | WriteMakefile( |
35 | INC => "-I..", |
36 | NAME => 'Encode::'.$name, |
37 | VERSION_FROM => "$name.pm", |
38 | OBJECT => '$(O_FILES)', |
39 | 'dist' => { |
40 | COMPRESS => 'gzip -9f', |
41 | SUFFIX => 'gz', |
42 | DIST_DEFAULT => 'all tardist', |
43 | }, |
44 | MAN3PODS => {}, |
45 | # OS 390 winges about line numbers > 64K ??? |
46 | XSOPT => '-nolinenumbers', |
47 | ); |
48 | |
49 | package MY; |
50 | |
51 | sub post_initialize |
52 | { |
53 | my ($self) = @_; |
54 | my %o; |
55 | my $x = $self->{'OBJ_EXT'}; |
56 | # Add the table O_FILES |
57 | foreach my $e (keys %tables) |
58 | { |
59 | $o{$e.$x} = 1; |
60 | } |
61 | $o{"$name$x"} = 1; |
62 | $self->{'O_FILES'} = [sort keys %o]; |
63 | my @files = ("$name.xs"); |
64 | $self->{'C'} = ["$name.c"]; |
65 | $self->{'H'} = [$self->catfile($self->updir,'encode.h')]; |
66 | my %xs; |
67 | foreach my $table (keys %tables) { |
68 | push (@{$self->{'C'}},"$table.c"); |
69 | # Do NOT add $table.h etc. to H_FILES unless we own up as to how they |
70 | # get built. |
71 | foreach my $ext (qw($(OBJ_EXT) .c .h _def.h .fnm)) { |
72 | push (@files,$table.$ext); |
73 | } |
74 | } |
75 | $self->{'XS'} = { "$name.xs" => "$name.c" }; |
76 | $self->{'clean'}{'FILES'} .= join(' ',@files); |
77 | open(XS,">$name.xs") || die "Cannot open $name.xs:$!"; |
78 | print XS <<'END'; |
79 | #include <EXTERN.h> |
80 | #include <perl.h> |
81 | #include <XSUB.h> |
82 | #define U8 U8 |
83 | #include "../encode.h" |
84 | END |
85 | foreach my $table (keys %tables) { |
86 | print XS qq[#include "${table}.h"\n]; |
87 | } |
88 | print XS <<"END"; |
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 | |
109 | MODULE = Encode::$name PACKAGE = Encode::$name |
110 | PROTOTYPES: DISABLE |
111 | BOOT: |
112 | { |
113 | END |
114 | foreach my $table (keys %tables) { |
115 | print XS qq[#include "${table}_def.h"\n]; |
116 | } |
117 | print XS "}\n"; |
118 | close(XS); |
119 | return "# Built $name.xs\n\n"; |
120 | } |
121 | |
122 | sub postamble |
123 | { |
124 | my $self = shift; |
125 | my $dir = $self->catdir($self->updir,'Encode'); |
126 | my $str = "# $name\$(OBJ_EXT) depends on .h and _def.h files not .c files - but all written by compile\n"; |
127 | $str .= "$name.c : $name.xs "; |
128 | foreach my $table (keys %tables) |
129 | { |
130 | $str .= " $table.c"; |
131 | } |
132 | $str .= "\n\n"; |
133 | $str .= "$name\$(OBJ_EXT) : $name.c\n\n"; |
134 | |
135 | my $compile = $self->catfile($self->updir,'compile'); |
136 | foreach my $table (keys %tables) |
137 | { |
138 | my $numlines = 1; |
139 | my $lengthsofar = length($str); |
140 | my $continuator = ''; |
141 | $str .= "$table.c : $compile 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 | $str .= $^O eq 'VMS' # In VMS quote to preserve case |
154 | ? qq{\n\t\$(PERL) $compile -"Q" -o \$\@ -f $table.fnm\n\n} |
155 | : qq{\n\t\$(PERL) $compile -Q -o \$\@ -f $table.fnm\n\n}; |
156 | open (FILELIST, ">$table.fnm") |
157 | || die "Could not open $table.fnm: $!"; |
158 | foreach my $file (@{$tables{$table}}) |
159 | { |
160 | print FILELIST $self->catfile($dir,$file) . "\n"; |
161 | } |
162 | close(FILELIST); |
163 | } |
164 | return $str; |
165 | } |
166 | |