Blame SOURCES/macros.kmp

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