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

3
_flavor=grsec
4
pkgname=linux-${_flavor}
5 6
pkgver=3.3.0
_kernver=3.3
7
pkgrel=0
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="http://ftp.kernel.org/pub/linux/kernel/v3.x/linux-$_kernver.tar.xz
	grsecurity-2.9-3.3.0-201204010912.patch
17 18
	
	0004-arp-flush-arp-cache-on-device-change.patch
19

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	install -Dm644 "$srcdir"/build/Module.symvers \
		"$dir"/Module.symvers
132 133 134 135

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

138 139
md5sums="7133f5a2086a7d7ef97abac610c094f5  linux-3.3.tar.xz
4a84e775da56db17d11945991029482c  grsecurity-2.9-3.3.0-201204010912.patch
140
776adeeb5272093574f8836c5037dd7d  0004-arp-flush-arp-cache-on-device-change.patch
141 142
51458d030e02ea7bc134df4f37557cb0  kernelconfig.x86
ae652877225cb3e3b8a3705b3a411d71  kernelconfig.x86_64"