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

3 4
_mainflavor=grsec
pkgname=linux-$_mainflavor
5
pkgver=4.1.11
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/~tteras/grsec/pax-linux-4.1.11-test24-alpine.patch
21
	http://dev.alpinelinux.org/~tteras/grsec/grsec-4.1.y-3.1-201509112213-alpine.patch
22

23
	0002-ipv4-Don-t-increase-PMTU-with-Datagram-Too-Big-messa.patch
24
	fix-spi-nor-namespace-clash.patch
25
	imx6q-no-unclocked-sleep.patch
26

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

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

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

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

60 61 62 63 64
	# first apply patches in specified order
	for i in $source; do
		case $i in
		*.patch)
			msg "Applying $i..."
65
			if ! patch -s -p1 -N -i "$srcdir"/${i##*/}; then
66 67 68
				echo $i >>failed
				_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
# we only provide -dev for main flavor for now
156
dev() {
157
	local _abi_release=${pkgver}-${pkgrel}-$_mainflavor
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 grsec 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
	cp "$srcdir"/config-grsec.${CARCH} "$dir"/.config
173 174
	echo "-$pkgrel-grsec" > "$dir"/localversion-alpine \
		|| 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-$_mainflavor/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
md5sums="fe9dc0f6729f36400ea81aa41d614c37  linux-4.1.tar.xz
207 208
46a403b167416719901565190298e680  patch-4.1.11.xz
15977c12236e3a4f8f61c74ce90a4402  pax-linux-4.1.11-test24-alpine.patch
209
d4d64785f2ff77db38477b3da0d86f9a  grsec-4.1.y-3.1-201509112213-alpine.patch
210
5d708f155fff5fbbbeed2785423832e2  0002-ipv4-Don-t-increase-PMTU-with-Datagram-Too-Big-messa.patch
211
b0337a2a9abed17c37eae5db332522d2  fix-spi-nor-namespace-clash.patch
212
1a307fc1d63231bf01d22493a4f14378  imx6q-no-unclocked-sleep.patch
213 214 215 216 217 218
1bcf1c98ab042ae7868aca90e0ceaaee  config-grsec.x86
ff2951230d00d1cb295031c682863748  config-grsec.x86_64
c4486da497494f746e54cf82cf2e153f  config-grsec.armhf
28754e558f94f3b3e0b0fcc27c1c955f  config-virtgrsec.x86
e1ee16152cd6b92aef67466e1710cf87  config-virtgrsec.x86_64"
sha256sums="caf51f085aac1e1cea4d00dbbf3093ead07b551fc07b31b2a989c05f8ea72d9f  linux-4.1.tar.xz
219 220
f98156dd7ceac2849de16b38cdb7a530cd3c74833ab613e0822b7bc4583cccb1  patch-4.1.11.xz
ed4626d4de2a283ac087617ebee5ec17e28b372ca060ae83bfd2b2e2cf0bb7f4  pax-linux-4.1.11-test24-alpine.patch
221
7258089a5e2d5ca65135e47cf13400c47a657f5b2f6ef3f2e2b7383a758e00f8  grsec-4.1.y-3.1-201509112213-alpine.patch
222
e6cef82ab135a8ab23111a90b95d3d034eaed32d7c5829c0322aaac491b781b7  0002-ipv4-Don-t-increase-PMTU-with-Datagram-Too-Big-messa.patch
223
01279cfb93273d99670c56e2465957ecde3d03693beeb929a743f03afa0b7bdc  fix-spi-nor-namespace-clash.patch
224
21179fbb22a5b74af0a609350ae1a170e232908572b201d02e791d2ce0a685d3  imx6q-no-unclocked-sleep.patch
225 226 227 228 229 230
d9fa91765f13f00fff2a4bb39e6ecf91940ff4e83e9b4ade5783eab4b7c0faac  config-grsec.x86
79cf436f28b723eaeae721e2ae5d2cd1aad5a6e16080cf314c481d5278d7346b  config-grsec.x86_64
6e6fdaab4a9229d4e3bd0e68e5ee7d5bf2562215a72cf16f98071015cd98ba52  config-grsec.armhf
fcfeedde29606b94f79f79ceb9351bd5d018aca6a76bba04459d85e4ad94939f  config-virtgrsec.x86
a3f09fc1092ecf4456980a6e2e723a9ea95746e0da5bf4a7363046614dc6ffd8  config-virtgrsec.x86_64"
sha512sums="168ef84a4e67619f9f53f3574e438542a5747f9b43443363cb83597fcdac9f40d201625c66e375a23226745eaada9176eb006ca023613cec089349e91751f3c0  linux-4.1.tar.xz
231 232
ebd9f9ed7a4921795a0aee43440f6c73bf2ba058a690eb96031b978e61e390ef4d3b64e818a7cce7fe520adb20b93e4b7dd485b50d32c2dcf3012db3477a852c  patch-4.1.11.xz
67bcf3f23a9ee93186e3307d0344a11a9172137d176182ac63b50960eccf9cc0ee476cde7aaee266b98b6121a3efbafdfa41466724e6b04057e91f839eaa636f  pax-linux-4.1.11-test24-alpine.patch
233
7d25216434876e4cdbab9c3a37f554a1ad908416c2afa8b70e92d681029accdd120c9ee4e5ed3df54f806920f05e0e29f0e06fc417083b953e26401be350858d  grsec-4.1.y-3.1-201509112213-alpine.patch
234
0d533a7ae0fd7a524326312d5e10f505936941826766b778508c91698e1ba5b7125248cc6fbbb6adc27db0f6172a68c818fb12818e6d6a27cf4f85a961013bdb  0002-ipv4-Don-t-increase-PMTU-with-Datagram-Too-Big-messa.patch
235
4e3aeb70712f9838afea75fe9e6c1389414d833a89286ea55441d6a8d54ce74b0e39b565721e3153443af0a614bff57c767251b7e5b81faa5e0784eddfcd2164  fix-spi-nor-namespace-clash.patch
236
87d1ad59732f265a5b0db54490dc1762c14ea4b868e7eb1aedc3ce57b48046de7bbc08cf5cfcf6f1380fa84063b0edb16ba3d5e3c5670be9bbb229275c88b221  imx6q-no-unclocked-sleep.patch
237 238 239 240 241
98eaa89a171bef67c59c51ad91ea764992a10cfbcce5b1ad01fbbb576f05de6db4dfbb5eabc166994ae7faacb7e89f53580fc0e609e4eebc7e5c8b1fe2d38b7f  config-grsec.x86
e441d0d7f0575656773e25c4cbde6668aaf1e96942482b5cecd78704b386d2be206104a501945476f5ff12af5a822c56af45a1d79d3e85b28afa3132cdd58062  config-grsec.x86_64
6bd17b168a3f083247e673cf9a8786059969796d4962fe6442f453fa3eae06f8c93131270d0cea2c0cb36515bd3cae4896c97ccf6c58c7cb9657843b31a1f307  config-grsec.armhf
caec0c97bfd25c9cc6921addc8b39941284a38746d5b9c5f19c0f1fe679d9f4c6ee7881a2eb95a16dcfbb082486435f467d27d539405ee6094b70d13b3bf2276  config-virtgrsec.x86
36f4cb73009cb5cf9f8e52ceae3537e8d84f4eaa1a7aa3850c893472cc661ce76b65b88403a3d7fa0bf31b179ac030bf0b8a1188214c771ebbc1c92c95d398a2  config-virtgrsec.x86_64"