rpmbuild:如何使用 rpmbuild 告诉 autoconf 或 configure 来禁用标志?

发布于 2024-12-05 04:14:08 字数 1972 浏览 2 评论 0原文

我正在 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

我知道正确的修复方法是作者修复代码,但我想在短期内解决这个问题。我需要一个工作转速。

看起来 ./configureautoconf 会自动添加 -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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静谧 2024-12-12 04:14:08

没有足够的信息来给出详细的答案,但您可能应该关注规范文件中的 %prep 部分。

如果幸运的话,这部分将调用configure。然后您应该能够查看配置脚本提供的参数并找出哪个参数负责 -Wall 标志。运行“configure --help”可能会列出可用的标志。

然后您应该能够更新规范文件,以便配置调用包含将跳过将 -Wall 添加到 CFLAGS 的标志

您也可以在配置调用期间设置 CFLAGS 环境变量,但是配置脚本可能会忽略或覆盖这些。

CFLAGS="-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Werror" configure --whatever

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
时光无声 2024-12-12 04:14:08

如何在缺少编辑的情况下禁用我的构建的 -Werror 标志
我自己的Makefile?

GCC手册在3.8请求或抑制警告的选项中有解决方案:

您可以使用以 -W' 开头的选项请求许多特定警告,
例如 -Wimplicit 请求有关隐式声明的警告。
每个特定警告选项也有否定形式
开始
-Wno-' 关闭警告;例如,-Wno-隐式。
本手册仅列出两种形式中的一种,以非
默认。

因此,设置 CFLAGS 环境变量 -Wno-error 对我来说就成功了。现在我知道我在寻找什么了,我可以看到 Stackoverflow 有丰富的答案:https: //stackoverflow.com/search?q=%22-Wno-%22 ,特别是 如何在启用 -Wall 时禁用特定警告

在我的具体情况下,构建由于“警告:未使用的变量”而失败,我可以使用 -Wno-unused-variable 抑制这些特定警告。

由于我使用的是 rpmbuild,因此我需要按照 @pwan 的建议将其放入 .spec 文件中。我能解决这个问题的唯一方法是:

  1. 构建 rpm 一次:

    rpmbuild -v -bb ~/rpmbuild/SPECS/sudosh.spec
    
  2. 搜索 ./configure 生成的 CFLAGS

    配置总结:
    =====================
    
      主机类型................: x86_64-redhat-linux-gnu
      CC......................:海湾合作委员会
      CFLAGS......................:-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-大小=4 -m64 -mtune=通用 -Werror
    
  3. 并手动将这些 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。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文