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

3
_flavor=grsec
4
pkgname=linux-${_flavor}
5
pkgver=3.6.9
6
_kernver=3.6
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
source="http://ftp.kernel.org/pub/linux/kernel/v3.x/linux-$_kernver.tar.xz
16
	http://ftp.kernel.org/pub/linux/kernel/v3.x/patch-$pkgver.xz
17
	grsecurity-2.9.1-3.6.9-201212031851.patch
18 19
	
	0004-arp-flush-arp-cache-on-device-change.patch
20

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

28 29
_abi_release=${pkgver}-${_flavor}

30
prepare() {
31
	local _patch_failed=
32
	cd "$srcdir"/linux-$_kernver
33 34
	if [ "${pkgver%.0}" = "$pkgver" ]; then
		msg "Applying patch-$pkgver.xz"
35
		unxz -c < "$srcdir"/patch-$pkgver.xz | patch -p1 -N || return 1
36 37
	fi

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

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

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

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

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

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

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

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

94 95 96 97 98
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
	#
99
	# this way you dont need to install the 300-400 kernel sources to
100 101
	# build a tiny kernel module
	#
102
	pkgdesc="Headers and script for third party modules for grsec kernel"
103
	depends="gmp-dev"
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="1a1760420eac802c541a20ab51a093d1  linux-3.6.tar.xz
142 143
a7c656034599f90dcbc50895b69022aa  patch-3.6.9.xz
f410ce5363d0681ba0d279eb3a5b1544  grsecurity-2.9.1-3.6.9-201212031851.patch
144
776adeeb5272093574f8836c5037dd7d  0004-arp-flush-arp-cache-on-device-change.patch
145
0b4abb6b3e32cc7ba656c24e30581349  kernelconfig.x86
146
ff85d700a38f78861ba04f0eddb26901  kernelconfig.x86_64"