GNU Linux-libre upgraded to the version 5.16.18 (including configs for i586, amd64)
[dragora.git] / recipes / kernel / generic / recipe
blobf1fe1fabd8401402d27b9ee9cf1eef22682df849
1 # Build recipe for linux-libre (generic).
3 # Copyright (c) 2017-2022 Matias Fonzo, <selk@dragora.org>.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 #    http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Exit immediately on any error
18 set -e
20 program=linux
21 version=5.16.18
22 release=1
24 # Define a category for the output of the package name
25 pkgcategory=kernel
27 pkgname=kernel-generic
29 tarname=${program}-libre-${version}-gnu.tar.lz
31 # Remote source(s)
32 fetch=https://linux-libre.fsfla.org/pub/linux-libre/releases/${version}-gnu/$tarname
34 homepage=https://www.gnu.org/software/linux-libre
36 description="
37 The Linux kernel image and modules.
39 This is a generic configuration for the Linux kernel
40 which intends to run well in all environments.
43 license="GPLv2 only"
45 build()
47     unpack "${tardir}/$tarname"
49     cd "$srcdir"
51     # Set sane permissions
52     chmod -R u+w,go-w,a+rX-s .
54     # Support LZIP (Thanks to the friend of the house "Antonio Diaz Diaz")
56     patch -p1 < "${worktree}/patches/kernel/linux-5.16.11_lzip-0.diff"
58     # Support Reiserfs4 (Thanks to "Edward Shishkin")
60     patch -p1 < "${worktree}/patches/kernel/reiser4-for-5.16.patch"
62     make mrproper
64     case $arch in
65     amd64 | x32 )
66         echo "Copying config-amd64_generic ..."
67         cp -p "${worktree}/archive/kernel/config-amd64_generic" .config
68         kernel_arch=x86_64
69         ;;
70     i586)
71         echo "Copying config-i586_generic ..."
72         cp -p "${worktree}/archive/kernel/config-i586_generic" .config
73         kernel_arch=i386
74         ;;
75     armhf)
76         echo "Copying config-c201-v12 ..."
77         cp -p "${worktree}/archive/kernel/config-c201-v12" .config
78         kernel_arch=arm
79         ;;
80     *)
81         echo "${0}: No custom configuration file detected for your architecture." 1>&2
82         exit 1;
83         ;;
84     esac
86     # An environment variable for config purposes
87     if test ! -z "$PRESERVE"
88     then
89         echo "PRESERVE has been set."
90         exit 99;
91     fi
93     make -j${jobs} ARCH=$kernel_arch bzImage
94     make -j${jobs} ARCH=$kernel_arch modules
95     make -j${jobs} ARCH=$kernel_arch \
96      INSTALL_MOD_PATH="$destdir" modules_install
98     # To extract the kernel string version
99     strver="$(ls -d "${destdir}"/lib/modules/*)"
100     strver="${strver##*/}"
102     # Install kernel images
103     mkdir -p "${destdir}/boot"
105     cp -p .config "${destdir}/boot/config-generic-${strver}"
106     cp -p System.map "${destdir}/boot/System.map-generic-${strver}"
108     if test -e "arch/${kernel_arch}/boot/bzImage"
109     then
110         cp -p "arch/${kernel_arch}/boot/bzImage" \
111               "${destdir}/boot/vmlinuz-generic-${strver}"
112     elif test -e "arch/${kernel_arch}/boot/zImage"
113     then
114         cp -p "arch/${kernel_arch}/boot/zImage" \
115               "${destdir}/boot/vmlinuz-generic-${strver}"
116     else
117         echo "${0}: No kernel image found: bzImage or zImage" 1>&2
118         exit 1;
119     fi
121     # Exclude files from the Graft installation,
122     # this will be copied via post-intall, since
123     # /boot could be a separated partition
124     touch "${destdir}/boot/.nograft"
126     # Insert post-install script manually
128     # This must be recreated on post-installation
129     rm -f "${destdir}"/lib/modules/${strver}/build \
130           "${destdir}"/lib/modules/${strver}/source
132     mkdir -p "${destdir}/var/lib/qi"
133     cat << EOF > "${destdir}/var/lib/qi/${full_pkgname}.sh"
135 # Kernel string version
136 strver=$strver
138 # Copy kernel image from 'packagedir' to 'rootdir/boot'
140 mkdir -p -- "\${rootdir}/boot"
142 cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/System.map-generic-${strver}" \\
143           "\${rootdir}/boot/"
145 cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/config-generic-${strver}" \\
146           "\${rootdir}/boot/"
148 cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/vmlinuz-generic-${strver}" \\
149           "\${rootdir}/boot/"
151 # Make generic symlinks for this kernel version
153 srcdir="${srcdir##*/}"
156     cd lib/modules/${strver} || exit 1
157     rm -f build source
158     ln -sf /usr/src/${srcdir} build
159     ln -sf /usr/src/${srcdir} source
162 # Generate or update the module dependency list
163 chroot "\$rootdir" /sbin/depmod -a $strver
167     # Preserve 'srcdir' in order to produce "kernel/buildtree-generic"
168     keep_srcdir=keep_srcdir
170     # Set ID for the recipe that will produce the package with the build tree
171     kernel_generic_has_been_built=kernel_generic_has_been_built
173     export keep_srcdir kernel_generic_has_been_built