This provides some examples on using dpkg-buildflags and buildflags.mk
in debian/rules, notes that --export=make is not recommended and
explicitly mentions that the list of build flags is subject to change.

Closes: #657627

Signed-off-by: Matthijs Kooijman <[email protected]>
---
 man/dpkg-buildflags.1 | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/man/dpkg-buildflags.1 b/man/dpkg-buildflags.1
index ea61306..219dc78 100644
--- a/man/dpkg-buildflags.1
+++ b/man/dpkg-buildflags.1
@@ -91,6 +91,11 @@ command-line. If the \fIformat\fP value is not
 given, \fBsh\fP is assumed. Only compilation flags starting with an
 upper case character are included, others are assumed to not be suitable
 for the environment.
+
+Note that evaluating \fB--export=make\fP output from a Makefile does not
+always work as expected, so it is recommended to use
+\fBbuildflags.mk\fP instead (see the \fBDEBIAN/RULES\fP section
+below).
 .TP
 .BI \-\-get " flag"
 Print the value of the flag on standard output. Exits with 0
@@ -161,6 +166,50 @@ objects (if the linker is called directly, then
 and
 .B ,
 have to be stripped from these options). Default value: empty.
+.P
+New flags might be added in the future if the need arises (for example
+to support other languages).
+.
+.SH DEBIAN/RULES
+You should call \fBdpkg-buildflags\fP or include \fBbuildflags.mk\fP
+from the \fBdebian/rules\fP file to obtain the needed build flags to
+pass to the build system.
+.P
+Note that older versions of dpkg (before 1.16.1) exported these flags
+automatically. However, you should not rely on this, since this breaks
+manual invocation of \fBdebian/rules\fP.
+.P
+For autoconf based packages, you can pass the relevant options to
+configure directly:
+.P
+  ./configure $(shell dpkg-buildflags --export=configure)
+.P
+For other build systems, or when you need more fine-grained control
+about which flags are passed where, you can include \fBbuildflags.mk\fP
+instead, which takes care of calling \fBdpkg-buildflags\fP and storing
+the build flags in make variables.
+.P
+If you want to export all buildflags into the environment (where they
+can be picked up by your build system):
+.P
+  DPKG_EXPORT_BUILDFLAGS = 1
+  include /usr/share/dpkg/buildflags.mk
+.P
+For some extra control over what is exported, you can manually export
+the variables:
+.P
+  include /usr/share/dpkg/buildflags.mk
+  export CPPFLAGS CFLAGS LDFLAGS
+.P
+And you can of course pass the flags to commands manually:
+.P
+  include /usr/share/dpkg/buildflags.mk
+  binary:
+    cc -o hello hello.c $(CFLAGS) $(LDFLAGS)
+.P
+When using the \fBbuildflags.mk\fP file, the package should Build-Depend
+on dpkg-dev (>= 1.16.1). Alternatively, you can use \fB\-include\fP to
+not fail when the file is missing.
 .
 .SH FILES
 .TP
@@ -169,6 +218,10 @@ System wide configuration file.
 .TP
 .BR $XDG_CONFIG_HOME/dpkg/buildflags.conf " or " 
$HOME/.config/dpkg/buildflags.conf
 User configuration file.
+.TP
+.B /usr/share/dpkg/buildflags.mk
+Makefile snippet that will load (and optionally export) all flags
+supported by \fBdpkg-buildflags\fP into variables.
 .SH ENVIRONMENT
 There are 2 sets of environment variables doing the same operations, the
 first one (DEB_\fIflag\fP_\fIop\fP) should never be used within
-- 
1.8.0


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to