Commit 8c5d4b64 authored by Masahiro Yamada's avatar Masahiro Yamada

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: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
parent 5289c322
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
# how we were called determines which rpms we build and how we build them # how we were called determines which rpms we build and how we build them
if [ "$1" = prebuilt ]; then if [ "$1" = prebuilt ]; then
PREBUILT=true S=DEL
else else
PREBUILT=false S=
fi fi
if grep -q CONFIG_DRM=y .config; then if grep -q CONFIG_DRM=y .config; then
...@@ -26,120 +26,112 @@ EXCLUDES="$RCS_TAR_IGNORE --exclude=.tmp_versions --exclude=*vmlinux* \ ...@@ -26,120 +26,112 @@ EXCLUDES="$RCS_TAR_IGNORE --exclude=.tmp_versions --exclude=*vmlinux* \
--exclude=*.o --exclude=*.ko --exclude=*.cmd --exclude=Documentation \ --exclude=*.o --exclude=*.ko --exclude=*.cmd --exclude=Documentation \
--exclude=.config.old --exclude=.missing-syscalls.d" --exclude=.config.old --exclude=.missing-syscalls.d"
echo "Name: kernel" # We can label the here-doc lines for conditional output to the spec file
echo "Summary: The Linux Kernel" #
echo "Version: $__KERNELRELEASE" # Labels:
echo "Release: $(cat .version 2>/dev/null || echo 1)" # $S: this line is enabled only when building source package
echo "License: GPL" sed -e '/^DEL/d' -e 's/^\t*//' <<EOF
echo "Group: System Environment/Kernel" Name: kernel
echo "Vendor: The Linux Community" Summary: The Linux Kernel
echo "URL: http://www.kernel.org" Version: $__KERNELRELEASE
Release: $(cat .version 2>/dev/null || echo 1)
License: GPL
Group: System Environment/Kernel
Vendor: The Linux Community
URL: http://www.kernel.org
$S Source: kernel-$__KERNELRELEASE.tar.gz
Provides: $PROVIDES
%define __spec_install_post /usr/lib/rpm/brp-compress || :
%define debug_package %{nil}
if ! $PREBUILT; then %description
echo "Source: kernel-$__KERNELRELEASE.tar.gz" The Linux Kernel, the operating system core itself
fi
echo "Provides: $PROVIDES" %package headers
echo "%define __spec_install_post /usr/lib/rpm/brp-compress || :" Summary: Header files for the Linux kernel for use by glibc
echo "%define debug_package %{nil}" Group: Development/System
echo "" Obsoletes: kernel-headers
echo "%description" Provides: kernel-headers = %{version}
echo "The Linux Kernel, the operating system core itself" %description headers
echo "" Kernel-headers includes the C header files that specify the interface
echo "%package headers" between the Linux kernel and userspace libraries and programs. The
echo "Summary: Header files for the Linux kernel for use by glibc" header files define structures and constants that are needed for
echo "Group: Development/System" building most standard programs and are also needed for rebuilding the
echo "Obsoletes: kernel-headers" glibc package.
echo "Provides: kernel-headers = %{version}"
echo "%description headers"
echo "Kernel-headers includes the C header files that specify the interface"
echo "between the Linux kernel and userspace libraries and programs. The"
echo "header files define structures and constants that are needed for"
echo "building most standard programs and are also needed for rebuilding the"
echo "glibc package."
echo ""
if ! $PREBUILT; then $S %package devel
echo "%package devel" $S Summary: Development package for building kernel modules to match the $__KERNELRELEASE kernel
echo "Summary: Development package for building kernel modules to match the $__KERNELRELEASE kernel" $S Group: System Environment/Kernel
echo "Group: System Environment/Kernel" $S AutoReqProv: no
echo "AutoReqProv: no" $S %description -n kernel-devel
echo "%description -n kernel-devel" $S This package provides kernel headers and makefiles sufficient to build modules
echo "This package provides kernel headers and makefiles sufficient to build modules" $S against the $__KERNELRELEASE kernel package.
echo "against the $__KERNELRELEASE kernel package." $S
echo "" $S %prep
echo "%prep" $S %setup -q
echo "%setup -q" $S
echo "" $S %build
echo "%build" $S make %{?_smp_mflags} KBUILD_BUILD_VERSION=%{release}
echo "make %{?_smp_mflags} KBUILD_BUILD_VERSION=%{release}" $S
echo "" %install
fi mkdir -p \$RPM_BUILD_ROOT/boot
%ifarch ia64
mkdir -p \$RPM_BUILD_ROOT/boot/efi
cp \$(make image_name) \$RPM_BUILD_ROOT/boot/efi/vmlinuz-$KERNELRELEASE
ln -s efi/vmlinuz-$KERNELRELEASE \$RPM_BUILD_ROOT/boot/
%else
cp \$(make image_name) \$RPM_BUILD_ROOT/boot/vmlinuz-$KERNELRELEASE
%endif
make %{?_smp_mflags} INSTALL_MOD_PATH=\$RPM_BUILD_ROOT KBUILD_SRC= modules_install
make %{?_smp_mflags} INSTALL_HDR_PATH=\$RPM_BUILD_ROOT/usr KBUILD_SRC= headers_install
cp System.map \$RPM_BUILD_ROOT/boot/System.map-$KERNELRELEASE
cp .config \$RPM_BUILD_ROOT/boot/config-$KERNELRELEASE
bzip2 -9 --keep vmlinux
mv vmlinux.bz2 \$RPM_BUILD_ROOT/boot/vmlinux-$KERNELRELEASE.bz2
$S rm -f \$RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/build
$S rm -f \$RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE/source
$S mkdir -p \$RPM_BUILD_ROOT/usr/src/kernels/$KERNELRELEASE
$S tar cf - . $EXCLUDES | tar xf - -C \$RPM_BUILD_ROOT/usr/src/kernels/$KERNELRELEASE
$S cd \$RPM_BUILD_ROOT/lib/modules/$KERNELRELEASE
$S ln -sf /usr/src/kernels/$KERNELRELEASE build
$S ln -sf /usr/src/kernels/$KERNELRELEASE source
echo "%install" %clean
echo 'mkdir -p $RPM_BUILD_ROOT/boot' rm -rf \$RPM_BUILD_ROOT
echo "%ifarch ia64"
echo 'mkdir -p $RPM_BUILD_ROOT/boot/efi'
echo 'cp $(make image_name) $RPM_BUILD_ROOT'"/boot/efi/vmlinuz-$KERNELRELEASE"
echo 'ln -s '"efi/vmlinuz-$KERNELRELEASE" '$RPM_BUILD_ROOT'"/boot/"
echo "%else"
echo 'cp $(make image_name) $RPM_BUILD_ROOT'"/boot/vmlinuz-$KERNELRELEASE"
echo "%endif"
echo 'make %{?_smp_mflags} INSTALL_MOD_PATH=$RPM_BUILD_ROOT KBUILD_SRC= modules_install'
echo 'make %{?_smp_mflags} INSTALL_HDR_PATH=$RPM_BUILD_ROOT/usr KBUILD_SRC= headers_install'
echo 'cp System.map $RPM_BUILD_ROOT'"/boot/System.map-$KERNELRELEASE"
echo 'cp .config $RPM_BUILD_ROOT'"/boot/config-$KERNELRELEASE"
echo 'bzip2 -9 --keep vmlinux'
echo 'mv vmlinux.bz2 $RPM_BUILD_ROOT'"/boot/vmlinux-$KERNELRELEASE.bz2"
if ! $PREBUILT; then %post
echo 'rm -f $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE/build" if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then
echo 'rm -f $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE/source" cp /boot/vmlinuz-$KERNELRELEASE /boot/.vmlinuz-$KERNELRELEASE-rpm
echo "mkdir -p "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE" cp /boot/System.map-$KERNELRELEASE /boot/.System.map-$KERNELRELEASE-rpm
echo "tar cf - . $EXCLUDES | tar xf - -C "'$RPM_BUILD_ROOT'"/usr/src/kernels/$KERNELRELEASE" rm -f /boot/vmlinuz-$KERNELRELEASE /boot/System.map-$KERNELRELEASE
echo 'cd $RPM_BUILD_ROOT'"/lib/modules/$KERNELRELEASE" /sbin/installkernel $KERNELRELEASE /boot/.vmlinuz-$KERNELRELEASE-rpm /boot/.System.map-$KERNELRELEASE-rpm
echo "ln -sf /usr/src/kernels/$KERNELRELEASE build" rm -f /boot/.vmlinuz-$KERNELRELEASE-rpm /boot/.System.map-$KERNELRELEASE-rpm
echo "ln -sf /usr/src/kernels/$KERNELRELEASE source" fi
fi
echo "" %preun
echo "%clean" if [ -x /sbin/new-kernel-pkg ]; then
echo 'rm -rf $RPM_BUILD_ROOT' new-kernel-pkg --remove $KERNELRELEASE --rminitrd --initrdfile=/boot/initramfs-$KERNELRELEASE.img
echo "" fi
echo "%post"
echo "if [ -x /sbin/installkernel -a -r /boot/vmlinuz-$KERNELRELEASE -a -r /boot/System.map-$KERNELRELEASE ]; then" %postun
echo "cp /boot/vmlinuz-$KERNELRELEASE /boot/.vmlinuz-$KERNELRELEASE-rpm" if [ -x /sbin/update-bootloader ]; then
echo "cp /boot/System.map-$KERNELRELEASE /boot/.System.map-$KERNELRELEASE-rpm" /sbin/update-bootloader --remove $KERNELRELEASE
echo "rm -f /boot/vmlinuz-$KERNELRELEASE /boot/System.map-$KERNELRELEASE" fi
echo "/sbin/installkernel $KERNELRELEASE /boot/.vmlinuz-$KERNELRELEASE-rpm /boot/.System.map-$KERNELRELEASE-rpm"
echo "rm -f /boot/.vmlinuz-$KERNELRELEASE-rpm /boot/.System.map-$KERNELRELEASE-rpm" %files
echo "fi" %defattr (-, root, root)
echo "" /lib/modules/$KERNELRELEASE
echo "%preun" %exclude /lib/modules/$KERNELRELEASE/build
echo "if [ -x /sbin/new-kernel-pkg ]; then" %exclude /lib/modules/$KERNELRELEASE/source
echo "new-kernel-pkg --remove $KERNELRELEASE --rminitrd --initrdfile=/boot/initramfs-$KERNELRELEASE.img" /boot/*
echo "fi"
echo "" %files headers
echo "%postun" %defattr (-, root, root)
echo "if [ -x /sbin/update-bootloader ]; then" /usr/include
echo "/sbin/update-bootloader --remove $KERNELRELEASE" $S
echo "fi" $S %files devel
echo "" $S %defattr (-, root, root)
echo "%files" $S /usr/src/kernels/$KERNELRELEASE
echo '%defattr (-, root, root)' $S /lib/modules/$KERNELRELEASE/build
echo "/lib/modules/$KERNELRELEASE" $S /lib/modules/$KERNELRELEASE/source
echo "%exclude /lib/modules/$KERNELRELEASE/build" EOF
echo "%exclude /lib/modules/$KERNELRELEASE/source"
echo "/boot/*"
echo ""
echo "%files headers"
echo '%defattr (-, root, root)'
echo "/usr/include"
if ! $PREBUILT; then
echo ""
echo "%files devel"
echo '%defattr (-, root, root)'
echo "/usr/src/kernels/$KERNELRELEASE"
echo "/lib/modules/$KERNELRELEASE/build"
echo "/lib/modules/$KERNELRELEASE/source"
fi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment