13

I got a package with:

$ apt-get source <pkg-name>

and now I am trying to build it with:

$ dpkg-buildpackage -uc -us -j8

At the beginning of the output, there is stated:

dpkg-buildpackage: export CFLAGS from dpkg-buildflags (origin: vendor): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security
dpkg-buildpackage: export CPPFLAGS from dpkg-buildflags (origin: vendor): -D_FORTIFY_SOURCE=2
dpkg-buildpackage: export CXXFLAGS from dpkg-buildflags (origin: vendor): -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security
dpkg-buildpackage: export FFLAGS from dpkg-buildflags (origin: vendor): -g -O2
dpkg-buildpackage: export LDFLAGS from dpkg-buildflags (origin: vendor): -Wl,-Bsymbolic-functions -Wl,-z,relro

I would like to override these CFLAGS (also, the LDFLAGS). I have tried exporting the CFLAGS envvar, the same way we do with plain configure, at no avail. How can I override these values?

lvella
  • 11,572
  • 10
  • 49
  • 96

1 Answers1

28

the package you are trying to rebuild, sets (read: overrides) the *FLAGS with hardening-specifics flags retrieved from dpkg-buildflags.

if you need to override those flags for your own purposes, you should tell dpkg-buildflags to provide the flags you want, rather than the (hardening) defaults. looking at man dpkg-buildflags, you find the section about environment variables, esp. see DEB_flag_SET and DEB_flag_APPEND

so this should do the trick (fill in your own *FLAGS):

$ DEB_CPPFLAGS_SET="-I/foo/bar/baz" DEB_CFLAGS_SET="-g -O6" DEB_LDFLAGS_SET="-L/fruzzel/frazzel/" dpkg-buildpackage -uc -us -j8 -rfakeroot
umläute
  • 26,106
  • 8
  • 56
  • 114
  • 2
    What if it doesn't look like dpkg-buildflags is being run? How hard is it to add that to a package? Is there an alternative command? – Adam Baxter Aug 08 '15 at 14:07
  • This answer may no longer be current. (See http://manpages.ubuntu.com/manpages/xenial/man1/dpkg-buildpackage.1.html#Notes) A more recent recommendation is to edit the debian/rules script inside your the distribution you've downloaded with apt-get source and search for instances of CFLAGS/CXXFLAGS/LFLAGS. – Dave McMordie Jan 10 '19 at 21:39
  • @DaveMcMordie Recommendation by whom? But indeed some packages might ignore `DEB_CFLAGS_SET`. I'm looking at you, `exim4` on Debian 6. In which case you can do `dpkg-buildpackage -R'make -f debian/rules CFLAGS=-g3`. Or `dpkg-buildpackage -R'sh ./1.sh'`, where `1.sh`: `make -f debian/rules CFLAGS='-g3 -Og' "$@"` (if your command needs quotes). On a side note, if I were up to debugging a program, I'd go with `-g3 -Og` or just `-g3` (if `-Og` is not supported). `-g` might also suffice, but the resulting image doesn't include macro info (can't use macros in expressions). – x-yuri May 01 '19 at 12:57