This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Merge branch 'blead' of ssh://perl5.git.perl.org/gitroot/perl into blead
[perl5.git] / cpan / Encode / Makefile.PL
1 #
2 # $Id: Makefile.PL,v 2.8 2009/07/08 13:34:15 dankogai Exp $
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
35 WriteMakefile(
36     NAME         => "Encode",
37     EXE_FILES    => \@exe_files,
38     VERSION_FROM => 'Encode.pm',
39     OBJECT       => '$(O_FILES)',
40     'dist'       => {
41         COMPRESS     => 'gzip -9f',
42         SUFFIX       => 'gz',
43         DIST_DEFAULT => 'all tardist',
44     },
45     INC         => '-I' . File::Spec->catfile( '.', 'Encode' ),
46     PMLIBDIRS   => \@pmlibdirs,
47     INSTALLDIRS => 'perl',
48 );
49
50 package MY;
51
52
53 sub post_initialize
54 {
55     my ($self) = @_;
56     my %o;
57     # Find existing O_FILES
58     foreach my $f (@{$self->{'O_FILES'}})
59     {
60     $o{$f} = 1;
61     }
62     my $x = $self->{'OBJ_EXT'};
63     # Add the table O_FILES
64     foreach my $e (keys %tables)
65     {
66     $o{$e.$x} = 1;
67     }
68     # Trick case-blind filesystems.
69     delete $o{'encode'.$x};
70     $o{'Encode'.$x} = 1;
71     # Reset the variable
72     $self->{'O_FILES'} = [sort keys %o];
73     my @files;
74     foreach my $table (keys %tables)
75     {
76     foreach my $ext (qw($(OBJ_EXT) .c .h .exh .fnm))
77     {
78     push (@files,$table.$ext);
79     }
80     $self->{SOURCE} .= " $table.c"
81     if $^O eq 'MacOS' && $self->{SOURCE} !~ /\b$table\.c\b/;
82 }
83 $self->{'clean'}{'FILES'} .= join(' ',@files);
84 return '';
85 }
86
87 sub postamble
88 {
89     my $self = shift;
90     my $dir  = $self->catdir($self->curdir,'ucm');
91     my $str  = "# Encode\$(OBJ_EXT) does not depend on .c files directly\n";
92     $str  .= "# (except Encode.c), but on .h and .exh files written by enc2xs\n";
93     $str  .= $^O eq 'MacOS' ? 'Encode.c.{$(MACPERL_BUILD_EXT_STATIC)}.o :' : 'Encode$(OBJ_EXT) :';
94     $str  .= ' Encode.c';
95     foreach my $table (keys %tables)
96     {
97     $str .= " $table.c";
98     }
99     $str .= "\n\n";
100     foreach my $table (keys %tables)
101     {
102     my $numlines = 1;
103     my $lengthsofar = length($str);
104     my $continuator = '';
105     my $enc2xs = $self->catfile('bin', 'enc2xs');
106     $str .= "$table.c : $enc2xs Makefile.PL";
107     foreach my $file (@{$tables{$table}})
108     {
109         $str .= $continuator.' '.$self->catfile($dir,$file);
110         if ( length($str)-$lengthsofar > 128*$numlines )
111         {
112         $continuator .= " \\\n\t";
113         $numlines++;
114         } else {
115         $continuator = '';
116         }
117     }
118     my $plib   = $self->{PERL_CORE} ? '"-I$(PERL_LIB)"' : '';
119     $plib .= " -MCross=$::Cross::platform" if defined $::Cross::platform;
120     my $ucopts = '-"Q" -"O"';
121     $str .=
122         qq{\n\t\$(PERL) $plib $enc2xs $ucopts -o \$\@ -f $table.fnm\n\n};
123     open (FILELIST, ">$table.fnm")
124         || die "Could not open $table.fnm: $!";
125     foreach my $file (@{$tables{$table}})
126     {
127         print FILELIST $self->catfile($dir,$file) . "\n";
128     }
129     close(FILELIST);
130     }
131     return $str;
132 }