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

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

21 22 23
	x86-centaur-enable-cx8-for-via-eden-too.patch
	linux-3.0.x-regression-with-ipv4-routes-having-mtu.patch

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

31 32
_abi_release=${pkgver}-${_flavor}

33
prepare() {
34
	local _patch_failed=
35 36
	cd "$srcdir"/linux-$_kernver
	if [ "$_kernver" != "$pkgver" ]; then
37
		bunzip2 -c < "$srcdir"/patch-$pkgver.bz2 | patch -p1 -N || return 1
38 39
	fi

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

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

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

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

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

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

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

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

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

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

114 115
	# remove the stuff that poits to real sources. we want 3rd party
	# modules to believe this is the soruces
116 117
	rm "$dir"/Makefile "$dir"/source

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

	install -Dm644 "$srcdir"/build/Module.symvers \
		"$dir"/Module.symvers
136 137 138 139

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

142
md5sums="7ceb61f87c097fc17509844b71268935  linux-3.2.tar.bz2
143
899624bffed6a19578613b672cc9483f  patch-3.2.7.bz2
144
27f2e8898e796ff0301f3193e2ba76b3  grsecurity-2.9-3.2.7-201202261954.patch
145
776adeeb5272093574f8836c5037dd7d  0004-arp-flush-arp-cache-on-device-change.patch
146 147
f3eda7112ef074a4121ec6de943c63ee  x86-centaur-enable-cx8-for-via-eden-too.patch
62cc7d7b5ba7ef05b72ff91c0411c189  linux-3.0.x-regression-with-ipv4-routes-having-mtu.patch
148 149
a4e7d46b18ca1495a1605c8520d74ee3  kernelconfig.x86
147306257d376f27799e9e72a303c80c  kernelconfig.x86_64"