#674912 debhelper: dh_auto_build should override CPPFLAGS and CFLAGS when building a Makefile project

#674912#5
Date:
2012-05-28 15:03:11 UTC
From:
To:
The attached test project demonstrates a lack in dh_auto_build for Makefile
projects: the Debian-specified build flags are not necessarily communicated to
the compiler.  Debhelper should override CPPFLAGS and CFLAGS on the make
command line.

It is, I think, quite common for Makefile projects to define defaults for
CFLAGS and sometimes even CPPFLAGS in their Makefiles.  However, this means
that the corresponding environment variables (which debhelper sets) are
ignored.  The correct way to override Makefile-specified defaults is to
pass the variables on the make command line.  Compare:

$ make CFLAGS="`dpkg-buildflags --get CFLAGS`"
gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security   -c -o testhello.o testhello.c
gcc   testhello.o   -o testhello

to

$ make
gcc -g   -c -o testhello.o testhello.c
gcc   testhello.o   -o testhello

(Both in the test project's toplevel directory.)

The current debhelper manner of passing CFLAGS is ignored by such projects:

$ DH_VERBOSE=1 debian/rules build
dh build
   dh_testdir
   dh_auto_configure
   dh_auto_build
	make -j1
make[1]: Siirrytään hakemistoon "/home/ajk/scratch/testhello-0.1"
gcc -g -D_FORTIFY_SOURCE=2  -c -o testhello.o testhello.c
gcc -Wl,-z,relro  testhello.o   -o testhello
make[1]: Poistutaan hakemistosta "/home/ajk/scratch/testhello-0.1"
   dh_auto_test

Notice how CPPFLAGS and LDFLAGS are honored but CFLAGS is ignored.

This currently affects dctrl-tools, but I'm going to work around the problem
in my next upload.

#674912#10
Date:
2012-05-28 17:33:32 UTC
From:
To:
Antti-Juhani Kaijanaho wrote:

It's far too late to change this in debhelper 9. I'm sure that many
Makefiles that set CFLAGS do it to pass their own options, which should
not be stomped on. It is, after all, quite easy to use CFLAGS ?= <default>
if it's only setting a default that should be overrideen by the
environment, or to use CFLAGS := $(CFLAGS) -foo if a certian option
should be present but also use the environment. These are also easy
changes for a debian maintainer to make to a Makefile if desired.

#674912#15
Date:
2012-05-28 17:54:24 UTC
From:
To:
True; which explains the wishlist severity.

But still, it would be nice to have it work out of the box.  (I hadn't noticed
the problem with dctrl-tools until lintian started nagging about hardening
recently:-)