Blame SOURCES/macros

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