I am running on a CentOS 5.7 system.
I downloaded a source package and a .spec file from someone else. I am trying to build a RPM from the source using a vanilla command like:
% rpmbuild -ba ~/rpmbuild/SPECS/foo.spec
...
Configuration summary:
======================
Host type................: x86_64-redhat-linux-gnu
CC.......................: gcc
CFLAGS...................: -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Werror
Package..................: sudosh2
Version..................: 1.0.4
Installation prefix......: /usr
Man directory............: /usr/share/man
sysconfdir...............: /etc
recording input..........: no
However, this build is failing. The code is a little sloppy and is generating some warnings. Some part of this toolchain is enabling -Werror
flag, which makes "all warnings into errors." Thus, the build fails with an error:
gcc -DHAVE_CONFIG_H -I. -I.. -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Werror -MT parse.o -MD -MP -MF .deps/parse.Tpo -c -o parse.o parse.c
cc1: warnings being treated as errors
sudosh.c: In function 'main':
sudosh.c:486: warning: unused variable 'written'
sudosh.c:112: warning: unused variable 'found'
cc1: warnings being treated as errors
parse.c: In function 'parse':
parse.c:20: warning: unused variable 'y'
parse.c:14: warning: unused variable 'opt'
parse.c:14: warning: unused variable 'cmt'
parse.c:14: warning: unused variable 'arg'
parse.c:10: warning: unused variable 'i'
parse.c:10: warning: unused variable 'line_number'
make[2]: *** [sudosh.o] Error 1
I know the proper fix is for the author to fix the code, but I want to work around this problem in the short term. I need a working RPM.
It looks like either ./configure
or autoconf
is automatically adding the -Werror
flag. How can I disable the -Werror
flags for my builds, short of editing the Makefile myself?
Update in response to @pwan's answer:
The .spec file is pretty generic, and doesn't specify any special flags:
%build
%configure \
--program-prefix="%{?_program_prefix}"
%{__make} %{?_smp_mflags}
There's not really enough info to give a detailed answer, but you should probably focus on the %prep section in the spec file.
If you're lucky, this section will be calling configure. Then you should be able to look at the arguments the configure script provides and figure out which one is responsible for the -Wall flag. Running 'configure --help' may list out the available flags.
Then you should be able to update the spec file so the configure call includes the flags that'll skip over adding the -Wall to CFLAGS
You may also be able to get away with setting the CFLAGS environment variable during the configure call, but the configure script may ignore or override these.
CFLAGS="-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Werror" configure --whatever