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