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

3
_flavor=grsec
4
pkgname=linux-${_flavor}
5
pkgver=2.6.37.2
6
_kernver=2.6.37
7
pkgrel=1
8 9
pkgdesc="Linux kernel with grsecurity"
url=http://grsecurity.net
10
depends="mkinitfs linux-firmware"
11
makedepends="perl installkernel bash"
12
options="!strip"
Natanael Copa's avatar
Natanael Copa committed
13
_config=${config:-kernelconfig.${CARCH}}
14
install=
15
source="ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-$_kernver.tar.bz2
16
	ftp://ftp.kernel.org/pub/linux/kernel/v2.6/patch-$pkgver.bz2
17
	grsecurity-2.2.1-2.6.37.2-201103021740.patch
18 19 20 21
	
	0001-xfrm-use-gre-key-as-flow-upper-protocol-info.patch
	xfrm-fix-gre-key-endianess.patch
	0004-arp-flush-arp-cache-on-device-change.patch
22

23
	kernelconfig.x86
24
	kernelconfig.x86_64
25
	"
26
subpackages="$pkgname-dev linux-firmware:firmware"
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
	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
	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 109
		silentoldconfig prepare scripts

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 140 141 142 143 144
firmware() {
	pkgdesc="Firmware for linux kernel"
	replaces="linux-grsec linux-vserver"
	mkdir -p "$subpkgdir"/lib
	mv "$pkgdir"/lib/firmware "$subpkgdir"/lib/
}

145
md5sums="c8ee37b4fdccdb651e0603d35350b434  linux-2.6.37.tar.bz2
146 147
bb5798f2a2a5af13219d1a250c4dad11  patch-2.6.37.2.bz2
023faa02aded5827539e7ed7653dc133  grsecurity-2.2.1-2.6.37.2-201103021740.patch
148 149 150
3152851c31bfa8c54660dbb84d75b38d  0001-xfrm-use-gre-key-as-flow-upper-protocol-info.patch
ea7a7eb2775b71ae5ef24d029a4905bd  xfrm-fix-gre-key-endianess.patch
776adeeb5272093574f8836c5037dd7d  0004-arp-flush-arp-cache-on-device-change.patch
151
7825fa82fecc817d6e2dfd3bb0c52f37  kernelconfig.x86
152
b72e1345ceddbe2d0d9de35e342b336d  kernelconfig.x86_64"