Package: dpkg-dev
Version: patch
Severity: minor
Tags: patch

I would like to have a simple way to query for a specific feature in
debian/rules.  E.g. an upstream package provides options to configure for lto or
pgo builds on it's own, like

  ifeq (yes,$(shell dpkg-buildflags --query-feature optimize lto))
    configure_args += --enable-lto
    # lto flags are set by the upstream build system
    export DEB_BUILD_MAINT_OPTIONS := $(DEB_BUILD_MAINT_OPTIONS) optimize=-lto
  endif

dpkg-buildflags already has a --query-features option, but that one would be
inconvenient to use in a Makefile.
--- scripts/dpkg-buildflags.pl~	2019-11-05 12:59:03.000000000 +0100
+++ scripts/dpkg-buildflags.pl	2021-03-27 12:32:39.965624383 +0100
@@ -52,6 +52,8 @@
   --query            like --status, but in deb822 format.
   --query-features <area>
                      output the status of features for the given area.
+  --query-feature <area> <feature>
+                     output the status of the feature for the given area.
   --list             output a list of the flags supported by the current vendor.
   --export=(sh|make|cmdline|configure)
                      output something convenient to import the compilation
@@ -62,7 +64,7 @@
 '), $Dpkg::PROGNAME;
 }
 
-my ($param, $action);
+my ($param, $param2, $action);
 my $load_config = 1;
 
 while (@ARGV) {
@@ -73,6 +75,13 @@
         $action = $1;
         $param = shift(@ARGV);
 	usageerr(g_('%s needs a parameter'), $_) unless defined $param;
+    } elsif (m/^--(query-feature)$/) {
+        usageerr(g_('two commands specified: --%s and --%s'), $1, $action)
+            if defined($action);
+        $action = $1;
+        $param = shift(@ARGV);
+        $param2 = shift(@ARGV);
+	usageerr(g_('%s needs two parameters'), $_) unless (defined $param && defined $param2);
     } elsif (m/^--export(?:=(sh|make|cmdline|configure))?$/) {
         usageerr(g_('two commands specified: --%s and --%s'), 'export', $action)
             if defined($action);
@@ -124,6 +133,12 @@
         printf "Feature: %s\n", $feature;
         printf "Enabled: %s\n", $features{$feature} ? 'yes' : 'no';
     }
+} elsif ($action eq 'query-feature') {
+    exit 1 unless $build_flags->has_features($param);
+
+    my %features = $build_flags->get_features($param);
+    exit 1 unless exists $features{$param2};
+    printf "%s\n", $features{$param2} ? 'yes' : 'no';
 } elsif ($action =~ m/^export-(.*)$/) {
     my $export_type = $1;
     foreach my $flag ($build_flags->list()) {

Reply via email to