aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile.PL
blob: 96f26301ab5714c16a6bdb36dd5d914d6e58e77f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use strict;
use ExtUtils::MakeMaker;
use ExtUtils::PkgConfig;

# minimum required version of dependencies we need to build
our %build_reqs = (
	'rpm' => '4.9.0',
);
our %CONFIGURE_REQUIRES = (
	'ExtUtils::Depends'   => '0.300',
	'ExtUtils::MakeMaker' => '6.64',
	'ExtUtils::PkgConfig' => '1.00', # for finding rpm-devel
);
my $is_debian = -f '/etc/debian_version';

# Writing a fake Makefile ensures that CPAN will pick up the correct
# dependencies and install them.
unless (eval "use ExtUtils::Depends '$CONFIGURE_REQUIRES{'ExtUtils::Depends'}';"
           . "use ExtUtils::PkgConfig '$CONFIGURE_REQUIRES{'ExtUtils::PkgConfig'}';"
           . "1") {
   warn "$@\n";
   WriteMakefile(
         NAME         => 'URPM',
         PREREQ_FATAL => 1,
         PREREQ_PM    => \%CONFIGURE_REQUIRES,
   );
   exit 1; # not reached
}

my %cfg;
unless (eval { %cfg = ExtUtils::PkgConfig->find("rpm >= $build_reqs{rpm}"); 1 })
{
	my $rpmdev_pkg   = $is_debian ? "librpm-dev" : "rpm-devel";
	warn "*** Ensure that $rpmdev_pkg is installed\n" . $@;
	exit 0;
}
my @rpm_version = split /\./, $cfg{modversion};
open(my $FH, "> rpmversion.h") or die "Can't open rpmversion.h";
print $FH "/* File generated by Makefile.PL\n";
print $FH " */\n\n";
print $FH "#ifndef RPMVERSION_H\n#define RPMVERSION_H\n\n";
foreach (qw(
    4.10.0
    4.11.0
    4.12.0
    4.13.0
    4.14.0
    4.14.2
    )) {
    my $v = $_;
    my $vobj = version->declare("v$_");
    $cfg{modversion} < $vobj and last;
    $v =~ s/\./_/g;
    print $FH "#define RPM$v\n";
}
print $FH "\n#endif\n";
close($FH);

my $workaround;
if (-e '/etc/mageia-release' && $cfg{modversion} =~ /4\.(11|9)\./) {
   $workaround = '-DPATCHED_MGA';
}
if (! -e '/etc/mageia-release' && -e '/etc/redhat-release' && $cfg{modversion} =~ /4.11/) {
   $workaround = '-DPATCHED_RH';
}
my $ccflags = join(' ', '-Wall -Wextra -fno-strict-aliasing', $cfg{cflags}, "-DRPM_VERSON=$cfg{modversion}", $workaround);

print "Found RPM version $cfg{modversion} (compiling with flags: $ccflags)\n";

WriteMakefile(
    NAME	=> 'URPM',
    ABSTRACT_FROM => 'URPM.pm',
    AUTHOR	=> 'Thierry Vignaud',
    LICENSE     => 'perl_5',
    CONFIGURE_REQUIRES => \%CONFIGURE_REQUIRES,
    PREREQ_PM	=> {
	'MDV::Packdrakeng' => '1.00', # for URPM::Build
    },
    'TEST_REQUIRES' => {
	'Test::Pod' => '1.14',
    },
    META_MERGE => {
	'meta-spec' => { version => 2 },
	# For proper CPAN indexation:
	provides => {
	    'URPM' => {
		file => 'URPM.pm',
		version => 'v5.24.1',
	    },
	    'URPM::Resolve' => {
		file => 'URPM/Resolve.pm',
	    },
	},
        resources => {
            repository  => {
		type => 'git',
		url => 'git://git.mageia.org/software/rpm/perl-URPM/',
		web =>  'http://gitweb.mageia.org/software/rpm/perl-URPM/',
	    },
        },
	release_status => 'stable'
    },
    MIN_PERL_VERSION => '5.008001',
    CCFLAGS	=> $ccflags,
    VERSION_FROM	=> 'URPM.pm',
    LIBS	=> [ $cfg{libs} . ' -lrpmbuild' ],
    dist	=> { COMPRESS => "xz -f", SUFFIX => ".xz" },
    realclean	=> { FILES => "t/RPMS/noarch/*" },
);