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

3
_flavor=grsec
4
pkgname=linux-${_flavor}
5
pkgver=2.6.38.8
6
_kernver=2.6.38
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.2-2.6.38.8-unofficial.patch
18 19
	
	0004-arp-flush-arp-cache-on-device-change.patch
20
	net-gre-provide-multicast-mappings-for-ipv4-and-ipv6.patch
21

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

29 30
_abi_release=${pkgver}-${_flavor}

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

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

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

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

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

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

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

85 86
	rm -f "$pkgdir"/lib/modules/${_abi_release}/build \
		"$pkgdir"/lib/modules/${_abi_release}/source
87 88
	rm -rf "$pkgdir"/lib/firmware

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

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

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

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

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

	install -Dm644 "$srcdir"/build/Module.symvers \
		"$dir"/Module.symvers
133 134 135 136

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

139
md5sums="7d471477bfa67546f902da62227fa976  linux-2.6.38.tar.bz2
140 141
c0f416f6a2e916633f697287cc7cb914  patch-2.6.38.8.bz2
58e1f9194fa75df9afdf2746370fa3cb  grsecurity-2.2.2-2.6.38.8-unofficial.patch
142
776adeeb5272093574f8836c5037dd7d  0004-arp-flush-arp-cache-on-device-change.patch
143
aa1b82da0cabfb41c5e6da5bddf60bab  net-gre-provide-multicast-mappings-for-ipv4-and-ipv6.patch
144 145
f4cf5b0ddfeef7aa87fb27792aff88a4  kernelconfig.x86
0a73d8d896101de90f47dae32119e7ca  kernelconfig.x86_64"