# Maintainer: Natanael Copa _flavor=grsec pkgname=linux-${_flavor} pkgver=3.14.12 case $pkgver in *.*.*) _kernver=${pkgver%.*};; *.*) _kernver=${pkgver};; esac pkgrel=0 pkgdesc="Linux kernel with grsecurity" url=http://grsecurity.net depends="mkinitfs linux-firmware" makedepends="perl sed installkernel bash gmp-dev bc" options="!strip" _config=${config:-kernelconfig.${CARCH}} install= source="http://ftp.kernel.org/pub/linux/kernel/v3.x/linux-$_kernver.tar.xz http://ftp.kernel.org/pub/linux/kernel/v3.x/patch-$pkgver.xz grsecurity-3.0-3.14.12-201407100035.patch fix-memory-map-for-PIE-applications.patch imx6q-no-unclocked-sleep.patch kernelconfig.x86 kernelconfig.x86_64 kernelconfig.armhf " subpackages="$pkgname-dev" arch="x86 x86_64 armhf" license="GPL-2" _abi_release=${pkgver}-${pkgrel}-${_flavor} prepare() { local _patch_failed= cd "$srcdir"/linux-$_kernver if [ "${pkgver%.0}" = "$pkgver" ]; then msg "Applying patch-$pkgver.xz" unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1 -N || return 1 fi # first apply patches in specified order for i in $source; do case $i in *.patch) msg "Applying $i..." if ! patch -s -p1 -N -i "$srcdir"/$i; then echo $i >>failed _patch_failed=1 fi ;; esac done if ! [ -z "$_patch_failed" ]; then error "The following patches failed:" cat failed return 1 fi rm -f localversion* echo "-$pkgrel-$_flavor" > localversion-alpine mkdir -p "$srcdir"/build cp "$srcdir"/$_config "$srcdir"/build/.config || return 1 make -C "$srcdir"/linux-$_kernver O="$srcdir"/build HOSTCC="${CC:-gcc}" \ silentoldconfig } # this is so we can do: 'abuild menuconfig' to reconfigure kernel menuconfig() { cd "$srcdir"/build || return 1 make menuconfig cp .config "$startdir"/$_config } build() { cd "$srcdir"/build export GCC_SPECS=hardenednopie.specs make CC="${CC:-gcc}" \ KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine" \ || return 1 } package() { cd "$srcdir"/build mkdir -p "$pkgdir"/boot "$pkgdir"/lib/modules local _install case "$CARCH" in arm*) local _dtbdir="$pkgdir"/usr/lib/linux-${_abi_release} mkdir -p "$_dtbdir" for i in arch/arm/boot/dts/*.dtb ; do install -m644 "$i" "$_dtbdir" done _install=zinstall ;; *) _install=install ;; esac make -j1 modules_install firmware_install $_install \ INSTALL_MOD_PATH="$pkgdir" \ INSTALL_PATH="$pkgdir"/boot \ || return 1 rm -f "$pkgdir"/lib/modules/${_abi_release}/build \ "$pkgdir"/lib/modules/${_abi_release}/source rm -rf "$pkgdir"/lib/firmware install -D include/config/kernel.release \ "$pkgdir"/usr/share/kernel/$_flavor/kernel.release } dev() { # copy the only the parts that we really need for build 3rd party # kernel modules and install those as /usr/src/linux-headers, # simlar to what ubuntu does # # this way you dont need to install the 300-400 kernel sources to # build a tiny kernel module # pkgdesc="Headers and script for third party modules for grsec kernel" depends="gmp-dev bash" local dir="$subpkgdir"/usr/src/linux-headers-${_abi_release} # first we import config, run prepare to set up for building # external modules, and create the scripts mkdir -p "$dir" cp "$srcdir"/$_config "$dir"/.config make -j1 -C "$srcdir"/linux-$_kernver O="$dir" HOSTCC="${CC:-gcc}" \ silentoldconfig prepare modules_prepare scripts # remove the stuff that poits to real sources. we want 3rd party # modules to believe this is the soruces rm "$dir"/Makefile "$dir"/source # copy the needed stuff from real sources # # this is taken from ubuntu kernel build script # http://kernel.ubuntu.com/git?p=ubuntu/ubuntu-jaunty.git;a=blob;f=debian/rules.d/3-binary-indep.mk;hb=HEAD cd "$srcdir"/linux-$_kernver find . -path './include/*' -prune -o -path './scripts/*' -prune \ -o -type f \( -name 'Makefile*' -o -name 'Kconfig*' \ -o -name 'Kbuild*' -o -name '*.sh' -o -name '*.pl' \ -o -name '*.lds' \) | cpio -pdm "$dir" cp -a drivers/media/dvb/dvb-core/*.h "$dir"/drivers/media/dvb/dvb-core cp -a drivers/media/video/*.h "$dir"/drivers/media/video cp -a drivers/media/dvb/frontends/*.h "$dir"/drivers/media/dvb/frontends cp -a scripts include "$dir" find $(find arch -name include -type d -print) -type f \ | cpio -pdm "$dir" install -Dm644 "$srcdir"/build/Module.symvers \ "$dir"/Module.symvers mkdir -p "$subpkgdir"/lib/modules/${_abi_release} ln -sf /usr/src/linux-headers-${_abi_release} \ "$subpkgdir"/lib/modules/${_abi_release}/build } md5sums="b621207b3f6ecbb67db18b13258f8ea8 linux-3.14.tar.xz 89a5af1f3609d0c27e63fea298dd80ed patch-3.14.12.xz e8b97fb869a7c8267f2601b6a2c4ce0d grsecurity-3.0-3.14.12-201407100035.patch c6a4ae7e8ca6159e1631545515805216 fix-memory-map-for-PIE-applications.patch 1a307fc1d63231bf01d22493a4f14378 imx6q-no-unclocked-sleep.patch 83f0e1b1d2413bcb2dddcf87a10dc42b kernelconfig.x86 0b07cc6ece6232c631e2d55f2dd860d6 kernelconfig.x86_64 887980f603af6a1ac6f67edeae2e0d07 kernelconfig.armhf" sha256sums="61558aa490855f42b6340d1a1596be47454909629327c49a5e4e10268065dffa linux-3.14.tar.xz b50d9569bc2e47f3be996fdbcb043e7eace9c92cbcb77d825dd1493f2d399475 patch-3.14.12.xz cda8726421ef4038b4883212efd1efd044f430929dfb74f29f1dc5f4e618a26d grsecurity-3.0-3.14.12-201407100035.patch 500f3577310be52e87b9fecdc2e9c4ca43210fd97d69089f9005d484563f74c7 fix-memory-map-for-PIE-applications.patch 21179fbb22a5b74af0a609350ae1a170e232908572b201d02e791d2ce0a685d3 imx6q-no-unclocked-sleep.patch 5431d66b9c1af413b4dc6f91de00a6e830e3d780a79c5f85d2d8b013b151c169 kernelconfig.x86 9f420cee74896fd3578c3b342188438ac5d6b0f327586c108367abcfc3f1e6ff kernelconfig.x86_64 ab3e07f85f4dd090b2d22b485881031bd479a1c34fc9a2e9707cb8cdebfcfda4 kernelconfig.armhf" sha512sums="5730d83a7a81134c1e77c0bf89e42dee4f8251ad56c1ac2be20c59e26fdfaa7bea55f277e7af156b637f22e1584914a46089af85039177cb43485089c74ac26e linux-3.14.tar.xz d5be9e74c530f1b48fd7fb38c91d375fe60c1d71e165b0cd7a39f49e7b79c0261c8170607e6fd67ef154273601fb5a8f078ee6deb1f973c180e39762634126bf patch-3.14.12.xz 8b1d8048bd84697c729fcfbfb4c1356773cbdd73e47747db922ce1eff676c399208354c2bfe100f7548a296c33a6d294c6d5d99079a1dad6d195690a36f0b94b grsecurity-3.0-3.14.12-201407100035.patch 4665c56ae1bbac311f9205d64918e84ee8b01d47d6e2396ff6b8adfb10aada7f7254531ce62e31edbb65c2a54a830f09ad05d314dfcd75d6272f4068945ad7c7 fix-memory-map-for-PIE-applications.patch 87d1ad59732f265a5b0db54490dc1762c14ea4b868e7eb1aedc3ce57b48046de7bbc08cf5cfcf6f1380fa84063b0edb16ba3d5e3c5670be9bbb229275c88b221 imx6q-no-unclocked-sleep.patch 03f817222bf5812fa8363542e4ab108767212c67efe3994ea8fe9d0751215d9c3f166ce41de41f9070c855db6c04606828dc61265a1738920b984a24077347c4 kernelconfig.x86 bc9e8f8a2ccb51fc2e03987657da80282354c248295f76541dba0f70b387161ad086b7a6c77647506e84064a9479f37a5a6e13a28f0aad6bbfef833bb746ee7d kernelconfig.x86_64 5a248ef45ad96557fd17f42d5e813d3be88e9bcbce6b0a545cd3831e466d8bfa5cba9d02ebf318d35b99274d39e0fd337050a4f8e5443447ac595db08f6ecb08 kernelconfig.armhf"