GNU Linux-libre upgraded to version 5.10.100 (for now)
[dragora.git] / recipes / kernel / generic / recipe
blobaeeb47c52727a5a7c0fd5420753dd6ebfac68025
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.10.100
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}-gnu1.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     # Preserve 'srcdir' in order to produce "buildtree-generic", later
48     keep_srcdir=keep_srcdir
50     unpack "${tardir}/$tarname"
52     cd "$srcdir"
54     # Set sane permissions
55     chmod -R u+w,go-w,a+rX-s .
57     # Support LZIP (Thanks to the friend of the house "Antonio Diaz Diaz")
59     patch -p1 < "${worktree}/patches/kernel/linux-5.10.25_lzip-0.diff"
61     # Support Reiserfs4
63     patch -p1 < "${worktree}/patches/kernel/reiser4-for-5.10.2.patch"
65     make mrproper
67     case $arch in
68     amd64 | x32 )
69         echo "Copying config-amd64_generic ..."
70         cp -p "${worktree}/archive/kernel/config-amd64_generic" .config
71         kernel_arch=x86_64
72         ;;
73     i586)
74         echo "Copying config-i586_generic ..."
75         cp -p "${worktree}/archive/kernel/config-i586_generic" .config
76         kernel_arch=i386
77         ;;
78     armhf)
79         echo "Copying config-c201-v12 ..."
80         cp -p "${worktree}/archive/kernel/config-c201-v12" .config
81         kernel_arch=arm
82         ;;
83     *)
84         echo "${0}: No custom configuration file detected for your architecture." 1>&2
85         exit 1;
86         ;;
87     esac
89     # An environment variable for config purposes
90     if test ! -z "$PRESERVE"
91     then
92         echo "PRESERVE has been set."
93         exit 99;
94     fi
96     make -j${jobs} ARCH=$kernel_arch bzImage
97     make -j${jobs} ARCH=$kernel_arch modules
98     make -j${jobs} ARCH=$kernel_arch \
99      INSTALL_MOD_PATH="$destdir" modules_install
101     # To extract the kernel string version
102     strver="$(ls -d "${destdir}"/lib/modules/*)"
103     strver="${strver##*/}"
105     # Install kernel images
106     mkdir -p "${destdir}/boot"
108     cp -p .config "${destdir}/boot/config-generic-${strver}"
109     cp -p System.map "${destdir}/boot/System.map-generic-${strver}"
111     if test -e "arch/${kernel_arch}/boot/bzImage"
112     then
113         cp -p "arch/${kernel_arch}/boot/bzImage" \
114               "${destdir}/boot/vmlinuz-generic-${strver}"
115     elif test -e "arch/${kernel_arch}/boot/zImage"
116     then
117         cp -p "arch/${kernel_arch}/boot/zImage" \
118               "${destdir}/boot/vmlinuz-generic-${strver}"
119     else
120         echo "${0}: No kernel image found: bzImage or zImage" 1>&2
121         exit 1;
122     fi
124     # Exclude files from the Graft installation,
125     # this will be copied via post-intall, since
126     # /boot could be a separated partition
127     touch "${destdir}/boot/.nograft"
129     # Insert post-install script manually
131     # This must be recreated on post-installation
132     rm -f "${destdir}"/lib/modules/${strver}/build \
133           "${destdir}"/lib/modules/${strver}/source
135     mkdir -p "${destdir}/var/lib/qi"
136     cat << EOF > "${destdir}/var/lib/qi/${full_pkgname}.sh"
138 # Kernel string version
139 strver=$strver
141 # Copy kernel image from 'packagedir' to 'rootdir/boot'
143 mkdir -p -- "\${rootdir}/boot"
145 cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/System.map-generic-${strver}" \\
146           "\${rootdir}/boot/"
148 cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/config-generic-${strver}" \\
149           "\${rootdir}/boot/"
151 cp -pf -- "\$rootdir${packagedir}/${full_pkgname}/boot/vmlinuz-generic-${strver}" \\
152           "\${rootdir}/boot/"
154 # Make generic symlinks for this kernel version
156 srcdir="${srcdir##*/}"
159     cd lib/modules/${strver} || exit 1
160     rm -f build source
161     ln -sf /usr/src/${srcdir} build
162     ln -sf /usr/src/${srcdir} source
165 # Generate or update the module dependency list
166 chroot "\$rootdir" /sbin/depmod -a $strver