# Maintainer: Natanael Copa _mainflavor=grsec pkgname=linux-$_mainflavor pkgver=4.4.59 case $pkgver in *.*.*) _kernver=${pkgver%.*};; *.*) _kernver=${pkgver};; esac pkgrel=0 pkgdesc="Linux kernel with grsecurity" url=http://grsecurity.net depends="mkinitfs" makedepends="perl sed installkernel bash gmp-dev bc linux-headers mpfr-dev mpc1-dev" options="!strip" install= source="https://cdn.kernel.org/pub/linux/kernel/v4.x/patch-$pkgver.xz https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-$_kernver.tar.xz http://dev.alpinelinux.org/~ncopa/grsec/grsecurity-3.1-$pkgver-201604252206-alpine.patch fix-spi-nor-namespace-clash.patch imx6q-no-unclocked-sleep.patch gcc6.patch config-grsec.x86 config-grsec.x86_64 config-grsec.armhf config-virtgrsec.x86 config-virtgrsec.x86_64 " subpackages="$pkgname-dev:_dev linux-virtgrsec-dev:_dev" _flavors= for _i in $source; do case $_i in config-*.$CARCH) _f=${_i%.$CARCH} _f=${_f#config-} _flavors="$_flavors ${_f}" if [ "linux-$_f" != "$pkgname" ]; then subpackages="$subpackages linux-${_f}" fi ;; esac done arch="x86 x86_64 armhf" license="GPL2" 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 local file=${i%::*} case $file in *.patch) msg "Applying $file..." if ! patch -s -p1 -N -i "$srcdir"/${file##*/}; then echo $file >>failed _patch_failed=1 fi ;; esac done if ! [ -z "$_patch_failed" ]; then error "The following patches failed:" cat failed return 1 fi # remove localversion from patch if any rm -f localversion* for i in $_flavors; do local _config=config-$i.${CARCH} local _builddir="$srcdir"/build-$i mkdir -p "$_builddir" echo "-$pkgrel-$i" > "$srcdir"/build-$i/localversion-alpine \ || return 1 cp "$srcdir"/$_config "$_builddir"/.config || return 1 make -C "$srcdir"/linux-$_kernver \ O="$_builddir" \ HOSTCC="${CC:-gcc}" \ silentoldconfig || return 1 done } build() { for i in $_flavors; do cd "$srcdir"/build-$i make CC="${CC:-gcc}" \ KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine" \ || return 1 done } _package() { local _buildflavor="$1" _outdir="$2" local _abi_release=${pkgver}-${pkgrel}-${_buildflavor} cd "$srcdir"/build-$_buildflavor || return 1 mkdir -p "$_outdir"/boot "$_outdir"/lib/modules local _install case "$CARCH" in arm*) local _dtbdir="$_outdir"/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="$_outdir" \ INSTALL_PATH="$_outdir"/boot \ || return 1 rm -f "$_outdir"/lib/modules/${_abi_release}/build \ "$_outdir"/lib/modules/${_abi_release}/source rm -rf "$_outdir"/lib/firmware install -D include/config/kernel.release \ "$_outdir"/usr/share/kernel/$_buildflavor/kernel.release } # main flavor installs in $pkgdir package() { depends="$depends linux-firmware" _package grsec "$pkgdir" } # subflavors install in $subpkgdir virtgrsec() { _package virtgrsec "$subpkgdir" } _dev() { local _flavor=$(echo $subpkgname | sed -E 's/(^linux-|-dev$)//g') local _abi_release=${pkgver}-${pkgrel}-$_flavor # 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 $_flavor 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-$_flavor.${CARCH} "$dir"/.config echo "-$pkgrel-$_flavor" > "$dir"/localversion-alpine \ || return 1 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-$_flavor/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="fbfec16499141aeedefac22ed2a8fdf0 patch-4.4.59.xz 9a78fa2eb6c68ca5a40ed5af08142599 linux-4.4.tar.xz ee1ab3813c33bcd9a5a74fe3c3170b94 grsecurity-3.1-4.4.59-201604252206-alpine.patch c32f1d7517a095a2645fc1c7dec5db8f fix-spi-nor-namespace-clash.patch b11c29ee88f7f537973191036d48bee7 imx6q-no-unclocked-sleep.patch 90e0fca6cb7bca277394b0db7f605098 gcc6.patch 0220ccde4e102bd54ad334a23347a432 config-grsec.x86 e1b185c3baea29a66dfa8f90967c1120 config-grsec.x86_64 35d10d9444978dc8009e9da5e33b0f43 config-grsec.armhf 9b89c4ec614023e20f8e905ec2bad212 config-virtgrsec.x86 87243f2790108ca568192169d3ca7408 config-virtgrsec.x86_64" sha256sums="356089a229c730e0b29d32b21354cee42646c600cafb5b923ecb32ba0f086421 patch-4.4.59.xz 401d7c8fef594999a460d10c72c5a94e9c2e1022f16795ec51746b0d165418b2 linux-4.4.tar.xz 3cab6e97352aa335027b3b7a920ebe97db8f3a522f4e46249fd5af4edc378c2b grsecurity-3.1-4.4.59-201604252206-alpine.patch b8ce28c61663dbd92f7e1c862c042c88c4d0459ce15f6e6ea121e20705b66212 fix-spi-nor-namespace-clash.patch 7e8a954750139a421a76e414e19a3b57645c9ec70e6c14a6b7708a3fa0cfd5e4 imx6q-no-unclocked-sleep.patch 21640b417cb9a389bf7be6a11dc71a481ec76fcfcc758992a9be158ab6a643e8 gcc6.patch 8ca6e71c3b0e0013a05dd95655de733f533055bdcdaade52667789c578b9bebc config-grsec.x86 588fb21febe695a7724ec00cb1576913cdb5ad12e12d00b3a0f73342c46cfe0c config-grsec.x86_64 d975df937d5a82b48bba790bd50bf7ed04782d92755a6eeacedc9e2796633e7a config-grsec.armhf 09e5db637018516a2216c9a45a47a471af69fdf94218e6ea016ec8261cd899d3 config-virtgrsec.x86 7b38853b6d83223242832413669d7818ef1218c6b9e565e11dcc8b08f64a26e3 config-virtgrsec.x86_64" sha512sums="f74eabfcd0e02f99ca62b6ed601325226841374107a30e0856f44c790d9a27dcd66af50d2da3425f8522ea84ba9829c5ab36a999fc42aa5cc9d438eb43414437 patch-4.4.59.xz 13c8459933a8b80608e226a1398e3d1848352ace84bcfb7e6a4a33cb230bbe1ab719d4b58e067283df91ce5311be6d2d595fc8c19e2ae6ecc652499415614b3e linux-4.4.tar.xz 76854afae8cda7800d828ead63ec50731e28c0df26ff0cb678b9d8cb840b6585e3c1ae14ddbda5de44088e4fc66d2b65e770df5653c9989d4c2004d4080b7bd3 grsecurity-3.1-4.4.59-201604252206-alpine.patch 410fe7dae27cb4998d17a441a5b2a19dd350636ead2de97d4ef5317501d9e82e2550bfca0f022c9be6296907c076c381e1e13060d1900ff26ee7d47f234fb104 fix-spi-nor-namespace-clash.patch 9980eb10f529bc5ce482ab0a0037febbc982b528c3e4d02fc4547e6dd45dc529a7b1711d0c89f942b1ae27842c3794b68a6b8959ef80f6fd00183d3a591cea07 imx6q-no-unclocked-sleep.patch edcebc229956a05621ec1c89039b56aa61b468c74b54420ff72bd08658b65d29d6af385a7d78d1ce4b39889b407106b99efe7309f8a82974a74eb9edb9e89b64 gcc6.patch 2d41ef3629dc4c2b71d2bd9707ecf1883bd9a264168425d56b35bb49cfd7b0a73b154501cf54c9f9df1848f3c564e502f276985b38a1dab3a067d5485874fcc6 config-grsec.x86 c064ba25b0cb28d2f9c20da77899c6df6844b2538225011a063094c527a5ba59de5fbf619494dfb5c45fae91b637876493cc839095a9fc559d2f8cf9aa8003d3 config-grsec.x86_64 a19b8179cce90e5cfe0ee30c85c0e9fd67274290d7556a5f2cb530ba9ee5f6e941ff96f20cebbd0223f3febfe8b0e3f30c7c2696dd9184c1d3ca9dcb0eca6f4a config-grsec.armhf 8c92f68afcf483ce203c8117d9459c3db0363a69b2112a2f1b67474532250d1ec9350aab555e69794709a045f8bf121ded9441f0cffc018b5a38746f9b908eee config-virtgrsec.x86 eb8d9d51dcbb762c954b41fa5e4d34d0a2da2fe6bd36a009db4fbf9513d07846ecbc648108cc93c1b6029b94f8a3dc703ab1d5f601fe8a70a369a3685fcb6260 config-virtgrsec.x86_64"