开发者

rpmbuild: How can I use rpmbuild tell autoconf or configure to disable a flag?

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


How can I disable the -Werror flags for my builds, short of editing the Makefile myself?

The GCC manual has the solution in 3.8 Options to Request or Suppress Warnings:

You can request many specific warnings with options beginning -W', for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning-Wno-' to turn off warnings; for example, -Wno-implicit. This manual lists only one of the two forms, whichever is not the default.

So, setting -Wno-error the CFLAGS environment variable did the trick for me. Now that I know what I'm looking for, I can see that Stackoverflow has a wealth of answers: https://stackoverflow.com/search?q=%22-Wno-%22 , specifically how to disable specific warning when -Wall is enabled.

In my specific case, the build was failing due to 'warning: unused variable", and I can suppress those specific warnings with -Wno-unused-variable.

Since I'm using rpmbuild, I need to put this in the .spec file as suggested by @pwan. The only way I could figure this out was to:

  1. Build the rpm once:

    rpmbuild -v -bb ~/rpmbuild/SPECS/sudosh.spec
    
  2. Search for the CFLAGS which is generated by ./configure

    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
    
  3. And manually append these CFLAGS to my .spec file, into the `%configure% section:

    %configure \
        --program-prefix="%{?_program_prefix}"
    #%{__make} %{?_smp_mflags}
    %{__make} %{?_smp_mflags} CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Werror -pedantic-errors -Wno-unused-variable -ansi -std=c99"
    

The above is a little hack-ish, because if the ./configure script is changed upstream I may need to re-adjust the CFLAGS in my .spec file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜