Rename ext/Win32API/File to ext/Win32API-File
[p5sagit/p5-mst-13.2.git] / ext / Win32API-File / Makefile.PL
1 #!/usr/bin/perl -w
2 use 5.001; #not tested
3 use ExtUtils::MakeMaker;
4 use Config;
5 use strict;
6 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
7 # the contents of the Makefile that is written.
8 unless ($^O eq "MSWin32" || $^O eq "cygwin" || $^O eq "interix") { #not tested on Interix
9     die "OS unsupported\n";
10 }
11
12 WriteMakefile(
13     'NAME'      => 'Win32API::File',
14     'VERSION_FROM' => 'File.pm', # finds $VERSION
15     (  $Config{archname} =~ /-object\b/i  ?  ( 'CAPI' => 'TRUE' )  :  ()  ),
16     'AUTHOR'            => 'Tye McQueen <tye@metronet.com>',
17     'ABSTRACT_FROM'     => 'File.pm',
18     'postamble' => { IMPORT_LIST => [qw(/._/ !/[a-z]/ :MEDIA_TYPE)],
19                      IFDEF => "!/[a-z\\d]/",
20                      CPLUSPLUS => 1,
21                      WRITE_PERL => 1,
22                      # Comment out next line to rebuild constants defs:
23                      NO_REBUILD => 1,
24                    },
25     (  ! $Config{libperl}  ?  ()  :  ( LIBPERL_A => $Config{libperl} )  ),
26     'INSTALLDIRS'   => ($] >= 5.008009 ? 'perl' : 'site'),
27     ($ExtUtils::MakeMaker::VERSION ge '6.31'? 
28      ('LICENSE' => 'perl', ) : ()),
29     ($ExtUtils::MakeMaker::VERSION ge '6.48'? 
30      ('MIN_PERL_VERSION' => 5.001,) : ()),
31     'PREREQ_PM' => {
32         'IO::File' => 0, #build
33         'File::Spec' => 0, #build
34         'Math::BigInt' => 0,
35         'Win32' => 0,
36     }
37 );
38
39 # Replacement for MakeMaker's "const2perl section" for versions
40 # of MakeMaker prior to the addition of this functionality:
41 sub MY::postamble
42 {
43     my( $self, %attribs )= @_;
44
45     # Don't do anything if MakeMaker has const2perl
46     # that already took care of all of this:
47     return   unless  %attribs;
48
49     # Don't require these here if we just C<return> above:
50     eval "use ExtUtils::Myconst2perl qw(ParseAttribs); 1"   or  die "$@";
51     eval "use ExtUtils::MakeMaker qw(neatvalue); 1"   or  die "$@";
52
53     # If only one module, can skip one level of indirection:
54     my $hvAttr= \%attribs;
55     if(  $attribs{IMPORT_LIST}  ) {
56         $hvAttr= { $self->{NAME} => \%attribs };
57     }
58
59     my( $module, @m, $_final, @clean, @realclean );
60     foreach $module (  keys %$hvAttr  ) {
61         my( $outfile, @perlfiles, @cfiles, $bin, $obj, $final, $noreb );
62
63         # Translate user-friendly options into coder-friendly specifics:
64         ParseAttribs( $module, $hvAttr->{$module}, { OUTFILE => \$outfile,
65           C_FILE_LIST => \@perlfiles, PERL_FILE_LIST => \@cfiles,
66           OBJECT => \$obj, BINARY => \$bin, FINAL_PERL => \$final,
67           NO_REBUILD => \$noreb } );
68         die "IFDEF option in Makefile.PL must be string, not code ref.\n"
69           if  ref $hvAttr->{$module}->{IFDEF};
70         die qq{IFDEF option in Makefile.PL must not contain quotes (").\n}
71           if  ref $hvAttr->{$module}->{IFDEF};
72
73         # How to create F<$outfile> via ExtUtils::Myconst2perl::Myconst2perl:
74         push @m, "
75 $outfile:       @perlfiles  @cfiles  Makefile" . '
76         $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -MExtUtils::Myconst2perl \\
77           -e "my %attribs;" \\
78           ';
79         $m[-1] =~ s/^/##/gm   if  $noreb;
80         my( $key, $value );
81         while(  ( $key, $value )= each %{$hvAttr->{$module}}  ) {
82             push @m, '-e "$$attribs{' . $key . '}= '
83               . neatvalue($value) . qq[;" \\\n\t  ];
84             $m[-1] =~ s/^/##/gm   if  $noreb;
85         }
86         push @m, '-e "Myconst2perl(' . neatvalue($module) . ",%attribs)\"\n";
87
88         # If requested extra work to generate Perl instead of XS code:
89         if(  $bin  ) {
90             my @path= split /::/, $module;
91             my $_final= $final;
92             $_final =~ s/\W/_/g;
93
94             # How to compile F<$outfile> and then run it to produce F<$final>:
95             push @m, "
96 $bin:   $outfile" . '
97         $(CC) $(INC) $(CCFLAGS) $(OPTIMIZE) $(PERLTYPE) $(LARGE) \\
98           $(SPLIT) $(DEFINE_VERSION) $(XS_DEFINE_VERSION) -I$(PERL_INC) \\
99           $(DEFINE)' . $outfile . " "
100           .  $self->catfile(qw[ $(PERL_INC) $(LIBPERL_A) ]) . " -o $bin
101
102 $final: $bin
103         " .  $self->catfile(".",$bin) . " >$final\n";
104             $m[-1] =~ s/^/##/gm   if  $noreb;
105
106             # Make sure the rarely-used $(INST_ARCHLIB) directory exists:
107             push @m, $self->dir_target('$(INST_ARCHLIB)');
108
109             ##warn qq{$path[-1].pm should C<require "},
110             ##  join("/",@path,$final), qq{">.\n};
111             # Install F<$final> whenever regular pm_to_blib target is built:
112             push @m, "
113 pm_to_blib: ${_final}_to_blib
114
115 ${_final}_to_blib: $final
116         " . '@$(PERL) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" \\
117         "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -MExtUtils::Install \\
118         -e "pm_to_blib({ ',neatvalue($final),',',
119         neatvalue($self->catfile('$(INST_ARCHLIB)',@path,$final)), ' },',
120         neatvalue($self->catfile(qw[$(INST_LIB) auto])), ')"
121         @$(TOUCH) ', $_final, "_to_blib
122
123 realclean ::
124         $self->{RM_RF} ", $self->catfile('$(INST_ARCHLIB)', $path[0]), "\n";
125
126             push( @clean, $outfile, $bin, $obj, $_final . "_to_blib" );
127             push( @realclean, $final )   unless  $noreb;
128         } else {
129
130             ##my $name= ( split /::/, $module )[-1];
131             ##warn qq{$name.xs should C<#include "$final"> },
132             ##  qq{in the C<BOOT:> section\n};
133             push( @realclean, $outfile )   unless  $noreb;
134         }
135     }
136
137     push @m, "
138 clean ::
139         $self->{RM_F} @clean\n"   if  @clean;
140     push @m, "
141 realclean ::
142         $self->{RM_F} @realclean\n"   if  @realclean;
143     return join('',@m);
144 }