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