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

3 4
_mainflavor=grsec
pkgname=linux-$_mainflavor
5
pkgver=3.18.18
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 linux-firmware"
14 15
makedepends="perl sed installkernel bash gmp-dev bc linux-headers mpfr-dev
	mpc1-dev"
16
options="!strip"
17
install=
18
source="http://ftp.kernel.org/pub/linux/kernel/v3.x/linux-$_kernver.tar.xz
19
	http://ftp.kernel.org/pub/linux/kernel/v3.x/patch-$pkgver.xz
20
	http://dev.alpinelinux.org/~tteras/grsec/grsecurity-3.1-3.18.18-201507111210-alpine.patch
21

22
	fix-memory-map-for-PIE-applications.patch
23
	0001-ip_tunnel-fix-ipv4-pmtu-check-to-honor-inner-ip-head.patch
24
	0002-ipv4-Don-t-increase-PMTU-with-Datagram-Too-Big-messa.patch
25
	0003-route-Use-ipv4_mtu-instead-of-raw-rt_pmtu.patch
26
	fix-spi-nor-namespace-clash.patch
27
	imx6q-no-unclocked-sleep.patch
28

29 30 31 32 33 34
	config-grsec.x86
	config-grsec.x86_64
	config-grsec.armhf

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

51
arch="x86 x86_64 armhf"
52
license="GPL-2"
Natanael Copa's avatar
Natanael Copa committed
53

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

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

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

81
	# remove localversion from patch if any
82
	rm -f localversion*
83

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

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

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

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

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

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

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

142
	install -D include/config/kernel.release \
143 144 145 146 147 148 149 150 151 152 153
		"$_outdir"/usr/share/kernel/$_buildflavor/kernel.release
}

# main flavor installs in $pkgdir
package() {
	_package grsec "$pkgdir"
}

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

156
# we only provide -dev for main flavor for now
157
dev() {
158
	local _abi_release=${pkgver}-${pkgrel}-$_mainflavor
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 grsec 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
	cp "$srcdir"/config-grsec.${CARCH} "$dir"/.config
174 175
	echo "-$pkgrel-grsec" > "$dir"/localversion-alpine \
		|| return 1
176
	make -j1 -C "$srcdir"/linux-$_kernver O="$dir" HOSTCC="${CC:-gcc}" \
177
		silentoldconfig prepare modules_prepare scripts
178

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

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

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

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

207
md5sums="9e854df51ca3fef8bfe566dbd7b89241  linux-3.18.tar.xz
208 209
8d2baec3d5817eb5501d5b1141279ef6  patch-3.18.18.xz
23230f4307dd6aac74266f7d80ef5ac9  grsecurity-3.1-3.18.18-201507111210-alpine.patch
210
c6a4ae7e8ca6159e1631545515805216  fix-memory-map-for-PIE-applications.patch
211
b7f15811ab0ae0a1225c03cc2cc24411  0001-ip_tunnel-fix-ipv4-pmtu-check-to-honor-inner-ip-head.patch
212
5d708f155fff5fbbbeed2785423832e2  0002-ipv4-Don-t-increase-PMTU-with-Datagram-Too-Big-messa.patch
213
7aa2fef1b8b352bae5b924ded5d9cab7  0003-route-Use-ipv4_mtu-instead-of-raw-rt_pmtu.patch
214
b0337a2a9abed17c37eae5db332522d2  fix-spi-nor-namespace-clash.patch
215
1a307fc1d63231bf01d22493a4f14378  imx6q-no-unclocked-sleep.patch
216 217 218
9c3fdf1aba9dffc9a5ebc16a2ba37735  config-grsec.x86
2cc37d1ed1e2ebf0aa1a0ace67d6f519  config-grsec.x86_64
36892e7e94abde237925ab15e9c7752c  config-grsec.armhf
219
18cb4521f9a8847637292f9f4c9e8256  config-virtgrsec.x86
220
80b45900be93b1183a6382adf710d961  config-virtgrsec.x86_64"
221
sha256sums="becc413cc9e6d7f5cc52a3ce66d65c3725bc1d1cc1001f4ce6c32b69eb188cbd  linux-3.18.tar.xz
222 223
bd43b683811ecd3b9515a3047ded08a8263f02750e335b96dfc99bf589e90d9e  patch-3.18.18.xz
f416fc2bcdfa2eabed2680d55d102d78ca47e18f17fd206794ac285955f32452  grsecurity-3.1-3.18.18-201507111210-alpine.patch
224
500f3577310be52e87b9fecdc2e9c4ca43210fd97d69089f9005d484563f74c7  fix-memory-map-for-PIE-applications.patch
225
b4a5d6fc7b1dfe43cee18cf47db3f588a4b8a03e6d474af9a6f9ef487233ba70  0001-ip_tunnel-fix-ipv4-pmtu-check-to-honor-inner-ip-head.patch
226
e6cef82ab135a8ab23111a90b95d3d034eaed32d7c5829c0322aaac491b781b7  0002-ipv4-Don-t-increase-PMTU-with-Datagram-Too-Big-messa.patch
227
14b5fb04a3cc5118a74a100fff626c73e7f297c7a020af654f2942207fe39ec9  0003-route-Use-ipv4_mtu-instead-of-raw-rt_pmtu.patch
228
01279cfb93273d99670c56e2465957ecde3d03693beeb929a743f03afa0b7bdc  fix-spi-nor-namespace-clash.patch
229
21179fbb22a5b74af0a609350ae1a170e232908572b201d02e791d2ce0a685d3  imx6q-no-unclocked-sleep.patch
230 231 232
5fc6db215c9566d937ed5162cea3a554352ba82a7b6754552e46d02ec39368d7  config-grsec.x86
c30182bf8c312141ef516154cbcf9ae6670dffeafa650126c2f375b5082087f3  config-grsec.x86_64
03ba6e2ed62e27e5fceb0bc405cccfe3de2e2d3be1486287500f38a1b2ecf786  config-grsec.armhf
233
47048993111506ab74db24c92d39b536cf5e684975844907d5cb6198c1dfd87f  config-virtgrsec.x86
234
015ce51a03f1337673b47ef996b77c55cf50a28240e37c5ebf7e66f5886d3aef  config-virtgrsec.x86_64"
235
sha512sums="2f0b72466e9bc538a675738aa416573d41bbbd7e3e2ffd5b5b127afde609ebc278cec5a3c37e73479607e957c13f1b4ed9782a3795e0dcc2cf8e550228594009  linux-3.18.tar.xz
236 237
4f1c15256b9fd72f8dc97871ab680db889bdf8c7df9ba60d36054abfdc979676e9b11d74b0438021e612046f48bcae54dc57c2628c12accdcb4fcc29231aca46  patch-3.18.18.xz
d5ee05c89c6416e70a92b0ae7f4ec5a4f1f7395e7e3ac1e5f7ee75f0a23aa2bc5cd8237cafa4defcd7ea1dd0e1e4bd30756019a8f90af4cacc07d98eff1a7832  grsecurity-3.1-3.18.18-201507111210-alpine.patch
238
4665c56ae1bbac311f9205d64918e84ee8b01d47d6e2396ff6b8adfb10aada7f7254531ce62e31edbb65c2a54a830f09ad05d314dfcd75d6272f4068945ad7c7  fix-memory-map-for-PIE-applications.patch
239
c5f7bda0a5bf88d7ce5de8c405ee5a018b652d70def2a5c6eea8e718b39efc0fed860bb61c70d950ba42cb11e0c264ee5ddd9a1505b7b60d19a56322ece894b6  0001-ip_tunnel-fix-ipv4-pmtu-check-to-honor-inner-ip-head.patch
240
0d533a7ae0fd7a524326312d5e10f505936941826766b778508c91698e1ba5b7125248cc6fbbb6adc27db0f6172a68c818fb12818e6d6a27cf4f85a961013bdb  0002-ipv4-Don-t-increase-PMTU-with-Datagram-Too-Big-messa.patch
241
af9059f3d62430e55c4105fcc28ebf4d176c0a642fc5594879eedbf5ab5bd605db32243bcbcfe5932487abe55f18ea9faee8b041dd14c3e1569331cb5db9a04f  0003-route-Use-ipv4_mtu-instead-of-raw-rt_pmtu.patch
242
4e3aeb70712f9838afea75fe9e6c1389414d833a89286ea55441d6a8d54ce74b0e39b565721e3153443af0a614bff57c767251b7e5b81faa5e0784eddfcd2164  fix-spi-nor-namespace-clash.patch
243
87d1ad59732f265a5b0db54490dc1762c14ea4b868e7eb1aedc3ce57b48046de7bbc08cf5cfcf6f1380fa84063b0edb16ba3d5e3c5670be9bbb229275c88b221  imx6q-no-unclocked-sleep.patch
244 245 246
1c8861bd213f2ed5a5d4b6205ca3453958f110ad0245940c824a3ef3983a10a937adf7e401f087d7cc6e6d0054cbb187139ef426b6e00d7fa707aab20f1d2666  config-grsec.x86
4dc18ddfd90167d5c00717fb3b4a8d8429af3613bcb6ad53e7660dd9c936e89cffbe97bc3177e655508f1bde603c18d4d4159e2de8a9b104377b74eae6eeca72  config-grsec.x86_64
025cd3689f2c1a469d855deccbab34a56e6cbcaaf59648c04af7257779136a6b4bbb96584d70ff2e2713af33da56e2b8f7eb59490ccf30eaa4b62a15051a4806  config-grsec.armhf
247
c6bebe64953a444bc7d13f932e44d081665c253121189a3ccca9d7f6145b4460e32dc0f21f4700bf6607c5c0cb79de5c8576e4da0c815d60cff0d3b90879c1d9  config-virtgrsec.x86
248
47f93ae57dc923efe81132b00a8c0a5f4aa029a5f64e411110b1ef99dc018f9d7d8af1632ea7ea42693e847388484b149f666db7dd7f423b5b1ad3baed83d75f  config-virtgrsec.x86_64"