More Encode tweaks:
[p5sagit/p5-mst-13.2.git] / ext / Encode / Makefile.PL
1 use 5.7.2;
2 use strict;
3 use ExtUtils::MakeMaker;
4
5 my %tables = (8859 => ['ascii.ucm', 'cp1250.ucm', 'koi8-r.ucm', 'jis0201.ucm' ],
6               EBCDIC  => ['cp1047.ucm','cp37.ucm','posix-bc.ucm'],
7               Symbols => ['symbol.ucm','dingbats.ucm'],
8               );
9
10 opendir(ENC,'Encode');
11 while (defined(my $file = readdir(ENC)))
12 {
13     if ($file =~ /8859.*\.ucm/)
14     {
15         push(@{$tables{8859}},$file);
16     }
17 }
18 closedir(ENC);
19
20
21 WriteMakefile(
22               NAME              => "Encode",
23               VERSION_FROM      => 'Encode.pm',
24               OBJECT            => '$(O_FILES)',
25               'dist'            => {
26                   COMPRESS      => 'gzip -9f',
27                   SUFFIX        => 'gz',
28                   DIST_DEFAULT => 'all tardist',
29               },
30               MAN3PODS  => {},
31               );
32
33 package MY;
34
35
36 sub post_initialize
37 {
38     my ($self) = @_;
39     my %o;
40     # Find existing O_FILES
41     foreach my $f (@{$self->{'O_FILES'}})
42     {
43         $o{$f} = 1;
44     }
45     my $x = $self->{'OBJ_EXT'};
46     # Add the table O_FILES
47     foreach my $e (keys %tables)
48     {
49         $o{$e.$x} = 1;
50     }
51     # Trick case-blind filesystems.
52     delete $o{'encode'.$x};
53     $o{'Encode'.$x} = 1;
54     # Reset the variable
55     $self->{'O_FILES'} = [sort keys %o];
56     my @files;
57     foreach my $table (keys %tables)
58     {
59         foreach my $ext (qw($(OBJ_EXT) .c .h _def.h .fnm))
60     {
61         push (@files,$table.$ext);
62     }
63 }
64 $self->{'clean'}{'FILES'} .= join(' ',@files);
65 return '';
66 }
67
68 sub postamble
69 {
70     my $self = shift;
71     my $dir  = $self->catdir($self->curdir,'Encode');
72     my $str  = "# Encode\$(OBJ_EXT) depends on .h and _def.h files not .c files - but all written by compile\n";
73     $str  .= 'Encode$(OBJ_EXT) :';
74     foreach my $table (keys %tables)
75     {
76         $str .= " $table.c";
77     }
78     $str .= "\n\n";
79     foreach my $table (keys %tables)
80     {
81         my $numlines = 1;
82         my $lengthsofar = length($str);
83         my $continuator = '';
84         $str .= "$table.c : compile Makefile.PL";
85         foreach my $file (@{$tables{$table}})
86         {
87             $str .= $continuator.' '.$self->catfile($dir,$file);
88             if ( length($str)-$lengthsofar > 128*$numlines )
89             {
90                 $continuator .= " \\\n\t";
91                 $numlines++;
92             } else {
93                 $continuator = '';
94             }
95         }
96         $str .= "\n\t\$(PERL) compile -O -o \$\@ -f $table.fnm\n\n";
97         open (FILELIST, ">$table.fnm")
98             || die "Could not open $table.fnm: $!";
99         foreach my $file (@{$tables{$table}})
100         {
101             print FILELIST $self->catfile($dir,$file) . "\n";
102         }
103         close(FILELIST);
104     }
105     return $str;
106 }