xref: /linux/scripts/package/PKGBUILD (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
1c8578539SThomas Weißschuh# SPDX-License-Identifier: GPL-2.0-only
2c8578539SThomas Weißschuh# Maintainer: Thomas Weißschuh <linux@weissschuh.net>
3c8578539SThomas Weißschuh# Contributor: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
4c8578539SThomas Weißschuh
5c8578539SThomas Weißschuhpkgbase=${PACMAN_PKGBASE:-linux-upstream}
6e6b65ee1SJose Fernandezpkgname=("${pkgbase}")
7e6b65ee1SJose Fernandez
8*4929f5b9SJose Fernandez_extrapackages=${PACMAN_EXTRAPACKAGES-headers api-headers debug}
9e6b65ee1SJose Fernandezfor pkg in $_extrapackages; do
10e6b65ee1SJose Fernandez	pkgname+=("${pkgbase}-${pkg}")
11e6b65ee1SJose Fernandezdone
12e6b65ee1SJose Fernandez
13c8578539SThomas Weißschuhpkgver="${KERNELRELEASE//-/_}"
14c8578539SThomas Weißschuh# The PKGBUILD is evaluated multiple times.
15c8578539SThomas Weißschuh# Running scripts/build-version from here would introduce inconsistencies.
16c8578539SThomas Weißschuhpkgrel="${KBUILD_REVISION}"
17c8578539SThomas Weißschuhpkgdesc='Upstream Linux'
18c8578539SThomas Weißschuhurl='https://www.kernel.org/'
19c8578539SThomas Weißschuh# Enable flexible cross-compilation
20c8578539SThomas Weißschuharch=(${CARCH})
21c8578539SThomas Weißschuhlicense=(GPL-2.0-only)
22c8578539SThomas Weißschuhmakedepends=(
23c8578539SThomas Weißschuh	bc
24c8578539SThomas Weißschuh	bison
25c8578539SThomas Weißschuh	cpio
26c8578539SThomas Weißschuh	flex
27c8578539SThomas Weißschuh	gettext
28c8578539SThomas Weißschuh	kmod
29c8578539SThomas Weißschuh	libelf
30c8578539SThomas Weißschuh	openssl
31c8578539SThomas Weißschuh	pahole
32c8578539SThomas Weißschuh	perl
33c8578539SThomas Weißschuh	python
34c8578539SThomas Weißschuh	rsync
35c8578539SThomas Weißschuh	tar
36c8578539SThomas Weißschuh)
37c8578539SThomas Weißschuhoptions=(!debug !strip !buildflags !makeflags)
38c8578539SThomas Weißschuh
39b6223c2dSMasahiro Yamada_prologue() {
40c8578539SThomas Weißschuh	# MAKEFLAGS from makepkg.conf override the ones inherited from kbuild.
41c8578539SThomas Weißschuh	# Bypass this override with a custom variable.
42c8578539SThomas Weißschuh	export MAKEFLAGS="${KBUILD_MAKEFLAGS}"
435b000f3cSMasahiro Yamada
445b000f3cSMasahiro Yamada	# Kbuild works in the output directory, where this PKGBUILD is located.
455b000f3cSMasahiro Yamada	cd "$(dirname "${BASH_SOURCE[0]}")"
46b6223c2dSMasahiro Yamada}
47b6223c2dSMasahiro Yamada
48b6223c2dSMasahiro Yamadabuild() {
49b6223c2dSMasahiro Yamada	_prologue
50c8578539SThomas Weißschuh
51c8578539SThomas Weißschuh	${MAKE} KERNELRELEASE="${KERNELRELEASE}" KBUILD_BUILD_VERSION="${pkgrel}"
52c8578539SThomas Weißschuh}
53c8578539SThomas Weißschuh
54c8578539SThomas Weißschuh_package() {
55c8578539SThomas Weißschuh	pkgdesc="The ${pkgdesc} kernel and modules"
56c8578539SThomas Weißschuh
57c8578539SThomas Weißschuh	local modulesdir="${pkgdir}/usr/${MODLIB}"
58c8578539SThomas Weißschuh
59b6223c2dSMasahiro Yamada	_prologue
60b6223c2dSMasahiro Yamada
61c8578539SThomas Weißschuh	echo "Installing boot image..."
62c8578539SThomas Weißschuh	# systemd expects to find the kernel here to allow hibernation
63c8578539SThomas Weißschuh	# https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
64c8578539SThomas Weißschuh	install -Dm644 "$(${MAKE} -s image_name)" "${modulesdir}/vmlinuz"
65c8578539SThomas Weißschuh
66c8578539SThomas Weißschuh	# Used by mkinitcpio to name the kernel
67c8578539SThomas Weißschuh	echo "${pkgbase}" > "${modulesdir}/pkgbase"
68c8578539SThomas Weißschuh
69c8578539SThomas Weißschuh	echo "Installing modules..."
70c8578539SThomas Weißschuh	${MAKE} INSTALL_MOD_PATH="${pkgdir}/usr" INSTALL_MOD_STRIP=1 \
71c8578539SThomas Weißschuh		DEPMOD=true modules_install
72c8578539SThomas Weißschuh
73c8578539SThomas Weißschuh	if [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then
74c8578539SThomas Weißschuh		echo "Installing dtbs..."
75c8578539SThomas Weißschuh		${MAKE} INSTALL_DTBS_PATH="${modulesdir}/dtb" dtbs_install
76c8578539SThomas Weißschuh	fi
77c8578539SThomas Weißschuh
78c8578539SThomas Weißschuh	# remove build link, will be part of -headers package
79c8578539SThomas Weißschuh	rm -f "${modulesdir}/build"
80c8578539SThomas Weißschuh}
81c8578539SThomas Weißschuh
82c8578539SThomas Weißschuh_package-headers() {
83c8578539SThomas Weißschuh	pkgdesc="Headers and scripts for building modules for the ${pkgdesc} kernel"
84c8578539SThomas Weißschuh
85c8578539SThomas Weißschuh	local builddir="${pkgdir}/usr/${MODLIB}/build"
86c8578539SThomas Weißschuh
87b6223c2dSMasahiro Yamada	_prologue
88b6223c2dSMasahiro Yamada
89e6b65ee1SJose Fernandez	if grep -q CONFIG_MODULES=y include/config/auto.conf; then
90c8578539SThomas Weißschuh		echo "Installing build files..."
91c8578539SThomas Weißschuh		"${srctree}/scripts/package/install-extmod-build" "${builddir}"
92e6b65ee1SJose Fernandez	fi
93c8578539SThomas Weißschuh
94c8578539SThomas Weißschuh	echo "Installing System.map and config..."
95e6b65ee1SJose Fernandez	mkdir -p "${builddir}"
96c8578539SThomas Weißschuh	cp System.map "${builddir}/System.map"
97c8578539SThomas Weißschuh	cp .config "${builddir}/.config"
98c8578539SThomas Weißschuh
99c8578539SThomas Weißschuh	echo "Adding symlink..."
100c8578539SThomas Weißschuh	mkdir -p "${pkgdir}/usr/src"
101c8578539SThomas Weißschuh	ln -sr "${builddir}" "${pkgdir}/usr/src/${pkgbase}"
102c8578539SThomas Weißschuh}
103c8578539SThomas Weißschuh
104c8578539SThomas Weißschuh_package-api-headers() {
105c8578539SThomas Weißschuh	pkgdesc="Kernel headers sanitized for use in userspace"
106c8578539SThomas Weißschuh	provides=(linux-api-headers)
107c8578539SThomas Weißschuh	conflicts=(linux-api-headers)
108c8578539SThomas Weißschuh
109b6223c2dSMasahiro Yamada	_prologue
110c8578539SThomas Weißschuh
111c8578539SThomas Weißschuh	${MAKE} headers_install INSTALL_HDR_PATH="${pkgdir}/usr"
112c8578539SThomas Weißschuh}
113c8578539SThomas Weißschuh
114*4929f5b9SJose Fernandez_package-debug(){
115*4929f5b9SJose Fernandez	pkgdesc="Non-stripped vmlinux file for the ${pkgdesc} kernel"
116*4929f5b9SJose Fernandez
117*4929f5b9SJose Fernandez	local debugdir="${pkgdir}/usr/src/debug/${pkgbase}"
118*4929f5b9SJose Fernandez	local builddir="${pkgdir}/usr/${MODLIB}/build"
119*4929f5b9SJose Fernandez
120*4929f5b9SJose Fernandez	_prologue
121*4929f5b9SJose Fernandez
122*4929f5b9SJose Fernandez	install -Dt "${debugdir}" -m644 vmlinux
123*4929f5b9SJose Fernandez	mkdir -p "${builddir}"
124*4929f5b9SJose Fernandez	ln -sr "${debugdir}/vmlinux" "${builddir}/vmlinux"
125*4929f5b9SJose Fernandez}
126*4929f5b9SJose Fernandez
127c8578539SThomas Weißschuhfor _p in "${pkgname[@]}"; do
128c8578539SThomas Weißschuh	eval "package_$_p() {
129c8578539SThomas Weißschuh		$(declare -f "_package${_p#$pkgbase}")
130c8578539SThomas Weißschuh		_package${_p#$pkgbase}
131c8578539SThomas Weißschuh	}"
132c8578539SThomas Weißschuhdone
133