2005-04-16 22:20:36 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2013-07-08 17:14:06 +00:00
|
|
|
# Output a simple RPM spec file.
|
|
|
|
# This version assumes a minimum of RPM 4.0.3.
|
2005-04-16 22:20:36 +00:00
|
|
|
#
|
|
|
|
# The only gothic bit here is redefining install_post to avoid
|
|
|
|
# stripping the symbols from files in the kernel which we want
|
|
|
|
#
|
|
|
|
# Patched for non-x86 by Opencon (L) 2002 <opencon@rio.skydome.net>
|
|
|
|
#
|
|
|
|
|
|
|
|
# how we were called determines which rpms we build and how we build them
|
2017-09-30 01:10:05 +00:00
|
|
|
if [ "$1" = prebuilt ]; then
|
2017-09-30 01:10:06 +00:00
|
|
|
S=DEL
|
2018-11-05 07:51:49 +00:00
|
|
|
MAKE="$MAKE -f $srctree/Makefile"
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2017-09-30 01:10:06 +00:00
|
|
|
S=
|
2005-04-16 22:20:36 +00:00
|
|
|
fi
|
|
|
|
|
2017-09-30 01:10:07 +00:00
|
|
|
if grep -q CONFIG_MODULES=y .config; then
|
|
|
|
M=
|
|
|
|
else
|
|
|
|
M=DEL
|
|
|
|
fi
|
|
|
|
|
2017-09-30 01:10:05 +00:00
|
|
|
if grep -q CONFIG_DRM=y .config; then
|
2005-04-16 22:20:36 +00:00
|
|
|
PROVIDES=kernel-drm
|
|
|
|
fi
|
|
|
|
|
|
|
|
PROVIDES="$PROVIDES kernel-$KERNELRELEASE"
|
2017-09-30 01:10:05 +00:00
|
|
|
__KERNELRELEASE=$(echo $KERNELRELEASE | sed -e "s/-/_/g")
|
kbuild: create *.mod with full directory path and remove MODVERDIR
While descending directories, Kbuild produces objects for modules,
but do not link final *.ko files; it is done in the modpost.
To keep track of modules, Kbuild creates a *.mod file in $(MODVERDIR)
for every module it is building. Some post-processing steps read the
necessary information from *.mod files. This avoids descending into
directories again. This mechanism was introduced in 2003 or so.
Later, commit 551559e13af1 ("kbuild: implement modules.order") added
modules.order. So, we can simply read it out to know all the modules
with directory paths. This is easier than parsing the first line of
*.mod files.
$(MODVERDIR) has a flat directory structure, that is, *.mod files
are named only with base names. This is based on the assumption that
the module name is unique across the tree. This assumption is really
fragile.
Stephen Rothwell reported a race condition caused by a module name
conflict:
https://lkml.org/lkml/2019/5/13/991
In parallel building, two different threads could write to the same
$(MODVERDIR)/*.mod simultaneously.
Non-unique module names are the source of all kind of troubles, hence
commit 3a48a91901c5 ("kbuild: check uniqueness of module names")
introduced a new checker script.
However, it is still fragile in the build system point of view because
this race happens before scripts/modules-check.sh is invoked. If it
happens again, the modpost will emit unclear error messages.
To fix this issue completely, create *.mod with full directory path
so that two threads never attempt to write to the same file.
$(MODVERDIR) is no longer needed.
Since modules with directory paths are listed in modules.order, Kbuild
is still able to find *.mod files without additional descending.
I also killed cmd_secanalysis; scripts/mod/sumversion.c computes MD4 hash
for modules with MODULE_VERSION(). When CONFIG_DEBUG_SECTION_MISMATCH=y,
it occurs not only in the modpost stage, but also during directory
descending, where sumversion.c may parse stale *.mod files. It would emit
'No such file or directory' warning when an object consisting a module is
renamed, or when a single-obj module is turned into a multi-obj module or
vice versa.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Nicolas Pitre <nico@fluxnic.net>
2019-07-17 06:17:57 +00:00
|
|
|
EXCLUDES="$RCS_TAR_IGNORE --exclude=*vmlinux* --exclude=*.mod \
|
2017-09-30 01:10:05 +00:00
|
|
|
--exclude=*.o --exclude=*.ko --exclude=*.cmd --exclude=Documentation \
|
kbuild: do not create wrappers for header-test-y
header-test-y does not work with headers in sub-directories.
For example, you may want to write a Makefile, like this:
include/linux/Kbuild:
header-test-y += mtd/nand.h
This entry will create a wrapper include/linux/mtd/nand.hdrtest.c
with the following content:
#include "mtd/nand.h"
To make this work, we need to add $(srctree)/include/linux to the
header search path. It would be tedious to add ccflags-y.
Instead, we could change the *.hdrtest.c rule to wrap:
#include "nand.h"
This works for in-tree build since #include "..." searches in the
relative path from the header with this directive. For O=... build,
we need to add $(srctree)/include/linux/mtd to the header search path,
which will be even more tedious.
After all, I thought it would be handier to compile headers directly
without creating wrappers.
I added a new build rule to compile %.h into %.h.s
The target is %.h.s instead of %.h.o because it is slightly faster.
Also, as for GCC, an empty assembly is smaller than an empty object.
I wrote the build rule:
$(CC) $(c_flags) -S -o $@ -x c /dev/null -include $<
instead of:
$(CC) $(c_flags) -S -o $@ -x c $<
Both work fine with GCC, but the latter is bad for Clang.
This comes down to the difference in the -Wunused-function policy.
GCC does not warn about unused 'static inline' functions at all.
Clang does not warn about the ones in included headers, but does
about the ones in the source. So, we should handle headers as
headers, not as source files.
In fact, this has been hidden since commit abb2ea7dfd82 ("compiler,
clang: suppress warning for unused static inline functions"), but we
should not rely on that.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Jani Nikula <jani.nikula@intel.com>
Tested-by: Jani Nikula <jani.nikula@intel.com>
2019-07-01 00:58:41 +00:00
|
|
|
--exclude=.config.old --exclude=.missing-syscalls.d --exclude=*.s"
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-09-30 01:10:06 +00:00
|
|
|
# We can label the here-doc lines for conditional output to the spec file
|
|
|
|
#
|
|
|
|
# Labels:
|
|
|
|
# $S: this line is enabled only when building source package
|
2017-09-30 01:10:07 +00:00
|
|
|
# $M: this line is enabled only when CONFIG_MODULES is enabled
|
2017-09-30 01:10:06 +00:00
|
|
|
sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
|
|
|
|
Name: kernel
|
|
|
|
Summary: The Linux Kernel
|
|
|
|
Version: $__KERNELRELEASE
|
|
|
|
Release: $(cat .version 2>/dev/null || echo 1)
|
|
|
|
License: GPL
|
|
|
|
Group: System Environment/Kernel
|
|
|
|
Vendor: The Linux Community
|
2020-07-19 19:46:02 +00:00
|
|
|
URL: https://www.kernel.org
|
2017-09-30 01:10:06 +00:00
|
|
|
$S Source: kernel-$__KERNELRELEASE.tar.gz
|
|
|
|
Provides: $PROVIDES
|
kbuild: rpm-pkg: fix build error when _arch is undefined
Cross-building (bin)rpm-pkg fails on several architectures.
For example, 'make ARCH=arm binrpm-pkg' fails like follows:
sh ./scripts/package/mkspec prebuilt > ./binkernel.spec
rpmbuild --define "_builddir ." --target \
arm -bb ./binkernel.spec
Building target platforms: arm
Building for target arm
warning: line 19: It's not recommended to have unversioned Obsoletes: Obsoletes: kernel-headers
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.0S8t2F
+ umask 022
+ cd .
+ mkdir -p /home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.%{_arch}/boot
+ make -f ./Makefile image_name
+ cp arch/arm/boot/zImage /home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.%{_arch}/boot/vmlinuz-5.19.0-rc6
+ make -f ./Makefile INSTALL_MOD_PATH=/home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.%{_arch} modules_install
make[3]: *** No rule to make target '/home/masahiro/rpmbuild/BUILDROOT/kernel-5.19.0_rc6-19.arch/arm/crypto/aes-arm-bs.ko{_arch}/lib/modules/5.19.0-rc6/kernel/%', needed by '__modinst'. Stop.
make[2]: *** [Makefile:1768: modules_install] Error 2
error: Bad exit status from /var/tmp/rpm-tmp.0S8t2F (%install)
By default, 'buildroot' contains %{_arch} (see /usr/lib/rpm/macros).
_arch is generally defined in /usr/lib/rpm/platforms/*/macros, where
the platform sub-directory is specified by --target= option for cross
builds.
If the given arch does not exist, %{_arch} is not expanded.
In the example above, --target=arm is passed to rpmbuild, but
/usr/lib/rpm/platforms/arm-linux/ does not exist.
The '%' character in the path confuses GNU make and rpmbuild.
The same occurs for such architectures as csky, microblaze, nios2, etc.
Define _arch if it has not been defined.
Reported-by: Jason Self <jason@bluehome.net>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2022-07-14 05:02:40 +00:00
|
|
|
# $UTS_MACHINE as a fallback of _arch in case
|
|
|
|
# /usr/lib/rpm/platform/*/macros was not included.
|
|
|
|
%define _arch %{?_arch:$UTS_MACHINE}
|
2017-09-30 01:10:06 +00:00
|
|
|
%define __spec_install_post /usr/lib/rpm/brp-compress || :
|
|
|
|
%define debug_package %{nil}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-09-30 01:10:06 +00:00
|
|
|
%description
|
|
|
|
The Linux Kernel, the operating system core itself
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-09-30 01:10:06 +00:00
|
|
|
%package headers
|
|
|
|
Summary: Header files for the Linux kernel for use by glibc
|
|
|
|
Group: Development/System
|
|
|
|
Obsoletes: kernel-headers
|
|
|
|
Provides: kernel-headers = %{version}
|
|
|
|
%description headers
|
|
|
|
Kernel-headers includes the C header files that specify the interface
|
|
|
|
between the Linux kernel and userspace libraries and programs. The
|
|
|
|
header files define structures and constants that are needed for
|
|
|
|
building most standard programs and are also needed for rebuilding the
|
|
|
|
glibc package.
|
2017-09-30 01:10:05 +00:00
|
|
|
|
2017-09-30 01:10:07 +00:00
|
|
|
$S$M %package devel
|
|
|
|
$S$M Summary: Development package for building kernel modules to match the $__KERNELRELEASE kernel
|
|
|
|
$S$M Group: System Environment/Kernel
|
|
|
|
$S$M AutoReqProv: no
|
|
|
|
$S$M %description -n kernel-devel
|
|
|
|
$S$M This package provides kernel headers and makefiles sufficient to build modules
|
|
|
|
$S$M against the $__KERNELRELEASE kernel package.
|
|
|
|
$S$M
|
2017-09-30 01:10:06 +00:00
|
|
|
$S %prep
|
|
|
|
$S %setup -q
|
|
|
|
$S
|
|
|
|
$S %build
|
2018-11-05 07:51:49 +00:00
|
|
|
$S $MAKE %{?_smp_mflags} KBUILD_BUILD_VERSION=%{release}
|
2017-09-30 01:10:06 +00:00
|
|
|
$S
|
|
|
|
%install
|
2017-09-30 01:10:08 +00:00
|
|
|
mkdir -p %{buildroot}/boot
|
2017-09-30 01:10:06 +00:00
|
|
|
%ifarch ia64
|
2017-09-30 01:10:08 +00:00
|
|
|
mkdir -p %{buildroot}/boot/efi
|
2022-09-16 12:41:12 +00:00
|
|
|
cp \$($MAKE -s image_name) %{buildroot}/boot/efi/vmlinuz-$KERNELRELEASE
|
2017-09-30 01:10:08 +00:00
|
|
|
ln -s efi/vmlinuz-$KERNELRELEASE %{buildroot}/boot/
|
2017-09-30 01:10:06 +00:00
|
|
|
%else
|
2022-09-16 12:41:12 +00:00
|
|
|
cp \$($MAKE -s image_name) %{buildroot}/boot/vmlinuz-$KERNELRELEASE
|
2017-09-30 01:10:06 +00:00
|
|
|
%endif
|
2018-11-05 07:51:49 +00:00
|
|
|
$M $MAKE %{?_smp_mflags} INSTALL_MOD_PATH=%{buildroot} modules_install
|
|
|
|
$MAKE %{?_smp_mflags} INSTALL_HDR_PATH=%{buildroot}/usr headers_install
|
2017-09-30 01:10:08 +00:00
|
|
|
cp System.map %{buildroot}/boot/System.map-$KERNELRELEASE
|
|
|
|
cp .config %{buildroot}/boot/config-$KERNELRELEASE
|
|
|
|
$S$M rm -f %{buildroot}/lib/modules/$KERNELRELEASE/build
|
|
|
|
$S$M rm -f %{buildroot}/lib/modules/$KERNELRELEASE/source
|
|
|
|
$S$M mkdir -p %{buildroot}/usr/src/kernels/$KERNELRELEASE
|
2018-03-23 17:59:36 +00:00
|
|
|
$S$M tar cf - $EXCLUDES . | tar xf - -C %{buildroot}/usr/src/kernels/$KERNELRELEASE
|
2017-09-30 01:10:08 +00:00
|
|
|
$S$M cd %{buildroot}/lib/modules/$KERNELRELEASE
|
2017-09-30 01:10:07 +00:00
|
|
|
$S$M ln -sf /usr/src/kernels/$KERNELRELEASE build
|
|
|
|
$S$M ln -sf /usr/src/kernels/$KERNELRELEASE source
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-09-30 01:10:06 +00:00
|
|
|
%clean
|
2017-09-30 01:10:08 +00:00
|
|
|
rm -rf %{buildroot}
|
2009-02-12 05:10:57 +00:00
|
|
|
|
2017-09-30 01:10:06 +00:00
|
|
|
%post
|
|
|
|
if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then
|
|
|
|
cp /boot/vmlinuz-$KERNELRELEASE /boot/.vmlinuz-$KERNELRELEASE-rpm
|
|
|
|
cp /boot/System.map-$KERNELRELEASE /boot/.System.map-$KERNELRELEASE-rpm
|
|
|
|
rm -f /boot/vmlinuz-$KERNELRELEASE /boot/System.map-$KERNELRELEASE
|
|
|
|
/sbin/installkernel $KERNELRELEASE /boot/.vmlinuz-$KERNELRELEASE-rpm /boot/.System.map-$KERNELRELEASE-rpm
|
|
|
|
rm -f /boot/.vmlinuz-$KERNELRELEASE-rpm /boot/.System.map-$KERNELRELEASE-rpm
|
|
|
|
fi
|
2013-07-08 17:14:06 +00:00
|
|
|
|
2017-09-30 01:10:06 +00:00
|
|
|
%preun
|
|
|
|
if [ -x /sbin/new-kernel-pkg ]; then
|
|
|
|
new-kernel-pkg --remove $KERNELRELEASE --rminitrd --initrdfile=/boot/initramfs-$KERNELRELEASE.img
|
2018-04-11 18:15:24 +00:00
|
|
|
elif [ -x /usr/bin/kernel-install ]; then
|
|
|
|
kernel-install remove $KERNELRELEASE
|
2017-09-30 01:10:06 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
%postun
|
|
|
|
if [ -x /sbin/update-bootloader ]; then
|
|
|
|
/sbin/update-bootloader --remove $KERNELRELEASE
|
|
|
|
fi
|
|
|
|
|
|
|
|
%files
|
|
|
|
%defattr (-, root, root)
|
2017-09-30 01:10:07 +00:00
|
|
|
$M /lib/modules/$KERNELRELEASE
|
|
|
|
$M %exclude /lib/modules/$KERNELRELEASE/build
|
|
|
|
$M %exclude /lib/modules/$KERNELRELEASE/source
|
2017-09-30 01:10:06 +00:00
|
|
|
/boot/*
|
|
|
|
|
|
|
|
%files headers
|
|
|
|
%defattr (-, root, root)
|
|
|
|
/usr/include
|
2017-09-30 01:10:07 +00:00
|
|
|
$S$M
|
|
|
|
$S$M %files devel
|
|
|
|
$S$M %defattr (-, root, root)
|
|
|
|
$S$M /usr/src/kernels/$KERNELRELEASE
|
|
|
|
$S$M /lib/modules/$KERNELRELEASE/build
|
|
|
|
$S$M /lib/modules/$KERNELRELEASE/source
|
2017-09-30 01:10:06 +00:00
|
|
|
EOF
|