Reputation: 21
On Debian stretch when trying to manually compile e.g. libpopt (I'm not intending to create debian packages), after I did
export DEB_BUILD_OPTIONS=hardening=+all
I've trouble passing dpkg-buildflags to ./configure
:
./configure $(dpkg-buildflags --export=cmdline) configure: error: unrecognized option: -O2 Try `./configure --help' for more information.
If I do:
dpkg-buildflags --export=cmdline
I get:
CFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" CPPFLAGS="-Wdate-time -D_FORTIFY_SOURCE=2" CXXFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" FCFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" FFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" GCJFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" LDFLAGS="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now" OBJCFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" OBJCXXFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security"
When I now pass this output manually (copy&paste) to ./configure
it works:
./configure CFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" CPPFLAGS="-Wdate-time -D_FORTIFY_SOURCE=2" CXXFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" FCFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" FFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" GCJFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong" LDFLAGS="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now" OBJCFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" OBJCXXFLAGS="-g -O2 -fdebug-prefix-map=/home/user/popt-1.16=. -fstack-protector-strong -Wformat -Werror=format-security" checking build system type... x86_64-unknown-linux-gnu [...]
How can I invoke dpkg-buildflags to automatically pass its flags to ./configure
?
Why does manual copy&paste work but not the other approach?
Upvotes: 2
Views: 193
Reputation: 126
Why does manual copy&paste work but not the other approach?
This is related to argument escaping. Consider the following function:
# This function simply prints its arguments, each on separate line
test () {
for arg in "$@"; do
echo "$arg"
done
}
This is what happens when you pass the output of dpkg-buildflags
manually:
$ test ROSES=red VIOLETS=blue CFLAGS="-O0 -ggdb"
ROSES=red
VIOLETS=blue
CFLAGS=-O0 -ggdb
Note that CFLAGS=-O0 -ggdb
is seen as a single argument, so escaping works.
Now let's try to evaluate an inline expression:
$ test $(echo ROSES=red VIOLETS=blue CFLAGS="-O0 -ggdb")
ROSES=red
VIOLETS=blue
CFLAGS=-O0
-ggdb
Boom! Somehow CFLAGS=-O0 -ggdb
got broken into CFLAGS=-O0
and -ggdb
. The same is happening in your case: the value of CFLAGS
gets split into multiple arguments, and indeed -O2
is not a valid option. This is why you're getting an error.
How can I invoke dpkg-buildflags to automatically pass its flags to
./configure
?
You can work this around using a pipe and xargs command:
dpkg-buildflags --export=cmdline | xargs ./configure
This solution works for me.
Upvotes: 1