From: Justin M. Forbes <jforbes@xxxxxxxxxxxxxxxxx> Add scaffolding to build the kernel-headers package for Fedora For years, the scripts to build the kernel headers package have been sitting on maintainers desktops. Let's get those into kernel-ark. I have been using these to create the Fedora kernel-headers dist-git for a while now. Signed-off-by: Justin M. Forbes <jforbes@xxxxxxxxxxxxxxxxx> diff --git a/redhat/Makefile b/redhat/Makefile index blahblah..blahblah 100644 --- a/redhat/Makefile +++ b/redhat/Makefile @@ -845,6 +845,22 @@ ifeq ("$(RHDISTGIT_BRANCH)", "") endif $(REDHAT)/scripts/rh-dist-git.sh +dist-headers-srpm: + @scripts/create_headers_tarball.sh + @cp $(REDHAT)/kernel-headers.spec.template $(SOURCES)/kernel-headers.spec + @$(REDHAT)/scripts/genspec/headerspec.sh + @cp $(SOURCES)/kernel-headers.spec $(SOURCES)/../SPECS/ + $(RPMBUILD) --define "_sourcedir $(SOURCES)" --define "_builddir $(RPM)/BUILD" --define "_srcrpmdir $(RPM)/SRPMS" --define "_rpmdir $(RPM)/RPMS" --define "_specdir $(RPM)/SPECS" --define "dist $(DIST)" --nodeps -bs $(RPM)/SOURCES/kernel-headers.spec + +dist-git-headers: dist-headers-srpm +ifeq ("$(RHDISTGIT_BRANCH)", "") + $(error RHDISTGIT_BRANCH unset) +endif + SPECPACKAGE_NAME=kernel-headers SRPM=$(SRPMS)/kernel-headers-$(BASEVERSION)$(DIST).src.rpm $(REDHAT)/scripts/rh-headers-dist-git.sh + +dist-git-headers-test: export RH_DIST_GIT_TEST="1" +dist-git-headers-test: dist-git-headers + dist-rtg: dist-release @$(MAKE) dist-release-tag @$(MAKE) dist-git diff --git a/redhat/kernel-headers.spec.template b/redhat/kernel-headers.spec.template new file mode 100644 index blahblah..blahblah 100644 --- /dev/null +++ b/redhat/kernel-headers.spec.template @@ -0,0 +1,112 @@ +# For a stable, released kernel, released_kernel should be 1. For rawhide +# and/or a kernel built from an rc or git snapshot, released_kernel should +# be 0. +%global released_kernel %%SPECRELEASED_KERNEL%% + +%%SPECBUILDID%% +%define specversion %%SPECVERSION%% +%define tarfile_release %%SPECTARFILE_RELEASE%% +# This is needed to do merge window version magic +# This allows pkg_release to have configurable %%{?dist} tag +%define specrelease %%SPECRELEASE%% + +# This package doesn't contain any binary, thus no debuginfo package is needed +%global debug_package %{nil} + +Name: kernel-headers +Summary: Header files for the Linux kernel for use by glibc +License: ((GPL-2.0-only WITH Linux-syscall-note) OR BSD-2-Clause) AND ((GPL-2.0-only WITH Linux-syscall-note) OR BSD-3-Clause) AND ((GPL-2.0-only WITH Linux-syscall-note) OR CDDL-1.0) AND ((GPL-2.0-only WITH Linux-syscall-note) OR Linux-OpenIB) AND ((GPL-2.0-only WITH Linux-syscall-note) OR MIT) AND ((GPL-2.0-or-later WITH Linux-syscall-note) OR BSD-3-Clause) AND ((GPL-2.0-or-later WITH Linux-syscall-note) OR MIT) AND BSD-3-Clause AND (GPL-1.0-or-later WITH Linux-syscall-note) AND GPL-2.0-only AND (GPL-2.0-only WITH Linux-syscall-note) AND (GPL-2.0-or-later WITH Linux-syscall-note) AND (LGPL-2.0-or-later WITH Linux-syscall-note) AND (LGPL-2.1-only WITH Linux-syscall-note) AND (LGPL-2.1-or-later WITH Linux-syscall-note) AND MIT +URL: http://www.kernel.org/ +Version: %{specversion} +Release: %{specrelease} +# This is a tarball with headers from the kernel, which should be created +# using create_headers_tarball.sh provided in the kernel source package. +# To create the tarball, you should go into a prepared/patched kernel sources +# directory, or git kernel source repository, and do eg.: +# For a RHEL package: (...)/create_headers_tarball.sh -m RHEL_RELEASE +# For a Fedora package: kernel/scripts/create_headers_tarball.sh -r <release number> +Source0: kernel-headers-%{tarfile_release}.tar.xz +Obsoletes: glibc-kernheaders < 3.0-46 +Provides: glibc-kernheaders = 3.0-46 +%if "0%{?variant}" +Obsoletes: kernel-headers < %{specversion}-%{specrelease} +Provides: kernel-headers = %{specversion}-%{specrelease} +%endif + +%description +Kernel-headers includes the C header files that specify the interface +between the Linux kernel and userspace libraries and programs. The +header files define structures and constants that are needed for +building most standard programs and are also needed for rebuilding the +glibc package. + +%package -n kernel-cross-headers +Summary: Header files for the Linux kernel for use by cross-glibc + +%description -n kernel-cross-headers +Kernel-cross-headers includes the C header files that specify the interface +between the Linux kernel and userspace libraries and programs. The +header files define structures and constants that are needed for +building most standard programs and are also needed for rebuilding the +cross-glibc package. + +%prep +%setup -q -c + +%build + +%install +# List of architectures we support and want to copy their headers +ARCH_LIST="arm arm64 powerpc riscv s390 x86" + +ARCH=%_target_cpu +case $ARCH in + armv7hl) + ARCH=arm + ;; + aarch64) + ARCH=arm64 + ;; + ppc64*) + ARCH=powerpc + ;; + riscv64) + ARCH=riscv + ;; + s390x) + ARCH=s390 + ;; + x86_64|i*86) + ARCH=x86 + ;; +esac + +cd arch-$ARCH/include +mkdir -p $RPM_BUILD_ROOT%{_includedir} +cp -a asm-generic $RPM_BUILD_ROOT%{_includedir} + +# Copy all the architectures we care about to their respective asm directories +for arch in $ARCH_LIST; do + mkdir -p $RPM_BUILD_ROOT%{_prefix}/${arch}-linux-gnu/include + cp -a asm-generic $RPM_BUILD_ROOT%{_prefix}/${arch}-linux-gnu/include/ +done + +# Remove what we copied already +rm -rf asm-generic + +# Copy the rest of the headers over +cp -a * $RPM_BUILD_ROOT%{_includedir}/ +for arch in $ARCH_LIST; do +cp -a * $RPM_BUILD_ROOT%{_prefix}/${arch}-linux-gnu/include/ +done + +%files +%defattr(-,root,root) +%{_includedir}/* + +%files -n kernel-cross-headers +%defattr(-,root,root) +%{_prefix}/*-linux-gnu/* + +%changelog +%autochangelog diff --git a/redhat/scripts/create_headers_tarball.sh b/redhat/scripts/create_headers_tarball.sh new file mode 100755 index blahblah..blahblah 100755 --- /dev/null +++ b/redhat/scripts/create_headers_tarball.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# shellcheck disable=SC2035 +# shellcheck disable=SC2038 +# shellcheck disable=SC3044 +# This script is aimed at generating the headers from the kernel sources. + +set -e + +# ARCH_LIST below has the default list of supported architectures +# (the architectures names may be different from rpm, you list here the +# names of arch/<arch> directories in the kernel sources) +ARCH_LIST="arm arm64 powerpc riscv s390 x86" + +headers_dir=$(mktemp -d) +trap 'rm -rf "$headers_dir"' SIGHUP SIGINT SIGTERM EXIT + +archs=${ARCH_LIST:-$(ls arch)} + +# Upstream rmeoved the headers_install_all target so do it manually +for arch in $archs; do + cd "$TOPDIR" + mkdir "$headers_dir/arch-$arch" + make ARCH="$arch" INSTALL_HDR_PATH="$headers_dir/arch-$arch" KBUILD_HEADERS=install headers_install +done +find "$headers_dir" \ + \( -name .install -o -name .check -o \ + -name ..install.cmd -o -name ..check.cmd \) | xargs rm -f + +TARBALL="$SOURCES/kernel-headers-$UPSTREAM_TARBALL_NAME.tar.xz" +pushd "$headers_dir" + tar -Jcf "$TARBALL" * +popd + +echo wrote "$TARBALL" diff --git a/redhat/scripts/genspec/headerspec.sh b/redhat/scripts/genspec/headerspec.sh new file mode 100755 index blahblah..blahblah 100755 --- /dev/null +++ b/redhat/scripts/genspec/headerspec.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# shellcheck disable=SC2153 + +if [ -n "$DISTLOCALVERSION" ]; then + SPECBUILDID=$(printf "%%define buildid %s" "$DISTLOCALVERSION") +else + SPECBUILDID="# define buildid .local" +fi + +# The SPECRELEASE variable uses the SPECBUILDID variable which is +# defined above. IOW, don't remove SPECBUILDID ;) +SPECRELEASE="${UPSTREAMBUILD}""${BUILD}""%{?buildid}%{?dist}" + +# self-test begin +test -f "$SOURCES/kernel-headers.spec" && + sed -i -e " + s/%%SPECBUILDID%%/$SPECBUILDID/ + s/%%SPECKVERSION%%/$SPECKVERSION/ + s/%%SPECKPATCHLEVEL%%/$SPECKPATCHLEVEL/ + s/%%SPECBUILD%%/$SPECBUILD/ + s/%%SPECRELEASE%%/$SPECRELEASE/ + s/%%SPECRELEASED_KERNEL%%/$SPECRELEASED_KERNEL/ + s/%%SPECINCLUDE_FEDORA_FILES%%/$SPECINCLUDE_FEDORA_FILES/ + s/%%SPECINCLUDE_RHEL_FILES%%/$SPECINCLUDE_RHEL_FILES/ + s/%%SPECPATCHLIST_CHANGELOG%%/$SPECPATCHLIST_CHANGELOG/ + s/%%SPECINCLUDE_RT_FILES%%/$SPECINCLUDE_RT_FILES/ + s/%%SPECVERSION%%/$SPECVERSION/ + s/%%SPECRPMVERSION%%/$SPECRPMVERSION/ + s/%%SPECKABIVERSION%%/$SPECKABIVERSION/ + s/%%SPECBPFTOOLVERSION%%/$SPECBPFTOOLVERSION/ + s/%%SPECTARFILE_RELEASE%%/$SPECTARFILE_RELEASE/ + s/%%SPECPACKAGE_NAME%%/$SPECPACKAGE_NAME/ + s/%%SPECGEMINI%%/$SPECGEMINI/ + s/%%SPECSELFTESTS_MUST_BUILD%%/$SPECSELFTESTS_MUST_BUILD/" "$SOURCES/kernel-headers.spec" +# self-test end diff --git a/redhat/scripts/rh-headers-dist-git.sh b/redhat/scripts/rh-headers-dist-git.sh new file mode 100755 index blahblah..blahblah 100755 --- /dev/null +++ b/redhat/scripts/rh-headers-dist-git.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# clones and updates a dist-git repo + +# shellcheck disable=SC2164 + +function die +{ + echo "Error: $1" >&2; + exit 1; +} + +function upload() +{ + [ -n "$RH_DIST_GIT_TEST" ] && return + $RHPKG_BIN new-sources "$@" >/dev/null || die "uploading $*"; +} + +if [ -z "$RHDISTGIT_BRANCH" ]; then + echo "$0: RHDISTGIT_BRANCH is not set" >&2 + exit 1 +fi + +echo "Cloning the repository" +# clone the dist-git, considering cache +date=$(date +"%Y-%m-%d") +tmpdir="$(mktemp -d --tmpdir="$RHDISTGIT_TMP" RHEL"$RHEL_MAJOR"."$date".XXXXXXXX)" +cd "$tmpdir" || die "Unable to create temporary directory"; +echo "Cloning using $RHPKG_BIN" >&2; +# shellcheck disable=SC2086 +eval $RHPKG_BIN clone "kernel-headers" >/dev/null || die "Unable to clone using $RHPKG_BIN"; + +echo "Switching the branch" +# change in the correct branch +cd "$tmpdir/kernel-headers"; +$RHPKG_BIN switch-branch "$RHDISTGIT_BRANCH" || die "switching to branch $RHDISTGIT_BRANCH"; + +echo "Unpacking from SRPM" +"$REDHAT"/scripts/expand_srpm.sh "$tmpdir" +git reset HEAD -- README.md +git checkout README.md +git add README.md + +# upload tarballs +upload_list="kernel-headers-$UPSTREAM_TARBALL_NAME.tar.xz" + +echo "Uploading new tarballs: $upload_list" +# We depend on word splitting here: +# shellcheck disable=SC2086 +upload $upload_list + +echo "Creating diff for review ($tmpdir/diff) and changelog" +# diff the result (redhat/git/dontdiff). note: diff reuturns 1 if +# differences were found +diff -X "$REDHAT"/git/dontdiff -upr "$tmpdir/kernel-headers" "$REDHAT"/rpm/SOURCES/ > "$tmpdir"/diff; + +# all done +echo "$tmpdir" -- https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2910 -- _______________________________________________ kernel mailing list -- kernel@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to kernel-leave@xxxxxxxxxxxxxxxxxxxxxxx Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kernel@xxxxxxxxxxxxxxxxxxxxxxx Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue