Blame SOURCES/macros.kmp

7689d7
# Use these macros to differentiate between RH and other KMP implementation(s).
7689d7
%global redhat_kernel_module_package	1
7689d7
%global kernel_module_package_release	1
7689d7
6b41b9
%global redhat_kmp_has_post_hooks	1
6b41b9
7689d7
%__brp_kmod_set_exec_bit  /usr/lib/rpm/redhat/brp-kmod-set-exec-bit
7689d7
%__brp_kmod_restore_perms /usr/lib/rpm/redhat/brp-kmod-restore-perms
7689d7
7689d7
%__kmod_brps_added 0
7689d7
7689d7
%__find_provides        /usr/lib/rpm/redhat/find-provides
7689d7
%__find_requires        /usr/lib/rpm/redhat/find-requires
7689d7
7689d7
#kernel_module_package [ -n name ] [ -v version ] [ -r release ] [ -s script ]
7689d7
#                      [ -f filelist] [ -x ] [ -p preamble ] flavor flavor ...
7689d7
7689d7
%kernel_module_package_buildreqs	%global kmodtool_generate_buildreqs 1 \
7689d7
					kernel-devel kernel-abi-whitelists redhat-rpm-config kernel-rpm-macros elfutils-libelf-devel kmod
7689d7
7689d7
%kernel_module_package(n:v:r:s:f:xp:) %{expand:%( \
7689d7
	## An ugly hack: we want kmods to be processed by find-debuginfo,
7689d7
	## but it processes only files with executable permission set.
7689d7
	## It is important now since, as of now, if debuginfo package
7689d7
	## is enabled (and it is enabled), there's an RPM build error
7689d7
	## as a result of lack of ether absence or emptiness of
7689d7
	## debugsourcefiles.list (which is likely a bug in RPM, but it looks
7689d7
	## like that there's no obvious fix and apparently no one have
7689d7
	## any issues with this).
7689d7
	## In order to minimise intrusiveness, usually (in Red Hat-built kmod
7689d7
	## RPMs) *.ko files just have executable permission being set as a part
7689d7
	## of %build section. There are two caveats with kmp, however:
7689d7
	##  * We have no control over %build section itself (and it wasn't
7689d7
	##    required previously)
7689d7
	##  * Changing the criteria used in find-debuginfo.sh/brp-strip
7689d7
	##    for selecting files that have to undergo debug section separation
7689d7
	##    may introduce regression.
7689d7
	## As a result, we insert additional hooks in __spec_install_post
7689d7
	## (__brp_kmod_set_exec_bit in the beginning and
7689d7
	## __brp_kmod_restore_perms in the end) that (temporarily) set
7689d7
	## executable permission for *.ko files so find-debuginfo.sh will pick
7689d7
	## them up.
7689d7
	## Unfortunately, __spec_install_post's body is copied here since
7689d7
	## we want that __debug_package macro expansion has been performed
7689d7
	## lazily and  it looks like RPM has no ability to provide a body
7689d7
	## of a macro verbatim.
7689d7
	if [ 0 = "%{__kmod_brps_added}" ]; then \
7689d7
		echo "%%global __spec_install_post \\\\" \
7689d7
		echo "	%%{?__brp_kmod_set_exec_bit} \\\\" \
7689d7
		echo "	%%%%{?__debug_package:%%%%{__debug_install_post}} \\\\" \
7689d7
		echo "	%%{__arch_install_post} \\\\" \
7689d7
		echo "	%%{__os_install_post} \\\\" \
6b41b9
		echo "	%%{?__brp_kmod_pre_sign_process} \\\\" \
6b41b9
		echo "	%%{?__brp_kmod_sign} \\\\" \
6b41b9
		echo "	%%{?__brp_kmod_post_sign_process} \\\\" \
6b41b9
		echo "	%%{?__brp_kmod_compress} \\\\" \
6b41b9
		echo "	%%{?__brp_kmod_post_compress_process} \\\\" \
7689d7
		echo "	%%{?__brp_kmod_restore_perms} \\\\" \
7689d7
		echo "%%{nil}" \
7689d7
	fi \
7689d7
	%global __kmod_brps_added 1 \
7689d7
	%global kmodtool %{-s*}%{!-s:/usr/lib/rpm/redhat/kmodtool} \
7689d7
	%global kmod_version %{-v*}%{!-v:%{version}} \
7689d7
	%global kmod_release %{-r*}%{!-r:%{release}} \
7689d7
	%global latest_kernel %({ rpm -q --qf '%%{VERSION}-%%{RELEASE}.%%{ARCH}\\\\n' `rpm -qa | egrep "^kernel(-rt|-aarch64)?-devel" | /usr/lib/rpm/redhat/rpmsort -r | head -n 1`; echo '%%%%{nil}'; } | head -n 1) \
7689d7
	%{!?kernel_version:%{expand:%%global kernel_version %{latest_kernel}}} \
7689d7
	%global kverrel %(%{kmodtool} verrel %{?kernel_version} 2>/dev/null) \
7689d7
	flavors="default" \
7689d7
	if [ -z "%*" ]; then \
7689d7
		flavors_to_build=$flavors \
7689d7
	elif [ -z "%{-x}" ]; then \
7689d7
		flavors_to_build="%*" \
7689d7
	else \
7689d7
		flavors_to_build=" $flavors "\
7689d7
		for i in %* \
7689d7
		do \
7689d7
			flavors_to_build=${flavors_to_build//$i /}
7689d7
		done \
7689d7
	fi \
7689d7
	echo "%%global flavors_to_build ${flavors_to_build:-%%nil}" \
7689d7
	echo "%%global kernel_source() \\\$([ default = \"%%%%{1}\" ] && echo \"/usr/src/kernels//%%%%kverrel\" || %{kmodtool} kernel_source \"%%%%{kverrel}\" \"%%%%{1}\" 2>/dev/null || { ls -Ud \"/usr/src/kernels///%%%%{kverrel}\"[.+]\"%%%%{1}\" | sort -V | tail -n 1; } || echo \"/usr/src/kernels////%%%%kverrel.%%%%1\")" \
7689d7
	echo "%%global kernel_module_package_moddir() extra" \
7689d7
	if [ ! -z "%{-f*}" ] \
7689d7
	then \
7689d7
		filelist="%{-f*}" \
7689d7
	fi \
7689d7
	if [ ! -z "%{-p*}" ] \
7689d7
	then \
7689d7
		preamble="%{-p*}" \
7689d7
	fi \
7689d7
	nobuildreqs="yes" \
7689d7
	if [ "x%{kmodtool_generate_buildreqs}" != "x1" ] \
7689d7
	then \
7689d7
		nobuildreqs="no" \
7689d7
	fi \
7689d7
	override_filelist="$filelist" override_preamble="$preamble" nobuildreqs="$nobuildreqs" kmod_version=%kmod_version kmod_release=%kmod_release %{kmodtool} rpmtemplate %{-n*}%{!-n:%name} %{kverrel} $flavors_to_build 2>/dev/null \
7689d7
)}