summaryrefslogtreecommitdiffstats
path: root/RPM4/src/Makefile.PL
blob: 8aacf154657eeb9bbd87b58047e2f92326f05f32 (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
# $Id$

# use 5.008;
use ExtUtils::MakeMaker;
use ExtUtils::PkgConfig;
use Getopt::Long;
use version;

my $rpmv;
GetOptions(
    'rpmversion=s' => \$rpmv,
    'rebuildh' => \my $rebh,
);

my $rpmheaderlocation;

foreach (qw(
    /usr/include
    /usr/local/include
    )) {
    if (-d "$_/rpm") {
        $rpmheaderlocation = "$_/rpm";
        last;
    }
}

$rpmheaderlocation or die "Can't find rpmheader location";

# Just to get rpm version. Deps checking has been done by ../Makefile.PL:
my %cfg = ExtUtils::PkgConfig->find("rpm");
$rpmv ||= $cfg{modversion};

# Generate version-features flags depending on installed rpm version:
open(my $FH, "> rpmversion.h") or die "Can't open rpmversion.h";
print $FH "/* File generated by Makefile.PL\n";
print $FH ' * $Id$' . "\n";
print $FH " */\n\n";
print $FH "#ifndef RPMVERSION_H\n#define RPMVERSION_H\n\n";
foreach (qw(
    4.12.90
    4.15.0
    )) {
    my $v = $_;
    my $vobj = version->declare("v$_");
    $rpmv < $vobj and last;
    $v =~ s/\./_/g;
    print $FH "#define RPM$v\n";
    $rpmv =~ /^\Q$_/ and last;
}
# Special case for patched rpm-4.12 in Mageia 5 & Fedora, 4.11 & 4.12 in Debian:
sub cat_ { my @l = map { my $F; open($F, '<', $_) ? <$F> : () } @_; wantarray() ? @l : join '', @l }
if (grep { /int rpmPkgSign.*rpmSignArgs/ } cat_("$rpmheaderlocation/rpmsign.h")) {
    print $FH "#define PATCHED_rpmPkgSign\n";
}
print $FH "\n#endif\n";
close($FH);
exit 0 if $rebh;

my @rpmconstantfiles = qw(
    rpmconstant.c
    rpmconstant.h
    rpmconstant_internal.c
    rpmh2tbl
    );

my ($obj, $ldd, $fl) =
    -f '/usr/include/rpmconstant/rpmconstant.h' ?
    ('', '-lrpmconstant', '-DHAVE_RPMCONSTANT') :
    ('rpmconstant.o rpmconstant_internal.o rpmconstanttbl.o', '', '');

sub MY::postamble() {
        my $first = <<RPMCONSTTBL;
rpmversion.h:
	\$(PERL) Makefile.PL --rebuildh

rpmconstanttbl.c: Makefile rpmh2tbl
	perl rpmh2tbl $rpmheaderlocation/*.h > \$@

RPMCONSTTBL
	# This code is to reduce duplication of files
	# in fact it is only usefull for the maintainers of this module
	# if you get the module from CPAN, those files are already here
	# if you're building from svn, you need rpmconstant directory
	my $second = "copyrpmconstant: " . join(" ", @rpmconstantfiles) . "\n\n";
	if (-d '../../rpmconstant') {
            foreach (@rpmconstantfiles) {
                $second .= "$_: ../../rpmconstant/$_\n\tcp -a \$< \$@\n\n";
            }
	}

	$first . $second;
}

my $v = $rpmv;
$v =~ s/\./_/g;
WriteMakefile(
    NAME         => 'RPM4',
    VERSION_FROM => '../lib/RPM4.pm',
    OBJECT       => "RPM4.o $obj",
    INC	         => "-I$rpmheaderlocation",
    LIBS         => [ $cfg{libs} . " -lrpmsign -lrpmbuild $ldd" ],
    CCFLAGS      => "$cfg{cflags} -Wall $fl -DRPM$v",
    depend       => { "RPM4.xs" => join(" ", @rpmconstantfiles) },
);