ff8035264e28f48a82caee9415a567930a69fdb6
[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 = 
6     (
7      8859 => ['ascii.ucm',  'koi8-r.ucm', 'viscii.ucm',
8               'ibm-1250.ucm',  'ibm-1251.ucm',
9               'ibm-1253.ucm',  'ibm-1254.ucm',
10               'ibm-1255.ucm',  'ibm-1256.ucm',
11               'ibm-1257.ucm',   'ibm-1258.ucm',
12               'ibm-1252.ucm',
13               qw(macCentEuro.enc  macCroatian.enc 
14                  macCyrillic.enc  macDingbats.enc 
15                  macGreek.enc     macIceland.enc 
16                  macRoman.enc     macRumanian.enc 
17                  macSami.enc      macThai.enc 
18                  macTurkish.enc   macUkraine.enc),
19               ],
20      EBCDIC  => ['cp1047.ucm','cp37.ucm','posix-bc.ucm'],
21      Symbols => ['symbol.ucm','dingbats.ucm'],
22      );
23
24 opendir(ENC,'Encode');
25 while (defined(my $file = readdir(ENC)))
26 {
27     if ($file =~ /8859.*\.ucm/)
28     {
29         push(@{$tables{8859}},$file);
30     }
31 }
32 closedir(ENC);
33
34
35 WriteMakefile(
36               NAME              => "Encode",
37               VERSION_FROM      => 'Encode.pm',
38               OBJECT            => '$(O_FILES)',
39               'dist'            => {
40                   COMPRESS      => 'gzip -9f',
41                   SUFFIX        => 'gz',
42                   DIST_DEFAULT => 'all tardist',
43               },
44               MAN3PODS  => {},
45               );
46
47 package MY;
48
49
50 sub post_initialize
51 {
52     my ($self) = @_;
53     my %o;
54     # Find existing O_FILES
55     foreach my $f (@{$self->{'O_FILES'}})
56     {
57         $o{$f} = 1;
58     }
59     my $x = $self->{'OBJ_EXT'};
60     # Add the table O_FILES
61     foreach my $e (keys %tables)
62     {
63         $o{$e.$x} = 1;
64     }
65     # Trick case-blind filesystems.
66     delete $o{'encode'.$x};
67     $o{'Encode'.$x} = 1;
68     # Reset the variable
69     $self->{'O_FILES'} = [sort keys %o];
70     my @files;
71     foreach my $table (keys %tables)
72     {
73         foreach my $ext (qw($(OBJ_EXT) .c .h _def.h .fnm))
74     {
75         push (@files,$table.$ext);
76     }
77 }
78 $self->{'clean'}{'FILES'} .= join(' ',@files);
79 return '';
80 }
81
82 sub postamble
83 {
84     my $self = shift;
85     my $dir  = $self->catdir($self->curdir,'Encode');
86     my $str  = "# Encode\$(OBJ_EXT) depends on .h and _def.h files not .c files - but all written by compile\n";
87     $str  .= 'Encode$(OBJ_EXT) :';
88     foreach my $table (keys %tables)
89     {
90         $str .= " $table.c";
91     }
92     $str .= "\n\n";
93     foreach my $table (keys %tables)
94     {
95         my $numlines = 1;
96         my $lengthsofar = length($str);
97         my $continuator = '';
98         $str .= "$table.c : compile Makefile.PL";
99         foreach my $file (@{$tables{$table}})
100         {
101             $str .= $continuator.' '.$self->catfile($dir,$file);
102             if ( length($str)-$lengthsofar > 128*$numlines )
103             {
104                 $continuator .= " \\\n\t";
105                 $numlines++;
106             } else {
107                 $continuator = '';
108             }
109         }
110         $str .= $^O eq 'VMS' # In VMS quote to preserve case
111             ? qq{\n\t\$(PERL) compile -"Q" -"O" -o \$\@ -f $table.fnm\n\n}
112             : qq{\n\t\$(PERL) compile -Q -O -o \$\@ -f $table.fnm\n\n};
113         open (FILELIST, ">$table.fnm")
114             || die "Could not open $table.fnm: $!";
115         foreach my $file (@{$tables{$table}})
116         {
117             print FILELIST $self->catfile($dir,$file) . "\n";
118         }
119         close(FILELIST);
120     }
121     return $str;
122 }