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

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

21
	fix-memory-map-for-PIE-applications.patch
22
	fix-spi-nor-namespace-clash.patch
23
	imx6q-no-unclocked-sleep.patch
24

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

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

47
arch="x86 x86_64 armhf"
48
license="GPL-2"
Natanael Copa's avatar
Natanael Copa committed
49

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

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

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

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

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

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

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

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

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

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

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

138
	install -D include/config/kernel.release \
139 140 141 142 143 144 145 146 147 148 149
		"$_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
150 151
}

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

166
	# first we import config, run prepare to set up for building
167
	# external modules, and create the scripts
168
	mkdir -p "$dir"
169
	cp "$srcdir"/config-grsec.${CARCH} "$dir"/.config
170
	make -j1 -C "$srcdir"/linux-$_kernver O="$dir" HOSTCC="${CC:-gcc}" \
171
		silentoldconfig prepare modules_prepare scripts
172

173 174
	# remove the stuff that poits to real sources. we want 3rd party
	# modules to believe this is the soruces
175 176
	rm "$dir"/Makefile "$dir"/source

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

193
	install -Dm644 "$srcdir"/build-$_mainflavor/Module.symvers \
194
		"$dir"/Module.symvers
195 196 197 198

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

201
md5sums="9e854df51ca3fef8bfe566dbd7b89241  linux-3.18.tar.xz
202
84d1fb9f072df226e920f6a0a3e7d10a  patch-3.18.12.xz
203
276ada8c66fa29524cceebbb75bb532a  grsecurity-3.1-3.18.11-201504190814-alpine.patch
204
c6a4ae7e8ca6159e1631545515805216  fix-memory-map-for-PIE-applications.patch
205
b0337a2a9abed17c37eae5db332522d2  fix-spi-nor-namespace-clash.patch
206
1a307fc1d63231bf01d22493a4f14378  imx6q-no-unclocked-sleep.patch
207 208
797644a9dda4436978498045ef7095b1  config-grsec.x86
9476dc4a1d21009764680816fde71152  config-grsec.x86_64
209
a0eb665beaf7f004b432b6ad10503868  config-grsec.armhf
210 211
18cb4521f9a8847637292f9f4c9e8256  config-virtgrsec.x86
2408367e7833084385bff42995dfcd3a  config-virtgrsec.x86_64"
212
sha256sums="becc413cc9e6d7f5cc52a3ce66d65c3725bc1d1cc1001f4ce6c32b69eb188cbd  linux-3.18.tar.xz
213
53245c0a5b172575867afe88c91fc46468ae06ed7bf4fa6d2150072e27f7209e  patch-3.18.12.xz
214
b224907d9e621ebd476d1f4af5f745d0251308a0482c5e96d441d04e4f7c57fc  grsecurity-3.1-3.18.11-201504190814-alpine.patch
215
500f3577310be52e87b9fecdc2e9c4ca43210fd97d69089f9005d484563f74c7  fix-memory-map-for-PIE-applications.patch
216
01279cfb93273d99670c56e2465957ecde3d03693beeb929a743f03afa0b7bdc  fix-spi-nor-namespace-clash.patch
217
21179fbb22a5b74af0a609350ae1a170e232908572b201d02e791d2ce0a685d3  imx6q-no-unclocked-sleep.patch
218 219
096425842c0c84c063fff14108630f49d32f64e970027e0f2050ce76558c05db  config-grsec.x86
18cc34f2d603baf82af7093daaf024d74047506154e53de27fb49ba65a2551d1  config-grsec.x86_64
220
48439398212aa21fd5bdea8e4c4b76ad4b4d4c534837e0f79f5c31639c80e8dd  config-grsec.armhf
221 222
47048993111506ab74db24c92d39b536cf5e684975844907d5cb6198c1dfd87f  config-virtgrsec.x86
0ebd5cf41a8c22fb8fe0c19d38833dc3e2b0b5e58b098e31315fcb766a18570e  config-virtgrsec.x86_64"
223
sha512sums="2f0b72466e9bc538a675738aa416573d41bbbd7e3e2ffd5b5b127afde609ebc278cec5a3c37e73479607e957c13f1b4ed9782a3795e0dcc2cf8e550228594009  linux-3.18.tar.xz
224
285322919b8638d821414bb494709008710ac55c0bc33d477b28013d51e9791a8487e9671cfdaaf0fa937fab119f40180c4577caac95263d1bb0c6e821069908  patch-3.18.12.xz
225
5b37c3b73a6c567128964c44bc474021df00d4ac575e53adf801a561726b0cc70f8e721363141d5f89df9e6b4e1e5e42a6521f5e969bcbd04a4567379b1cdef4  grsecurity-3.1-3.18.11-201504190814-alpine.patch
226
4665c56ae1bbac311f9205d64918e84ee8b01d47d6e2396ff6b8adfb10aada7f7254531ce62e31edbb65c2a54a830f09ad05d314dfcd75d6272f4068945ad7c7  fix-memory-map-for-PIE-applications.patch
227
4e3aeb70712f9838afea75fe9e6c1389414d833a89286ea55441d6a8d54ce74b0e39b565721e3153443af0a614bff57c767251b7e5b81faa5e0784eddfcd2164  fix-spi-nor-namespace-clash.patch
228
87d1ad59732f265a5b0db54490dc1762c14ea4b868e7eb1aedc3ce57b48046de7bbc08cf5cfcf6f1380fa84063b0edb16ba3d5e3c5670be9bbb229275c88b221  imx6q-no-unclocked-sleep.patch
229 230
ee88d6b3984a97f18d721d49ae76b302a80d4c0f8779d580199d35869358423e22895b1245725d345b6c99714844444ab9c433281f129347e4d5510336ca9cff  config-grsec.x86
20ba11b7b2d874a354aa4c364cac6885863deddd4c166ad98e0d5dcb24d102b0e3875eef60a252e1bedb1526fd25e11721c78e6ca50baf5fc4a9ec58e1c3b1a2  config-grsec.x86_64
231
9764c1c7cb69169f68d05fadfcd14d6d90b32e92416b45b06d74ebcfad17f2b6d43ad0f525c90e0cdb746c667755a9b89bce385a6505b0fd2fea3b0cb6c78a73  config-grsec.armhf
232 233
c6bebe64953a444bc7d13f932e44d081665c253121189a3ccca9d7f6145b4460e32dc0f21f4700bf6607c5c0cb79de5c8576e4da0c815d60cff0d3b90879c1d9  config-virtgrsec.x86
0d1a243b87ec7ba7fa7d1ba1608c6bbce1cecf0b19c912f596c5574f5bc027eb71b07ed28afefc7c209bb718e137b6e11ffb3172deb41cc61f022e32acd8022e  config-virtgrsec.x86_64"