APKBUILD 4.25 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=0
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
	kernelconfig.x86
20
	kernelconfig.x86_64
21
	"
22
subpackages="$pkgname-dev linux-firmware:firmware"
23
arch="x86 x86_64 arm"
24
license="GPL-2"
Natanael Copa's avatar
Natanael Copa committed
25

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

141
md5sums="c8ee37b4fdccdb651e0603d35350b434  linux-2.6.37.tar.bz2
142 143
bb5798f2a2a5af13219d1a250c4dad11  patch-2.6.37.2.bz2
023faa02aded5827539e7ed7653dc133  grsecurity-2.2.1-2.6.37.2-201103021740.patch
144
7825fa82fecc817d6e2dfd3bb0c52f37  kernelconfig.x86
145
b72e1345ceddbe2d0d9de35e342b336d  kernelconfig.x86_64"