Add Compress-Raw-Bzip2, by Paul Marquess
[p5sagit/p5-mst-13.2.git] / ext / Compress-Raw-Bzip2 / Makefile.PL
1 #! perl -w
2
3 use strict ;
4 require 5.004 ;
5
6 use private::MakeUtil;
7 use ExtUtils::MakeMaker 5.16 ;
8
9 my $WALL= '';
10 $WALL = ' -Wall -Wno-comment ' if $Config{'cc'} =~ /gcc/ ;
11 my $USE_PPPORT_H = ($ENV{PERL_CORE}) ? '' : '-DUSE_PPPORT_H';
12
13
14 my $BUILD_BZIP2 = defined($ENV{BUILD_BZIP2}) ? $ENV{BUILD_BZIP2} : 1;
15 my $BZIP2_LIB = defined($ENV{BZIP2_LIB}) ? $ENV{BZIP2_LIB} : 'bzip2-src';
16 my $BZIP2_INCLUDE = defined($ENV{BZIP2_INCLUDE}) ? $ENV{BZIP2_INCLUDE} : '.';
17
18 #ParseCONFIG() ;
19
20 UpDowngrade(getPerlFiles('MANIFEST')) 
21     unless $ENV{PERL_CORE};
22
23 WriteMakefile( 
24     NAME         => 'Compress::Raw::Bzip2',
25     VERSION_FROM => 'lib/Compress/Raw/Bzip2.pm',
26     INC          => "-I$BZIP2_INCLUDE" ,
27     DEFINE       => "$WALL -DBZ_NO_STDIO $USE_PPPORT_H" ,
28     XS           => { 'Bzip2.xs' => 'Bzip2.c'},
29     'clean'      => { FILES      => '*.c bzip2.h bzlib.h bzlib_private.h constants.h constants.xs' },
30    #'depend'     => { 'Makefile'   => 'config.in' },
31     'dist'       => { COMPRESS     => 'gzip', 
32                       TARFLAGS     => '-chvf',
33                       SUFFIX       => 'gz',
34                       DIST_DEFAULT => 'MyTrebleCheck tardist',
35                     },
36
37     (
38       $ENV{SKIP_FOR_CORE}
39         ? (MAN3PODS    => {})
40         : ()
41     ),
42        
43
44     (
45       $BUILD_BZIP2
46         ? bzip2_files($BZIP2_LIB)
47         : (LIBS => [ "-L$BZIP2_LIB -lbz2 " ])
48     ),
49       
50     (
51       $] >= 5.005
52         ? (ABSTRACT_FROM => 'lib/Compress/Raw/Bzip2.pm',
53             AUTHOR       => 'Paul Marquess <pmqs@cpan.org>')
54         : ()
55     ),
56
57     ((ExtUtils::MakeMaker->VERSION() gt '6.30') ?
58         ('LICENSE'  => 'perl')         : ()),    
59
60 ) ;
61
62 my @names = qw(
63                 BZ_RUN
64                 BZ_FLUSH
65                 BZ_FINISH
66
67                 BZ_OK
68                 BZ_RUN_OK
69                 BZ_FLUSH_OK
70                 BZ_FINISH_OK
71                 BZ_STREAM_END
72                 BZ_SEQUENCE_ERROR
73                 BZ_PARAM_ERROR
74                 BZ_MEM_ERROR
75                 BZ_DATA_ERROR
76                 BZ_DATA_ERROR_MAGIC
77                 BZ_IO_ERROR
78                 BZ_UNEXPECTED_EOF
79                 BZ_OUTBUFF_FULL
80                 BZ_CONFIG_ERROR
81         );
82
83 if (eval {require ExtUtils::Constant; 1}) {
84     # Check the constants above all appear in @EXPORT in Bzip2.pm
85     my %names = map { $_, 1} @names ; #, 'BZ_VERSION';
86     open F, "<lib/Compress/Raw/Bzip2.pm" or die "Cannot open Bzip2.pm: $!\n";
87     while (<F>)
88     {
89         last if /^\s*\@EXPORT\s+=\s+qw\(/ ;
90     }
91
92     while (<F>)
93     {
94         last if /^\s*\)/ ;
95         /(\S+)/ ;
96         delete $names{$1} if defined $1 ;
97     }
98     close F ;
99
100     if ( keys %names )
101     {
102         my $missing = join ("\n\t", sort keys %names) ;
103         die "The following names are missing from \@EXPORT in Bzip2.pm\n" .
104             "\t$missing\n" ;
105     }
106     
107     #push @names, {name => 'BZ_VERSION', type => 'PV' };
108
109     ExtUtils::Constant::WriteConstants(
110                                      NAME     => 'Bzip2',
111                                      NAMES    => \@names,
112                                      C_FILE   => 'constants.h',
113                                      XS_FILE  => 'constants.xs',
114                                                                        
115                                     );
116
117 else {
118     foreach my $name (qw( constants.h constants.xs ))
119     {
120         my $from = catfile('fallback', $name);
121         copy ($from, $name)
122           or die "Can't copy $from to $name: $!";
123     }
124 }
125
126
127 sub bzip2_files
128 {
129     my $dir = shift ;
130
131     my @c_files = qw(
132         blocksort.c
133         huffman.c
134         crctable.c
135         randtable.c
136         compress.c
137         decompress.c
138         bzlib.c
139     );
140
141     my @h_files = qw( bzlib.h  bzlib_private.h );
142
143     foreach my $file (@c_files, @h_files)
144       { copy(catfile($dir, $file), '.') }
145     
146     
147     @h_files = map { catfile($dir, $_)  } @h_files ;
148     my @o_files = map { "$_\$(OBJ_EXT)" } 'Bzip2', @c_files;
149     push @c_files, 'Bzip2.c' ;
150
151     return (
152         #'H'         =>  [ @h_files ],
153         'C'         =>  [ @c_files ] ,
154         #'OBJECT'    => qq[ @o_files ],
155         'OBJECT'    => q[ $(O_FILES) ],
156         
157
158            ) ;
159 }
160
161
162