[PATCH] encoding and open pragmas
[p5sagit/p5-mst-13.2.git] / ext / Encode / Makefile.PL
1 use 5.007003;
2 use ExtUtils::MakeMaker;
3
4 # Just for sure :)
5 my %ARGV = map { split /=/; defined $_[1] or $_[1]=1; @_ } @ARGV;
6 $ARGV{DEBUG} and warn "$_ => $ARGV{$_}\n" for keys  %ARGV;
7 $ENV{PERL_CORE} ||= $ARGV{PERL_CORE};
8
9 my %tables = 
10     (
11      def_t => ['ascii.ucm',
12                '8859-1.ucm',
13                'null.ucm',
14                'ctrl.ucm',
15                ]
16      );
17
18 my @exe_files = qw(bin/enc2xs
19                    bin/piconv
20                    );
21 my @more_exe_files = qw(
22                         unidump
23                         );
24 my @pmlibdirs = qw(lib Encode);
25
26 $ARGV{MORE_SCRIOPTS} and push @exe_files, @more_exe_files;
27 $ARGV{INSTALL_UCM}   and push @pmlibdirs, "ucm";
28
29 WriteMakefile(
30               NAME              => "Encode",
31               EXE_FILES         => \@exe_files,
32               VERSION_FROM      => 'Encode.pm',
33               OBJECT            => '$(O_FILES)',
34               'dist'            => {
35                   COMPRESS      => 'gzip -9f',
36                   SUFFIX        => 'gz',
37                   DIST_DEFAULT => 'all tardist',
38               },
39               MAN3PODS  => {},
40               INC       => "-I./Encode",
41               PMLIBDIRS => \@pmlibdirs,
42               INSTALLDIRS => 'perl',
43               );
44
45 package MY;
46
47
48 sub post_initialize
49 {
50     my ($self) = @_;
51     my %o;
52     # Find existing O_FILES
53     foreach my $f (@{$self->{'O_FILES'}})
54     {
55         $o{$f} = 1;
56     }
57     my $x = $self->{'OBJ_EXT'};
58     # Add the table O_FILES
59     foreach my $e (keys %tables)
60     {
61         $o{$e.$x} = 1;
62     }
63     # Trick case-blind filesystems.
64     delete $o{'encode'.$x};
65     $o{'Encode'.$x} = 1;
66     # Reset the variable
67     $self->{'O_FILES'} = [sort keys %o];
68     my @files;
69     foreach my $table (keys %tables)
70     {
71         foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm))
72     {
73         push (@files,$table.$ext);
74     }
75     $self->{SOURCE} .= " $table.c"
76         if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$table\.c\b/;
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,'ucm');
86     my $str  = "# Encode\$(OBJ_EXT) depends on .h and .exh files not .c files - but all written by enc2xs\n";
87     $str  .= $^O eq 'MacOS' ? 'Encode.c.{$(MACPERL_BUILD_EXT_STATIC)}.o :' : '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         my $enc2xs = $self->catfile('bin', 'enc2xs');
99         $str .= "$table.c : $enc2xs Makefile.PL";
100         foreach my $file (@{$tables{$table}})
101         {
102             $str .= $continuator.' '.$self->catfile($dir,$file);
103             if ( length($str)-$lengthsofar > 128*$numlines )
104             {
105                 $continuator .= " \\\n\t";
106                 $numlines++;
107             } else {
108                 $continuator = '';
109             }
110         }
111         my $plib   = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : '';
112         $plib .= " -MCross=$::Cross::platform" if defined $::Cross::platform;
113         my $ucopts = '-"Q" -"O"';
114         $str .=
115             qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n};
116         open (FILELIST, ">$table.fnm")
117             || die "Could not open $table.fnm: $!";
118         foreach my $file (@{$tables{$table}})
119         {
120             print FILELIST $self->catfile($dir,$file) . "\n";
121         }
122         close(FILELIST);
123     }
124     return $str;
125 }