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

3
_flavor=grsec
4
pkgname=linux-${_flavor}
5
pkgver=3.0.17
6
_kernver=3.0
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="ftp://ftp.kernel.org/pub/linux/kernel/v3.0/linux-$_kernver.tar.bz2
	ftp://ftp.kernel.org/pub/linux/kernel/v3.0/patch-$pkgver.bz2
17
	grsecurity-2.2.2-$pkgver-unofficial.patch
18
	grsec-timblogiw-noconst.patch
19
	
20
	0001-ip_gre-dont-increase-dev-needed_headroom-on-a-live-d.patch
21
	0004-arp-flush-arp-cache-on-device-change.patch
22

23 24
	x86-centaur-enable-cx8-for-via-eden-too.patch
	linux-3.0.x-regression-with-ipv4-routes-having-mtu.patch
25
	net-flow-remove-sleeping-and-deferral-mechanism-from-flow_cache_flush.patch
26

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

34 35
_abi_release=${pkgver}-${_flavor}

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

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

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

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

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

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

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

91 92
	rm -f "$pkgdir"/lib/modules/${_abi_release}/build \
		"$pkgdir"/lib/modules/${_abi_release}/source
93 94
	rm -rf "$pkgdir"/lib/firmware

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

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

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

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

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

	install -Dm644 "$srcdir"/build/Module.symvers \
		"$dir"/Module.symvers
139 140 141 142

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

145
md5sums="398e95866794def22b12dfbc15ce89c0  linux-3.0.tar.bz2
146 147
8beef6d04bfa8b26446378682b332cfe  patch-3.0.17.bz2
3c0fcf923a27a963ae86a3e694cb6bbd  grsecurity-2.2.2-3.0.17-unofficial.patch
148
c41cf0ee9794f393423c6b2093072260  grsec-timblogiw-noconst.patch
149
ebb99ef6ad8cd2d9fd8f49d5c5849057  0001-ip_gre-dont-increase-dev-needed_headroom-on-a-live-d.patch
150
776adeeb5272093574f8836c5037dd7d  0004-arp-flush-arp-cache-on-device-change.patch
151 152
f3eda7112ef074a4121ec6de943c63ee  x86-centaur-enable-cx8-for-via-eden-too.patch
62cc7d7b5ba7ef05b72ff91c0411c189  linux-3.0.x-regression-with-ipv4-routes-having-mtu.patch
153
b25335e8fcbf8c969230d55ac4e75cf8  net-flow-remove-sleeping-and-deferral-mechanism-from-flow_cache_flush.patch
154
587b1fb2f6a5c9ba714900b856f57f09  kernelconfig.x86
155
99836ffe918bbdef7da1a56a3d075c7a  kernelconfig.x86_64"