scripts/mk: fix buildflags.mk to make use of the DEB_*_MAINT_* variables
authorRaphaël Hertzog <hertzog@debian.org>
Mon, 10 Oct 2011 08:50:02 +0000 (10:50 +0200)
committerRaphaël Hertzog <hertzog@debian.org>
Mon, 10 Oct 2011 08:50:02 +0000 (10:50 +0200)
Make does not export its own variables (even those which have been
exported explicitly) to sub-shells executed with $(shell …). Since
dpkg-buildflags is called that way, we have to modify the command
line to embed variable initializations to ensure that we forward the
variables that have been set by the maintainer in debian/rules.

Since this code required to loop over all possible flags, I took
the opportunity to also set the output variables within a loop construct
using a single template (avoids copy&paste mistakes).

Reported-by: Pierre Chifflier <pollux@debian.org>

debian/changelog
scripts/mk/buildflags.mk

index cb6e194..3376439 100644 (file)
@@ -16,6 +16,8 @@ dpkg (1.16.1.1) UNRELEASED; urgency=low
     triggers-pending or installed. Closes: #644492
   * Fix dpkg-source to ignore changes on debian/patches/.dpkg-source-applied
     when building a "2.0" source package. Closes: #642656
+  * Fix buildflags.mk to re-export the environment variables that
+    the maintainer can use to change the build flags. Closes: #644412
 
   [ Guillem Jover ]
   * Change dpkg-buildflags to set preprocessor option -D_FORTIFY_SOURCE=2
index 1b4a22c..8f0f215 100644 (file)
 
 dpkg_late_eval ?= $(or $(value DPKG_CACHE_$(1)),$(eval DPKG_CACHE_$(1) := $(shell $(2)))$(value DPKG_CACHE_$(1)))
 
-CFLAGS = $(call dpkg_late_eval,CFLAGS,dpkg-buildflags --get CFLAGS)
-CPPFLAGS = $(call dpkg_late_eval,CPPFLAGS,dpkg-buildflags --get CPPFLAGS)
-CXXFLAGS = $(call dpkg_late_eval,CXXFLAGS,dpkg-buildflags --get CXXFLAGS)
-FFLAGS = $(call dpkg_late_eval,FFLAGS,dpkg-buildflags --get FFLAGS)
-LDFLAGS = $(call dpkg_late_eval,LDFLAGS,dpkg-buildflags --get LDFLAGS)
+DPKG_BUILDFLAGS_LIST = CFLAGS CPPFLAGS CXXFLAGS FFLAGS LDFLAGS
+
+define dpkg_buildflags_export_envvar
+ifdef $(1)
+DPKG_BUILDFLAGS_EXPORT_ENVVAR += $(1)="$(value $(1))"
+endif
+endef
+
+$(eval $(call dpkg_buildflags_export_envvar,DEB_BUILD_MAINT_OPTIONS))
+$(foreach flag,$(DPKG_BUILDFLAGS_LIST),\
+  $(foreach operation,SET STRIP APPEND PREPEND,\
+    $(eval $(call dpkg_buildflags_export_envvar,DEB_$(flag)_MAINT_$(operation)))))
+
+dpkg_buildflags_setvar = $(1) = $(call dpkg_late_eval,$(1),$(DPKG_BUILDFLAGS_EXPORT_ENVVAR) dpkg-buildflags --get $(1))
+
+$(foreach flag,$(DPKG_BUILDFLAGS_LIST),\
+  $(eval $(call dpkg_buildflags_setvar,$(flag))))
 
 ifdef DPKG_EXPORT_BUILDFLAGS
-  export CFLAGS CPPFLAGS CXXFLAGS FFLAGS LDFLAGS
+  export $(DPKG_BUILDFLAGS_LIST)
 endif