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

3
_flavor=grsec
4
pkgname=linux-${_flavor}
5 6
pkgver=2.6.37
_kernver=2.6.37
7
pkgrel=3
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
	grsecurity-2.2.1-2.6.37-201102121148.patch
17

18
	kernelconfig.x86
19
	kernelconfig.x86_64
20
	"
21
subpackages="$pkgname-dev linux-firmware:firmware"
22
arch="x86 x86_64 arm"
23
license="GPL-2"
Natanael Copa's avatar
Natanael Copa committed
24

25 26
_abi_release=${pkgver}-${_flavor}

27
prepare() {
28
	local _patch_failed=
29 30
	cd "$srcdir"/linux-$_kernver
	if [ "$_kernver" != "$pkgver" ]; then
31
		bunzip2 -c < ../patch-$pkgver.bz2 | patch -p1 -N || return 1
32 33
	fi

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

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

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

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

build() {
	cd "$srcdir"/build
68
	make CC="${CC:-gcc}" \
69 70
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-Alpine" \
		|| return 1
71
}
Natanael Copa's avatar
Natanael Copa committed
72

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

81 82
	rm -f "$pkgdir"/lib/modules/${_abi_release}/build \
		"$pkgdir"/lib/modules/${_abi_release}/source
83
	install -D include/config/kernel.release \
84
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
Natanael Copa's avatar
Natanael Copa committed
85 86
}

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

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

105 106
	# remove the stuff that poits to real sources. we want 3rd party
	# modules to believe this is the soruces
107 108
	rm "$dir"/Makefile "$dir"/source

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

	install -Dm644 "$srcdir"/build/Module.symvers \
		"$dir"/Module.symvers
127 128 129 130

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

133 134 135 136 137 138 139
firmware() {
	pkgdesc="Firmware for linux kernel"
	replaces="linux-grsec linux-vserver"
	mkdir -p "$subpkgdir"/lib
	mv "$pkgdir"/lib/firmware "$subpkgdir"/lib/
}

140 141
md5sums="c8ee37b4fdccdb651e0603d35350b434  linux-2.6.37.tar.bz2
f56bdcd16fa540cddf075be6842edaaa  grsecurity-2.2.1-2.6.37-201102121148.patch
142 143
7825fa82fecc817d6e2dfd3bb0c52f37  kernelconfig.x86
ebac0a8e3b2f7c063bf151dfb7a1b434  kernelconfig.x86_64"