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

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

23
	fix-spi-nor-namespace-clash.patch
24
	imx6q-no-unclocked-sleep.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"
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
61
62
63
	# first apply patches in specified order
	for i in $source; do
		case $i in
		*.patch)
			msg "Applying $i..."
64
			if ! patch -s -p1 -N -i "$srcdir"/${i##*/}; then
65
66
67
				echo $i >>failed
				_patch_failed=1
			fi
68
69
			;;
		esac
70
71
	done

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

205
md5sums="fe9dc0f6729f36400ea81aa41d614c37  linux-4.1.tar.xz
206
207
208
e1005015404c53692e8aa6dd14efff74  patch-4.1.13.xz
60472958af5339402061fce591d4bda6  pax-linux-4.1.13-test24-alpine.patch
0400a58a7adea38a1db7c05b4b3fea0d  grsec-4.1.13-3.1-201509112213-alpine.patch
209
b0337a2a9abed17c37eae5db332522d2  fix-spi-nor-namespace-clash.patch
210
1a307fc1d63231bf01d22493a4f14378  imx6q-no-unclocked-sleep.patch
211
212
213
f8eec4df8fcd64f5f4810a2840e8cee7  config-grsec.x86
dcccfa220ed2b2041971492d1dfa9440  config-grsec.x86_64
41dc69b5f5ceb6224a4d50e3837eaa6f  config-grsec.armhf
214
215
216
28754e558f94f3b3e0b0fcc27c1c955f  config-virtgrsec.x86
e1ee16152cd6b92aef67466e1710cf87  config-virtgrsec.x86_64"
sha256sums="caf51f085aac1e1cea4d00dbbf3093ead07b551fc07b31b2a989c05f8ea72d9f  linux-4.1.tar.xz
217
218
219
1c3ba78cbaa1a260798d6d0d2aa319ff41ae676b443e5bf06ab441436dcdd171  patch-4.1.13.xz
ed1f9bda75ea85c19f14c287dcf806edbaa4dd2b61b454bc1c1d1989302cf266  pax-linux-4.1.13-test24-alpine.patch
42072c95e94ecb22ee41901ddab0d07be1fb718e1032e32b263b3725f2f1d862  grsec-4.1.13-3.1-201509112213-alpine.patch
220
01279cfb93273d99670c56e2465957ecde3d03693beeb929a743f03afa0b7bdc  fix-spi-nor-namespace-clash.patch
221
21179fbb22a5b74af0a609350ae1a170e232908572b201d02e791d2ce0a685d3  imx6q-no-unclocked-sleep.patch
222
223
224
b179db21c31861da5da8a49307994e11e6a6b83d88fb3dffcf20b369ab32f8e6  config-grsec.x86
f2c3a2b565346baa29bdf48bab6da6fcfa1723b505237ef33a0655bf80ef2e18  config-grsec.x86_64
450fed9f9573bed167d34d2f00d71563cba131d3b4eac9c0348ae3e7692fb30d  config-grsec.armhf
225
226
227
fcfeedde29606b94f79f79ceb9351bd5d018aca6a76bba04459d85e4ad94939f  config-virtgrsec.x86
a3f09fc1092ecf4456980a6e2e723a9ea95746e0da5bf4a7363046614dc6ffd8  config-virtgrsec.x86_64"
sha512sums="168ef84a4e67619f9f53f3574e438542a5747f9b43443363cb83597fcdac9f40d201625c66e375a23226745eaada9176eb006ca023613cec089349e91751f3c0  linux-4.1.tar.xz
228
229
230
0fa60b9fceb6103c11ed1df8d4f264d1c4efcd75da258709f1d0a6813f8117977fa2279b36da22bd69cc2bc808b092207a438c2e80a65a988f4c72363a605832  patch-4.1.13.xz
e4a3dda981c5171155dc796e7d44756231fb7eb3f0adb233a264cb1a83058c5f075fc6e9cd1dd34823f62d308925e9536841a8f5b30c6be41a3228363e33e8e5  pax-linux-4.1.13-test24-alpine.patch
d0ff6f83f6c8e57335028ecc503ec54deb58e893eea9d409b4ffa0e99dde0fd7b2eff02dc6dcb606f42a71b05245ba4f67ce5d29c36628fa06f4238fdf3c33f9  grsec-4.1.13-3.1-201509112213-alpine.patch
231
4e3aeb70712f9838afea75fe9e6c1389414d833a89286ea55441d6a8d54ce74b0e39b565721e3153443af0a614bff57c767251b7e5b81faa5e0784eddfcd2164  fix-spi-nor-namespace-clash.patch
232
87d1ad59732f265a5b0db54490dc1762c14ea4b868e7eb1aedc3ce57b48046de7bbc08cf5cfcf6f1380fa84063b0edb16ba3d5e3c5670be9bbb229275c88b221  imx6q-no-unclocked-sleep.patch
233
234
235
b31862d0998cbe72882f2db3ab9452051bb5202a3921f5f4aebb24727a187227792af88c6b6ceef8ff28ab34123d1321bb8d06656f37c844afcf566571ba8865  config-grsec.x86
87c4c3be53f03ee6e7c4fa1853b43c506ee5d35d4c156b5030424b7712e469521898a56c0b6a4562e31ea2bca855dae7429ea9048f9d2fa8b29db2d14211d230  config-grsec.x86_64
7cf01405de57b195799395298e76aae9857aef180dd92e08dafbfe8a957d98821032b1c34db3d287430b9b8d4a9e9d0fe9e8f1fc46fd6f2e94b969faf41d2aab  config-grsec.armhf
236
237
caec0c97bfd25c9cc6921addc8b39941284a38746d5b9c5f19c0f1fe679d9f4c6ee7881a2eb95a16dcfbb082486435f467d27d539405ee6094b70d13b3bf2276  config-virtgrsec.x86
36f4cb73009cb5cf9f8e52ceae3537e8d84f4eaa1a7aa3850c893472cc661ce76b65b88403a3d7fa0bf31b179ac030bf0b8a1188214c771ebbc1c92c95d398a2  config-virtgrsec.x86_64"