To pass build flags to a build command in a makefile:
$(MAKE) $(shell dpkg-buildflags --export=cmdline)
./configure $(shell dpkg-buildflags --export=cmdline)
To set build flags in a shell script or shell fragment, eval
can
be used to interpret the output and to export the flags in the
environment:
eval "$(dpkg-buildflags --export=sh)" && make
or to set the positional parameters to pass to a command:
eval "set -- $(dpkg-buildflags --export=cmdline)"
for dir in a b c; do (cd $dir && ./configure "$@" && make); done
Usage in debian/rules
You should call dpkg-buildflags
or include buildflags.mk
from the
debian/rules
file to obtain the needed build flags to pass to the
build system. Note that older versions of dpkg-buildpackage
(before dpkg 1.16.1) exported these flags automatically. However,
you should not rely on this, since this breaks manual invocation
of debian/rules
.
For packages with autoconf-like build systems, you can pass the
relevant options to configure or make(1) directly, as shown
above.
For other build systems, or when you need more fine-grained
control about which flags are passed where, you can use --get
. Or
you can include buildflags.mk
instead, which takes care of
calling dpkg-buildflags
and storing the build flags in make
variables.
If you want to export all buildflags into the environment (where
they can be picked up by your build system):
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/local/share/dpkg/buildflags.mk
For some extra control over what is exported, you can manually
export the variables (as none are exported by default):
include /usr/local/share/dpkg/buildflags.mk
export CPPFLAGS CFLAGS LDFLAGS
And you can of course pass the flags to commands manually:
include /usr/local/share/dpkg/buildflags.mk
build-arch:
$(CC) -o hello hello.c $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)