5dce3cf733d37eb02be87cf91269d1fec141e930
[ipfire-3.x.git] / kernel / kernel.nm
1 ###############################################################################
2 # IPFire.org    - An Open Source Firewall Solution                            #
3 # Copyright (C) - IPFire Development Team <info@ipfire.org>                   #
4 ###############################################################################
5
6 name       = kernel
7 version    = 4.20
8 release    = 5
9 thisapp    = linux-%{version}
10
11 maintainer = Arne Fitzenreiter <arne.fitzenreiter@ipfire.org>
12 groups     = System/Kernels
13 url        = http://www.kernel.org/
14 license    = GPLv2
15 summary    = The Linux kernel.
16
17 description
18         The kernel package contains the Linux kernel (vmlinuz), the core of any
19         Linux operating system. The kernel handles the basic functions
20         of the operating system: memory allocation, process allocation, device
21         input and output, etc.
22 end
23
24 # Version helper variables.
25 localversion = %{release}.%{DISTRO_DISTTAG}.%{DISTRO_ARCH}
26 fullver      = %{version}-%{localversion}
27
28 source_dl    = http://www.kernel.org/pub/linux/kernel/v4.x/
29 sources      = %{thisapp}.tar.xz
30
31 build
32         kernel_logo = /usr/share/pixmaps/kernel-logo.ppm
33
34         requires
35                 asciidoc
36                 bc
37                 binutils >= 2.25
38                 binutils-devel
39                 bison
40                 elfutils-devel
41                 flex
42                 gcc >= 4.9
43                 gcc-plugin-devel
44                 gettext
45                 hostname
46                 libunwind-devel
47                 ncurses-devel
48                 net-tools
49                 newt-devel
50                 pciutils-devel
51                 perl
52                 python-devel
53                 openssl-devel
54                 slang-devel
55                 xmlto
56                 xz
57
58                 /sbin/depmod
59                 %{kernel_logo}
60         end
61
62         # A list of kernels to build.
63         kernels =
64
65         kernel_arch = %{DISTRO_PLATFORM}
66         kernel_target = bzImage
67         kernel_image = arch/%{kernel_arch}/boot/%{kernel_target}
68
69         if "%{DISTRO_ARCH}" == "x86_64"
70                 build_kernel_default = 1
71         end
72
73         if "%{DISTRO_ARCH}" == "aarch64"
74                 build_kernel_default = 1
75
76                 kernel_arch = arm64
77                 kernel_target = Image.gz
78         end
79
80         if "%{DISTRO_ARCH}" == "armv7hl"
81                 # Build the default unified kernel.
82                 build_kernel_default = 1
83
84                 kernel_target = zImage
85         end
86
87         # mkimage is a requirement to build uImage images.
88         if "%{kernel_target}" == "uImage"
89                 requires += u-boot-tools
90         end
91
92         # Build default kernel.
93         if "%{build_kernel_default}" == "1"
94                 kernels += default
95         end
96
97         prepare_cmds
98                 # Disable the colorize plugin.
99                 # It's generally very nice but it clutters our
100                 # logfiles.
101                 sed -e "/^COLORIZE_PLUGIN_CFLAGS/d" \
102                         -i Makefile
103
104                 sed -e "s/\$(HOST_LFS_CFLAGS)/& -fPIC/g" -i Makefile
105
106                 cp -vf %{kernel_logo} \
107                         drivers/video/logo/logo_linux_clut224.ppm
108
109                 # Get rid of unwanted files resulting from patch fuzz.
110                 find . \( -name "*.orig" -o -name "*~" \) -exec rm -f {} \; >/dev/null
111
112                 # Remove unnecessary SCM files.
113                 find . -name .gitignore -exec rm -f {} \; >/dev/null
114
115                 # This prevents scripts/setlocalversion from mucking with our version numbers.
116                 touch .scmversion
117
118                 mkdir -pv configs
119
120                 cd %{DIR_SOURCE}
121                 configure_kernel() {
122                         local flavour=${1}
123                         local suffix
124                         if [ "${flavour}" != "default" ]; then
125                                 suffix="-${flavour}"
126                         fi
127
128                         scripts/configure --kernel-dir=%{DIR_APP} \
129                                 merge %{DISTRO_ARCH} ${flavour} %{DIR_APP}/configs/config.${flavour}
130                 }
131
132                 # Generate configuration files for all kernels we are going to
133                 # build.
134                 for kernel in %{kernels}; do
135                         configure_kernel ${kernel}
136                 done
137         end
138
139         build
140                 build_kernel() {
141                         local flavour=${1}
142                         local suffix
143                         local localversion="%{localversion}"
144                         local fullversion="%{fullver}"
145                         if [ "${flavour}" != "default" ]; then
146                                 suffix="-${flavour}"
147                                 localversion="${localversion}.${flavour}"
148                                 fullversion="${fullversion}.${flavour}"
149                         fi
150
151                         # Label the build.
152                         sed -i Makefile \
153                                 -e "s/^EXTRAVERSION.*/EXTRAVERSION = -${localversion}/"
154
155                         # Clean up the source tree.
156                         make mrproper
157
158                         # Install configuration file.
159                         cp configs/config.${flavour} .config
160                         cat .config
161
162                         # Run the build.
163                         make ARCH=%{kernel_arch} olddefconfig >/dev/null
164                         make ARCH=%{kernel_arch} %{kernel_target} modules \
165                                 %{PARALLELISMFLAGS}
166
167                         # Compile Flattened Device Tree database
168                         case "${DISTRO_ARCH}" in
169                                 aarch64|arm*)
170                                         make ARCH=%{kernel_arch} dtbs
171
172                                         mkdir -pv %{BUILDROOT}/boot/dtb-${fullversion}
173                                         for file in arch/arm/boot/dts/*.dtb; do
174                                                 [ -e "${file}" ] || continue
175
176                                                 install -m 644 ${file} %{BUILDROOT}/boot/dtb-${fullversion} || exit 1
177                                                 rm -f ${file}
178                                         done
179                                         ;;
180                         esac
181
182                         # Install the results.
183                         mkdir -pv %{BUILDROOT}/boot %{BUILDROOT}/usr/lib/modules/${fullversion}
184                         install -m 755 %{kernel_image} %{BUILDROOT}/boot/vmlinuz-${fullversion}
185                         install -m 644 .config %{BUILDROOT}/boot/config-${fullversion}
186                         install -m 644 System.map %{BUILDROOT}/boot/System.map-${fullversion}
187
188                         # Create empty initramfs (20M).
189                         dd if=/dev/zero of=%{BUILDROOT}/boot/initramfs-${fullversion}.img bs=1M count=20
190
191                         # Install modules.
192                         make ARCH=%{kernel_arch} INSTALL_MOD_PATH=%{BUILDROOT}/usr mod-fw= V=1 \
193                                 KERNELRELEASE=${fullversion} modules_install
194
195                         # Create an empty settings file for dracut
196                         mkdir -p %{BUILDROOT}/etc/ld.so.conf.d
197                         echo "# Placeholder file, no vDSO hwcap entries used in this kernel." \
198                                 > %{BUILDROOT}/etc/ld.so.conf.d/kernel-${fullversion}.conf
199
200                         # And now the scary looking part.
201                         #
202                         # Recreate source and build links.
203                         rm -f %{BUILDROOT}/usr/lib/modules/${fullversion}/{build,source}
204                         mkdir -p %{BUILDROOT}/usr/lib/modules/${fullversion}/build
205                         ln -sf build %{BUILDROOT}/usr/lib/modules/${fullversion}/source
206
207                         # Create dirs for extra modules.
208                         mkdir -p %{BUILDROOT}/usr/lib/modules/${fullversion}/extra
209
210                         cp --parents $(find -type f -name "Makefile*" -o -name "Kconfig*") \
211                                 %{BUILDROOT}/usr/lib/modules/${fullversion}/build
212                         cp Module.symvers System.map \
213                                 %{BUILDROOT}/usr/lib/modules/${fullversion}/build
214                         rm -rf %{BUILDROOT}/usr/lib/modules/${fullversion}/build/{Documentation,scripts,include}
215
216                         cp .config %{BUILDROOT}/usr/lib/modules/${fullversion}/build
217                         cp -a scripts %{BUILDROOT}/usr/lib/modules/${fullversion}/build
218                         find %{BUILDROOT}/usr/lib/modules/${fullversion}/build/scripts -name "*.o" \
219                                 -exec rm -vf {} \;
220
221                         cp -a --parents arch/%{kernel_arch}/include \
222                                 %{BUILDROOT}/usr/lib/modules/${fullversion}/build
223                         cp -a include %{BUILDROOT}/usr/lib/modules/${fullversion}/build/include
224
225                         # Make sure we can build external modules.
226                         touch -r %{BUILDROOT}/usr/lib/modules/${fullversion}/build/Makefile \
227                                 %{BUILDROOT}/usr/lib/modules/${fullversion}/build/include/linux/version.h
228                         touch -r %{BUILDROOT}/usr/lib/modules/${fullversion}/build/.config \
229                                 %{BUILDROOT}/usr/lib/modules/${fullversion}/build/autoconf.h
230                         cp %{BUILDROOT}/usr/lib/modules/${fullversion}/build/.config \
231                                 %{BUILDROOT}/usr/lib/modules/${fullversion}/build/include/config/auto.conf
232
233                         find %{BUILDROOT}/usr/lib/modules/${fullversion} -name "*.ko" -type f | \
234                                 xargs --no-run-if-empty chmod u+x
235
236                         # Move all development files to /usr/src.
237                         mkdir -p %{BUILDROOT}/usr/src/kernels
238                         mv %{BUILDROOT}/usr/lib/modules/${fullversion}/build \
239                                 %{BUILDROOT}/usr/src/kernels/${fullversion}
240                         ln -sf ../../../src/kernels/${fullversion} \
241                                 %{BUILDROOT}/usr/lib/modules/${fullversion}/build
242
243                         # Fix permissions.
244                         find %{BUILDROOT}/usr/src/kernels -name "modules.order" \
245                                 -exec chmod 644 {} \;
246
247                         find %{BUILDROOT}/usr/src/kernels -name ".*.cmd" -exec rm -f {} \;
248
249                         # remove device tree compiler because there are dead links
250                         rm -rf %{BUILDROOT}/usr/src/kernels/*/scripts/dtc
251                 }
252
253                 for kernel in %{kernels}; do
254                         build_kernel ${kernel}
255                 done
256
257                 # cpupower
258                 chmod +x tools/power/cpupower/utils/version-gen.sh
259                 make -C tools/power/cpupower CPUFREQ_BENCH=false %{PARALLELISMFLAGS}
260
261                 pushd tools/thermal/tmon
262                 make
263                 popd
264         end
265
266         install
267                 # When no kernels are configured, we create a default config
268                 # which enables us to install at least the header files.
269                 [ -n "%{kernels}" ] || make ARCH=%{kernel_arch} defconfig
270
271                 # Install the header files
272                 make ARCH=%{kernel_arch} INSTALL_HDR_PATH=dest headers_install
273                 mkdir -pv %{BUILDROOT}/usr/include
274                 find dest/include \( -name .install -o -name ..install.cmd \) -delete
275                 cp -rv dest/include/* %{BUILDROOT}/usr/include
276
277                 # Glibc provides these headers
278                 rm -rfv %{BUILDROOT}/usr/include/scsi \
279                         %{BUILDROOT}/usr/include/asm*/atomic.h \
280                         %{BUILDROOT}/usr/include/asm*/io.h \
281                         %{BUILDROOT}/usr/include/asm*/irq.h
282
283                 # Remove all firmware files which are distributed by linux-firmware
284                 rm -rfv %{BUILDROOT}/lib/firmware
285
286                 # Install tools.
287                 # cpupower
288                 make -C tools/power/cpupower DESTDIR=%{BUILDROOT} libdir=%{libdir} \
289                         mandir=%{mandir} CPUFREQ_BENCH=false install
290
291                 chmod 0755 %{BUILDROOT}%{libdir}/libcpupower.so*
292
293                 # tmon
294                 pushd tools/thermal/tmon
295                 make INSTALL_ROOT=%{BUILDROOT} install
296                 popd
297         end
298 end
299
300 packages
301         template KERNEL
302                 kernel_name = kernel
303                 kernel_release = %{fullver}
304
305                 summary = The Linux kernel %{kernel_release}.
306
307                 prerequires
308                         /sbin/depmod
309                 end
310
311                 provides
312                         kernel=%{kernel_release}
313                 end
314
315                 requires
316                         dracut
317                         grubby
318                         linux-firmware
319                 end
320
321                 files
322                         /boot/System.map-%{kernel_release}
323                         /boot/dtb-%{kernel_release}
324                         /boot/vmlinuz-%{kernel_release}
325                         /boot/initramfs-%{kernel_release}.img
326                         /etc/ld.so.conf.d/kernel-%{kernel_release}.conf
327                         /usr/lib/modules/%{kernel_release}
328                 end
329
330                 _posttrans
331                         /sbin/new-kernel-pkg --package %{kernel_name} --mkinitrd --dracut --depmod --update %{kernel_release}
332                         /sbin/new-kernel-pkg --package %{kernel_name} --rpmposttrans %{kernel_release}
333                 end
334
335                 script posttransin
336                         %{_posttrans}
337                 end
338
339                 script posttransup
340                         %{_posttrans}
341                 end
342
343                 script postin
344                         /sbin/new-kernel-pkg --package %{kernel_name} --install %{kernel_release}
345                 end
346
347                 script postup
348                         /sbin/new-kernel-pkg --package %{kernel_name} --install %{kernel_release}
349                 end
350
351                 script preun
352                         /sbin/new-kernel-pkg --rminitrd --rmmoddep --remove %{kernel_release}
353                 end
354         end
355
356         template KERNELDEVEL
357                 kernel_release = %{fullver}
358
359                 summary = Development files of kernel-%{kernel_release}.
360                 description
361                         %{summary}
362
363                         Install this package in order to compile modules for
364                         kernel release %{kernel_release}.
365                 end
366
367                 provides
368                         kernel-devel = %{thisver}
369                 end
370
371                 filter_requires
372                         perl>=[0-9]\:.*
373                 end
374
375                 files
376                         /usr/lib/modules/%{kernel_release}/build
377                         /usr/lib/modules/%{kernel_release}/source
378                         /usr/src/kernels/%{kernel_release}
379                 end
380         end
381
382         if "%{build_kernel_default}" == "1"
383                 if "%{DISTRO_ARCH}" == "armv7hl"
384                         package kernel
385                                 template KERNEL
386
387                                 kernel_name = kernel
388                                 kernel_release = %{fullver}
389
390                                 # Replace the Exynos kernel.
391                                 obsoletes += kernel-exynos < %{kernel_release}
392                                 conflicts += kernel-exynos < %{kernel_release}
393
394                                 # Replace the OMAP kernel.
395                                 obsoletes += kernel-omap < %{kernel_release}
396                                 conflicts += kernel-omap < %{kernel_release}
397                         end
398
399                         package kernel-devel
400                                 template KERNELDEVEL
401
402                                 kernel_name = kernel
403                                 kernel_release = %{fullver}
404
405                                 # Replace the Exynos kernel.
406                                 obsoletes += kernel-exynos-devel < %{kernel_release}
407                                 conflicts += kernel-exynos-devel < %{kernel_release}
408
409                                 # Replace the OMAP kernel.
410                                 obsoletes += kernel-omap-devel < %{kernel_release}
411                                 conflicts += kernel-omap-devel < %{kernel_release}
412                         end
413
414                 else
415                         package kernel
416                                 template KERNEL
417
418                                 kernel_name = kernel
419                                 kernel_release = %{fullver}
420                         end
421
422                         package kernel-devel
423                                 template KERNELDEVEL
424
425                                 kernel_name = kernel
426                                 kernel_release = %{fullver}
427                         end
428                 end
429         end
430
431         package kernel-headers
432                 summary = Header files of the kernel release %{fullver}.
433                 desciption = %{summary}
434
435                 files
436                         /usr/include
437                 end
438         end
439
440         package kernel-tools
441                 summary = Assortment of tools for the Linux kernel.
442                 description = %{summary}
443
444                 filter_requires
445                         perl>=[0-9]\:.*
446                 end
447
448                 files
449                         /
450                         !/boot
451                         !/usr/include
452                         !/usr/lib/modules
453                         !/usr/src
454                         !/usr/src/debug
455                         !/usr/lib/debug
456                 end
457         end
458 end