There are a few larger programs I am interested in compiling with -Os. The normal method I use to patch/recompile programs is apt-get source followed by dpkg-buildpackage.

I learned from the dpkg-buildflags man page that I can set global flags in a configuration file. This seems to work for only some packages if I append the flags I want. The problem is that most programs ignore the flags and build with -O2 (and in some cases -O3) anyway.

Is there a way I can force the compiler to use -Os?

  • 1
    Can you list some specific packages so other people can try to help/reproduce your problem?
    – Mikel
    Apr 20, 2011 at 12:05
  • Alright. Well, the handbrake-gtk package from Debian multimedia gets -O3 from a script, I think the only way to set it up to compile with -Os is to modify the scripts. I was hoping there was a global way to do so. When I tried to rebuild pulseaudio, it accepts my build options, but appends -O2 to the end making it impossible to build it as -Os. Apr 21, 2011 at 5:21
  • You can normally set the compile options in the rules file. Are you saying this doesn't work for you? Apr 21, 2011 at 14:58
  • I looked at handbrake. You could just change this line in debian/rules - ./configure --gcc=/usr/lib/ccache/gcc CXX="$(CXX)" CFLAGS="$(CFLAGS)" \ --build build --prefix=/usr Apr 21, 2011 at 15:02
  • Ok, I see. You want to change that everywhere. Apr 21, 2011 at 15:03

1 Answer 1


There is no way to set this absolutely globally, short of patching the compiler itself. There is no firm policy for configuring this thing. The dpkg-buildflags approach is an attempt to unify this to some degree, bit it is still young. It should work for most packages, but if it doesn't, you'll have to patch the source package (and perhaps inform the package maintainer to sort this out).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .