-
Notifications
You must be signed in to change notification settings - Fork 5
/
dh_rtems
executable file
·123 lines (89 loc) · 3.35 KB
/
dh_rtems
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/perl
=head1 NAME
dh_rtems - Generate RTEMS dependency information
=cut
use strict;
use Debian::Debhelper::Dh_Lib;
use Parse::DebControl;
=head1 SYNOPSIS
B<dh_rtems> [S<I<debhelper options>>]
=head1 DESCRIPTION
This helper uses the 'X-Rtems-Build-Depends' tag in the source section of 'debian/control'
to create a list of binary package dependencies for RTEMS libraries using the
correct bsp name. This list is used to define the substvar '${rtems:Depends}'
for each package.
The list of names given in 'X-Rtems-Build-Depends' are of the form 'rtems-modulename'
or 'rtems' for RTEMS itself. These names are expanded to the full
'rtems-modulename-bspname'. This list will almost always include 'rtems'.
Since RTEMS does not use ELF shared libraries the usual methods for automatically
generating binary package dependencies will not work. Instead this program assumes
that the depended packages are compatible in the range VER-CUR through VER-9999.
If the current version of the package 'rtems-mvme3100' is 4.9.3-4, then this becomes:
4.9.3-4 through 4.9.3-9999.
This assumes that every upstream change is ABI incompatible. While not
always true, absent significant auditing, it is the only safe default.
Note: For compatibility 'Rtems-Depends' is also recognized.
=cut
init();
my $parser = new Parse::DebControl;
my $control = $parser->parse_file('./debian/control', { useTieIxHash => 'true' });
my @rdeps;
my %srcfields = %{$control->[0]};
while (my ($k,$v) = each(%srcfields)) {
next unless( $k =~ m/^(?:X[BCS]*-)?Rtems-(?:Build-)?Depends$/ );
@rdeps = split(",",$v);
foreach my $rdep (@rdeps) {
chomp($rdep);
}
last;
}
foreach my $pkg(getpackages()) {
verbose_print("Package: $pkg\n");
# Skip packages not named 'rtems-modulename-bspname'
if( $pkg !~ /^rtems-[^-]+-[^-]+$/) {
next;
}
my ($mod, $bsp) = ($pkg =~ /^rtems-(.+)-([^-]+)$/);
# for each listed dependency
foreach my $rdep (@rdeps) {
$rdep =~ s/^\s+//;
$rdep =~ s/\s+$//;
# Find version of <module>--<bspname> (eg. rtems-mvme3100 or rtems-cexp-mvme3100)
my $ver = `dpkg-query -W --showformat='\${Version}' $rdep-$bsp`;
# The following requires perl >= 5.10
if( ${^CHILD_ERROR_NATIVE} != 0 ) {
warning("Package name $rdep-$bsp not installed");
next;
}
# construct condition for direct dependency
if( $ver =~ m/^(.*)-[^-]*$/m ) {
# Non-native package
verbose_print("Dep: $rdep-$bsp (>= $ver), $rdep-$bsp (<= $1-9999)\n");
addsubstvar($pkg, "rtems:Depends", "$rdep-$bsp", ">= $ver");
addsubstvar($pkg, "rtems:Depends", "$rdep-$bsp", "<= $1-9999");
} else {
# Native Debian package
verbose_print("Dep: $rdep-$bsp\n");
addsubstvar($pkg, "rtems:Depends", "$rdep-$bsp", ">= $ver");
# this should cover any binary rebuilds...
addsubstvar($pkg, "rtems:Depends", "$rdep-$bsp", "<= ${ver}++");
}
my $depends = `dpkg-query -W --showformat='\${Depends}\n' $rdep-$bsp`;
# copy conditions for indirect dependencies
if(length $depends) {
my @deps = split(",", $depends);
my @res = ();
for my $dep (@deps) {
# only those involving bsp specific packages
unshift(@res,$dep) if( $dep =~ m/$bsp/);
}
addsubstvar($pkg, "rtems:Depends", join(", ", @res) );
}
}
}
=head1 SEE ALSO
L<debhelper(7)>, L<epics-debhelper(7)>
This program is a not part of the official debhelper package.
=head1 AUTHOR
Michael Davidsaver <mdavidsaver@gmail.com>
=cut