# vim: set syn=sh: #Maintainer: Dimitris Tzemos # Use fake-uname to match the kernel version you want to compile KVER=$(uname -r) pkgname=kernel pkgver=$(echo $KVER|tr - .) pkgrel=1dj source=(modules.conf config-x86_64-$KVER config-x86-$KVER) docs=("copying") slackdesc=\ ( #|-----handy-ruler------------------------------------------------------| "$pkgname (Linux kernel for Salix)" "" "This is the same kernel config as kernel-huge" ) build() { export KVEREXTRA=$(uname -r) export KVER=$(echo $KVEREXTRA|sed 's/\(.*\)-.*/\1/') export SRC=$startdir/src export DEST=$startdir/pkg export nbthreads=$(cat /proc/cpuinfo | grep ^processor | wc -l) # clone the kernel echo '########################################' echo "Cloning /usr/src/linux-$KVER..." echo '########################################' rsync --inplace --progress -a /usr/src/linux-$KVER/ $SRC/linuxsrc/ || exit 1 ( ARCH_BAK=$ARCH unset ARCH cd $SRC/linuxsrc # clean the kernel make mrproper || exit 1 # use a suitable configuration for new kernel. if [[ "$arch" == "x86_64" ]]; then cp $SRC/config-x86_64-$KVEREXTRA .config else cp $SRC/config-x86-$KVEREXTRA .config fi make oldconfig scripts prepare || exit 1 echo "about to compile..." echo "Press any key to continue..." read R echo '########################################' echo "Compiling modules..." echo '########################################' make -j $nbthreads modules || exit 1 echo '########################################' echo "Compiling kernel image..." echo '########################################' make -j $nbthreads bzImage || exit 1 export INSTALL_MOD_PATH=$DEST echo '########################################' echo "Installing modules..." echo '########################################' make modules_install || exit 1 echo '########################################' echo "Installing firmware..." echo '########################################' make firmware_install || exit 1 unset INSTALL_MOD_PATH ARCH=$ARCH_BAK ) if [ $? -ne 0 ]; then exit 1 fi echo '########################################' echo "copy the kernel..." echo '########################################' # copy the kernel cd $DEST mkdir -p boot ( cd boot cp $SRC/linuxsrc/.config config-$KVEREXTRA cp $SRC/linuxsrc/System.map System.map-$KVEREXTRA cp $SRC/linuxsrc/arch/x86/boot/bzImage vmlinuz-$KVEREXTRA ln -s config-$KVEREXTRA config ln -s System.map-$KVEREXTRA System.map ln -s vmlinuz-$KVEREXTRA vmlinuz ) echo '########################################' echo "create rc.modules..." echo '########################################' # create rc.modules mkdir -p etc/rc.d cat << EOF > etc/rc.d/rc.modules #!/bin/sh # rc.modules $(date) # # This file loads extra drivers into the Linux kernel. # As kmod and udev handle module loading, this file will be mostly # commented out, but is still useful for loading selected modules at boot time. # RELEASE=\$(uname -r) # Update kernel module dependencies: if [ -e "/lib/modules/$RELEASE/modules.dep" ]; then echo "Updating module dependency list for $RELEASE: /sbin/depmod --quick" /sbin/depmod --quick else echo "Creating module dependency list for $RELEASE: /sbin/depmod --all" /sbin/depmod --all fi # Run any rc.modules-$(uname -r) file that exists (this is used # if you have specific modules which should only be loaded for # specific kernel versions): if [ -x "/etc/rc.d/rc.modules-$RELEASE" ]; then /etc/rc.d/rc.modules-$RELEASE fi # Run a local (sysadmin-version) of rc.modules if it exists: if [ -x "/etc/rc.d/rc.modules.local" ]; then /etc/rc.d/rc.modules.local fi EOF sed -e "s@_ROOT_@$DEST@ ; s/_KVER_/${KVEREXTRA}/" $SRC/modules.conf > $DEST/modules.conf export MODULECONF=$DEST/modules.conf /sbin/depmod -a -b $DEST -F $DEST/boot/System.map $KVEREXTRA || exit 1 /bin/chmod 755 etc/rc.d/rc.modules rm -rf $DEST/modules.conf $DEST/persist unset MODULECONF echo '##############################################################################' echo "copy the kernel source outside the SLKBUILD tree to keep it...." echo '##############################################################################' # copy the kernel source outside the SLKBUILD tree to keep it. mkdir -p $startdir/linuxsrc/usr/src/linux-$KVER cp -r $SRC/linuxsrc/* $startdir/linuxsrc/usr/src/linux-$KVER echo '##############################################################################' echo "copy files necessary for later builds, like nvidia, ati, vbox and vmware...." echo '##############################################################################' # copy files necessary for later builds, like nvidia, ati, vbox and vmware ( cd $SRC/linuxsrc mkdir -p $DEST/usr/src/linux-$KVER/include mkdir -p $DEST/usr/src/linux-$KVER/arch for i in acpi asm-generic config drm generated linux math-emu media net pcmcia scsi sound trace video xen; do cp -rf include/$i $DEST/usr/src/linux-$KVER/include/ done cp -rf arch/x86 $DEST/usr/src/linux-$KVER/arch/ cp -rf scripts Makefile Kbuild Module.symvers .config $DEST/usr/src/linux-$KVER/ # fix permissions on scripts dir chmod 755 -R $DEST/usr/src/linux-$KVER/scripts echo '########################################' echo "copy Kconfig files...." echo '########################################' # copy Kconfig files for i in $(find . -name "Kconfig*"); do mkdir -p $DEST/usr/src/linux-$KVER/$(dirname $i) cp $i $DEST/usr/src/linux-$KVER/$i done echo '###########################################################' echo "delete the kernel binary in the sources...." echo '###########################################################' # delete the kernel binary in the sources rm -f $DEST/usr/src/linux-$KVER/arch/x86/boot/compressed/vmlinux $DEST/usr/src/linux-$KVER/arch/x86/boot/compressed/vmlinux.bin* $DEST/usr/src/linux-$KVER/arch/x86/boot/vmlinux.bin $DEST/usr/src/linux-$KVER/arch/x86/boot/bzImage echo '########################################' echo "delete all .o files...." echo '########################################' # delete all .o files for i in $(find $DEST/usr/src/linux-$KVER -name '*.o'); do rm -f $i done ) echo '###########################################################' echo "fix build and source link in /lib/modules/XXX/...." echo '###########################################################' # fix build and source link in /lib/modules/XXX/ ( cd $DEST/lib/modules/$KVEREXTRA/ rm -f build && ln -s /usr/src/linux-$KVER build rm -f source && ln -s /usr/src/linux-$KVER source ) ( echo '############################################################################################################' echo "create kernel-custom, kernel-custom-modules, kernel-custom-firmware, kernel-custom-source packages...." echo '############################################################################################################' rm -rf $startdir/${pkgname} rm -rf $startdir/${pkgname}-modules rm -rf $startdir/${pkgname}-firmware mkdir $startdir/${pkgname} mkdir -p $startdir/${pkgname}-modules/lib mkdir -p $startdir/${pkgname}-firmware/lib cp -r $DEST/boot $startdir/${pkgname} cp -r $DEST/etc $startdir/${pkgname}-modules/ cp -r $DEST/lib/modules $startdir/${pkgname}-modules/lib/ cp -r $DEST/lib/firmware $startdir/${pkgname}-firmware/lib/ cd $startdir/${pkgname} echo '########################################' echo "create package $pkgname-custom-$pkgver-$arch-$pkgrel.txz...." echo '########################################' makepkg -l y -c n $startdir/$pkgname-custom-$pkgver-$arch-$pkgrel.txz cd $startdir/$pkgname-modules/ echo '########################################' echo "create package $pkgname-custom-modules-$pkgver-$arch-$pkgrel.txz...." echo '########################################' makepkg -l y -c n $startdir/$pkgname-custom-modules-$pkgver-$arch-$pkgrel.txz cd $startdir/$pkgname-firmware/ echo '########################################' echo "create package $pkgname-custom-firmware-$pkgver-$arch-$pkgrel.txz...." echo '########################################' makepkg -l y -c n $startdir/$pkgname-custom-firmware-$pkgver-$arch-$pkgrel.txz # create the kernel source package need for build kernel modules cd $startdir/linuxsrc/usr/src/linux-$KVER cp $SRC/linuxsrc/.config .config make clean cd $startdir/linuxsrc/usr/src/ ln -sf linux-$KVER linux cd $startdir/linuxsrc/ echo '########################################' echo "create package $pkgname-custom-source-$pkgver-$arch-$pkgrel.txz...." echo '########################################' makepkg -l y -c n $startdir/$pkgname-custom-source-$pkgver-noarch-$pkgrel.txz cd $startdir/ md5sum $pkgname-custom-$pkgver-$arch-$pkgrel.txz > $pkgname-custom-$pkgver-$arch-$pkgrel.md5 md5sum $pkgname-custom-modules-$pkgver-$arch-$pkgrel.txz > $pkgname-custom-modules-$pkgver-$arch-$pkgrel.md5 md5sum $pkgname-custom-firmware-$pkgver-$arch-$pkgrel.txz > $pkgname-custom-firmware-$pkgver-$arch-$pkgrel.md5 md5sum $pkgname-custom-source-$pkgver-noarch-$pkgrel.txz > $pkgname-custom-source-$pkgver-noarch-$pkgrel.md5 # clean build directories rm -rf $startdir/${pkgname} rm -rf $startdir/${pkgname}-modules rm -rf $startdir/${pkgname}-firmware ) }