Blame SOURCES/macros

396caf
# Per-platform rpm configuration file.
396caf
396caf
#==============================================================================
396caf
# ---- per-platform macros.
396caf
#
396caf
%_vendor		redhat
396caf
%_os			linux
396caf
%_target_platform	%{_target_cpu}-%{_vendor}-%{_target_os}%{?_gnu}
396caf
396caf
#==============================================================================
396caf
# ---- configure macros.  note that most of these are inherited
396caf
#      from the defaults.
396caf
#
396caf
%_localstatedir		/var
396caf
396caf
%_pkgdocdir             %{_docdir}/%{name}
396caf
%_docdir_fmt            %%{NAME}
396caf
396caf
%_fmoddir		%{_libdir}/gfortran/modules
396caf
396caf
%source_date_epoch_from_changelog 1
396caf
396caf
%_enable_debug_packages 1
396caf
%_include_minidebuginfo 1
396caf
%_include_gdb_index     1
396caf
%_debugsource_packages  1
396caf
%_debuginfo_subpackages 1
396caf
396caf
# GCC toolchain
396caf
%__cc_gcc gcc
396caf
%__cxx_gcc g++
396caf
%__cpp_gcc gcc -E
396caf
396caf
# Clang toolchain
396caf
%__cc_clang clang
396caf
%__cxx_clang clang++
396caf
%__cpp_clang clang-cpp
396caf
396caf
# Default to the GCC toolchain
396caf
#
396caf
# It is enough to override `toolchain` macro and all relevant macro for C/C++
396caf
# compilers will be switched. Either in the spec or in the command-line.
396caf
#
396caf
#     %global toolchain clang
396caf
#
396caf
# or:
396caf
#
396caf
#     rpmbuild -D "toolchain clang" …
396caf
#
396caf
# Inside a spec file it is also possible to determine which toolchain is in use
396caf
# by testing the same macro. For example:
396caf
#
396caf
#     %if "%{toolchain}" == "gcc"
396caf
#     BuildRequires: gcc
396caf
#     %endif
396caf
#
396caf
# or:
396caf
#
396caf
#     %if "%{toolchain}" == "clang"
396caf
#     BuildRequires: clang compiler-rt
396caf
#     %endif
396caf
#
396caf
%toolchain gcc
396caf
396caf
%__cc %{expand:%%{__cc_%{toolchain}}}
396caf
%__cxx %{expand:%%{__cxx_%{toolchain}}}
396caf
%__cpp %{expand:%%{__cpp_%{toolchain}}}
396caf
396caf
#==============================================================================
396caf
# ---- compiler flags.
396caf
396caf
# C compiler flags.  This is traditionally called CFLAGS in makefiles.
396caf
# Historically also available as %%{optflags}, and %%build sets the
396caf
# environment variable RPM_OPT_FLAGS to this value.
396caf
%build_cflags %{optflags}
396caf
396caf
# C++ compiler flags.  This is traditionally called CXXFLAGS in makefiles.
396caf
%build_cxxflags %{optflags}
396caf
396caf
# Fortran compiler flags.  Makefiles use both FFLAGS and FCFLAGS as
396caf
# the corresponding variable names.
396caf
%build_fflags %{optflags} -I%{_fmoddir}
396caf
396caf
# Link editor flags.  This is usually called LDFLAGS in makefiles.
396caf
# (Some makefiles use LFLAGS instead.)  The default value assumes that
396caf
# the flags, while intended for ld, are still passed through the gcc
396caf
# compiler driver.  At the beginning of %%build, the environment
396caf
# variable RPM_LD_FLAGS to this value.
396caf
# When clang is used as a linker driver, it does not auto-detect the LTO
396caf
# bytecode and neither does bfd, so we need to explicitly pass the -flto
396caf
# flag when linking.
396caf
%build_ldflags -Wl,-z,relro %{_ld_as_needed_flags} %{_ld_symbols_flags} %{_hardened_ldflags} %{_annotation_ldflags} %[ "%{toolchain}" == "clang" ? "%{?_lto_cflags}" : "" ]
396caf
396caf
# Expands to shell code to set the compiler/linker environment
396caf
# variables CFLAGS, CXXFLAGS, FFLAGS, FCFLAGS, LDFLAGS if they have
396caf
# not been set already.  RPM_OPT_FLAGS and RPM_LD_FLAGS have already
396caf
# been set implicitly at the start of the %%build section.
396caf
# LT_SYS_LIBRARY_PATH is used by libtool script.
396caf
%set_build_flags \
396caf
  CFLAGS="${CFLAGS:-%{build_cflags}}" ; export CFLAGS ; \
396caf
  CXXFLAGS="${CXXFLAGS:-%{build_cxxflags}}" ; export CXXFLAGS ; \
396caf
  FFLAGS="${FFLAGS:-%{build_fflags}}" ; export FFLAGS ; \
396caf
  FCFLAGS="${FCFLAGS:-%{build_fflags}}" ; export FCFLAGS ; \
396caf
  LDFLAGS="${LDFLAGS:-%{build_ldflags}}" ; export LDFLAGS ; \
396caf
  LT_SYS_LIBRARY_PATH="${LT_SYS_LIBRARY_PATH:-%_libdir:}" ; export LT_SYS_LIBRARY_PATH ; \
396caf
  CC="${CC:-%{__cc}}" ; export CC ; \
396caf
  CXX="${CXX:-%{__cxx}}" ; export CXX
396caf
396caf
# Internal-only.  Do not use.  Expand a variable and strip the flags
396caf
# not suitable to extension builders.
396caf
%__extension_strip_flags() %{lua:
396caf
local name = rpm.expand("%{1}")
396caf
local value = " " .. rpm.expand("%{build_" .. name .. "}")
396caf
local specs_pattern = "%s+-specs=[^%s]+"
396caf
local lto_flags_pattern = rpm.expand("%{?_lto_cflags}"):gsub("[%-%.]", "%%%1")
396caf
local result = value:gsub(specs_pattern, " "):gsub(lto_flags_pattern, "")
396caf
print(result)
396caf
}
396caf
396caf
# Variants of CFLAGS, CXXFLAGS, FFLAGS, LDFLAGS for use within
396caf
# extension builders.
396caf
%extension_cflags %{__extension_strip_flags cflags}
396caf
%extension_cxxflags %{__extension_strip_flags cxxflags}
396caf
%extension_fflags %{__extension_strip_flags fflags}
396caf
%extension_ldflags %{__extension_strip_flags ldflags}
396caf
396caf
# Deprecated names.  For backwards compatibility only.
396caf
%__global_cflags %{build_cflags}
396caf
%__global_cxxflags %{build_cxxflags}
396caf
%__global_fflags %{build_fflags}
396caf
%__global_fcflags %{build_fflags}
396caf
%__global_ldflags %{build_ldflags}
396caf
396caf
# Architecture-specific support.  Internal.  Do not use directly.
396caf
396caf
%__cflags_arch_x86_64 %[0%{?rhel} >= 9 ? "-march=x86-64-v2" : ""]
396caf
396caf
# Also used for s390.
396caf
%__cflags_arch_s390x %[0%{?rhel} >= 9 ? "-march=z14 -mtune=z15" : "-march=zEC12 -mtune=z13"]
396caf
396caf
# Also used for ppc64le.
396caf
%__cflags_arch_ppc64le %[0%{?rhel} >= 9 ? "-mcpu=power9 -mtune=power9" : "-mcpu=power8 -mtune=power8"]
396caf
396caf
#==============================================================================
396caf
# ---- configure and makeinstall.
396caf
#
396caf
%_configure_gnuconfig_hack	1
396caf
%_configure_libtool_hardening_hack	1
396caf
# If defined, _configure_disable_silent_rules will cause --disable-silent-rules
396caf
# to be added to the list of options passed to the configure script.
396caf
# Eventually we'll want to turn this on by default, but this gives packagers a
396caf
# way to turn it back off.
396caf
# %_configure_disable_silent_rules 1
396caf
396caf
# This fixes various easy resolved configure tests that are compromised by LTO.
396caf
#
396caf
# We use this within the standard %configure macro, but also make it available
396caf
# for packages which don't use %configure
396caf
#
396caf
# The first three are common ways to test for the existence of a function, so
396caf
# we ensure the reference to the function is preserved
396caf
#
396caf
# The fourth are constants used to then try to generate NaNs and other key
396caf
# floating point numbers.  We then use those special FP numbers to try and
396caf
# raise a SIGFPE.  By declaring x & y volatile we prevent the optimizers
396caf
# from removing the computation
396caf
#
396caf
# The fifth (and worst) addresses problems with autoconf/libtool's approach
396caf
# to extracting symbols from .o files and generating C code.  In an LTO world
396caf
# types matter much more closely and you can't have an object in one context
396caf
# that is a function definition and a simple scalar variable in another.
396caf
# Thankfully HP-UX has always had that restriction and is supported by
396caf
# autoconf/libtool.  The insane sed script replaces the "generic" code with
396caf
# the HP-UX version.
396caf
#
396caf
# If we do not make changes, we put the original file back.  This avoids
396caf
# unnecessary rebuilds of things that may have dependencies on the configure
396caf
# files.
396caf
#
396caf
%_fix_broken_configure_for_lto \
396caf
  for file in $(find . -type f -name configure -print); do \
396caf
    %{__sed} -r --in-place=.backup 's/^char \\(\\*f\\) \\(\\) = /__attribute__ ((used)) char (*f) () = /g' $file; \
396caf
    diff -u $file.backup $file && mv $file.backup $file \
396caf
    %{__sed} -r --in-place=.backup 's/^char \\(\\*f\\) \\(\\);/__attribute__ ((used)) char (*f) ();/g' $file; \
396caf
    diff -u $file.backup $file && mv $file.backup $file \
396caf
    %{__sed} -r --in-place=.backup 's/^char \\$2 \\(\\);/__attribute__ ((used)) char \\$2 ();/g' $file; \
396caf
    diff -u $file.backup $file && mv $file.backup $file \
396caf
    %{__sed} --in-place=.backup '1{$!N;$!N};$!N;s/int x = 1;\\nint y = 0;\\nint z;\\nint nan;/volatile int x = 1; volatile int y = 0; volatile int z, nan;/;P;D' $file; \
396caf
    diff -u $file.backup $file && mv $file.backup $file \
396caf
    %{__sed} --in-place=.backup 's#^lt_cv_sys_global_symbol_to_cdecl=.*#lt_cv_sys_global_symbol_to_cdecl="sed -n -e '"'"'s/^T .* \\\\(.*\\\\)$/extern int \\\\1();/p'"'"' -e '"'"'s/^$symcode* .* \\\\(.*\\\\)$/extern char \\\\1;/p'"'"'"#' $file; \
396caf
    diff -u $file.backup $file && mv $file.backup $file \
396caf
  done
396caf
396caf
%configure \
396caf
  %{set_build_flags}; \
396caf
  [ "%{_lto_cflags}"x != x ] && %{_fix_broken_configure_for_lto}; \
396caf
  [ "%_configure_gnuconfig_hack" = 1 ] && for i in $(find $(dirname %{_configure}) -name config.guess -o -name config.sub) ; do \
396caf
      [ -f /usr/lib/rpm/redhat/$(basename $i) ] && %{__rm} -f $i && %{__cp} -fv /usr/lib/rpm/redhat/$(basename $i) $i ; \
396caf
  done ; \
396caf
  [ "%_configure_libtool_hardening_hack" = 1 ] && [ x != "x%{_hardened_ldflags}" ] && \
396caf
      for i in $(find . -name ltmain.sh) ; do \
396caf
        %{__sed} -i.backup -e 's~compiler_flags=$~compiler_flags="%{_hardened_ldflags}"~' $i \
396caf
      done ; \
396caf
  %{_configure} --build=%{_build} --host=%{_host} \\\
396caf
	--program-prefix=%{?_program_prefix} \\\
396caf
	--disable-dependency-tracking \\\
396caf
	%{?_configure_disable_silent_rules:--disable-silent-rules} \\\
396caf
	--prefix=%{_prefix} \\\
396caf
	--exec-prefix=%{_exec_prefix} \\\
396caf
	--bindir=%{_bindir} \\\
396caf
	--sbindir=%{_sbindir} \\\
396caf
	--sysconfdir=%{_sysconfdir} \\\
396caf
	--datadir=%{_datadir} \\\
396caf
	--includedir=%{_includedir} \\\
396caf
	--libdir=%{_libdir} \\\
396caf
	--libexecdir=%{_libexecdir} \\\
396caf
	--localstatedir=%{_localstatedir} \\\
396caf
	--sharedstatedir=%{_sharedstatedir} \\\
396caf
	--mandir=%{_mandir} \\\
396caf
	--infodir=%{_infodir}
396caf
396caf
#==============================================================================
396caf
# ---- Build policy macros.
396caf
#
396caf
#
396caf
#---------------------------------------------------------------------
396caf
#	Expanded at beginning of %install scriptlet.
396caf
#
396caf
396caf
%__spec_install_pre %{___build_pre}\
396caf
    [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "${RPM_BUILD_ROOT}"\
396caf
    mkdir -p `dirname "$RPM_BUILD_ROOT"`\
396caf
    mkdir "$RPM_BUILD_ROOT"\
396caf
%{nil}
396caf
396caf
#---------------------------------------------------------------------
396caf
#	Expanded at end of %install scriptlet.
396caf
#
396caf
396caf
%__arch_install_post   /usr/lib/rpm/check-buildroot
396caf
396caf
# Build root policy macros. Standard naming:
396caf
# convert all '-' in basename to '_', add two leading underscores.
396caf
%__brp_ldconfig /usr/lib/rpm/redhat/brp-ldconfig
396caf
%__brp_compress /usr/lib/rpm/brp-compress
396caf
%__brp_strip /usr/lib/rpm/brp-strip %{__strip}
396caf
%__brp_strip_lto /usr/lib/rpm/redhat/brp-strip-lto %{__strip}
396caf
%__brp_strip_comment_note /usr/lib/rpm/brp-strip-comment-note %{__strip} %{__objdump}
396caf
%__brp_strip_static_archive /usr/lib/rpm/brp-strip-static-archive %{__strip}
396caf
%__brp_python_bytecompile /usr/lib/rpm/redhat/brp-python-bytecompile "" "%{?_python_bytecompile_errors_terminate_build}" "%{?_python_bytecompile_extra}"
396caf
%__brp_fix_pyc_reproducibility /usr/lib/rpm/redhat/brp-fix-pyc-reproducibility
396caf
%__brp_python_hardlink /usr/lib/rpm/brp-python-hardlink
396caf
# __brp_mangle_shebangs_exclude - shebangs to exclude
396caf
# __brp_mangle_shebangs_exclude_file - file from which to get shebangs to exclude
396caf
# __brp_mangle_shebangs_exclude_from - files to ignore
396caf
# __brp_mangle_shebangs_exclude_from_file - file from which to get files to ignore
396caf
%__brp_mangle_shebangs /usr/lib/rpm/redhat/brp-mangle-shebangs %{?__brp_mangle_shebangs_exclude:--shebangs "%{?__brp_mangle_shebangs_exclude}"} %{?__brp_mangle_shebangs_exclude_file:--shebangs-from "%{__brp_mangle_shebangs_exclude_file}"} %{?__brp_mangle_shebangs_exclude_from:--files "%{?__brp_mangle_shebangs_exclude_from}"} %{?__brp_mangle_shebangs_exclude_from_file:--files-from "%{__brp_mangle_shebangs_exclude_from_file}"}
396caf
396caf
%__os_install_post    \
396caf
    %{?__brp_ldconfig} \
396caf
    %{?__brp_compress} \
396caf
    %{!?__debug_package:\
396caf
    %{?__brp_strip} \
396caf
    %{?__brp_strip_comment_note} \
396caf
    } \
396caf
    %{?__brp_strip_lto} \
396caf
    %{?__brp_strip_static_archive} \
396caf
    %{?py_auto_byte_compile:%{?__brp_python_bytecompile}} \
396caf
    %{?py_reproducible_pyc_path:%{?__brp_fix_pyc_reproducibility} "%{py_reproducible_pyc_path}"} \
396caf
    %{?__brp_python_hardlink} \
396caf
    %{?__brp_mangle_shebangs} \
396caf
%{nil}
396caf
396caf
%__spec_install_post\
396caf
    %{?__debug_package:%{__debug_install_post}}\
396caf
    %{__arch_install_post}\
396caf
    %{__os_install_post}\
396caf
%{nil}
396caf
396caf
%install %{?_enable_debug_packages:%{?buildsubdir:%{debug_package}}}\
396caf
%%install\
396caf
%{nil}
396caf
396caf
#
396caf
# Should missing buildids terminate a build?
396caf
%_missing_build_ids_terminate_build    1
396caf
396caf
#
396caf
## Automatically compile python files
396caf
%py_auto_byte_compile 1
396caf
396caf
#
396caf
## Should python bytecompilation errors terminate a build?
396caf
%_python_bytecompile_errors_terminate_build 1
396caf
## Should python bytecompilation compile outisde python specific directories?
396caf
%_python_bytecompile_extra 0
396caf
396caf
# Use SHA-256 for FILEDIGESTS instead of default MD5
396caf
%_source_filedigest_algorithm 8
396caf
%_binary_filedigest_algorithm 8
396caf
396caf
# Use Zstandard compression for binary payloads
396caf
%_binary_payload w19.zstdio
396caf
396caf
%_hardening_gcc_cflags   -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1
396caf
%_hardening_clang_cflags --config /usr/lib/rpm/redhat/redhat-hardened-clang.cfg
396caf
%_hardening_cflags	 %{expand:%%{_hardening_%{toolchain}_cflags}} -fstack-protector-strong
396caf
# we don't escape symbols '~', '"', etc. so be careful when changing this
396caf
%_hardening_ldflags	 -Wl,-z,now %[ "%{toolchain}" == "gcc" ? "-specs=/usr/lib/rpm/redhat/redhat-hardened-ld" : "" ]
396caf
396caf
# Harden packages by default for Fedora 23+:
396caf
# https://fedorahosted.org/fesco/ticket/1384 (accepted on 2014-02-11)
396caf
# Use "%undefine _hardened_build" to disable.
396caf
%_hardened_build	1
396caf
%_hardened_cflags	%{?_hardened_build:%{_hardening_cflags}}
396caf
%_hardened_ldflags	%{?_hardened_build:%{_hardening_ldflags}}
396caf
396caf
# Add extra information to binary objects created by the compiler:
396caf
# https://pagure.io/fesco/issue/1780 (accepted on 2017-10-30)
396caf
# Use "%undefine _annotated_build" to disable.
396caf
%_annotated_build	1
396caf
%_annobin_gcc_plugin	-specs=/usr/lib/rpm/redhat/redhat-annobin-cc1
396caf
# The annobin plugin is not built for clang yet
396caf
%_annobin_clang_plugin	%dnl-fplugin=/usr/lib64/clang/`clang -dumpversion`/lib/annobin.so
396caf
%_annotation_cflags     %{?_annotated_build:%{expand:%%{_annobin_%{toolchain}_plugin}}}
396caf
%_annotation_ldflags	%{?_lto_cflags:%{_annotation_cflags}}
396caf
396caf
# Fail linking if there are undefined symbols.  Required for proper
396caf
# ELF symbol versioning support.  Disabled by default.
396caf
# Use "%define _ld_strict_symbol_defs 1" to enable.
396caf
#%_ld_strict_symbol_defs		1
396caf
%_ld_symbols_flags		%{?_ld_strict_symbol_defs:-Wl,-z,defs}
396caf
396caf
# https://fedoraproject.org/wiki/Changes/RemoveExcessiveLinking
396caf
# use "%undefine _ld_as_needed" to disable.
396caf
%_ld_as_needed		1
396caf
%_ld_as_needed_flags	%{?_ld_as_needed:-Wl,--as-needed}
396caf
396caf
# LTO is the default in Fedora.
396caf
#   "%define _lto_cflags %{nil}"  to opt out
396caf
#
396caf
# We currently have -ffat-lto-objects turned on out of an abundance of
396caf
# caution.  To remove it we need to do a check of the installed .o/.a files
396caf
# to verify they have real sections/symbols after LTO stripping.  That
396caf
# way we can detect installing an unusable .o/.a file.  This is on the TODO
396caf
# list for F34.
396caf
%_gcc_lto_cflags	-flto=auto -ffat-lto-objects
396caf
%_clang_lto_cflags	-flto
396caf
%_lto_cflags		%{expand:%%{_%{toolchain}_lto_cflags}}
396caf
396caf
%_general_options       -O2 %{?_lto_cflags} -fexceptions -g -grecord-gcc-switches -pipe
396caf
%_warning_options       -Wall -Werror=format-security
396caf
%_preprocessor_defines  -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS
396caf
396caf
# Common variables are no longer generated by default by gcc and clang
396caf
# If they are needed then add "%define _legacy_common_support 1" to the spec file.
396caf
%_legacy_options	%{?_legacy_common_support: -fcommon}
396caf
396caf
%__global_compiler_flags %{_general_options} %{_warning_options} %{_preprocessor_defines} %{_hardened_cflags} %{_annotation_cflags} %{_legacy_options}
396caf
396caf
# Automatically trim changelog entries after 2 years
396caf
%_changelog_trimtime	%{lua:print(os.time() - 2 * 365 * 86400)}
396caf
396caf
#==============================================================================
396caf
# ---- Generic auto req/prov filtering macros
396caf
#
396caf
# http://fedoraproject.org/wiki/PackagingDrafts/AutoProvidesAndRequiresFiltering
396caf
396caf
# prevent anything matching from being scanned for provides
396caf
%filter_provides_in(P) %{expand: \
396caf
%global __filter_prov_cmd %{?__filter_prov_cmd} %{__grep} -v %{-P} '%*' | \
396caf
}
396caf
396caf
# prevent anything matching from being scanned for requires
396caf
%filter_requires_in(P) %{expand: \
396caf
%global __filter_req_cmd %{?__filter_req_cmd} %{__grep} -v %{-P} '%*' | \
396caf
}
396caf
396caf
# filter anything matching out of the provides stream
396caf
%filter_from_provides() %{expand: \
396caf
%global __filter_from_prov %{?__filter_from_prov} | %{__sed} -e '%*' \
396caf
}
396caf
396caf
# filter anything matching out of the requires stream
396caf
%filter_from_requires() %{expand: \
396caf
%global __filter_from_req %{?__filter_from_req} | %{__sed} -e '%*' \
396caf
}
396caf
396caf
# actually set up the filtering bits
396caf
%filter_setup %{expand: \
396caf
%global _use_internal_dependency_generator 0 \
396caf
%global __deploop() while read FILE; do echo "${FILE}" | /usr/lib/rpm/rpmdeps -%{1}; done | /bin/sort -u \
396caf
%global __find_provides /bin/sh -c "%{?__filter_prov_cmd} %{__deploop P} %{?__filter_from_prov}" \
396caf
%global __find_requires /bin/sh -c "%{?__filter_req_cmd}  %{__deploop R} %{?__filter_from_req}" \
396caf
}