5 # Copyright © 2010-2011 Raphaël Hertzog <hertzog@debian.org>
6 # Copyright © 2012-2013 Guillem Jover <guillem@debian.org>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
26 use Dpkg::ErrorHandling qw(:DEFAULT report REPORT_STATUS);
29 use Dpkg::Vendor qw(get_current_vendor);
31 textdomain('dpkg-dev');
34 printf g_("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION;
37 This is free software; see the GNU General Public License version 2 or
38 later for copying conditions. There is NO warranty.
44 'Usage: %s [<command>]')
47 --get <flag> output the requested flag to stdout.
48 --origin <flag> output the origin of the flag to stdout:
49 value is one of vendor, system, user, env.
50 --query-features <area>
51 output the status of features for the given area.
52 --list output a list of the flags supported by the current vendor.
53 --export=(sh|make|cmdline|configure)
54 output something convenient to import the compilation
55 flags in a shell script, in make, or in a command line.
56 --dump output all compilation flags with their values
57 --status print a synopsis with all parameters affecting the
58 behaviour of dpkg-buildflags and the resulting flags
60 --help show this help message.
61 --version show the version.
70 if (m/^--(get|origin|query-features)$/) {
71 usageerr(g_('two commands specified: --%s and --%s'), $1, $action)
74 $param = shift(@ARGV);
75 usageerr(g_('%s needs a parameter'), $_) unless defined $param;
76 } elsif (m/^--export(?:=(sh|make|cmdline|configure))?$/) {
77 usageerr(g_('two commands specified: --%s and --%s'), 'export', $action)
79 my $type = $1 || 'sh';
81 $type = 'cmdline' if $type eq 'configure';
82 $action = "export-$type";
83 } elsif (m/^--(list|status|dump)$/) {
84 usageerr(g_('two commands specified: --%s and --%s'), $1, $action)
87 $load_config = 0 if $action eq 'list';
88 } elsif (m/^-(?:\?|-help)$/) {
91 } elsif (m/^--version$/) {
95 usageerr(g_("unknown option '%s'"), $_);
101 my $build_flags = Dpkg::BuildFlags->new();
103 $build_flags->load_config() if $load_config;
105 if ($action eq 'list') {
106 foreach my $flag ($build_flags->list()) {
109 } elsif ($action eq 'get') {
110 exit 1 unless $build_flags->has($param);
112 print $build_flags->get($param) . "\n";
113 } elsif ($action eq 'origin') {
114 exit 1 unless $build_flags->has($param);
116 print $build_flags->get_origin($param) . "\n";
117 } elsif ($action eq 'query-features') {
118 exit 1 unless $build_flags->has_features($param);
120 my %features = $build_flags->get_features($param);
122 foreach my $feature (sort keys %features) {
123 print $para_shown++ ? "\n" : '';
124 printf "Feature: %s\n", $feature;
125 printf "Enabled: %s\n", $features{$feature} ? 'yes' : 'no';
127 } elsif ($action =~ m/^export-(.*)$/) {
128 my $export_type = $1;
129 foreach my $flag ($build_flags->list()) {
130 next unless $flag =~ /^[A-Z]/; # Skip flags starting with lowercase
131 my $value = $build_flags->get($flag);
132 if ($export_type eq 'sh') {
134 print "export $flag=\"$value\"\n";
135 } elsif ($export_type eq 'make') {
136 $value =~ s/\$/\$\$/g;
137 print "export $flag := $value\n";
138 } elsif ($export_type eq 'cmdline') {
139 print "$flag=\"$value\" ";
142 } elsif ($action eq 'dump') {
143 foreach my $flag ($build_flags->list()) {
144 my $value = $build_flags->get($flag);
145 print "$flag=$value\n";
147 } elsif ($action eq 'status') {
148 # Prefix everything with "dpkg-buildflags: status: " to allow easy
149 # extraction from a build log. Thus we use report with a non-translated
152 # First print all environment variables that might have changed the
153 # results (only existing ones, might make sense to add an option to
154 # also show which ones could have set to modify it).
155 my @envvars = Dpkg::Build::Env::list_accessed();
156 for my $envvar (@envvars) {
157 if (exists $ENV{$envvar}) {
158 printf report(REPORT_STATUS, 'environment variable %s=%s',
159 $envvar, $ENV{$envvar});
162 my $vendor = Dpkg::Vendor::get_current_vendor() || 'undefined';
163 print report(REPORT_STATUS, "vendor is $vendor");
164 # Then the resulting features:
165 foreach my $area (sort $build_flags->get_feature_areas()) {
167 my %features = $build_flags->get_features($area);
168 foreach my $feature (sort keys %features) {
169 $fs .= sprintf(' %s=%s', $feature, $features{$feature} ? 'yes' : 'no');
171 print report(REPORT_STATUS, "$area features:$fs");
173 # Then the resulting values (with their origin):
174 foreach my $flag ($build_flags->list()) {
175 my $value = $build_flags->get($flag);
176 my $origin = $build_flags->get_origin($flag);
177 my $maintainer = $build_flags->is_maintainer_modified($flag) ? '+maintainer' : '';
178 print report(REPORT_STATUS, "$flag [$origin$maintainer]: $value");