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

3
_flavor=grsec
4
pkgname=linux-${_flavor}
5
pkgver=3.0.9
6
_kernver=3.0
7
pkgrel=1
8 9
pkgdesc="Linux kernel with grsecurity"
url=http://grsecurity.net
10
depends="mkinitfs linux-firmware"
Natanael Copa's avatar
Natanael Copa committed
11
makedepends="perl installkernel bash gmp-dev"
12
options="!strip"
Natanael Copa's avatar
Natanael Copa committed
13
_config=${config:-kernelconfig.${CARCH}}
14
install=
15 16
source="ftp://ftp.kernel.org/pub/linux/kernel/v3.0/linux-$_kernver.tar.bz2
	ftp://ftp.kernel.org/pub/linux/kernel/v3.0/patch-$pkgver.bz2
17
	grsecurity-2.2.2-3.0.9-201111121310.patch
18
	grsec-timblogiw-noconst.patch
19
	
20
	0001-ip_gre-dont-increase-dev-needed_headroom-on-a-live-d.patch
21
	0004-arp-flush-arp-cache-on-device-change.patch
22

23
	kernelconfig.x86
24
	kernelconfig.x86_64
25
	"
26
subpackages="$pkgname-dev"
27
arch="x86 x86_64 arm"
28
license="GPL-2"
Natanael Copa's avatar
Natanael Copa committed
29

30 31
_abi_release=${pkgver}-${_flavor}

32
prepare() {
33
	local _patch_failed=
34 35
	cd "$srcdir"/linux-$_kernver
	if [ "$_kernver" != "$pkgver" ]; then
36
		bunzip2 -c < "$srcdir"/patch-$pkgver.bz2 | patch -p1 -N || return 1
37 38
	fi

39 40 41 42 43
	# first apply patches in specified order
	for i in $source; do
		case $i in
		*.patch)
			msg "Applying $i..."
44 45 46 47
			if ! patch -s -p1 -N -i "$srcdir"/$i; then
				echo $i >>failed
				_patch_failed=1
			fi
48 49
			;;
		esac
50 51
	done

52 53 54 55 56 57
	if ! [ -z "$_patch_failed" ]; then
		error "The following patches failed:"
		cat failed
		return 1
	fi

58
	mkdir -p "$srcdir"/build
59
	cp "$srcdir"/$_config "$srcdir"/build/.config || return 1
60
	make -C "$srcdir"/linux-$_kernver O="$srcdir"/build HOSTCC="${CC:-gcc}" \
61
		silentoldconfig
62 63 64 65
}

# this is so we can do: 'abuild menuconfig' to reconfigure kernel
menuconfig() {
66
	cd "$srcdir"/build || return 1
67 68 69 70 71 72
	make menuconfig
	cp .config "$startdir"/$_config
}

build() {
	cd "$srcdir"/build
73
	export GCC_SPECS=/usr/share/gcc/hardenednopie.specs
74
	make CC="${CC:-gcc}" \
75 76
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine" \
		|| return 1
77
}
Natanael Copa's avatar
Natanael Copa committed
78

79 80
package() {
	cd "$srcdir"/build
81
	mkdir -p "$pkgdir"/boot "$pkgdir"/lib/modules
Natanael Copa's avatar
Natanael Copa committed
82
	make -j1 modules_install firmware_install install \
83
		INSTALL_MOD_PATH="$pkgdir" \
84 85
		INSTALL_PATH="$pkgdir"/boot \
		|| return 1
86

87 88
	rm -f "$pkgdir"/lib/modules/${_abi_release}/build \
		"$pkgdir"/lib/modules/${_abi_release}/source
89 90
	rm -rf "$pkgdir"/lib/firmware

91
	install -D include/config/kernel.release \
92
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
Natanael Copa's avatar
Natanael Copa committed
93 94
}

95 96 97 98 99
dev() {
	# 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
	#
100
	# this way you dont need to install the 300-400 kernel sources to
101 102
	# build a tiny kernel module
	#
103
	pkgdesc="Headers and script for third party modules for grsec kernel"
104
	local dir="$subpkgdir"/usr/src/linux-headers-${_abi_release}
105

106
	# first we import config, run prepare to set up for building
107
	# external modules, and create the scripts
108
	mkdir -p "$dir"
109
	cp "$srcdir"/$_config "$dir"/.config
110
	make -j1 -C "$srcdir"/linux-$_kernver O="$dir" HOSTCC="${CC:-gcc}" \
111
		silentoldconfig prepare modules_prepare scripts 
112

113 114
	# remove the stuff that poits to real sources. we want 3rd party
	# modules to believe this is the soruces
115 116
	rm "$dir"/Makefile "$dir"/source

117 118
	# copy the needed stuff from real sources
	#
119
	# this is taken from ubuntu kernel build script
120
	# http://kernel.ubuntu.com/git?p=ubuntu/ubuntu-jaunty.git;a=blob;f=debian/rules.d/3-binary-indep.mk;hb=HEAD
121 122 123 124 125 126 127 128 129 130 131
	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"
132 133 134

	install -Dm644 "$srcdir"/build/Module.symvers \
		"$dir"/Module.symvers
135 136 137 138

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

141
md5sums="398e95866794def22b12dfbc15ce89c0  linux-3.0.tar.bz2
142 143
0154d21e63d3f14fc1084cdb130fab2d  patch-3.0.9.bz2
32508aac1ff87cdc72227c86141ed549  grsecurity-2.2.2-3.0.9-201111121310.patch
144
c41cf0ee9794f393423c6b2093072260  grsec-timblogiw-noconst.patch
145
ebb99ef6ad8cd2d9fd8f49d5c5849057  0001-ip_gre-dont-increase-dev-needed_headroom-on-a-live-d.patch
146
776adeeb5272093574f8836c5037dd7d  0004-arp-flush-arp-cache-on-device-change.patch
147 148
36330138ac7e1e776b3917a81ba51546  kernelconfig.x86
f00f1c26ef7ddcdc4467bb883a71522b  kernelconfig.x86_64"