wok-current view linux/receipt @ rev 25585

Fix linux build with gcc > 6
author Stanislas Leduc <shann@slitaz.org>
date Thu May 25 15:49:26 2023 +0000 (13 months ago)
parents e53dd413c6de
children d93a872413c7
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 patch -p1 < $stuff/linux-with-gcc8.patch
241 # Mrproper and lguest
242 echo "Make kernel proper and then build lguest..."
243 make mrproper
244 cd tools/lguest
245 make lguest || return 1
247 echo "Build usbip..."
248 cd $src/drivers/staging/usbip/userspace
249 ./autogen.sh
250 ./configure CFLAGS="$CFLAGS -Wno-error=uninitialized" \
251 --with-usbids-dir=/usr/share/misc \
252 --mandir=/usr/share/man $CONFIGURE_ARGS &&
253 make && make DESTDIR=$DESTDIR/usbip install || return 1
255 cd $src
257 #
258 # Arch x86_64: TODO have a real cross environment
259 #
260 if [ ! "$nox64" ]; then
261 echo "Compiling: x86_64 Kernel"
263 # Build bzImage64 without modules first
264 if [ ! "$nonomods" ]; then
265 [ -d $DESTDIR/linux64 ] || mkdir -p $DESTDIR/linux64 ||
266 return 1
267 cp -f $stuff/$PACKAGE-slitaz.config64 .config
268 sed -i 's/CONFIG_MODULES=y/# CONFIG_MODULES is not set/' .config
269 echo -e "\n* Configure bzImage64 without modules...\n"
270 yes '' | make ARCH=x86_64 oldconfig
271 echo -e "\n* Building bzImage64 without modules...\n"
272 make ARCH=x86_64 CROSS_COMPILE=uclibc-x86_64- bzImage || exit 1
273 mv arch/x86/boot/bzImage $DESTDIR/linux64
274 mv System.map System.map-without-modules64
275 mv vmlinux vmlinux-without-modules64
276 mv .config config-without-modules64
277 fi
279 # Build bzImage64 with modules
280 cp -f $stuff/$PACKAGE-slitaz.config64 .config
281 echo -e "\n* Configure bzImage64 with modules...\n"
282 yes '' | make ARCH=x86_64 oldconfig
283 echo -e "\n* Building bzImage64 with modules...\n"
284 make ARCH=x86_64 CROSS_COMPILE=uclibc-x86_64- bzImage &&
285 make ARCH=x86_64 CROSS_COMPILE=uclibc-x86_64- modules &&
286 make ARCH=x86_64 INSTALL_MOD_PATH=$DESTDIR/linux64 modules_install &&
287 make ARCH=x86_64 INSTALL_HDR_PATH=$DESTDIR/linux64/usr headers_install &&
288 ln .config $WOK/$PACKAGE/source/slitaz/config64
289 [ -s arch/x86/boot/bzImage ] || return 1
290 mkdir -p $DESTDIR/linux64/boot 2> /dev/null
291 mv arch/x86/boot/bzImage $DESTDIR/linux64/boot/vmlinuz-$VERSION-slitaz64
292 KVERSION=$VERSION-slitaz64
293 install_module_headers $DESTDIR/linux64
294 ln System.map System.map-modules64
295 ln vmlinux vmlinux-modules64
296 ln Module.symvers Module.symvers-modules64
297 cp .config config-modules64
298 else
299 echo "* Skipping: x86_64 Kernel..."
300 fi
302 #
303 # Linux Arch i386 - GCC arch i486
304 #
305 echo "Compiling: i386 Kernel..."
307 # Build bzImage without modules first
308 if [ ! "$nonomods" ]; then
309 cp -f $stuff/$PACKAGE-slitaz.config .config
310 sed -i 's/CONFIG_MODULES=y/# CONFIG_MODULES is not set/' .config
311 echo -e "\n* Configure bzImage without modules...\n"
312 yes '' | make ARCH=i386 oldconfig
313 echo -e "\n* Building bzImage without modules...\n"
314 make ARCH=i386 bzImage || exit 1
315 [ -d $DESTDIR ] || mkdir -p $DESTDIR
316 mv arch/x86/boot/bzImage $DESTDIR
317 mv System.map System.map-without-modules
318 mv vmlinux vmlinux-without-modules
319 mv .config config-without-modules
320 fi
322 # Build bzImage with modules
323 cp -f $stuff/$PACKAGE-slitaz.config .config
324 echo -e "\n* Configure bzImage with modules...\n"
325 yes '' | make ARCH=i386 oldconfig
326 ln .config $WOK/$PACKAGE/source/slitaz/config
327 echo -e "\n* Building bzImage with modules...\n"
328 make ARCH=i386 bzImage &&
329 make ARCH=i386 modules &&
330 make ARCH=i386 INSTALL_MOD_PATH=$DESTDIR modules_install &&
331 make ARCH=i386 INSTALL_HDR_PATH=$DESTDIR/usr headers_install &&
332 [ -s arch/x86/boot/bzImage ] || return 1
333 mkdir -p $DESTDIR/boot 2> /dev/null
334 mv arch/x86/boot/bzImage $DESTDIR/boot/vmlinuz-$VERSION-slitaz
335 KVERSION=$VERSION-slitaz
336 install_module_headers $DESTDIR
338 # Compress all modules.
339 if [ -d "$DESTDIR/lib/modules/$VERSION-slitaz" ]; then
340 $stuff/gztazmod.sh $DESTDIR/lib/modules/$VERSION-slitaz
341 else
342 return 1
343 fi
344 if [ -d "$DESTDIR/linux64/lib/modules/$VERSION-slitaz64" ]; then
345 $stuff/gztazmod.sh $DESTDIR/linux64/lib/modules/$VERSION-slitaz64
346 fi
347 ln System.map System.map-modules
348 ln vmlinux vmlinux-modules
349 ln Module.symvers Module.symvers-modules
350 cp .config config-modules
351 }
353 # Rules to gen a SliTaz package suitable for Tazpkg.
354 genpkg_rules()
355 {
356 case "$ARCH" in
357 arm)
358 echo "Packing: ARM Kernel"
359 cp -a $install/* $fs
360 rm -f $fs/lib/modules/*/build $fs/lib/modules/*/source
361 return 0 ;;
362 x86_64)
363 echo "TODO: use default or custom x86_64 packing"
364 return 0 ;;
365 esac
367 export PACKAGE VERSION
368 local path
369 cp -a $install/boot $fs
371 # Compress all modules.
372 path=$fs/lib/modules/$VERSION-slitaz/kernel
373 mkdir -p $path
375 # Get the base modules
376 export src install
377 mkdir -p $WOK/$PACKAGE/source/tmp
378 # Warning stuff/list_modules.sh must find the generated modules.list
379 $stuff/list_modules.sh \
380 $(cat $stuff/modules.list) > $WOK/$PACKAGE/source/tmp/modules.list
381 while read module; do
382 dir=$(dirname $module)
383 [ -d $path/$dir ] || mkdir -p $path/$dir
384 cp -a $install/lib/modules/$VERSION-slitaz/kernel/$module $path/$dir
385 done < $WOK/$PACKAGE/source/tmp/modules.list
387 # Remove unresolved links
388 rm -f $fs/lib/modules/$VERSION-slitaz/build
389 rm -f $fs/lib/modules/$VERSION-slitaz/source
391 # We only need module.{order,builtin} because other map files are
392 # generated by depmod in post_install
393 cp -a $install/lib/modules/$VERSION-slitaz/modules.order \
394 $install/lib/modules/$VERSION-slitaz/modules.builtin \
395 $fs/lib/modules/$VERSION-slitaz
397 # Pack all packages with a kernel module
398 sed -i "/^$PACKAGE\$/d" $CACHE/broken 2>/dev/null || true
399 for i in $(cd $WOK; grep -l '^WANTED="linux"' */receipt); do
400 [ ! -d "$install/lib/modules/$VERSION-slitaz" ] && return 1
401 cook ${i%/receipt}
402 done
404 # Check any module in kernel .config that's not added to a linux-* pkgs
405 # and remove aufs patches: we dont need them in HG wok.
406 $stuff/check_modules.sh
408 # Keep fixed patches !
409 #rm -f $stuff/aufs3-*
410 }
412 # Pre and post install commands for Tazpkg.
413 post_install()
414 {
415 chroot "$root/" depmod -a $VERSION-slitaz
417 # Handle multiarch installation
418 case "$SLITAZ_ARCH" in
419 arm)
420 echo "Kernel : /boot/linux-$VERSION-slitaz-$ARCH"
421 echo "Modules: /lib/modules/$VERSION-slitaz"
422 return 0 ;;
423 esac
425 # GRUB stuff.
426 if [ -f "$1/boot/grub/menu.lst" ]; then
427 # Current root device
428 root_dev="/dev/$(lsblk | grep '/$'| grep -o '[a-z]d[a-z][0-9]*')"
429 grub_part="$(( $(echo $root_dev | grep -o '[0-9]*$')-1 ))"
430 # Use device.map to find grub device number
431 grub_dev="$(grep $(echo $root_dev | grep -o '^/dev/.d.' ) \
432 "$1/boot/grub/device.map" | cut -f1 | sed "s/)$/.$grub_part)/g")"
434 # Add and clean kernel entries in case of upgrade for installed system.
435 if ! grep -q vmlinuz-$VERSION-slitaz "$1/boot/grub/menu.lst"; then
437 # Clean the old entry
438 # TODO: old vmlinuz file is removed but the entry is still there.
439 # So grub error:15 when selected: http://bugs.slitaz.org/?id=74
441 # Add the new entry
442 cat >> "$1/boot/grub/menu.lst" << EOT
444 title SliTaz GNU/Linux (Kernel $VERSION-slitaz)
445 $grub_dev
446 kernel /boot/vmlinuz-$VERSION-slitaz root=$root_dev quiet
447 EOT
448 # Make it the default entry
449 last_entry=$(( $(grep -c '^title' "$1/boot/grub/menu.lst")-1 ))
450 sed -e "s/^default.*/default $last_entry/g" -i "$1/boot/grub/menu.lst"
451 fi
453 # Display information message.
454 cat <<EOT
456 ----
457 GRUB is installed, these tree lines must be in your /boot/grub/menu.lst:
459 title SliTaz GNU/Linux (Kernel $VERSION-slitaz)
460 $grub_dev
461 kernel /boot/vmlinuz-$VERSION-slitaz root=$root_dev
462 ----
463 EOT
464 fi
465 true
466 }