A new user interface for you! Read more...

File PKGBUILD of Package linux-pf-core2

# Maintainer: Oleksandr Natalenko aka post-factum <oleksandr@natalenko.name>

_basename="linux-pf"
_suffix="core2"
pkgname=(
		"${_basename}-${_suffix}" "${_basename}-headers-${_suffix}" "${_basename}-docs-${_suffix}"
	)
_linux_major=5
_linux_minor=2
_release=1
_basever=${_linux_major}.${_linux_minor}.0-pf${_release}
pkgver=${_linux_major}.${_linux_minor}.${_release}
pkgrel=1
arch=(x86_64)
url="https://gitlab.com/post-factum/pf-kernel/wikis/README"
license=(GPL2)
makedepends=(xmlto kmod inetutils bc libelf python-sphinx graphviz)
options=('!strip')
_srcname="linux-${_linux_major}.${_linux_minor}"
source=(
		"linux-${_linux_major}.${_linux_minor}.tar.xz"
		"patch-${_linux_major}.${_linux_minor}-pf${_release}.diff"
		"config_arch_${_suffix}"
		"linux.preset"
		"60-linux.hook"
		"90-linux.hook"
	)

sha256sums=('54ad66f672e1a831b574f5e704e8a05f1e6180a8245d4bdd811208a6cb0ac1e7'
            '310518d8a556d8557e7ee89edbaf16ac78415387c43079e7ea1fa9487f756d5d'
            'e3a3f503786f32472dc3c47f7f3240b38c2b2ef2c123b6a67fcf480899c2c880'
            'ad6344badc91ad0630caacde83f7f9b97276f80d26a20619a87952be65492c65'
            'ae2e95db94ef7176207c690224169594d49445e04249d2499e9d2fbc117a0b21'
            'c043f3033bb781e2688794a59f6d1f7ed49ef9b13eb77ff9a425df33a244a636')

prepare() {
	cd "${_srcname}"

	msg2 "Applying pf-kernel patch..."
	patch -Np1 -i ${srcdir}/patch-${_linux_major}.${_linux_minor}-pf${_release}.diff

	msg2 "Setting config..."
	cp "../config_arch_${_suffix}" .config
	make olddefconfig

	make -s kernelrelease >../version
	msg2 "Prepared pf-kernel version %s" "$(<../version)"
}

build() {
	cd "${_srcname}"

	make -j$(nproc) bzImage modules htmldocs
}

_package() {
	pkgdesc="The pf-kernel and its modules"
	provides=(linux-pf)
	conflicts=(linux-pf)
	depends=(coreutils linux-firmware kmod mkinitcpio)
	optdepends=('crda: to set the correct wireless channels of your country')
	backup=("etc/mkinitcpio.d/${_basename}.preset")
	install=linux.install

	local modulesdir="${pkgdir}/usr/lib/modules/${_basever}"

	cd "${_srcname}"

	msg2 "Installing boot image..."
	# systemd expects to find the kernel here to allow hibernation
	# https://github.com/systemd/systemd/commit/edda44605f06a41fb86b7ab8128dcf99161d2344
	install -Dm644 "$(make -s image_name)" "${modulesdir}/vmlinuz"
	install -Dm644 "${modulesdir}/vmlinuz" "${pkgdir}/boot/vmlinuz-${_basename}"

	msg2 "Installing modules..."
	make INSTALL_MOD_PATH="${pkgdir}/usr" modules_install

	# a place for external modules,
	# with version file for building modules and running depmod from hook
	local extramodules="extramodules-${_basever}"
	local extradir="${pkgdir}/usr/lib/modules/${extramodules}"
	install -Dt "${extradir}" -m644 ../version
	ln -sr "${extradir}" "${modulesdir}/extramodules"

	# remove build and source links
	rm "${modulesdir}"/{source,build}

	msg2 "Installing hooks..."
	# sed expression for following substitutions
	local _subst="
		s|%PKGBASE%|${_basename}|g
		s|%KERNVER%|${_basever}|g
		s|%EXTRAMODULES%|${extramodules}|g
		"

	# hack to allow specifying an initially nonexisting install file
	sed "${_subst}" "${startdir}/${install}" >"${startdir}/${install}.pkg"
	true && install=${install}.pkg

	# fill in mkinitcpio preset and pacman hooks
	sed "${_subst}" ../linux.preset | install -Dm644 /dev/stdin \
		"${pkgdir}/etc/mkinitcpio.d/${_basename}.preset"
	sed "${_subst}" ../60-linux.hook | install -Dm644 /dev/stdin \
		"${pkgdir}/usr/share/libalpm/hooks/60-${_basename}.hook"
	sed "${_subst}" ../90-linux.hook | install -Dm644 /dev/stdin \
		"${pkgdir}/usr/share/libalpm/hooks/90-${_basename}.hook"

	msg2 "Fixing permissions..."
	chmod -Rc u=rwX,go=rX "${pkgdir}"
}

_package-headers() {
	pkgdesc="Header files and scripts for building modules for the pf-kernel"

	local builddir="${pkgdir}/usr/lib/modules/$(<version)/build"

	cd "${_srcname}"

	msg2 "Installing build files..."
	install -Dt "${builddir}" -m644 Makefile .config Module.symvers System.map vmlinux
	install -Dt "${builddir}/kernel" -m644 kernel/Makefile
	install -Dt "${builddir}/arch/x86" -m644 arch/x86/Makefile
	cp -t "${builddir}" -a scripts

	# add objtool for external module building and enabled VALIDATION_STACK option
	install -Dt "${builddir}/tools/objtool" tools/objtool/objtool

	# add xfs and shmem for aufs building
	mkdir -p "${builddir}"/{fs/xfs,mm}

	# ???
	mkdir "${builddir}/.tmp_versions"

	msg2 "Installing headers..."
	cp -t "${builddir}" -a include
	cp -t "${builddir}/arch/x86" -a arch/x86/include
	install -Dt "${builddir}/arch/x86/kernel" -m644 arch/x86/kernel/asm-offsets.s

	install -Dt "${builddir}/drivers/md" -m644 drivers/md/*.h
	install -Dt "${builddir}/net/mac80211" -m644 net/mac80211/*.h

	# http://bugs.archlinux.org/task/13146
	install -Dt "${builddir}/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h

	# http://bugs.archlinux.org/task/20402
	install -Dt "${builddir}/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h
	install -Dt "${builddir}/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h
	install -Dt "${builddir}/drivers/media/tuners" -m644 drivers/media/tuners/*.h

	msg2 "Installing Kconfig files..."
	find . -name 'Kconfig*' -exec install -Dm644 {} "${builddir}/{}" \;

	# remove unneeded architectures
	local arch
	for arch in "${builddir}"/arch/*/; do
		[[ ${arch} = */x86/ ]] && continue
		echo "Removing $(basename "${arch}")"
		rm -r "${arch}"
	done

	msg2 "Removing documentation..."
	rm -r "${builddir}/Documentation"

	msg2 "Removing broken symlinks..."
	find -L "${builddir}" -type l -printf 'Removing %P\n' -delete

	msg2 "Removing loose objects..."
	find "${builddir}" -type f -name '*.o' -printf 'Removing %P\n' -delete

	msg2 "Stripping build tools..."
	local file
	while read -rd '' file; do
		case "$(file -bi "${file}")" in
			application/x-sharedlib\;*)      # Libraries (.so)
				strip -v $STRIP_SHARED "${file}" ;;
			application/x-archive\;*)        # Libraries (.a)
				strip -v $STRIP_STATIC "${file}" ;;
			application/x-executable\;*)     # Binaries
				strip -v $STRIP_BINARIES "${file}" ;;
			application/x-pie-executable\;*) # Relocatable binaries
				strip -v $STRIP_SHARED "${file}" ;;
		esac
	done < <(find "${builddir}" -type f -perm -u+x ! -name vmlinux -print0)

	msg2 "Adding symlink..."
	mkdir -p "${pkgdir}/usr/src"
	ln -sr "${builddir}" "$pkgdir/usr/src/${_basename}-${_basever}"

	msg2 "Fixing permissions..."
	chmod -Rc u=rwX,go=rX "${pkgdir}"
}

_package-docs() {
	pkgdesc="Kernel hackers manual - HTML documentation that comes with the pf-kernel"

	local builddir="${pkgdir}/usr/lib/modules/$(<version)/build"

	cd "${_srcname}"

	msg2 "Installing documentation..."
	mkdir -p "${builddir}"
	cp -t "${builddir}" -a Documentation

	msg2 "Removing doctrees..."
	rm -r "${builddir}/Documentation/output/.doctrees"

	msg2 "Moving HTML docs..."
	local src dst
	while read -rd '' src; do
		dst="${builddir}/Documentation/${src#$builddir/Documentation/output/}"
		mkdir -p "${dst%/*}"
		mv "${src}" "${dst}"
		rmdir -p --ignore-fail-on-non-empty "${src%/*}"
	done < <(find "${builddir}/Documentation/output" -type f -print0)

	msg2 "Adding symlink..."
	mkdir -p "${pkgdir}/usr/share/doc"
	ln -sr "${builddir}/Documentation" "${pkgdir}/usr/share/doc/${_basename}"

	msg2 "Fixing permissions..."
	chmod -Rc u=rwX,go=rX "${pkgdir}"
}

for _p in ${pkgname[@]}; do
	_i=$(echo ${_p} | sed "s/-${_suffix}//g")
	eval "package_${_i}-${_suffix}() {
		$(declare -f "_package${_i#${_basename}}")
		_package${_i#${_basename}}
	}"
done