Call %set_build_flags before %build, %check, and %install stages
https://fedoraproject.org/wiki/Changes/SetBuildFlagsBuildCheck
This commit is contained in:
parent
bc87a0d123
commit
9183c1c8d4
@ -5,6 +5,20 @@ and how to use them.
|
||||
|
||||
# Using RPM build flags
|
||||
|
||||
The %set_build_flags macro sets the environment variables `CFLAGS`,
|
||||
`CXXFLAGS`, `FFLAGS`, `FCFLAGS`, `LDFLAGS` and `LT_SYS_LIBRARY_PATH` to
|
||||
the value of their corresponding rpm macros. %set_build_flags is automatically
|
||||
called prior to the %build, %check, and %install phases so these flags can be
|
||||
used by makefiles and other build tools.
|
||||
|
||||
You can opt out of this behavior by doing:
|
||||
|
||||
%undefine _auto_set_build_flags
|
||||
|
||||
If you do opt out of this behavior, you can still manually use %set_build_flags
|
||||
by adding it to the %build section of your spec file or by using one of the
|
||||
build system helper macros like %configure, %cmake, and %meson
|
||||
|
||||
For packages which use autoconf to set up the build environment, use
|
||||
the `%configure` macro to obtain the full complement of flags, like
|
||||
this:
|
||||
@ -16,20 +30,6 @@ This will invoke `./configure` with arguments (such as
|
||||
to that, some common problems in autotools scripts are automatically
|
||||
patched across the source tree.
|
||||
|
||||
As a side effect, this will set the environment variables `CFLAGS`,
|
||||
`CXXFLAGS`, `FFLAGS`, `FCFLAGS`, `LDFLAGS` and `LT_SYS_LIBRARY_PATH`,
|
||||
so they can be used by makefiles and other build tools. (However,
|
||||
existing values for these variables are not overwritten.)
|
||||
|
||||
If your package does not use autoconf, you can still set the same
|
||||
environment variables using
|
||||
|
||||
%set_build_flags
|
||||
|
||||
early in the `%build` section. (Again, existing environment variables
|
||||
are not overwritten.) `%set_build_flags` does not perform autotools
|
||||
script rewriting, unlike `%configure`.
|
||||
|
||||
Individual build flags are also available through RPM macros:
|
||||
|
||||
* `%{build_cc}` for the command name of the C compiler.
|
||||
|
8
macros
8
macros
@ -89,6 +89,13 @@
|
||||
CC="${CC:-%{__cc}}" ; export CC ; \
|
||||
CXX="${CXX:-%{__cxx}}" ; export CXX
|
||||
|
||||
# Automatically use set_build_flags macro for build, check, and
|
||||
# install phases.
|
||||
# Use "%undefine _auto_set_build_flags" to disable"
|
||||
%_auto_set_build_flags 1
|
||||
%__spec_build_pre %{___build_pre} %{?_auto_set_build_flags:%{set_build_flags}}
|
||||
%__spec_check_pre %{___build_pre} %{?_auto_set_build_flags:%{set_build_flags}}
|
||||
|
||||
# Internal-only. Do not use. Expand a variable and strip the flags
|
||||
# not suitable to extension builders.
|
||||
%__extension_strip_flags() %{lua:
|
||||
@ -211,6 +218,7 @@ print(result)
|
||||
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "${RPM_BUILD_ROOT}"\
|
||||
mkdir -p "`dirname "$RPM_BUILD_ROOT"`"\
|
||||
mkdir "$RPM_BUILD_ROOT"\
|
||||
%{?_auto_set_build_flags:%{set_build_flags}}\
|
||||
%{nil}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
Summary: Red Hat specific rpm configuration files
|
||||
Name: redhat-rpm-config
|
||||
Version: 207
|
||||
Version: 208
|
||||
Release: 1%{?dist}
|
||||
# No version specified.
|
||||
License: GPL+
|
||||
@ -190,6 +190,9 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua
|
||||
%doc buildflags.md
|
||||
|
||||
%changelog
|
||||
* Tue Jan 04 2022 Tom Stellard <tstellar@redhat.com> - 208-1
|
||||
- Call %%set_build_flags before %%build, %%check, and %%install stages
|
||||
|
||||
* Tue Dec 14 2021 Tom Stellard <tstellar@redhat.com> - 207-1
|
||||
- Add -Wl,--build-id=sha1 to the default LDFLAGS
|
||||
|
||||
|
11
tests/auto-set-build-flags/Makefile
Normal file
11
tests/auto-set-build-flags/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
.phony: all
|
||||
|
||||
all: hello-c hello-cpp
|
||||
|
||||
clean:
|
||||
rm -Rf *.o hello-c hello-cpp
|
||||
|
||||
hello-c: main-c.o hello-c.o
|
||||
|
||||
hello-cpp: main-cpp.o hello-cpp.o
|
||||
$(CXX) $(LDFLAGS) -o $@ $^
|
5
tests/auto-set-build-flags/hello-c.c
Normal file
5
tests/auto-set-build-flags/hello-c.c
Normal file
@ -0,0 +1,5 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void hello(void) {
|
||||
printf("Hello, World!");
|
||||
}
|
5
tests/auto-set-build-flags/hello-cpp.cpp
Normal file
5
tests/auto-set-build-flags/hello-cpp.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include <iostream>
|
||||
|
||||
void hello(void) {
|
||||
std::cout << "Hello, World!\n";
|
||||
}
|
5
tests/auto-set-build-flags/main-c.c
Normal file
5
tests/auto-set-build-flags/main-c.c
Normal file
@ -0,0 +1,5 @@
|
||||
void hello(void);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
hello();
|
||||
}
|
5
tests/auto-set-build-flags/main-cpp.cpp
Normal file
5
tests/auto-set-build-flags/main-cpp.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
void hello(void);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
hello();
|
||||
}
|
7
tests/auto-set-build-flags/runtest.sh
Executable file
7
tests/auto-set-build-flags/runtest.sh
Executable file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
dnf -y build-dep test.spec
|
||||
rpmbuild --define '_sourcedir .' --define '_builddir .' -bi test.spec
|
||||
rpmbuild --without auto_set_build_flags --define '_sourcedir .' --define '_builddir .' -bi test.spec
|
39
tests/auto-set-build-flags/test.spec
Normal file
39
tests/auto-set-build-flags/test.spec
Normal file
@ -0,0 +1,39 @@
|
||||
%bcond_without auto_set_build_flags
|
||||
|
||||
%if %{without auto_set_build_flags}
|
||||
%undefine _auto_set_build_flags
|
||||
%endif
|
||||
|
||||
Name: test
|
||||
Version: 1
|
||||
Release: 1
|
||||
Summary: Test package for checking %%set_build_flag usage
|
||||
License: MIT
|
||||
|
||||
BuildRequires: gcc gcc-c++ make
|
||||
BuildRequires: annobin-annocheck
|
||||
|
||||
Source0: Makefile
|
||||
Source1: main-c.c
|
||||
Source2: hello-c.c
|
||||
Source3: main-cpp.cpp
|
||||
Source4: hello-cpp.cpp
|
||||
|
||||
%global build_and_check \
|
||||
make \
|
||||
%{!?with_auto_set_build_flags:!} annocheck hello-c hello-cpp \
|
||||
make clean
|
||||
|
||||
%description
|
||||
Test package for checking %%set_build_flag usage
|
||||
|
||||
%prep
|
||||
|
||||
%build
|
||||
%build_and_check
|
||||
|
||||
%check
|
||||
%build_and_check
|
||||
|
||||
%install
|
||||
%build_and_check
|
@ -31,6 +31,11 @@
|
||||
- gcc
|
||||
- gcc-c++
|
||||
- annobin-annocheck
|
||||
#auto-set-build-flags
|
||||
- gcc
|
||||
- gcc-c++
|
||||
- annobin-annocheck
|
||||
- make
|
||||
# no-new-dependency
|
||||
- diffutils
|
||||
- grep
|
||||
@ -44,3 +49,4 @@
|
||||
- clang/fedora-flags
|
||||
- gcc-fedora-flags
|
||||
- no-new-dependency
|
||||
- auto-set-build-flags
|
||||
|
Loading…
Reference in New Issue
Block a user