3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 use Test
::More tests
=> 21;
22 use_ok
('Dpkg::BuildFlags');
27 my ($bf, $optflag) = @_;
29 foreach my $flag (qw(CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS GCJFLAGS
31 my $value = $bf->get($flag);
32 ok
($value =~ m/$optflag/, "$flag contains $optflag: $value");
40 # Test the LTO flags enabled by default on some arches.
41 ok
($bf->get('LDFLAGS') =~ m/-flto=auto -ffat-lto-objects/,
42 "LDFLAGS contains LTO flags on $ENV{DEB_HOST_ARCH}");
49 # Test the LTO flags not being enabled.
50 ok
($bf->get('LDFLAGS') !~ m/-flto=auto -ffat-lto-objects/,
51 "LDFLAGS does not contain LTO flags on $ENV{DEB_HOST_ARCH}");
56 # Force loading the Dpkg::Vendor::Ubuntu module.
57 $ENV{DEB_VENDOR
} = 'Ubuntu';
59 # Test the optimization flag inherited from the Dpkg::Vendor::Debian module.
60 $ENV{DEB_HOST_ARCH
} = 'amd64';
61 $bf = Dpkg
::BuildFlags
->new();
63 test_optflag
($bf, '-O2');
66 # Test the overlaid Ubuntu-specific linker flag.
67 ok
($bf->get('LDFLAGS') =~ m/-Wl,-Bsymbolic-functions/,
68 'LDFLAGS contains -Bsymbolic-functions');
70 # Test the optimization flag override only for ppc64el.
71 $ENV{DEB_HOST_ARCH
} = 'ppc64el';
72 $bf = Dpkg
::BuildFlags
->new();
74 test_optflag
($bf, '-O3');
77 # Test the optimization flag not enabled for riscv64.
78 $ENV{DEB_HOST_ARCH
} = 'riscv64';
79 $bf = Dpkg
::BuildFlags
->new();
83 # Test the optimization flag override by DEB_BUILD_MAINT_OPTIONS.
84 $ENV{DEB_BUILD_MAINT_OPTIONS
} = 'optimize=+lto';
85 $bf = Dpkg
::BuildFlags
->new();
89 $ENV{DEB_HOST_ARCH
} = 'amd64';
90 $ENV{DEB_BUILD_MAINT_OPTIONS
} = 'optimize=-lto';
91 $bf = Dpkg
::BuildFlags
->new();