kbuild: rpm-pkg: fix build error when _arch is undefined
authorMasahiro Yamada <masahiroy@kernel.org>
Thu, 14 Jul 2022 05:02:40 +0000 (14:02 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Wed, 27 Jul 2022 12:18:00 +0000 (21:18 +0900)
commit3089b2be0cce14bd026a1018b8f6e5aed8244545
tree12d2e0d3c5c8419a67b4460fb40ee5ff533cc9eb
parent59316eac0e5ba5863594a793f6d8b5d8ccb8e880
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>
scripts/package/mkspec