APKBUILD 8.65 KB
Newer Older
1
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
2

3 4
_mainflavor=grsec
pkgname=linux-$_mainflavor
5
pkgver=4.4.20
6 7 8 9
case $pkgver in
*.*.*)	_kernver=${pkgver%.*};;
*.*)	_kernver=${pkgver};;
esac
10
pkgrel=0
11 12
pkgdesc="Linux kernel with grsecurity"
url=http://grsecurity.net
13
depends="mkinitfs"
14 15
makedepends="perl sed installkernel bash gmp-dev bc linux-headers mpfr-dev
	mpc1-dev"
16
options="!strip"
17
install=
18 19
source="http://ftp.kernel.org/pub/linux/kernel/v4.x/linux-$_kernver.tar.xz
	http://ftp.kernel.org/pub/linux/kernel/v4.x/patch-$pkgver.xz
20
	http://dev.alpinelinux.org/~ncopa/grsec/grsecurity-3.1-$pkgver-201604252206-alpine.patch
21

22
	fix-spi-nor-namespace-clash.patch
23
	imx6q-no-unclocked-sleep.patch
24
	gcc6.patch
25

26 27 28 29 30 31
	config-grsec.x86
	config-grsec.x86_64
	config-grsec.armhf

	config-virtgrsec.x86
	config-virtgrsec.x86_64
32
	"
33
subpackages="$pkgname-dev linux-virtgrsec-dev"
34 35 36 37 38 39 40 41 42 43 44 45 46 47
_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

48
arch="x86 x86_64 armhf"
49
license="GPL2"
Natanael Copa's avatar
Natanael Copa committed
50

51
prepare() {
52
	local _patch_failed=
53
	cd "$srcdir"/linux-$_kernver
54 55
	if [ "${pkgver%.0}" = "$pkgver" ]; then
		msg "Applying patch-$pkgver.xz"
56
		unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1 -N || return 1
57 58
	fi

59 60
	# first apply patches in specified order
	for i in $source; do
61 62
		local file=${i%::*}
		case $file in
63
		*.patch)
64 65 66
			msg "Applying $file..."
			if ! patch -s -p1 -N -i "$srcdir"/${file##*/}; then
				echo $file >>failed
67 68
				_patch_failed=1
			fi
69 70
			;;
		esac
71 72
	done

73 74 75 76 77 78
	if ! [ -z "$_patch_failed" ]; then
		error "The following patches failed:"
		cat failed
		return 1
	fi

79
	# remove localversion from patch if any
80
	rm -f localversion*
81

82 83 84 85 86 87 88 89 90 91 92 93 94
	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
95 96 97
}

build() {
98
	export GCC_SPECS=hardenednopie.specs
99 100 101 102
	for i in $_flavors; do
		cd "$srcdir"/build-$i
		make CC="${CC:-gcc}" \
			KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine" \
103
			KCFLAGS="-fno-pie" \
104 105
			|| return 1
	done
106
}
Natanael Copa's avatar
Natanael Copa committed
107

108 109 110
_package() {
	local _buildflavor="$1" _outdir="$2"
	local _abi_release=${pkgver}-${pkgrel}-${_buildflavor}
111

112 113 114
	cd "$srcdir"/build-$_buildflavor || return 1

	mkdir -p "$_outdir"/boot "$_outdir"/lib/modules
115 116 117 118

	local _install
	case "$CARCH" in
	arm*)
119
		local _dtbdir="$_outdir"/usr/lib/linux-${_abi_release}
120 121 122 123 124 125 126 127 128 129 130 131 132
		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 \
133 134
		INSTALL_MOD_PATH="$_outdir" \
		INSTALL_PATH="$_outdir"/boot \
135
		|| return 1
136

137 138 139
	rm -f "$_outdir"/lib/modules/${_abi_release}/build \
		"$_outdir"/lib/modules/${_abi_release}/source
	rm -rf "$_outdir"/lib/firmware
140

141
	install -D include/config/kernel.release \
142 143 144 145 146
		"$_outdir"/usr/share/kernel/$_buildflavor/kernel.release
}

# main flavor installs in $pkgdir
package() {
147
	depends="$depends linux-firmware"
148 149 150 151 152 153
	_package grsec "$pkgdir"
}

# subflavors install in $subpkgdir
virtgrsec() {
	_package virtgrsec "$subpkgdir"
Natanael Copa's avatar
Natanael Copa committed
154 155
}

156 157 158
_dev() {
	local _flavor="$1"
	local _abi_release=${pkgver}-${pkgrel}-$_flavor
159 160 161 162
	# 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
	#
163
	# this way you dont need to install the 300-400 kernel sources to
164 165
	# build a tiny kernel module
	#
166
	pkgdesc="Headers and script for third party modules for $_flavor kernel"
167
	depends="gmp-dev bash"
168
	local dir="$subpkgdir"/usr/src/linux-headers-${_abi_release}
169

170
	# first we import config, run prepare to set up for building
171
	# external modules, and create the scripts
172
	mkdir -p "$dir"
173 174
	cp "$srcdir"/config-$_flavor.${CARCH} "$dir"/.config
	echo "-$pkgrel-$_flavor" > "$dir"/localversion-alpine \
175
		|| return 1
176
	make -j1 -C "$srcdir"/linux-$_kernver O="$dir" HOSTCC="${CC:-gcc}" \
177
		KCFLAGS="-fno-pie" \
178
		silentoldconfig prepare modules_prepare scripts
179

180 181
	# remove the stuff that poits to real sources. we want 3rd party
	# modules to believe this is the soruces
182 183
	rm "$dir"/Makefile "$dir"/source

184 185
	# copy the needed stuff from real sources
	#
186
	# this is taken from ubuntu kernel build script
187
	# http://kernel.ubuntu.com/git?p=ubuntu/ubuntu-jaunty.git;a=blob;f=debian/rules.d/3-binary-indep.mk;hb=HEAD
188 189 190 191 192 193 194 195 196 197 198
	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"
199

200
	install -Dm644 "$srcdir"/build-$_flavor/Module.symvers \
201
		"$dir"/Module.symvers
202 203 204 205

	mkdir -p "$subpkgdir"/lib/modules/${_abi_release}
	ln -sf /usr/src/linux-headers-${_abi_release} \
		"$subpkgdir"/lib/modules/${_abi_release}/build
206 207
}

208 209 210 211 212 213 214 215
dev() {
	_dev grsec
}

virtgrsec_dev() {
	_dev virtgrsec
}

216
md5sums="9a78fa2eb6c68ca5a40ed5af08142599  linux-4.4.tar.xz
217 218
335c5874b26a814987960b9170547a64  patch-4.4.20.xz
64062fa71e77623c3164b47ee6fa92f2  grsecurity-3.1-4.4.20-201604252206-alpine.patch
219 220
c32f1d7517a095a2645fc1c7dec5db8f  fix-spi-nor-namespace-clash.patch
b11c29ee88f7f537973191036d48bee7  imx6q-no-unclocked-sleep.patch
221 222 223
90e0fca6cb7bca277394b0db7f605098  gcc6.patch
2da05cb44c4f954f05f58734f4e16760  config-grsec.x86
8d86b346ae0a68fea58f3eab2338641b  config-grsec.x86_64
224
49b78c9cd95a16fa3592615efa1099b3  config-grsec.armhf
225 226
429e5174e3cbbacff55d8055df37719e  config-virtgrsec.x86
1106a5fdbf270683d91e7f20abd5fa1f  config-virtgrsec.x86_64"
227
sha256sums="401d7c8fef594999a460d10c72c5a94e9c2e1022f16795ec51746b0d165418b2  linux-4.4.tar.xz
228 229
da9d7d3548070bc4a333786778f628eaa2a76e10f21a34567f591834a9e87d27  patch-4.4.20.xz
0fe119716bc047ae2221e760bf3023c27ccfde2cfd040d405c462a315548154c  grsecurity-3.1-4.4.20-201604252206-alpine.patch
230 231
b8ce28c61663dbd92f7e1c862c042c88c4d0459ce15f6e6ea121e20705b66212  fix-spi-nor-namespace-clash.patch
7e8a954750139a421a76e414e19a3b57645c9ec70e6c14a6b7708a3fa0cfd5e4  imx6q-no-unclocked-sleep.patch
232 233 234
21640b417cb9a389bf7be6a11dc71a481ec76fcfcc758992a9be158ab6a643e8  gcc6.patch
4098706e52e79c99b56e74c5aea53ba157c561c794819c130656d92a7b452210  config-grsec.x86
7a332837c3d63bf90bbab1df759801834393894e13f8a0647976dcec9d87a376  config-grsec.x86_64
235
1a7b3e4e11c1bd28dae47eae32662191371fd94a453e7b29264c5201d804aeb6  config-grsec.armhf
236 237
67814690ece448328e4004a979f27d14a2b2eef5f5ec5a0f9fa0cc9b42157967  config-virtgrsec.x86
166c6cec181cb1e4db38b3d5b34c5db561ec78b38b40112cde916267c3a75260  config-virtgrsec.x86_64"
238
sha512sums="13c8459933a8b80608e226a1398e3d1848352ace84bcfb7e6a4a33cb230bbe1ab719d4b58e067283df91ce5311be6d2d595fc8c19e2ae6ecc652499415614b3e  linux-4.4.tar.xz
239 240
551c375ce851304edbf8969e104e4d5b570b280a90ef5502f560dc482f6d8140256baba057ce4ffeea1a9338b2775cc1dbdc9a5f2acdf630c78fce32932deadb  patch-4.4.20.xz
d5367618ea58a63fa1014522adb64574bdda5c959f829ba284015b0ff99cfd8c9500383cb900e959ef4b5967d0f7b35c4c4b94a944a4aa84fa342ecd1ccbd7a8  grsecurity-3.1-4.4.20-201604252206-alpine.patch
241 242
410fe7dae27cb4998d17a441a5b2a19dd350636ead2de97d4ef5317501d9e82e2550bfca0f022c9be6296907c076c381e1e13060d1900ff26ee7d47f234fb104  fix-spi-nor-namespace-clash.patch
9980eb10f529bc5ce482ab0a0037febbc982b528c3e4d02fc4547e6dd45dc529a7b1711d0c89f942b1ae27842c3794b68a6b8959ef80f6fd00183d3a591cea07  imx6q-no-unclocked-sleep.patch
243 244 245
edcebc229956a05621ec1c89039b56aa61b468c74b54420ff72bd08658b65d29d6af385a7d78d1ce4b39889b407106b99efe7309f8a82974a74eb9edb9e89b64  gcc6.patch
0ba45dc80b9070a18bd31155eb2e658efdf8106fb331978d0b32bea68c9a401990b681df834319c9fa8599a78583bd4c45c274aa3d251aabc740d06141c5beb6  config-grsec.x86
65c8a18d3107be8766060eb7d7c89f2b865b38dc7e93f4110bffd98ef009f9cc192b3c9ad6fecbe412208c8efa93a526e81d4362bd207e6a585f30cc22ee8603  config-grsec.x86_64
246
3e899b536d3377179f26c826d21c03e3b6792fdc1ca8576cd7a10da638f1189b1dffca4a4bf9e711fbba3b2ffe79e755b8d64d3be2511428faadd77b1fbfa8eb  config-grsec.armhf
247 248
1718c78d4d57c67cbe49d54f28789e38528eb4ebebe2e2c616a40655d6e37f29fbd4b104dfc2dc204d1114489ad549f272ef8cfd447a24bbc10a320a5b12cfd4  config-virtgrsec.x86
6dd579d31d6bf0b30058466ba9556b84d72f7ddb9630f39124cd319e9f9c57ba72af86c93ae95535be66c39e306e106b0515bd2bda5acc132533dac639810325  config-virtgrsec.x86_64"