rpmbuild:如何使用 rpmbuild 告诉 autoconf 或 configure 来禁用标志?
我正在 CentOS 5.7 系统上运行。
我从别人那里下载了一个源码包和一个.spec文件。我正在尝试使用像这样的普通命令从源代码构建 RPM:
% 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
但是,此构建失败了。该代码有点草率并且会生成一些警告。该工具链的某些部分正在启用 -Werror
标志,这使得“所有警告陷入错误。”因此,构建失败并出现错误:
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
我知道正确的修复方法是作者修复代码,但我想在短期内解决这个问题。我需要一个工作转速。
看起来 ./configure
或 autoconf
会自动添加 -Werror
标志。如果不亲自编辑 Makefile,如何禁用我的构建的 -Werror
标志?
更新响应 @pwan 的答案:
.spec 文件非常通用,并且没有指定任何特殊标志:
%build
%configure \
--program-prefix="%{?_program_prefix}"
%{__make} %{?_smp_mflags}
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}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有足够的信息来给出详细的答案,但您可能应该关注规范文件中的 %prep 部分。
如果幸运的话,这部分将调用configure。然后您应该能够查看配置脚本提供的参数并找出哪个参数负责 -Wall 标志。运行“configure --help”可能会列出可用的标志。
然后您应该能够更新规范文件,以便配置调用包含将跳过将 -Wall 添加到 CFLAGS 的标志
您也可以在配置调用期间设置 CFLAGS 环境变量,但是配置脚本可能会忽略或覆盖这些。
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.
GCC手册在3.8请求或抑制警告的选项中有解决方案:
因此,设置 CFLAGS 环境变量 -Wno-error 对我来说就成功了。现在我知道我在寻找什么了,我可以看到 Stackoverflow 有丰富的答案:https: //stackoverflow.com/search?q=%22-Wno-%22 ,特别是 如何在启用 -Wall 时禁用特定警告。
在我的具体情况下,构建由于“警告:未使用的变量”而失败,我可以使用
-Wno-unused-variable
抑制这些特定警告。由于我使用的是 rpmbuild,因此我需要按照 @pwan 的建议将其放入 .spec 文件中。我能解决这个问题的唯一方法是:
构建 rpm 一次:
搜索
./configure 生成的 CFLAGS
并手动将这些 CFLAGS 附加到我的 .spec 文件中的 `%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 -迂腐错误 -Wno-unused-variable -ansi -std=c99"
上面的内容有点 hack,因为如果 ./configure 脚本在上游发生更改,我可能需要重新调整我的 .spec 文件中的 CFLAGS。
The GCC manual has the solution in 3.8 Options to Request or Suppress Warnings:
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:
Build the rpm once:
Search for the CFLAGS which is generated by
./configure
And manually append these CFLAGS to my .spec file, into the `%configure% section:
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.