History log of /linux-master/scripts/package/mkspec
Revision Date Author Comments
# ffa46bbc 30-Sep-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: generate kernel.spec in rpmbuild/SPECS/

kernel.spec is the last piece that resides outside the rpmbuild/
directory. Move all the RPM-related files to rpmbuild/ consistently.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>


# 37477496 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: refactor *rpm-pkg targets

Merge the similar build targets.

Also, make the output location consistent.

Previously, source packages were created in the build directory,
while binary packages under ~/rpmbuild/RPMS/.

Now, Kbuild creates the rpmbuild/ directory in the build directory,
and saves all packages under it.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 49c803cd 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: split out the body of spec file

Most of the lines in the spec file are independent of any build
condition.

Split the body of the spec file into scripts/package/kernel.spec.
scripts/package/mkspec will prepend some env-dependent variables.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 2a291fc3 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: introduce %{with_devel} switch to select devel package

scripts/package/mkspec preprocesses the spec file by sed, but it is
unreadable. This commit removes the last portion of the sed scripting.

Remove the $S$M prefixes from the conditionally generated lines.
Instead, surround the code with %if %{with_devel} ... %endif.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# b537925f 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: run modules_install for non-modular kernel

For the same reason as commit 4243afdb9326 ("kbuild: builddeb: always
make modules_install, to install modules.builtin*"), run modules_install
even when CONFIG_MODULES=n to install modules.builtin*.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 1789fc91 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: invoke the kernel build from rpmbuild for binrpm-pkg

To reduce the preprocess of the spec file, invoke the kernel build
from rpmbuild.

Run init/build-version to increment the release number not only for
binrpm-pkg but also for srcrpm-pkg and rpm-pkg.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# d4f65127 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: use a dummy string for _arch when undefined

If this affects only %{buildroot}, it should be enough to use a fixed
string for _arch when it is undefined.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# d5d2d4cc 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: derive the Version from %{KERNELRELEASE}

Avoid hard-coding the Version field in the generated spec file.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# fe66b5d2 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: refactor kernel-devel RPM package and linux-headers Deb package

The kernel-devel RPM package and the linux-headers Debian package
provide headers and scripts needed for building external modules.

They copy the necessary files in slightly different ways - the RPM
copies almost everything except some exclude patterns, while the Debian
copies less number of files. There is no need to maintain different code
to do the same thing.

Split the Debian code out to scripts/package/install-extmod-build, which
is called from both of the packages.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 93ed5605 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: replace $KERNELRELEASE in spec file with %{KERNELRELEASE}

Avoid hard-coding the value of KERNELRELEASE in the generated spec file.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 5d8e41b5 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: replace $__KERNELRELEASE in spec file with %{version}

${version} will be replaced with the value of the Version field.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# a06d9ef8 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: record ARCH option in spec file

Currently, we rely on the top Makefile defining ARCH option when we
run 'make rpm-pkg' or 'make binrpm-pkg'.

It does not apply when we run 'make srcrpm-pkg', and separately run
'rpmbuild' for the generated SRPM. This is a problem for cross-build.

Just like the Debian package, save the value of ARCH in the spec file.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# fe809b82 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: use %{makeflags} to pass common Make options

This is useful to pass more common Make options.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 19286825 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: do not hard-code $MAKE in spec file

Currently, $MAKE will expand to the GNU Make program that created the
source RPM. This is problematic if you carry it to a different build
host to run 'rpmbuild' there.

Consider this command:

$ /path/to/my/custom/make srcrpm-pkg

The spec file in the SRPM will record '/path/to/my/custom/make', which
exists only on that build environment.

To create a portable SRPM, the spec file should avoid hard-coding $MAKE.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 61eca933 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: remove unneeded '-f $srctree/Makefile' in spec file

This is unneeded because the Makefile in the output directory wraps
the top-level Makefile in the srctree.

Just run $MAKE irrespective of the build location.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 233046a2 21-Jul-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: define _arch conditionally

Commit 3089b2be0cce ("kbuild: rpm-pkg: fix build error when _arch is
undefined") does not work as intended; _arch is always defined as
$UTS_MACHINE.

The intention was to define _arch to $UTS_MACHINE only when it is not
defined.

Fixes: 3089b2be0cce ("kbuild: rpm-pkg: fix build error when _arch is undefined")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# c90b3bbf 17-Apr-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: remove kernel-drm PROVIDES

This code was added more than 20 years ago. [1]

I checked the kernel spec files in Fedora and OpenSUSE, but did not
see 'kernel-drm'. I do not know if there exists a distro that uses it
in RPM dependency.

Remove this, and let's see if somebody complains about it.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=6d956df7d6b716b28c910c4f5b360c4d44d96c4d

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>


# aa7d233f 10-Apr-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: give up untracked files for source package builds

When the source tree is dirty and contains untracked files, package
builds may fail, for example, when a broken symlink exists, a file
path contains whitespaces, etc.

Since commit 05e96e96a315 ("kbuild: use git-archive for source package
creation"), the source tarball only contains committed files because
it is created by 'git archive'. scripts/package/gen-diff-patch tries
to address the diff from HEAD, but including untracked files by the
hand-crafted script introduces more complexity. I wrote a patch [1] to
make it work in most cases, but still wonder if this is what we should
aim for.

To simplify the code, this patch just gives up untracked files. Going
forward, it is your responsibility to do 'git add' for what you want in
the source package. The script shows a warning just in case you forgot
to do so. It should be checked only when building source packages.

[1]: https://lore.kernel.org/all/CAK7LNAShbZ56gSh9PrbLnBDYKnjtTkHMoCXeGrhcxMvqXGq9=g@mail.gmail.com/2-0001-kbuild-make-package-builds-more-robust.patch

Fixes: 05e96e96a315 ("kbuild: use git-archive for source package creation")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>


# 05e96e96 15-Mar-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: use git-archive for source package creation

Commit 5c3d1d0abb12 ("kbuild: add a tool to list files ignored by git")
added a new tool, scripts/list-gitignored. My intention was to create
source packages without cleaning the source tree, without relying on git.

Linus strongly objected to it, and suggested using 'git archive' instead.
[1] [2] [3]

This commit goes in that direction - Remove scripts/list-gitignored.c
and rewrites Makefiles and scripts to use 'git archive' for building
Debian and RPM source packages. It also makes 'make perf-tar*-src-pkg'
use 'git archive' again.

Going forward, building source packages is only possible in a git-managed
tree. Building binary packages does not require git.

[1]: https://lore.kernel.org/lkml/CAHk-=wi49sMaC7vY1yMagk7eqLK=1jHeHQ=yZ_k45P=xBccnmA@mail.gmail.com/
[2]: https://lore.kernel.org/lkml/CAHk-=wh5AixGsLeT0qH2oZHKq0FLUTbyTw4qY921L=PwYgoGVw@mail.gmail.com/
[3]: https://lore.kernel.org/lkml/CAHk-=wgM-W6Fu==EoAVCabxyX8eYBz9kNC88-tm9ExRQwA79UQ@mail.gmail.com/

Fixes: 5c3d1d0abb12 ("kbuild: add a tool to list files ignored by git")
Fixes: e0ca16749ac3 ("kbuild: make perf-tar*-src-pkg work without relying on git")
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 81f59a26 15-Mar-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: move source components to rpmbuild/SOURCES

Prepare to add more files to the source RPM.

Also, fix the build error when KCONFIG_CONFIG is set:
error: Bad file: ./.config: No such file or directory

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 7adf14d8 22-Feb-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: remove unneeded KERNELRELEASE from modules/headers_install

This is a temporary workaround added by commit f6e09b07cc12 ("kbuild:
do not put .scmversion into the source tarball").

Since commit 1cb86b6c3136 ("kbuild: save overridden KERNELRELEASE in
include/config/kernel.release"), the user-supplied KERNELRELEASE is
saved in include/config/kernel.release.

Remove it again.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>


# 6fc91752 14-Feb-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: srcrpm-pkg: create source package without cleaning

If you run 'make (src)rpm-pkg', all objects are lost due to 'make clean',
which makes the incremental builds impossible.

Instead of cleaning, pass the exclude list to tar's --exclude-from
option.

Previously, the .config was contained in the source tarball.

With this commit, the source rpm consists of separate linux.tar.gz
and .config.

Remove stale comments. Now, 'make (src)rpm-pkg' works with O= option.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# f6e09b07 22-Jan-2023 Masahiro Yamada <masahiroy@kernel.org>

kbuild: do not put .scmversion into the source tarball

.scmversion is used by (src)rpm-pkg and deb-pkg to carry KERNELRELEASE.

In fact, deb-pkg does not rely on it any more because the generated
debian/rules specifies KERNELRELEASE from the command line.

Do likwise for (src)rpm-pkg, and remove this feature.
For the same reason, you do not need to save LOCALVERSION in the
spec file.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>


# 169dd780 11-Jan-2023 Arend van Spriel <arend.vanspriel@broadcom.com>

scripts: rpm: make clear that mkspec script contains 4.13 feature

A fix was made in the mkspec script that uses a feature, ie. the
OR expression, which requires RPM 4.13. However, the script indicates
another minimum version. Lower versions may have success by using
the --no-deps option as suggested, but feels like bumping the version
to 4.13 is reasonable as it put me on the wrong track at first with
RPM 4.11 on my Centos7 machine.

Fixes: 02a893bc9975 ("kbuild: rpm-pkg: add libelf-devel as alternative for BuildRequires")
Signed-off-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 02a893bc 28-Dec-2022 Masahiro Yamada <masahiroy@kernel.org>

kbuild: rpm-pkg: add libelf-devel as alternative for BuildRequires

Guoqing Jiang reports that openSUSE cannot compile the kernel rpm due
to "BuildRequires: elfutils-libelf-devel" added by commit 8818039f959b
("kbuild: add ability to make source rpm buildable using koji").
The relevant package name in openSUSE is libelf-devel.

Add it as an alternative package.

BTW, if it is impossible to solve the build requirement, the final
resort would be:

$ make RPMOPTS=--nodeps rpm-pkg

This passes --nodeps to the rpmbuild command so it will not verify
build dependencies. This is useful to test rpm builds on non-rpm
system. On Debian/Ubuntu, for example, you can install rpmbuild by
'apt-get install rpm'.

NOTE1:
Likewise, it is possible to bypass the build dependency check for
debian package builds:

$ make DPKG_FLAGS=-d deb-pkg

NOTE2:
The 'or' operator is supported since RPM 4.13. So, old distros such
as CentOS 7 will break. I suggest installing newer rpmbuild in such
cases.

Link: https://lore.kernel.org/linux-kbuild/ee227d24-9c94-bfa3-166a-4ee6b5dfea09@linux.dev/T/#u
Fixes: 8818039f959b ("kbuild: add ability to make source rpm buildable using koji")
Reported-by: Guoqing Jiang <guoqing.jiang@linux.dev>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Guoqing Jiang <guoqing.jiang@linux.dev>
Acked-by: Jonathan Toppins <jtoppins@redhat.com>


# 8818039f 21-Nov-2022 Ivan Vecera <ivecera@redhat.com>

kbuild: add ability to make source rpm buildable using koji

Changes:
- added new target 'srcrpm-pkg' to generate source rpm
- added required build tools to spec file
- removed locally compiled host tools to force their re-compile

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
Signed-off-by: Jonathan Toppins <jtoppins@redhat.com>
Acked-by: Íñigo Huguet <ihuguet@redhat.com>
Tested-by: Ivan Vecera <ivecera@redhat.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# fc8c2d8f 06-Oct-2022 Zack Rusin <zackr@vmware.com>

kbuild: Stop including vmlinux.bz2 in the rpm's

vmlinux.bz2 was added to the rpm packages in 2009 in the
fc370ecfdb37 ("kbuild: add vmlinux to kernel rpm") but seemingly hasn't
been used since.

Originally this should have been split up in a seperate debugging
package because it massively increases the size of the generated rpm's
e.g. kernel rpm built using binrpm-pkg on Fedora 36 default 5.19.8 kernel
config and localmodconfig is ~255MB with vmlinux.bz2 and only ~65MB
without it.

Make the kernel built rpms about 4x smaller by not including the unused
vmlinux.bz2 in them.

Signed-off-by: Zack Rusin <zackr@vmware.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 2e07005f 16-Sep-2022 Janis Schoetterl-Glausch <scgl@linux.ibm.com>

kbuild: rpm-pkg: fix breakage when V=1 is used

Doing make V=1 binrpm-pkg results in:

Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.EgV6qJ
+ umask 022
+ cd .
+ /bin/rm -rf /home/scgl/rpmbuild/BUILDROOT/kernel-6.0.0_rc5+-1.s390x
+ /bin/mkdir -p /home/scgl/rpmbuild/BUILDROOT
+ /bin/mkdir /home/scgl/rpmbuild/BUILDROOT/kernel-6.0.0_rc5+-1.s390x
+ mkdir -p /home/scgl/rpmbuild/BUILDROOT/kernel-6.0.0_rc5+-1.s390x/boot
+ make -f ./Makefile image_name
+ cp test -e include/generated/autoconf.h -a -e include/config/auto.conf || ( \ echo >&2; \ echo >&2 " ERROR: Kernel configuration is invalid."; \ echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";\ echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \ echo >&2 ; \ /bin/false) arch/s390/boot/bzImage /home/scgl/rpmbuild/BUILDROOT/kernel-6.0.0_rc5+-1.s390x/boot/vmlinuz-6.0.0-rc5+
cp: invalid option -- 'e'
Try 'cp --help' for more information.
error: Bad exit status from /var/tmp/rpm-tmp.EgV6qJ (%install)

Because the make call to get the image name is verbose and prints
additional information.

Fixes: 993bdde94547 ("kbuild: add image_name to no-sync-config-targets")
Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# 3089b2be 13-Jul-2022 Masahiro Yamada <masahiroy@kernel.org>

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>


# 16a122c7 19-Jul-2020 Alexander A. Klimov <grandmaster@al2klimov.de>

kbuild: Replace HTTP links with HTTPS ones

Rationale:
Reduces attack surface on kernel devs opening the links for MITM
as HTTPS traffic is much harder to manipulate.

Deterministic algorithm:
For each file:
If not .svg:
For each line:
If doesn't contain `\bxmlns\b`:
For each link, `\bhttp://[^# \t\r\n]*(?:\w|/)`:
If neither `\bgnu\.org/license`, nor `\bmozilla\.org/MPL\b`:
If both the HTTP and HTTPS versions
return 200 OK and serve the same content:
Replace HTTP with HTTPS.

Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


# b7dca6dd 17-Jul-2019 Masahiro Yamada <yamada.masahiro@socionext.com>

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>


# c93a0368 30-Jun-2019 Masahiro Yamada <yamada.masahiro@socionext.com>

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>


# 21b42eb4 05-Nov-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: rpm-pkg: fix binrpm-pkg breakage when O= is used

Zhenzhong Duan reported that running 'make O=/build/kernel binrpm-pkg'
failed with the following errors:

Running 'make O=/build/kernel binrpm-pkg' failed with below two errors.

Makefile:600: include/config/auto.conf: No such file or directory

+ cp make -C /mnt/root/kernel O=/build/kernel image_name make -f
/mnt/root/kernel/Makefile ...
cp: invalid option -- 'C'
Try 'cp --help' for more information.

Prior to commit 80463f1b7bf9 ("kbuild: add --include-dir flag only
for out-of-tree build"), both srctree and objtree were added to
--include-dir redundantly, and the wrong code 'make image_name'
was working by relying on that. Now, the potential issue that had
previously been hidden just showed up.

'make image_name' recurses to the generated $(objtree)/Makefile and
ends up with running in srctree, which is incorrect. It should be
invoked with '-f $srctree/Makefile' (or KBUILD_SRC=) to be executed
in objtree.

Fixes: 80463f1b7bf9 ("kbuild: add --include-dir flag only for out-of-tree build")
Reported-by: Zhenzhong Duan <zhenzhong.duan@oracle.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# eea6f62b 11-Apr-2018 Javier Martinez Canillas <javierm@redhat.com>

kbuild: rpm-pkg: use kernel-install as a fallback for new-kernel-pkg

The new-kernel-pkg script is only present when grubby is installed, but it
may not always be the case. So if the script isn't present, attempt to use
the kernel-install script as a fallback instead.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 8a6105c4 23-Mar-2018 Jason Gunthorpe <jgg@ziepe.ca>

kbuild: rpm-pkg: Support GNU tar >= 1.29

There is a change in how command line parsing is done in this version.
Excludes and includes are now ordered with the file list. Since
the spec file puts the file list before the exclude list it means newer
tar ignores the excludes and packs all the build output into the
kernel-devel RPM resulting in a huge package.

Simple argument re-ordering fixes the problem.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 002494d8 29-Sep-2017 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: rpm-pkg: replace $RPM_BUILD_ROOT with %{buildroot}

$RPM_BUILD_ROOT must be escaped to prevent shell from expanding it
when generating the spec file.

%{build_root} is more readable than \$RPM_BUILD_ROOT.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 0b7f12f5 29-Sep-2017 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: rpm-pkg: fix build error when CONFIG_MODULES is disabled

When CONFIG_MODULES is disabled, make rpm-pkg / binrpm-pkg fails
with the following message:

The present kernel configuration has modules disabled.
Type 'make config' and enable loadable module support.
Then build a kernel with module support enabled.

Do not install modules in the case. Also, omit the devel package.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 8c5d4b64 29-Sep-2017 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: rpm-pkg: refactor mkspec with here doc

The repeat of echo is unreadable. The here-document is a well-known
device for such scripts. One difficulty is we have a bunch of PREBUILT
conditionals that would split the here-document.

My idea is to add "$S" annotatation to lines only for the source package
spec file, then post-process it by sed. I hope it will make our life
easier than repeat of "cat <<EOF ..."

I confirmed this commit still produced the same (bin)kernel.spec as
before.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 5289c322 29-Sep-2017 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: rpm-pkg: clean up mkspec

Clean up the mkspec without changing the behavior.

- grep CONFIG_DRM=y more simply

- move "EXCLUDE" out of the "%install" section because it can be
computed when the spec file is generated

- remove "BuildRoot:" field, which is now redundant

- do not mkdir $RPM_BUILD_ROOT/lib/modules explicitly because it
is automatically created by "make modules_install"

- exclude "%package devel" from source package spec file because
it does not make sense where "%files devel" is already excluded

- exclude "%build" from source package spec file

- remove unneeded "make clean" because we had already cleaned
before making tar file

- merge two %ifarch ia64 conditionals

- replace KBUILD_IMAGE with direct use of $(make image_name)

- remove trailing empty line from the spec file

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 81771ce2 29-Sep-2017 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: rpm-pkg: install vmlinux.bz2 unconditionally

This conditional was added by commit fc370ecfdb37 ("kbuild: add
vmlinux to kernel rpm"). Its git-log mentioned vmlinux.bz2 was
necessary for debugging, but did not explain why ppc64 was an
exception. I see no problem to copy vmlinux.bz2 all the time.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 6736ce27 29-Sep-2017 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: rpm-pkg: remove ppc64 specific image handling

This conditional was added by commit 1a0f3d422bb9 ("kbuild: fix
make rpm for powerpc"). Its git-log explains the default kernel
image is zImage, but obviously the current arch/powerpc/Makefile
does not set KBUILD_IMAGE, so the image file is actually vmlinux.

Moreover, since commit 09549aa1baa9 ("deb-pkg: Remove the KBUILD_IMAGE
workaround"), all architectures are supposed to set the full path to
the image in KBUILD_IMAGE. I see no good reason to differentiate
ppc64 from others. Rip off the conditional.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 25b080bd 20-Sep-2017 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: rpm-pkg: fix version number handling

The "Release:" field of the spec file is determined based on the
.version file.

However, the .version file is not copied to the source tar file.
So, when we build the kernel from the source package, the UTS_VERSION
always indicates #1. This does not match with "rpm -q".

The kernel UTS_VERSION and "rpm -q" do not agree for binrpm-pkg, either.
Please note the kernel has already been built before the spec file is
created. Currently, mkspec invokes mkversion. This script returns an
incremented version. So, the "Release:" field of the spec file is
greater than the version in the kernel by one.

For the source package build (where .version file is missing), we can
give KBUILD_BUILD_VERSION=%{release} to the build command.

For the binary package build, we can simply read out the .version file
because it contains the version number that was used for building the
kernel image.

We can remove scripts/mkversion because scripts/package/Makefile need
not touch the .version file.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# 9e090074 18-Sep-2017 Masahiro Yamada <yamada.masahiro@socionext.com>

kbuild: rpm-pkg: delete firmware_install to fix build error

Commit 5620a0d1aacd ("firmware: delete in-kernel firmware") deleted
in-kernel firmware support, including "make firmware_install".

Since then, "make rpm-pkg" / "make binrpm-pkg" fails to build with
the error:

make[2]: *** No rule to make target `firmware_install'. Stop.

Commit df85b2d767aa ("firmware: Restore support for built-in firmware")
restored the build infrastructure for CONFIG_EXTRA_FIRMWARE, but this
is out of the scope of "make firmware_install". So, the right thing to
do is to kill the use of "make firmware_install".

Fixes: 5620a0d1aacd ("firmware: delete in-kernel firmware")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 51a5f810 25-Oct-2016 Anton Tikhomirov <anton.tikhomirov@cdnetworks.com>

kbuild/mkspec: avoid using brace expansion

Brace expansion might not work properly if _buildshell RPM macro
points to a shell other than bash. Particularly, with _bulidshell
defined to /bin/dash it leads to broken build and source symlinks.

Signed-off-by: Anton Tikhomirov <anton.tikhomirov@cdnetworks.com>
Signed-off-by: Michal Marek <mmarek@suse.com>


# 27c3bffd 07-Apr-2016 Jiri Kosina <jkosina@suse.cz>

kbuild/mkspec: support 'update-bootloader'-based systems

When uninstalling kernel RPM, we're unconditionally calling
"new-kernel-pkg --remove". This is useless on systems which are based on
'update-bootloader' script instead.

Support update-bootloader removal method as well in case the script is
present; contrary to new-kernel-pkg, this needs to be done in %postun,
otherwise update-bootloader will refuse to remove entry for kernel for
which the binary still exists.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Michal Marek <mmarek@suse.com>


# 6ef41e22 02-Mar-2016 Paolo Abeni <pabeni@redhat.com>

kbuild/mkspec: clean boot loader configuration on rpm removal

This patch add a rpm preuninstall scriptlet to cleanup the
boot loader configuration on kernel package uninstall.
The initrd for the to-be-removed kernel is deleted, too.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Michal Marek <mmarek@suse.com>


# c8b08ca5 26-Feb-2016 Jiri Kosina <jkosina@suse.cz>

kbuild/mkspec: fix grub2 installkernel issue

mkspec is copying built kernel to temporrary location

/boot/vmlinuz-$KERNELRELEASE-rpm

and runs installkernel on it. This however directly leads to grub2
menuentry for this suffixed binary being generated as well during the run
of installkernel script.

Later in the process the temporary -rpm suffixed files are removed, and
therefore we end up with spurious (and non-functional) grub2 menu entries
for each installed kernel RPM.

Fix that by using a different temporary name (prefixed by '.'), so that
the binary is not recognized as an actual kernel binary and no menuentry
is created for it.

Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Fixes: 3c9c7a14b627 ("rpm-pkg: add %post section to create initramfs and grub hooks")
Signed-off-by: Michal Marek <mmarek@suse.com>


# a9dd941d 13-Aug-2015 Mike Marciniszyn <mike.marciniszyn@intel.com>

kbuild: avoid listing /lib/modules in kernel spec file

This causes conflicts when using multiple kernels built
with this mechanism.

Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Michal Marek <mmarek@suse.com>


# 92f43c45 18-Apr-2015 Borislav Petkov <bp@suse.de>

kbuild/mkspec: Simplify vmlinux.bz2 creation

No need for the intermediary vmlinux.orig - bzip2 can keep the original
files used for compression with --keep.

Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# b9a54424 04-Dec-2014 Jérôme Glisse <jglisse@redhat.com>

scripts/package: binrpm-pkg do not create source and devel package

When doing make binrpm-pkg we only want to build the binary and header
package as the documentation of binrpm-pkg target claims. Hence this
patch avoid building the source and devel package. This makes binrpm-pkg
target lot faster and way more usefull.

Signed-off-by: Jérôme Glisse <jglisse@redhat.com>
Cc: Michal Marek <mmarek@suse.cz>
[mmarek: used subject line from v3]
Signed-off-by: Michal Marek <mmarek@suse.cz>


# 2174d292 08-Jul-2013 Mike Marciniszyn <mike.marciniszyn@intel.com>

rpm-pkg: add generation of kernel-devel

Change the spec file to generate a kernel-devel module
allowing for compilation of external kernel modules.

This patch requires a new minimum RPM level of 4.0.3.

Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# 41612378 24-Jun-2013 Mike Marciniszyn <mike.marciniszyn@intel.com>

rpm-pkg: install firmware files in kernel relative directory

Prior to this patch, firmware files were being installed
in /lib/firmware with a potential conflict with already
installed kernels.

firmware files are now installed in /lib/firmware/<release>
and packaged with the rest of the modules.

Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# 3c9c7a14 24-Jun-2013 Mike Marciniszyn <mike.marciniszyn@intel.com>

rpm-pkg: add %post section to create initramfs and grub hooks

/sbin/installkernel is used to insure grub hooks are
inserted and the initramfs is created on the
target system.

The invokation installkernel will work with any
kernel as long as:
- /sbin/installkernel exists
- the kernel and sysem map files are readable

Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# c398ff00 24-Jun-2013 Mike Marciniszyn <mike.marciniszyn@intel.com>

kbuild: fix error when building from src rpm

The following issue can be reproduced with Linus' tree on
an x86_64 server.

>+ cp /home/user/rpmbuild-test/BUILDROOT/kernel-3.9.2.x86_64/boot/vmlinuz-3.9.2
>cp: missing destination file operand after
>/home/user/rpmbuild-test/BUILDROOT/kernel-3.9.2-1.x86_64/boot/vmlinuz-3.9.2'
>Try `cp --help' for more information.
>error: Bad exit status from /var/tmp/rpm-tmp.R4o0iI (%install)

Here are the commands to reproduce:

make defconfig
make rpm-pkg

Use the resulting src rpm to build as follows:

mkdir ~/rpmbuild-test
cd ~/rpmbuild-test
rpmbuild --rebuild --define "_topdir `pwd`" -vv ~/rpmbuild/SRPMS/kernel-3.10.0_rc1+-1.src.rpm

The issue is because the %install script uses $KBUILD_IMAGE and it hasn't
been set since it is only available in the kbuild system and not in the
%install script.

This patch adds a Makefile target to emit the image_name that can be used
and modifies the mkspec to use the dynamic name in %install.

Signed-off-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# e0367a61 12-Jan-2013 David R. Bild <drbild@umich.edu>

kbuild: clear KBUILD_SRC when calling 'make' in RPM spec

'make rpm-pkg' and 'make binrpm-pkg' fail when the kernel source is
read-only. Specifically, when the RPM spec generated by
scripts/package/mkspec is run, KBUILD_SRC happens to be set to the
source location and thus the invocation of 'make headers_install'
fails when an internal call to 'filechk' tries to write a file into
the source tree.

The fix is to clear KBUILD_SRC for the 'make headers_install'
invocation in the spec file, as is already done for the 'make
modules_install' invocation.

Signed-off-by: David R. Bild <drbild@umich.edu>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# 0bd41dfc 17-May-2011 Arun Sharma <asharma@fb.com>

kbuild: Create a kernel-headers RPM

To compile binaries which depend on new kernel interfaces, we need a
kernel-headers RPM

Signed-off-by: Arun Sharma <asharma@fb.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# e1287eb8 04-May-2011 Arun Sharma <asharma@fb.com>

Replace '-' in kernel version with '_'

Removing the '-' results in hard to read filenames such as:
kernel-2.6.35.2000042g76e4caf-28.x86_64.rpm

kernel-2.6.35.2_000042_g76e4caf-28.x86_64.rpm is easier to
read.

Signed-off-by: Arun Sharma <asharma@fb.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# c2d5a730 13-Oct-2010 Nishanth Aravamudan <nacc@us.ibm.com>

scripts/package: don't break if %{_smp_mflags} isn't set

Same fix as in 13797b77d419fc1b16eebf2993bf7b5cea65f0bf is needed for the "new"
line invoking _smp_mflags for modules_install. Without the fix, `make
binrpm-pkg` fails with:

+ make '%{_smp_mflags}' KBUILD_SRC= modules_install
make[2]: warning: jobserver unavailable: using -j1. Add `+' to parent make rule.
make[2]: *** No rule to make target `%{_smp_mflags}'. Stop.
error: Bad exit status from /var/tmp/rpm-tmp.8S9B9e (%install)

Signed-off-by: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# f77f13e2 29-Mar-2010 Gilles Espinasse <g.esp@free.fr>

Fix comment and Kconfig typos for 'require' and 'fragment'

Signed-off-by: Gilles Espinasse <g.esp@free.fr>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>


# 880df92f 31-Jan-2010 John Saalwaechter <saalwaechter@gmail.com>

scripts: use %_tmppath in "make rpm-pkg"

The mkspec script hardcodes "/var/tmp" into the generated rpm spec file's
BuildRoot. The user, however, may have a custom setting for %_tmppath,
which should be used in BuildRoot. This patch changes mkspec's
BuildRoot output to appropriately use %_tmppath.

Signed-off-by: John Saalwaechter <saalwaechter@gmail.com>
Signed-off-by: Michal Marek <mmarek@suse.cz>


# db9038c8 25-Aug-2009 Frans Pop <elendil@planet.nl>

kbuild: fix the binrpm-pkg target to work with KBUILD_OUTPUT set

The binrpm-pkg target (binary RPM only) fails when called with
KBUILD_OUTPUT set. This patch makes it work.

For the rpm-pkg target (source + binary RPM), building with
KBUILD_OUTPUT set is not possible and also not needed as the
actual build is done in a temporary directory anyway, so check
that KBUILD_OUTPUT is not set in that case to avoid later errors.

Signed-off-by: Frans Pop <elendil@planet.nl>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# a2ebcc7a 22-Feb-2009 Josh Hunt <josh@scalex86.org>

kbuild: fix mkspec to cleanup RPM_BUILD_ROOT

The contents of the %clean section in mkspec is currently commented
out leaving RPM_BUILD_ROOT and its contents on the build machine.
This patch removes it once the rpm build process is complete.

Signed-off-by: Josh Hunt <josh@scalex86.org>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# fc370ecf 11-Feb-2009 Josh Hunt <josh@scalex86.org>

kbuild: add vmlinux to kernel rpm

We are building an automated system to test kernels weekly and need to
provide an rpm to our QA dept. We would like to use the ability to create
kernel rpms already in the kernel's Makefile, but need the vmlinux file
included in the rpm for later debugging.

This patch adds a compressed vmlinux to the kernel rpm when doing a
make rpm-pkg or binrpm-pkg and upon install places the vmlinux file in /boot.

Signed-off-by: Josh Hunt <josh@scalex86.org>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# 13797b77 25-Oct-2008 Jeremy Kerr <jk@ozlabs.org>

scripts/package: don't break if %{_smp_mflags} isn't set

Currently, if we do a 'make rpm-pkg' without the _smp_mflags rpm macro
defined, the build fails with:

[snip]
Executing(%build): /bin/bash -e /var/tmp/rpm-tmp.67959
+ umask 022
+ cd /home/jk/devel/kernel-snapshot/rpm/BUILD
+ cd kernel-2.6.26
+ make clean
+ make '%{_smp_mflags}'
make[3]: *** No rule to make target `%{_smp_mflags}'. Stop.
error: Bad exit status from /var/tmp/rpm-tmp.67959 (%build)

This change uses the 'null if not set' reference to the _smp_mflags
macro instead.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# 46dca86c 15-Oct-2008 Evgeniy Manachkin <sfstudio@mail.ru>

kbuild: mkspec - fix build rpm

This is patch to fix incorrect mkspec script to make rpm correctly at 2.6.27 vanilla kernel.
This is regression in 2.6.27. 2.6.26 make rpm work good.
In 2.6.27 'make rpm' say error from rpmbuild "Many unpacked files (*.fw)."

Signed-off-by: Evgeniy Manachkin <sfstudio@mail.ru>
Acked-by: Alan Cox <alan@redhat.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Stable <stable@kernel.org>


# a5fa393b 14-Aug-2006 Rolf Eike Beer <eike-kernel@sf-tec.de>

kbuild: fix "mkdir -p" usage in scripts/package/mkspec

"mkdir -p" does not only mean not to complain if the directory already
exists, but also to create the parent directories if needed. This patch
removes "lib" from the list of directories to create as we will also create
"lib/modules".

Signed-off-by: Rolf Eike Beer <eike-kernel@sf-tec.de>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# 1a0f3d42 02-Jun-2006 Mike Wolf <mjw@us.ibm.com>

kbuild: fix make rpm for powerpc

The default target for most powerpc platforms is zImage. The
zImage however is in arch/powerpc/boot and the mkspec script
was set up to get the kernel from the top level of the kernel
tree. This patch copies vmlinux to arch/powerpc/boot and then
copies the kernel to the tmp directory so the rpm can be made.

Signed-off-by: Mike Wolf <mjw@us.ibm.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# d2cb1a95 29-Jul-2004 Greg Edwards <edwardsg@sgi.com>

[PATCH] kbuild: add ia64 support to rpm Makefile target

On ia64, only the EFI (fat) partition is available to boot from. The rpm
needs to install the kernel under /boot/efi to be useable on ia64.

Signed-off-by: Greg Edwards <edwardsg@sgi.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>


# 1da177e4 16-Apr-2005 Linus Torvalds <torvalds@ppc970.osdl.org>

Linux-2.6.12-rc2

Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.

Let it rip!