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

3 4
_mainflavor=grsec
pkgname=linux-$_mainflavor
5
pkgver=4.4.8
6 7 8 9
case $pkgver in
*.*.*)	_kernver=${pkgver%.*};;
*.*)	_kernver=${pkgver};;
esac
10
pkgrel=2
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
	https://raw.githubusercontent.com/slashbeast/grsecurity-scrape/master/test/grsecurity-3.1-4.4.8-201604252206.patch
21

22
	fix-spi-nor-namespace-clash.patch
23
	imx6q-no-unclocked-sleep.patch
24
	xsa174.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 103 104
	for i in $_flavors; do
		cd "$srcdir"/build-$i
		make CC="${CC:-gcc}" \
			KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine" \
			|| return 1
	done
105
}
Natanael Copa's avatar
Natanael Copa committed
106

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

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

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

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

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

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

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

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

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

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

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

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

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

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

206 207 208 209 210 211 212 213
dev() {
	_dev grsec
}

virtgrsec_dev() {
	_dev virtgrsec
}

214
md5sums="9a78fa2eb6c68ca5a40ed5af08142599  linux-4.4.tar.xz
215
c1d8f46e5b2ee7c925fc38f20a3726d3  patch-4.4.8.xz
216
c2a6b88b18bc5b54d0d7122a1c692060  grsecurity-3.1-4.4.8-201604252206.patch
217 218
c32f1d7517a095a2645fc1c7dec5db8f  fix-spi-nor-namespace-clash.patch
b11c29ee88f7f537973191036d48bee7  imx6q-no-unclocked-sleep.patch
219
14a8a1826416f04ae98918145139cea6  xsa174.patch
220
af91f128ddf9407bb212cbaebca79354  config-grsec.x86
221
503656217c0cfb0c481b3804285f0166  config-grsec.x86_64
222 223
a453b5ddc5ce5b1ed487747ae785d615  config-grsec.armhf
ff753181afb1538d9d3d14fe65f834c8  config-virtgrsec.x86
224
807a5cc9253c26d96243cc3188f7ea8c  config-virtgrsec.x86_64"
225
sha256sums="401d7c8fef594999a460d10c72c5a94e9c2e1022f16795ec51746b0d165418b2  linux-4.4.tar.xz
226
11ec99ae0600bd831ff8d71b77e64592f4b6918b7857fd9ff0284ea4cf267b4e  patch-4.4.8.xz
227
b631b75cf38e08409812e9869f3a8b5b5b5085ba32ab62fd4c03d803f652a57f  grsecurity-3.1-4.4.8-201604252206.patch
228 229
b8ce28c61663dbd92f7e1c862c042c88c4d0459ce15f6e6ea121e20705b66212  fix-spi-nor-namespace-clash.patch
7e8a954750139a421a76e414e19a3b57645c9ec70e6c14a6b7708a3fa0cfd5e4  imx6q-no-unclocked-sleep.patch
230
cbec70e183f76b4081ebba05c0a8105bd4952d164a2e5c40528c05bf8861ddef  xsa174.patch
231
c247a003fb358f611d801277f89a13393d1620ad804553ada97433ef52a7706b  config-grsec.x86
232
d2b771f67eecad71745956dc0dea40fc702f39e4caee195b11877307d5ab2622  config-grsec.x86_64
233 234
ac8407f225ff6cb6be9ccd69729262241e61455f816cdea3070e30ddf453f7db  config-grsec.armhf
8b4a1927b831e94f65ec1b08f9e3bf3f64cea1e6e85e3b6b3dc1a8796e0f206d  config-virtgrsec.x86
235
5d46d80c811d6d321569f3f4550769cd4f68b46b8fa5406e7b0f350e00eec1a6  config-virtgrsec.x86_64"
236
sha512sums="13c8459933a8b80608e226a1398e3d1848352ace84bcfb7e6a4a33cb230bbe1ab719d4b58e067283df91ce5311be6d2d595fc8c19e2ae6ecc652499415614b3e  linux-4.4.tar.xz
237
d53d6950bc121107fecec91b4cd33473b0b18e7188bd387cd02f3ab4ece0f7dc6f1530ad9b7a44655afb7d823fb94ad8d8710902367c9b12911eb2247a12f2c7  patch-4.4.8.xz
238
49ec328ec1a5232af1f370101a64d9b7021bd2cb7744b3db181311d6aa4886ba1ef36457fbf22b97b21b0ad313fbea780c9441778e4d5bb9f8deae76dd6e499d  grsecurity-3.1-4.4.8-201604252206.patch
239 240
410fe7dae27cb4998d17a441a5b2a19dd350636ead2de97d4ef5317501d9e82e2550bfca0f022c9be6296907c076c381e1e13060d1900ff26ee7d47f234fb104  fix-spi-nor-namespace-clash.patch
9980eb10f529bc5ce482ab0a0037febbc982b528c3e4d02fc4547e6dd45dc529a7b1711d0c89f942b1ae27842c3794b68a6b8959ef80f6fd00183d3a591cea07  imx6q-no-unclocked-sleep.patch
241
a86f88db750defec35d3afebdde565de2c6bc304f9a110c6091e0d38261a4bdc0ddbdd1df1913a894f57877acacfdb96d98635729f913a7ed344f627e40a9af3  xsa174.patch
242
d7cb2b8600bd95c25aba5fc21f27a89eb1257d003c6e98bc81989a6027536c15c4c4abbcdc16fadd84383d3e29c6814ddf0c4f8524b53b69eed8763cc2c14e92  config-grsec.x86
243
900d18cb27b99ca91cb48fa8fc27a74f1b700eb826ef26fcfa18a379e9b7521ddac65edc57757de766e76d1c576a4d6e80a6778afc3c34394b165ab9a707cba0  config-grsec.x86_64
244 245
97de0656bbf99b66431587fda8c914aa08950c1865de018ed7a1b5f99b98f91e2e935d2341dbab44af1ca8c2370953fbbeca58c00e201f97e1b15bbec41d52d6  config-grsec.armhf
fdfdb0600ac79a08d1cd3bd54a70e0bb6ba714f9b1680336d51b64a8a007abae15adb3ce4f94ffc76f0744c4a8ffe553d0cc9a15c3e4e1629935ce50a533e798  config-virtgrsec.x86
246
815498782a00d2d3137390961dbf7bd2c0f06f110a4e593418b7edb5497a543a0ace225509cda90af6dd6ec1e9e4584c7a602fabd03e274bc29f27e176e5bb45  config-virtgrsec.x86_64"