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