# vim:ts=4 sw=4 noet ft=spec # Kernel specific macro definitions. %__modinfo /sbin/modinfo # Alternative kernel type/version %_alt_kernel %{nil}%{?alt_kernel:-%{?alt_kernel}} %_build_kernels %{nil}%{?build_kernels:%{?build_kernels}}%{!?build_kernels:%{?alt_kernel}} # Macros for building kernel packages for multiple kernels from same spec # Usage: # # %{expand:%buildrequires_kernel kernel%%{_alt_kernel}-module-build >= 3:2.6.20.2}} # %{expand:%create_kernel_packages} # %{expand:%build_kernel_packages} # %{expand:%install_kernel_packages} # %buildrequires_kernel() %(echo %{_build_kernels} | tr , '\\n' | while read n ; do \ echo %%undefine alt_kernel \ [ -z "$n" -o "$n" = "head" ] || echo %%define alt_kernel $n \ echo "BuildRequires: %{*}" \ done) %create_kernel_packages %(echo %{_build_kernels} | tr , '\\n' | while read n ; do \ echo %%undefine alt_kernel \ [ -z "$n" -o "$n" = "head" ] || echo %%define alt_kernel $n \ echo %%kernel_pkg \ done) %build_kernel_packages %(echo %{_build_kernels} | tr , '\\n' | while read n ; do \ echo %%undefine alt_kernel \ [ -z "$n" -o "$n" = "head" ] || echo %%define alt_kernel $n \ echo %%build_kernel_pkg \ done) %install_kernel_packages %(echo %{_build_kernels} | tr , '\\n' | while read n ; do \ echo %%undefine alt_kernel \ [ -z "$n" -o "$n" = "head" ] || echo %%define alt_kernel $n \ echo %%install_kernel_pkg \ done) # The directory holding Linux kernel sources %_kernelsrcdir /usr/src/linux%{_alt_kernel} # rpm -qf on kernel version.h file %__kernel_qf() %(R=$(cd %{_kernelsrcdir} 2>/dev/null && LC_ALL=C rpm -q --qf '%*' -f include/linux/version.h 2>/dev/null | grep -v 'is not'); echo ${R:-ERROR}) # kernel %{name} and kernel %{epoch}:%{version}-%{release} macro respecing alt_kernel %kernel_name %(N=%{__kernel_qf %{N}}; echo ${N%%-headers}) %kernel_version %{__kernel_qf %|E?{%{E}:}|%{V}-%{R}} # -n drm to generate kernel%{_alt_kernel}-drm dependency %releq_kernel(n:) %{kernel_name}%{?-n:-%{-n*}} = %{kernel_version} %releq_kernel_up(n:) %{kernel_name}-up%{?-n:-%{-n*}} = %{kernel_version} %releq_kernel_smp(n:) %{kernel_name}-smp%{?-n:-%{-n*}} = %{kernel_version} # -s post to generate Requires(post) dependency %requires_releq_kernel(s:n:) Requires%{-s:(%{-s*})}: %releq_kernel %requires_releq_kernel_up(s:n:) Requires%{-s:(%{-s*})}: %releq_kernel_up %requires_releq_kernel_smp(s:n:) Requires%{-s:(%{-s*})}: %releq_kernel_smp # kernel version-release handling, `uname -r` used for building/installing kernel modules %_kernel_ver %( \\ Z=$([ -f '%{_kernelsrcdir}/include/generated/utsrelease.h' ] && \\ awk -F'"' '/UTS_RELEASE/{print $2}' %{_kernelsrcdir}/include/{linux/version,generated/utsrelease}.h 2>/dev/null || \\ awk -F'"' '/UTS_RELEASE/{print $2}' %{_kernelsrcdir}/include/linux/{version,utsrelease}.h 2>/dev/null); \\ Z=${Z:-$(awk -F' = ' '/^VERSION/{v=$2} /^PATCHLEVEL/{p=$2} /^SUBLEVEL/{s=$2} /^EXTRAVERSION/{e=$2} END {printf("%d.%d.%d%s", v, p, s, e)}' \\ %{_kernelsrcdir}/Makefile 2>/dev/null)}; \\ echo ${Z:-ERROR}; \\ ) # left for compatibility %__kernel_ver %{_kernel_ver} # package version to be used in @release field %_kernel_ver_str %( \\ Z=$([ -f '%{_kernelsrcdir}/include/generated/utsrelease.h' ] && \\ awk -F'"' '/UTS_RELEASE/{gsub(/-/,"_",$2); print $2}' %{_kernelsrcdir}/include/{linux/version,generated/utsrelease}.h 2>/dev/null || \\ awk -F'"' '/UTS_RELEASE/{gsub(/-/,"_",$2); print $2}' %{_kernelsrcdir}/include/linux/{version,utsrelease}.h 2>/dev/null); \\ Z=${Z:-$(awk -F' = ' '/^VERSION/{v=$2} /^PATCHLEVEL/{p=$2} /^SUBLEVEL/{s=$2} /^EXTRAVERSION/{e=$2} END {z=sprintf("%d.%d.%d%s", v, p, s, e); gsub(/-/,"_",z); print z}' \\ %{_kernelsrcdir}/Makefile 2>/dev/null)}; \\ echo ${Z:-ERROR}; \\ ) %_kernel_version_code %( \\ Z=$(awk '/LINUX_VERSION_CODE/{print $3}' %{_kernelsrcdir}/include/linux/version.h 2>/dev/null); \\ echo ${Z:-16777215}; \\ ) %_kernel_version_magic() %(echo $((%{1} * 65536 + %{2} * 256 + %{3}))) %_host_base_arch %{expand:%%global _host_base_arch %(echo %{_host_cpu} | sed 's/i.86/i386/;s/athlon/i386/;s/pentium./i386/;s/amd64/x86_64/;s/ia32e/x86_64/;s/x32/x86_64/;s/sparcv./sparc/;s/arm.*/arm/')}%_host_base_arch %_target_base_arch %{expand:%%global _target_base_arch %(echo %{_target_cpu} | sed 's/i.86/i386/;s/athlon/i386/;s/pentium./i386/;s/amd64/x86_64/;s/ia32e/x86_64/;s/x32/x86_64/;s/sparcv./sparc/;s/arm.*/arm/')}%_target_base_arch # Compression used for %__spec_install_post_compress_modules # Supported values: # - "gzip -9nf" (module-init-tools and kmod) # - "xz" (kmod) # - "xz -9e" (kmod), however size difference with "xz" default options is very minimal # @since 1.707 %kmod_compress_cmd %{__gzip} -9nf #----------------------------------------------------------------- # Find and compress all kernel modules # # Requires: find # Depends: kmod_compress_cmd # #%no_install_post_compress_modules 1 %__spec_install_post_compress_modules { \ %{!?no_install_post_compress_modules: __spec_install_post_compress_modules() { \ %{!?debug:set +x;} \ if [ -d $RPM_BUILD_ROOT/lib/modules ]; then \ tool=$(%{kmod_compress_cmd} --version | head -n1); \ case "$tool" in gzip*) ext=gz;; xz*) ext=xz;; esac; \ q=$(find $RPM_BUILD_ROOT/lib/modules -name '*.ko' -type f -print); \ if [ "$q" ]; then \ printf "Compress %d kernel modules..." $(echo "$q" | wc -l); \ echo "$q" | xargs -r %{kmod_compress_cmd}; \ echo "DONE"; \ find $RPM_BUILD_ROOT/lib/modules -name '*.ko' -type l -printf "%p %l\n" | \ while read a b; do ln -sf $b.$ext $a.$ext; rm -f $a; done; \ fi; \ fi; \ }; __spec_install_post_compress_modules } } # Build modules for kernels 2.6 # Author: Przemyslaw Iskra # # Usage: # %build_kernel_modules -m -C # # remember that proper Makefile is still required # Options: # -m (required) -- comma-separated list of modules to save, # without .ko extension, may be placed in subdirectory # -C -- change to before doing anything # -p , -P -- arguments passeed to make scripts # -c -- do not execute make clean # -- all additional arguments will be passed to # make modules # # Additional patching supported via here document. Try: # %build_kernel_modules -m module <<'EOF' # your patch script here # EOF # Don't use it unless patching depends on config options. # Developer note: don't touch it unless you know how to handle '\'. # - \ in script expands to nothing # - \\\ in script expands to \ # - \\\ inside definition expands to nothing # - \\\\\\\ inside definition expands to \ # - in last line \ has to touch arguments so arguments passing # in new lines (using \) will be supported %build_kernel_modules(p:P:m:C:c) \ %{!?-m:%{error:%{0}: Required module name/list missing} exit 1} \ \ %define Opts \\\\\\\ %if "%{_target_base_arch}" != "%{_host_base_arch}" \\\ %if "%{_host_base_arch}" == "x86_64" && "%{_target_base_arch}" == "i386" \\\ CC="%{__cc}" ARCH=%{_target_base_arch} \\\ %else \\\ ARCH=%{_target_base_arch} CROSS_COMPILE=%{_target_cpu}-pld-linux- \\\ %endif \\\ %else \\\ %ifarch aarch64 \\\ ARCH=arm64 \\\ %endif \\\ %ifarch ppc ppc64 \\\ ARCH=powerpc \\\ %endif \\\ %ifnarch aarch64 ppc ppc64 \\\ ARCH=%{_target_base_arch} \\\ %endif \\\ CC="%{__cc}" \\\ %endif \ %define MakeOpts HOSTCC="%{__cc}" SYSSRC=%{_kernelsrcdir} SYSOUT=$PWD/o \\\\\\\ %{?with_verbose:V=1} %{Opts} \ \ %{?-C:cd %{-C*}} \ compile() { \ local L="<" PATCH_SH; \ [[ '%{*}' != *$L$L* ]] || PATCH_SH="set -x -e;$(cat)" \ set -e -x \ \ [ -r "%{_kernelsrcdir}/.config" ] || exit 1 \ rm -rf o \ install -d o/include/linux o/include/generated o/arch/x86/include o/arch/powerpc/lib \ ln -sf %{_kernelsrcdir}/.config o/.config \ ln -sf %{_kernelsrcdir}/Module.symvers o/Module.symvers \ if [ -f %{_kernelsrcdir}/include/generated/autoconf.h ]; then \ ln -sf %{_kernelsrcdir}/include/generated/autoconf.h o/include/generated/autoconf.h \ ln -s ../generated/autoconf.h o/include/linux/autoconf.h \ else \ ln -sf %{_kernelsrcdir}/include/linux/autoconf.h o/include/linux/autoconf.h \ fi \ if [ -d %{_kernelsrcdir}/arch/x86/include/generated ]; then \ ln -s %{_kernelsrcdir}/arch/x86/include/generated o/arch/x86/include \ fi \ \ set +x \ [ -z "$PATCH_SH" ] || echo "$PATCH_SH" | %__spec_build_shell \ set -x \ \ install -d o/include/config \ touch o/include/config/MARKER \ ln -sf %{_kernelsrcdir}/include/config/auto.conf o/include/config/auto.conf \ ln -sf %{_kernelsrcdir}/scripts o/scripts \ \ %{!?-c:%{__make} -C %{_kernelsrcdir} clean \\\ RCS_FIND_IGNORE="-name '*.[ks]o' -o" \\\ ${1+"$@"} \\\ M=$PWD %{MakeOpts}} \ \ %{__make} -C %{_kernelsrcdir} modules \\\ ${1+"$@"} \\\ M=$PWD CONSTIFY_PLUGIN="" %{MakeOpts} \ %{?-C:cd -} \ } \ compile %{*} \ %{nil} %build_kernel_modules_compat(p:P:m:C:c) \ %{!?-m:%{error:%{0}: Required module name/list missing} exit 1} \ \ %define Opts \\\\\\\ %if "%{_target_base_arch}" != "%{_host_base_arch}" \\\ %if "%{_host_base_arch}" == "x86_64" && "%{_target_base_arch}" == "i386" \\\ CC="%{__cc}" ARCH=%{_target_base_arch} \\\ %else \\\ ARCH=%{_target_base_arch} CROSS_COMPILE=%{_target_cpu}-pld-linux- \\\ %endif \\\ %else \\\ CC="%{__cc}" \\\ %endif \ %define MakeOpts HOSTCC="%{__cc}" SYSSRC=%{_kernelsrcdir} SYSOUT=$PWD/o \\\\\\\ %{?with_verbose:V=1} %{Opts} \ \ %{?-C:cd %{-C*}} \ compile() { \ local L="<" PATCH_SH; \ [[ '%{*}' != *$L$L* ]] || PATCH_SH="set -x -e;$(cat)" \ set -e -x \ local cfgs='%{?with_dist_kernel:%{?with_smp: smp}%{?with_up: up}}%{!?with_dist_kernel: nondist}' \ \ for cfg in ${cfgs:-dist}; do \ [ -r "%{_kernelsrcdir}/config-$cfg" ] || exit 1 \ \ rm -rf o \ install -d o/include/linux o/include/generated o/arch/powerpc/lib \ ln -sf %{_kernelsrcdir}/config-$cfg o/.config \ ln -sf %{_kernelsrcdir}/Module.symvers-$cfg o/Module.symvers \ if [ -f %{_kernelsrcdir}/include/generated/autoconf-$cfg.h ]; then \ ln -sf %{_kernelsrcdir}/include/generated/autoconf-$cfg.h o/include/generated/autoconf.h \ ln -s ../generated/autoconf.h o/include/linux/autoconf.h \ else \ ln -sf %{_kernelsrcdir}/include/linux/autoconf-$cfg.h o/include/linux/autoconf.h \ fi \ \ set +x \ [ -z "$PATCH_SH" ] || echo "$PATCH_SH" | %__spec_build_shell \ set -x \ \ %if %{with dist_kernel} || %(test -f %{_kernelsrcdir}/scripts/bin2c ; echo $?) \ %{__make} -j1 -C %{_kernelsrcdir} prepare scripts \\\ %{-p*} %{-P*} \\\ %{MakeOpts} \ %else \ install -d o/include/config \ touch o/include/config/MARKER \ ln -sf %{_kernelsrcdir}/include/config/auto-$cfg.conf o/include/config/auto.conf \ ln -sf %{_kernelsrcdir}/scripts o/scripts \ %endif \ \ %{!?-c:%{__make} -C %{_kernelsrcdir} clean \\\ RCS_FIND_IGNORE="-name '*.[ks]o' -o" \\\ ${1+"$@"} \\\ M=$PWD %{MakeOpts}} \ \ %{__make} -C %{_kernelsrcdir} modules \\\ ${1+"$@"} \\\ M=$PWD CONSTIFY_PLUGIN="" %{MakeOpts} \ \ for MODULE in {%{-m*},}; do \ [ -z "${MODULE}" ] || mv ${MODULE}{,-$cfg}.ko \ done \ done \ %{?-C:cd -} \ } \ compile %{*} \ %{nil} # Install kernel modules built by %build_kernel_modules # Author: Przemyslaw Iskra # # Usage: # %install_kernel_modules -m -d # # Options: # -m (required) -- comma-separated list of modules to install, # without .ko extension, may be placed in subdirectory # -d (required) -- in what subdirectory modules should be # installed (eg. misc, kernel/drivers/net) # -s -- suffix to use when installing modules, useful when module # with same name exists in kernel already # -n -- name of modprobe config file to use (without .conf extension) # for defining aliases, only useful with -s # -D -- DESTDIR, base directory for installed files, # defaults to RPM_BUILD_ROOT %install_kernel_modules(m:d:s:n:D:) \ %{!?-m:%{error:%{0}: Required module name (-m) missing}exit 1} \ %{!?-d:%{error:%{0}: Required module directory missing}exit 1} \ %{?-n:%{!?-s:%{error:%{0}: Modprobe .conf file requires module suffix}exit 1}} \ \ INSTALLROOT=%{-D*} \ [ -n "$INSTALLROOT" ] || INSTALLROOT=$RPM_BUILD_ROOT \ \ %{!?debug:set +x;} \ \ for MODULE in {%{-m*},}; do \ [ -n "${MODULE}" ] || continue \ MNAME=${MODULE##*/} \ install -m 644 -D ${MODULE}.ko $INSTALLROOT/lib/modules/%{_kernel_ver}/%{-d*}/${MNAME}%{-s:-%{-s*}}.ko \ %{?-s:install -d $INSTALLROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver} \ echo "alias ${MNAME} ${MNAME}-%{-s*}" >> $INSTALLROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver}/%{-n*}.conf} \ done \ unset INSTALLROOT \ %{nil} %install_kernel_modules_compat(m:d:s:n:D:) \ %{!?-m:%{error:%{0}: Required module name (-m) missing}exit 1} \ %{!?-d:%{error:%{0}: Required module directory missing}exit 1} \ %{?-n:%{!?-s:%{error:%{0}: Modprobe .conf file requires module suffix}exit 1}} \ \ INSTALLROOT=%{-D*} \ [ -n "$INSTALLROOT" ] || INSTALLROOT=$RPM_BUILD_ROOT \ \ %{!?debug:set +x;} \ local cfgs='%{?with_dist_kernel:%{?with_smp: smp}%{?with_up: up}}%{!?with_dist_kernel: nondist}' \ \ for MODULE in {%{-m*},}; do \ [ -n "${MODULE}" ] || continue \ for cfg in ${cfgs:-dist}; do \ [ "$cfg" = smp ] && suf=smp || suf= \ MNAME=${MODULE##*/} \ install -m 644 -D ${MODULE}-$cfg.ko \\\ $INSTALLROOT/lib/modules/%{_kernel_ver}$suf/%{-d*}/${MNAME}%{-s:-%{-s*}}.ko \ %{?-s:install -d $INSTALLROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver}$suf \ echo "alias ${MNAME} ${MNAME}-%{-s*}" \\\ >> $INSTALLROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver} $suf/%{-n*}.conf} \ done \ done \ unset INSTALLROOT \ %{nil}