wok-current view linux/receipt @ rev 25586

Fix linux build with gcc > 6 again
author Stanislas Leduc <shann@slitaz.org>
date Mon May 29 12:23:26 2023 +0000 (13 months ago)
parents a58264a81dff
children 22166ae1fc15
line source
1 # SliTaz package receipt.
3 PACKAGE="linux"
4 VERSION="3.16.55"
5 CATEGORY="base-system"
6 SHORT_DESC="The Linux kernel and modules."
7 MAINTAINER="devel@slitaz.org"
8 LICENSE="GPL2"
9 TARBALL="$PACKAGE-$VERSION.tar.xz"
10 WEB_SITE="https://www.kernel.org/"
11 WGET_URL="https://cdn.kernel.org/pub/linux/kernel/v${VERSION%%.*}.x/$TARBALL"
12 HOST_ARCH="i486 arm x86_64"
14 DEPENDS="kmod"
15 BUILD_DEPENDS="bash perl git xz lzma patch kmod uclibc-cross-compiler-x86_64 bc \
16 sysfsutils-dev libtool glib-dev libwrap libwrap-dev udev-dev"
18 #
19 # The Linux receipt handle cross compilation. For x86_64 we actually use
20 # the uclibc-cross-compiler-x86_64 and for ARM we use a real cross env.
21 # Please discuss any change and keep it simple, dont play with VERSION
22 # string or Kernel SUBLEVEL because depmod and Pankso dont like that!
23 #
24 # The receipt also handle some cook options for faster build:
25 # --nox64 : Skip the x86_64 cross compilation
26 # --nonomods : Skip bzImage without modules build
27 #
29 # Aufs enable chroot
30 AUFS_NOT_RAMFS="uclibc-cross-compiler-x86_64 is not compatible with aufs+tmpfs 8("
32 current_version()
33 {
34 wget -O - $WEB_SITE 2> /dev/null | grep -A 1 longterm | \
35 sed '/strong/!d;s|.*<strong>||;s|</s.*||;q'
36 }
38 # Handle multiarch compilation. Less bdeps when cross-compiling for ARM
39 case "$ARCH" in
40 arm) BUILD_DEPENDS="xz" ;;
41 x86_64) BUILD_DEPENDS="xz" ;;
42 esac
44 # Handle multiarch installation. ARM use Busybox modutils, so avoid any
45 # deps on kmod. SLITAZ_ARCH can have also custom post_install commands
46 if [ -f $root/etc/slitaz/slitaz.conf ]; then
47 . $root/etc/slitaz/slitaz.conf
48 case "$SLITAZ_ARCH" in
49 arm) DEPENDS="" ;;
50 esac
51 fi
53 install_module_headers()
54 {
55 local path
56 path=usr/src/linux-$KVERSION
57 mkdir -p $1/lib/modules/$KVERSION
58 ln -sf /$path $1/lib/modules/$KVERSION/build
59 install -D -m644 $src/Makefile \
60 $1/$path/Makefile
61 install -D -m644 $src/kernel/Makefile \
62 $1/$path/kernel/Makefile
63 install -D -m644 $src/.config \
64 $1/$path/.config
65 mkdir -p $1/$path/include
67 cp -a $src/include/* $1/$path/include/
68 rm -f $1/$path/include/Kbuild
70 # copy arch includes for external modules
71 mkdir -p $1/$path/arch/x86
72 cp -a $src/arch/x86/include $1/$path/arch/x86/
74 # copy files necessary for later builds, like nvidia and vmware
75 cp -a $src/Module.symvers $1/$path/Module.symvers
76 cp -a $src/scripts $1/$path
77 # fix permissions on scripts dir
78 chmod og-w -R $1/$path/scripts
79 mkdir -p $1/$path/.tmp_versions
81 mkdir -p $1/$path/arch/x86/kernel
82 cp -a $src/arch/x86/Makefile $1/$path/arch/x86/
83 cp -a $src/arch/x86/Makefile_32.cpu $1/$path/arch/x86/
84 cp -a $src/arch/x86/kernel/asm-offsets.s $1/$path/arch/x86/kernel/
86 # add headers for lirc package
87 mkdir -p $1/$path/drivers/media
88 ( cd $src/drivers/media ; find i2c -name '*.h' | cpio -o -H newc ) | \
89 ( cd $1/$path/drivers/media ; cpio -idmu )
91 # add docbook makefile
92 install -D -m644 $src/Documentation/DocBook/Makefile \
93 $1/$path/Documentation/DocBook/Makefile
95 # add dm headers
96 mkdir -p $1/$path/drivers/md
97 cp -a $src/drivers/md/*.h $1/$path/drivers/md
99 # add inotify.h
100 mkdir -p $1/$path/include/linux
101 cp -a $src/include/linux/inotify.h $1/$path/include/linux/
103 # add wireless headers
104 mkdir -p $1/$path/net/mac80211/
105 cp -a $src/net/mac80211/*.h $1/$path/net/mac80211/
107 # add dvb headers for external modules
108 # in reference to:
109 # http://bugs.archlinux.org/task/9912
110 mkdir -p $1/$path/drivers/media/dvb-core
111 cp -a $src/drivers/media/dvb-core/*.h $1/$path/drivers/media/dvb-core/
113 # add dvb headers for external modules
114 # in reference to:
115 # http://bugs.archlinux.org/task/11194
116 if [ -d $src/include/config/dvb/ ]; then
117 mkdir -p $1/$path/include/config/dvb/
118 cp $src/include/config/dvb/*.h $1/$path/include/config/dvb/
119 fi
121 # add dvb headers for http://mcentral.de/hg/~mrec/em28xx-new
122 # in reference to:
123 # http://bugs.archlinux.org/task/13146
124 mkdir -p $1/$path/drivers/media/dvb-frontends/
125 cp -a $src/drivers/media/dvb-frontends/lgdt330x.h $1/$path/drivers/media/dvb-frontends/
126 cp -a $src/drivers/media/i2c/msp3400-driver.h $1/$path/drivers/media/dvb-frontends/
128 # add dvb headers
129 # in reference to:
130 # http://bugs.archlinux.org/task/20402
131 mkdir -p $1/$path/drivers/media/usb/dvb-usb
132 cp -a $src/drivers/media/usb/dvb-usb/*.h $1/$path/drivers/media/usb/dvb-usb/
133 mkdir -p $1/$path/drivers/media/dvb-frontends
134 cp -a $src/drivers/media/dvb-frontends/*.h $1/$path/drivers/media/dvb-frontends/
135 mkdir -p $1/$path/drivers/media/tuners
136 cp -a $src/drivers/media/tuners/*.h $1/$path/drivers/media/tuners/
138 # add xfs and shmem for aufs building
139 mkdir -p $1/$path/fs/xfs
140 mkdir -p $1/$path/mm
141 cp -a $src/fs/xfs/xfs_sb.h $1/$path/fs/xfs/xfs_sb.h
142 cp -a $src/fs/*.h $1/$path/fs/
144 # copy in Kconfig files
145 for i in $(find . -name "Kconfig*"); do
146 mkdir -p $1/$path/$(echo $i | sed 's|/Kconfig.*||')
147 cp -a $src/$i $1/$path/$i
148 done
150 chown -R root.root $1/$path
151 find $1/$path -type d -exec chmod 755 {} \;
152 # remove unneeded architectures
153 rm -rf $1/$path/arch/{alpha,arm,arm26,avr32,blackfin,cris,frv,h8300,ia64,m32r,m68k,m68knommu,mips,microblaze,mn10300,parisc,powerpc,ppc,s390,sh,sh64,sparc,sparc64,um,v850,xtensa}
154 }
156 # Rules to configure and make the package.
157 compile_rules()
158 {
159 if [ -f "/usr/share/boot/initrd" ]; then
160 cp /usr/share/boot/initrd initrd.cpio
161 fi
163 # Handle cross compilation
164 case "$ARCH" in
165 arm)
166 echo "Compiling: $ARCH Kernel"
167 make mrproper
168 patch -Np1 < $stuff/$ARCH/linux-arm.patch || exit 1
169 cp -f $stuff/$ARCH/linux-arm.config .config
170 yes '' | make ARCH=$ARCH oldconfig
171 make ARCH=$ARCH CROSS_COMPILE=${HOST_SYSTEM}- bzImage &&
172 make ARCH=$ARCH CROSS_COMPILE=${HOST_SYSTEM}- modules &&
173 make ARCH=$ARCH CROSS_COMPILE=${HOST_SYSTEM}- \
174 INSTALL_MOD_PATH=$DESTDIR modules_install &&
175 mkdir -p $DESTDIR/boot &&
176 cp -a arch/arm/boot/zImage \
177 $DESTDIR/boot/linux-$VERSION-slitaz-$ARCH
178 #$stuff/gztazmod.sh $DESTDIR/lib/modules/$VERSION-slitaz
179 return 0 ;;
180 x86_64)
181 echo "TODO: Maybe use default ? But cross compile in x86_64 chroot"
182 echo "so we can remove the 64 build by uclibc-cross-compiler-x86_64"
183 return 0 ;;
184 esac
186 # Check for Aufs and get source/patches if needed
187 echo "Checking for Aufs packages..."
188 AUFSVER=$(grep ^VERSION= $WOK/linux-aufs/receipt | cut -d "=" -f2 | sed -e 's/"//g')
189 AUFSSRCDIR="$WOK/linux-aufs/source"
190 AUFSDIR="$AUFSSRCDIR/linux-aufs-${AUFSVER}"
191 if [ ! -d "$AUFSDIR" ]; then
192 [ ! -f "$SRC/aufs-${AUFSVER}.tar.bz2" ] && cook aufs --getsrc
193 mkdir -p $AUFSSRCDIR
194 echo "Extracting: aufs-${AUFSVER}.tar.bz2"
195 tar xjf $SRC/aufs-${AUFSVER}.tar.bz2 -C $AUFSSRCDIR/
196 ( cd $AUFSDIR ; [ -d fs ] || git checkout origin/aufs${VERSION%.*} )
197 fi
199 echo "cook:linux" > $command
201 echo "Copying Aufs files and patches..."
202 cp -a $AUFSDIR/Documentation $AUFSDIR/fs $AUFSDIR/include $src
204 # Use fixed patchs from stuff
205 cp -a $AUFSDIR/aufs3-*.patch $stuff
207 # SliTaz db stuff
208 [ -d $WOK/$PACKAGE/source/slitaz ] && rm -rf $WOK/$PACKAGE/source/slitaz
209 mkdir -p $WOK/$PACKAGE/source/slitaz
210 echo "$WGET_URL" > $WOK/$PACKAGE/source/slitaz/url
211 cp $stuff/gztazmod.sh $stuff/list_modules.sh $WOK/$PACKAGE/source/slitaz
212 cp $stuff/bootloader.sh $WOK/$PACKAGE/source/slitaz
214 # Apply patches
215 echo "Applying patches..."
216 while read patch_file; do
217 echo "$patch_file" >> $WOK/$PACKAGE/source/slitaz/patches
218 cp $stuff/$patch_file $WOK/$PACKAGE/source/slitaz
219 if [ -f done.$patch_file ]; then
220 echo "Skipping $patch_file" && continue
221 fi
222 echo "Apply $patch_file"
223 patch -p1 < $WOK/$PACKAGE/source/slitaz/$patch_file || return 1
224 touch done.$patch_file
225 done <<EOT
226 $PACKAGE-diff.u
227 $PACKAGE-freeinitrd.u
228 $PACKAGE-subroot.u
229 $PACKAGE-romfs.u
230 $PACKAGE-tcp_stealth.u
231 $PACKAGE-efi.u
232 aufs3-base.patch
233 aufs3-standalone.patch
234 aufs3-loopback.patch
235 aufs3-mmap.patch
236 EOT
238 # Patch for GCC > 6.x
239 # usbip (format overflow / implicit-fallthrough)
240 # kernel (format overflow)
241 patch -p1 < $stuff/linux-usbip-fix-format-overflow-gcc8.patch
242 patch -p1 < $stuff/linux-usbip-fix-implicit-fallthrough-gcc8.patch
243 patch -p1 < $stuff/linux-fix-format-overflow-gcc8.patch
244 patch -p1 < $stuff/linux-fix-noreturn-attributes-gcc8.patch
246 # Mrproper and lguest
247 echo "Make kernel proper and then build lguest..."
248 make mrproper
249 cd tools/lguest
250 make lguest || return 1
252 echo "Build usbip..."
253 cd $src/drivers/staging/usbip/userspace
254 ./autogen.sh
255 ./configure CFLAGS="$CFLAGS -Wno-error=uninitialized" \
256 --with-usbids-dir=/usr/share/misc \
257 --mandir=/usr/share/man $CONFIGURE_ARGS &&
258 make && make DESTDIR=$DESTDIR/usbip install || return 1
260 cd $src
262 #
263 # Arch x86_64: TODO have a real cross environment
264 #
265 if [ ! "$nox64" ]; then
266 echo "Compiling: x86_64 Kernel"
268 # Build bzImage64 without modules first
269 if [ ! "$nonomods" ]; then
270 [ -d $DESTDIR/linux64 ] || mkdir -p $DESTDIR/linux64 ||
271 return 1
272 cp -f $stuff/$PACKAGE-slitaz.config64 .config
273 sed -i 's/CONFIG_MODULES=y/# CONFIG_MODULES is not set/' .config
274 echo -e "\n* Configure bzImage64 without modules...\n"
275 yes '' | make ARCH=x86_64 oldconfig
276 echo -e "\n* Building bzImage64 without modules...\n"
277 make ARCH=x86_64 CROSS_COMPILE=uclibc-x86_64- bzImage || exit 1
278 mv arch/x86/boot/bzImage $DESTDIR/linux64
279 mv System.map System.map-without-modules64
280 mv vmlinux vmlinux-without-modules64
281 mv .config config-without-modules64
282 fi
284 # Build bzImage64 with modules
285 cp -f $stuff/$PACKAGE-slitaz.config64 .config
286 echo -e "\n* Configure bzImage64 with modules...\n"
287 yes '' | make ARCH=x86_64 oldconfig
288 echo -e "\n* Building bzImage64 with modules...\n"
289 make ARCH=x86_64 CROSS_COMPILE=uclibc-x86_64- bzImage &&
290 make ARCH=x86_64 CROSS_COMPILE=uclibc-x86_64- modules &&
291 make ARCH=x86_64 INSTALL_MOD_PATH=$DESTDIR/linux64 modules_install &&
292 make ARCH=x86_64 INSTALL_HDR_PATH=$DESTDIR/linux64/usr headers_install &&
293 ln .config $WOK/$PACKAGE/source/slitaz/config64
294 [ -s arch/x86/boot/bzImage ] || return 1
295 mkdir -p $DESTDIR/linux64/boot 2> /dev/null
296 mv arch/x86/boot/bzImage $DESTDIR/linux64/boot/vmlinuz-$VERSION-slitaz64
297 KVERSION=$VERSION-slitaz64
298 install_module_headers $DESTDIR/linux64
299 ln System.map System.map-modules64
300 ln vmlinux vmlinux-modules64
301 ln Module.symvers Module.symvers-modules64
302 cp .config config-modules64
303 else
304 echo "* Skipping: x86_64 Kernel..."
305 fi
307 #
308 # Linux Arch i386 - GCC arch i486
309 #
310 echo "Compiling: i386 Kernel..."
312 # Build bzImage without modules first
313 if [ ! "$nonomods" ]; then
314 cp -f $stuff/$PACKAGE-slitaz.config .config
315 sed -i 's/CONFIG_MODULES=y/# CONFIG_MODULES is not set/' .config
316 echo -e "\n* Configure bzImage without modules...\n"
317 yes '' | make ARCH=i386 oldconfig
318 echo -e "\n* Building bzImage without modules...\n"
319 make ARCH=i386 bzImage || exit 1
320 [ -d $DESTDIR ] || mkdir -p $DESTDIR
321 mv arch/x86/boot/bzImage $DESTDIR
322 mv System.map System.map-without-modules
323 mv vmlinux vmlinux-without-modules
324 mv .config config-without-modules
325 fi
327 # Build bzImage with modules
328 cp -f $stuff/$PACKAGE-slitaz.config .config
329 echo -e "\n* Configure bzImage with modules...\n"
330 yes '' | make ARCH=i386 oldconfig
331 ln .config $WOK/$PACKAGE/source/slitaz/config
332 echo -e "\n* Building bzImage with modules...\n"
333 make ARCH=i386 bzImage &&
334 make ARCH=i386 modules &&
335 make ARCH=i386 INSTALL_MOD_PATH=$DESTDIR modules_install &&
336 make ARCH=i386 INSTALL_HDR_PATH=$DESTDIR/usr headers_install &&
337 [ -s arch/x86/boot/bzImage ] || return 1
338 mkdir -p $DESTDIR/boot 2> /dev/null
339 mv arch/x86/boot/bzImage $DESTDIR/boot/vmlinuz-$VERSION-slitaz
340 KVERSION=$VERSION-slitaz
341 install_module_headers $DESTDIR
343 # Compress all modules.
344 if [ -d "$DESTDIR/lib/modules/$VERSION-slitaz" ]; then
345 $stuff/gztazmod.sh $DESTDIR/lib/modules/$VERSION-slitaz
346 else
347 return 1
348 fi
349 if [ -d "$DESTDIR/linux64/lib/modules/$VERSION-slitaz64" ]; then
350 $stuff/gztazmod.sh $DESTDIR/linux64/lib/modules/$VERSION-slitaz64
351 fi
352 ln System.map System.map-modules
353 ln vmlinux vmlinux-modules
354 ln Module.symvers Module.symvers-modules
355 cp .config config-modules
356 }
358 # Rules to gen a SliTaz package suitable for Tazpkg.
359 genpkg_rules()
360 {
361 case "$ARCH" in
362 arm)
363 echo "Packing: ARM Kernel"
364 cp -a $install/* $fs
365 rm -f $fs/lib/modules/*/build $fs/lib/modules/*/source
366 return 0 ;;
367 x86_64)
368 echo "TODO: use default or custom x86_64 packing"
369 return 0 ;;
370 esac
372 export PACKAGE VERSION
373 local path
374 cp -a $install/boot $fs
376 # Compress all modules.
377 path=$fs/lib/modules/$VERSION-slitaz/kernel
378 mkdir -p $path
380 # Get the base modules
381 export src install
382 mkdir -p $WOK/$PACKAGE/source/tmp
383 # Warning stuff/list_modules.sh must find the generated modules.list
384 $stuff/list_modules.sh \
385 $(cat $stuff/modules.list) > $WOK/$PACKAGE/source/tmp/modules.list
386 while read module; do
387 dir=$(dirname $module)
388 [ -d $path/$dir ] || mkdir -p $path/$dir
389 cp -a $install/lib/modules/$VERSION-slitaz/kernel/$module $path/$dir
390 done < $WOK/$PACKAGE/source/tmp/modules.list
392 # Remove unresolved links
393 rm -f $fs/lib/modules/$VERSION-slitaz/build
394 rm -f $fs/lib/modules/$VERSION-slitaz/source
396 # We only need module.{order,builtin} because other map files are
397 # generated by depmod in post_install
398 cp -a $install/lib/modules/$VERSION-slitaz/modules.order \
399 $install/lib/modules/$VERSION-slitaz/modules.builtin \
400 $fs/lib/modules/$VERSION-slitaz
402 # Pack all packages with a kernel module
403 sed -i "/^$PACKAGE\$/d" $CACHE/broken 2>/dev/null || true
404 for i in $(cd $WOK; grep -l '^WANTED="linux"' */receipt); do
405 [ ! -d "$install/lib/modules/$VERSION-slitaz" ] && return 1
406 cook ${i%/receipt}
407 done
409 # Check any module in kernel .config that's not added to a linux-* pkgs
410 # and remove aufs patches: we dont need them in HG wok.
411 $stuff/check_modules.sh
413 # Keep fixed patches !
414 #rm -f $stuff/aufs3-*
415 }
417 # Pre and post install commands for Tazpkg.
418 post_install()
419 {
420 chroot "$root/" depmod -a $VERSION-slitaz
422 # Handle multiarch installation
423 case "$SLITAZ_ARCH" in
424 arm)
425 echo "Kernel : /boot/linux-$VERSION-slitaz-$ARCH"
426 echo "Modules: /lib/modules/$VERSION-slitaz"
427 return 0 ;;
428 esac
430 # GRUB stuff.
431 if [ -f "$1/boot/grub/menu.lst" ]; then
432 # Current root device
433 root_dev="/dev/$(lsblk | grep '/$'| grep -o '[a-z]d[a-z][0-9]*')"
434 grub_part="$(( $(echo $root_dev | grep -o '[0-9]*$')-1 ))"
435 # Use device.map to find grub device number
436 grub_dev="$(grep $(echo $root_dev | grep -o '^/dev/.d.' ) \
437 "$1/boot/grub/device.map" | cut -f1 | sed "s/)$/.$grub_part)/g")"
439 # Add and clean kernel entries in case of upgrade for installed system.
440 if ! grep -q vmlinuz-$VERSION-slitaz "$1/boot/grub/menu.lst"; then
442 # Clean the old entry
443 # TODO: old vmlinuz file is removed but the entry is still there.
444 # So grub error:15 when selected: http://bugs.slitaz.org/?id=74
446 # Add the new entry
447 cat >> "$1/boot/grub/menu.lst" << EOT
449 title SliTaz GNU/Linux (Kernel $VERSION-slitaz)
450 $grub_dev
451 kernel /boot/vmlinuz-$VERSION-slitaz root=$root_dev quiet
452 EOT
453 # Make it the default entry
454 last_entry=$(( $(grep -c '^title' "$1/boot/grub/menu.lst")-1 ))
455 sed -e "s/^default.*/default $last_entry/g" -i "$1/boot/grub/menu.lst"
456 fi
458 # Display information message.
459 cat <<EOT
461 ----
462 GRUB is installed, these tree lines must be in your /boot/grub/menu.lst:
464 title SliTaz GNU/Linux (Kernel $VERSION-slitaz)
465 $grub_dev
466 kernel /boot/vmlinuz-$VERSION-slitaz root=$root_dev
467 ----
468 EOT
469 fi
470 true
471 }