1 # Copyright © 2008 Ian Jackson <ijackson@chiark.greenend.org.uk>
2 # Copyright © 2008 Canonical, Ltd.
3 # written by Colin Watson <cjwatson@ubuntu.com>
4 # Copyright © 2008 James Westby <jw+debian@jameswestby.net>
5 # Copyright © 2009 Raphaël Hertzog <hertzog@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 package Dpkg::Vendor::Ubuntu;
25 our $VERSION = '0.01';
27 use Dpkg::ErrorHandling;
29 use Dpkg::Path qw(find_command);
30 use Dpkg::Control::Types;
31 use Dpkg::BuildOptions;
32 use Dpkg::Arch qw(debarch_eq get_host_arch);
34 use parent qw(Dpkg::Vendor::Debian);
40 Dpkg::Vendor::Ubuntu - Ubuntu vendor object
44 This vendor object customizes the behaviour of dpkg scripts for Ubuntu
45 specific behavior and policies.
50 my ($self, $hook, @params) = @_;
52 if ($hook eq 'before-source-build') {
53 my $src = shift @params;
54 my $fields = $src->{fields};
56 # check that Maintainer/XSBC-Original-Maintainer comply to
57 # https://wiki.ubuntu.com/DebianMaintainerField
58 if (defined($fields->{'Version'}) and defined($fields->{'Maintainer'}) and
59 $fields->{'Version'} =~ /ubuntu/) {
60 if ($fields->{'Maintainer'} !~ /ubuntu/i) {
61 if (length $ENV{DEBEMAIL} and $ENV{DEBEMAIL} =~ /\@ubuntu\.com/) {
62 error(g_('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
64 warning(g_('Version number suggests Ubuntu changes, but Maintainer: does not have Ubuntu address'));
67 unless ($fields->{'Original-Maintainer'}) {
68 warning(g_('Version number suggests Ubuntu changes, but there is no XSBC-Original-Maintainer field'));
72 } elsif ($hook eq 'keyrings') {
73 return $self->run_hook('package-keyrings', @params);
74 } elsif ($hook eq 'package-keyrings') {
75 return ($self->SUPER::run_hook($hook),
76 '/usr/share/keyrings/ubuntu-archive-keyring.gpg');
77 } elsif ($hook eq 'archive-keyrings') {
78 return ($self->SUPER::run_hook($hook),
79 '/usr/share/keyrings/ubuntu-archive-keyring.gpg');
80 } elsif ($hook eq 'archive-keyrings-historic') {
81 return ($self->SUPER::run_hook($hook),
82 '/usr/share/keyrings/ubuntu-archive-removed-keys.gpg');
83 } elsif ($hook eq 'register-custom-fields') {
84 my @field_ops = $self->SUPER::run_hook($hook);
86 [ 'register', 'Launchpad-Bugs-Fixed',
87 CTRL_FILE_CHANGES | CTRL_CHANGELOG ],
88 [ 'insert_after', CTRL_FILE_CHANGES, 'Closes', 'Launchpad-Bugs-Fixed' ],
89 [ 'insert_after', CTRL_CHANGELOG, 'Closes', 'Launchpad-Bugs-Fixed' ];
92 } elsif ($hook eq 'post-process-changelog-entry') {
93 my $fields = shift @params;
95 # Add Launchpad-Bugs-Fixed field
96 my $bugs = find_launchpad_closes($fields->{'Changes'} // '');
98 $fields->{'Launchpad-Bugs-Fixed'} = join(' ', @$bugs);
101 } elsif ($hook eq 'update-buildflags') {
102 my $flags = shift @params;
103 my $build_opts = Dpkg::BuildOptions->new();
105 if (!$build_opts->has('noopt')) {
106 if (debarch_eq(get_host_arch(), 'ppc64el')) {
107 for my $flag (qw(CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS GCJFLAGS
109 $flags->set($flag, '-g -O3', 'vendor');
113 # Per https://wiki.ubuntu.com/DistCompilerFlags
114 $flags->set('LDFLAGS', '-Wl,-Bsymbolic-functions', 'vendor');
116 # Run the Debian hook to add hardening flags
117 $self->SUPER::run_hook($hook, $flags);
119 return $self->SUPER::run_hook($hook, @params);
124 =head1 PUBLIC FUNCTIONS
128 =item $bugs = Dpkg::Vendor::Ubuntu::find_launchpad_closes($changes)
130 Takes one string as argument and finds "LP: #123456, #654321" statements,
131 which are references to bugs on Launchpad. Returns all closed bug
132 numbers in an array reference.
136 sub find_launchpad_closes {
141 ($changes =~ /lp:\s+\#\d+(?:,\s*\#\d+)*/pig)) {
142 $closes{$_} = 1 foreach (${^MATCH} =~ /\#?\s?(\d+)/g);
145 my @closes = sort { $a <=> $b } keys %closes;
156 This is a semi-private module. Only documented functions are public.