2018-04-05 19:22:29 +08:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
|
|
|
|
#
|
|
|
|
# Simple script to generate a debian/ directory for a Linux kernel.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2018-07-26 18:21:01 +08:00
|
|
|
is_enabled() {
|
2019-03-08 17:56:25 +08:00
|
|
|
grep -q "^$1=y" include/config/auto.conf
|
2018-07-26 18:21:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if_enabled_echo() {
|
|
|
|
if is_enabled "$1"; then
|
|
|
|
echo -n "$2"
|
|
|
|
elif [ $# -ge 3 ]; then
|
|
|
|
echo -n "$3"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-04-05 19:22:29 +08:00
|
|
|
set_debarch() {
|
2018-07-26 18:20:28 +08:00
|
|
|
if [ -n "$KBUILD_DEBARCH" ] ; then
|
|
|
|
debarch="$KBUILD_DEBARCH"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2018-04-05 19:22:29 +08:00
|
|
|
# Attempt to find the correct Debian architecture
|
|
|
|
case "$UTS_MACHINE" in
|
2018-07-26 18:22:47 +08:00
|
|
|
i386|ia64|alpha|m68k|riscv*)
|
2018-04-05 19:22:29 +08:00
|
|
|
debarch="$UTS_MACHINE" ;;
|
|
|
|
x86_64)
|
|
|
|
debarch=amd64 ;;
|
|
|
|
sparc*)
|
2019-03-08 17:56:23 +08:00
|
|
|
debarch=sparc$(if_enabled_echo CONFIG_64BIT 64) ;;
|
2018-04-05 19:22:29 +08:00
|
|
|
s390*)
|
2018-07-26 18:20:54 +08:00
|
|
|
debarch=s390x ;;
|
2018-04-05 19:22:29 +08:00
|
|
|
ppc*)
|
2019-03-08 17:56:23 +08:00
|
|
|
if is_enabled CONFIG_64BIT; then
|
|
|
|
debarch=ppc64$(if_enabled_echo CONFIG_CPU_LITTLE_ENDIAN el)
|
2018-07-26 18:21:09 +08:00
|
|
|
else
|
2019-03-08 17:56:23 +08:00
|
|
|
debarch=powerpc$(if_enabled_echo CONFIG_SPE spe)
|
2018-07-26 18:21:09 +08:00
|
|
|
fi
|
|
|
|
;;
|
2018-04-05 19:22:29 +08:00
|
|
|
parisc*)
|
|
|
|
debarch=hppa ;;
|
|
|
|
mips*)
|
2019-03-08 17:56:23 +08:00
|
|
|
if is_enabled CONFIG_CPU_LITTLE_ENDIAN; then
|
|
|
|
debarch=mips$(if_enabled_echo CONFIG_64BIT 64)$(if_enabled_echo CONFIG_CPU_MIPSR6 r6)el
|
|
|
|
elif is_enabled CONFIG_CPU_MIPSR6; then
|
|
|
|
debarch=mips$(if_enabled_echo CONFIG_64BIT 64)r6
|
2018-07-26 18:21:16 +08:00
|
|
|
else
|
|
|
|
debarch=mips
|
|
|
|
fi
|
|
|
|
;;
|
2018-04-05 19:22:29 +08:00
|
|
|
aarch64|arm64)
|
|
|
|
debarch=arm64 ;;
|
|
|
|
arm*)
|
2019-03-08 17:56:23 +08:00
|
|
|
if is_enabled CONFIG_AEABI; then
|
|
|
|
debarch=arm$(if_enabled_echo CONFIG_VFP hf el)
|
2018-04-05 19:22:29 +08:00
|
|
|
else
|
2018-07-26 18:21:01 +08:00
|
|
|
debarch=arm
|
2018-04-05 19:22:29 +08:00
|
|
|
fi
|
|
|
|
;;
|
2018-07-26 18:22:34 +08:00
|
|
|
openrisc)
|
|
|
|
debarch=or1k ;;
|
2018-07-26 18:22:54 +08:00
|
|
|
sh)
|
2019-03-08 17:56:23 +08:00
|
|
|
if is_enabled CONFIG_CPU_SH3; then
|
|
|
|
debarch=sh3$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb)
|
|
|
|
elif is_enabled CONFIG_CPU_SH4; then
|
|
|
|
debarch=sh4$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb)
|
2018-07-26 18:22:54 +08:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
if [ -z "$debarch" ]; then
|
2018-07-26 18:20:45 +08:00
|
|
|
debarch=$(dpkg-architecture -qDEB_HOST_ARCH)
|
2018-04-05 19:22:29 +08:00
|
|
|
echo "" >&2
|
|
|
|
echo "** ** ** WARNING ** ** **" >&2
|
|
|
|
echo "" >&2
|
|
|
|
echo "Your architecture doesn't have its equivalent" >&2
|
|
|
|
echo "Debian userspace architecture defined!" >&2
|
2018-07-26 18:20:45 +08:00
|
|
|
echo "Falling back to the current host architecture ($debarch)." >&2
|
2018-04-05 19:22:29 +08:00
|
|
|
echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
|
|
|
|
echo "" >&2
|
2018-07-26 18:22:54 +08:00
|
|
|
fi
|
2018-04-05 19:22:29 +08:00
|
|
|
}
|
|
|
|
|
kbuild: give up untracked files for source package builds
When the source tree is dirty and contains untracked files, package
builds may fail, for example, when a broken symlink exists, a file
path contains whitespaces, etc.
Since commit 05e96e96a315 ("kbuild: use git-archive for source package
creation"), the source tarball only contains committed files because
it is created by 'git archive'. scripts/package/gen-diff-patch tries
to address the diff from HEAD, but including untracked files by the
hand-crafted script introduces more complexity. I wrote a patch [1] to
make it work in most cases, but still wonder if this is what we should
aim for.
To simplify the code, this patch just gives up untracked files. Going
forward, it is your responsibility to do 'git add' for what you want in
the source package. The script shows a warning just in case you forgot
to do so. It should be checked only when building source packages.
[1]: https://lore.kernel.org/all/CAK7LNAShbZ56gSh9PrbLnBDYKnjtTkHMoCXeGrhcxMvqXGq9=g@mail.gmail.com/2-0001-kbuild-make-package-builds-more-robust.patch
Fixes: 05e96e96a315 ("kbuild: use git-archive for source package creation")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
2023-04-10 20:09:07 +08:00
|
|
|
# Create debian/source/ if it is a source package build
|
|
|
|
gen_source ()
|
|
|
|
{
|
|
|
|
mkdir -p debian/source
|
|
|
|
|
|
|
|
echo "3.0 (quilt)" > debian/source/format
|
|
|
|
|
|
|
|
{
|
|
|
|
echo "diff-ignore"
|
|
|
|
echo "extend-diff-ignore = .*"
|
|
|
|
} > debian/source/local-options
|
|
|
|
|
|
|
|
# Add .config as a patch
|
|
|
|
mkdir -p debian/patches
|
|
|
|
{
|
|
|
|
echo "Subject: Add .config"
|
|
|
|
echo "Author: ${maintainer}"
|
|
|
|
echo
|
|
|
|
echo "--- /dev/null"
|
|
|
|
echo "+++ linux/.config"
|
|
|
|
diff -u /dev/null "${KCONFIG_CONFIG}" | tail -n +3
|
|
|
|
} > debian/patches/config.patch
|
|
|
|
echo config.patch > debian/patches/series
|
|
|
|
|
|
|
|
"${srctree}/scripts/package/gen-diff-patch" debian/patches/diff.patch
|
|
|
|
if [ -s debian/patches/diff.patch ]; then
|
|
|
|
sed -i "
|
|
|
|
1iSubject: Add local diff
|
|
|
|
1iAuthor: ${maintainer}
|
|
|
|
1i
|
|
|
|
" debian/patches/diff.patch
|
|
|
|
|
|
|
|
echo diff.patch >> debian/patches/series
|
|
|
|
else
|
|
|
|
rm -f debian/patches/diff.patch
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-02-15 09:20:24 +08:00
|
|
|
rm -rf debian
|
kbuild: give up untracked files for source package builds
When the source tree is dirty and contains untracked files, package
builds may fail, for example, when a broken symlink exists, a file
path contains whitespaces, etc.
Since commit 05e96e96a315 ("kbuild: use git-archive for source package
creation"), the source tarball only contains committed files because
it is created by 'git archive'. scripts/package/gen-diff-patch tries
to address the diff from HEAD, but including untracked files by the
hand-crafted script introduces more complexity. I wrote a patch [1] to
make it work in most cases, but still wonder if this is what we should
aim for.
To simplify the code, this patch just gives up untracked files. Going
forward, it is your responsibility to do 'git add' for what you want in
the source package. The script shows a warning just in case you forgot
to do so. It should be checked only when building source packages.
[1]: https://lore.kernel.org/all/CAK7LNAShbZ56gSh9PrbLnBDYKnjtTkHMoCXeGrhcxMvqXGq9=g@mail.gmail.com/2-0001-kbuild-make-package-builds-more-robust.patch
Fixes: 05e96e96a315 ("kbuild: use git-archive for source package creation")
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
2023-04-10 20:09:07 +08:00
|
|
|
mkdir debian
|
|
|
|
|
|
|
|
email=${DEBEMAIL-$EMAIL}
|
|
|
|
|
|
|
|
# use email string directly if it contains <email>
|
|
|
|
if echo "${email}" | grep -q '<.*>'; then
|
|
|
|
maintainer=${email}
|
|
|
|
else
|
|
|
|
# or construct the maintainer string
|
|
|
|
user=${KBUILD_BUILD_USER-$(id -nu)}
|
|
|
|
name=${DEBFULLNAME-${user}}
|
|
|
|
if [ -z "${email}" ]; then
|
|
|
|
buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)}
|
|
|
|
email="${user}@${buildhost}"
|
|
|
|
fi
|
|
|
|
maintainer="${name} <${email}>"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = --need-source ]; then
|
|
|
|
gen_source
|
|
|
|
fi
|
2023-02-15 09:20:24 +08:00
|
|
|
|
2018-04-05 19:22:29 +08:00
|
|
|
# Some variables and settings used throughout the script
|
|
|
|
version=$KERNELRELEASE
|
|
|
|
if [ -n "$KDEB_PKGVERSION" ]; then
|
|
|
|
packageversion=$KDEB_PKGVERSION
|
|
|
|
else
|
2023-03-15 23:50:18 +08:00
|
|
|
packageversion=$(${srctree}/scripts/setlocalversion --no-local ${srctree})-$($srctree/init/build-version)
|
2018-04-05 19:22:29 +08:00
|
|
|
fi
|
2023-02-15 09:20:27 +08:00
|
|
|
sourcename=${KDEB_SOURCENAME:-linux-upstream}
|
2018-04-05 19:22:29 +08:00
|
|
|
|
|
|
|
if [ "$ARCH" = "um" ] ; then
|
2020-10-14 02:38:20 +08:00
|
|
|
packagename=user-mode-linux
|
|
|
|
else
|
|
|
|
packagename=linux-image
|
2018-04-05 19:22:29 +08:00
|
|
|
fi
|
|
|
|
|
2020-10-14 02:38:20 +08:00
|
|
|
debarch=
|
|
|
|
set_debarch
|
|
|
|
|
2018-04-05 19:22:29 +08:00
|
|
|
# Try to determine distribution
|
|
|
|
if [ -n "$KDEB_CHANGELOG_DIST" ]; then
|
|
|
|
distribution=$KDEB_CHANGELOG_DIST
|
|
|
|
# In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
|
|
|
|
elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then
|
|
|
|
: # nothing to do in this case
|
|
|
|
else
|
|
|
|
distribution="unstable"
|
|
|
|
echo >&2 "Using default distribution of 'unstable' in the changelog"
|
|
|
|
echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo $debarch > debian/arch
|
2019-12-30 22:07:47 +08:00
|
|
|
extra_build_depends=", $(if_enabled_echo CONFIG_UNWINDER_ORC libelf-dev:native)"
|
2019-03-08 17:56:23 +08:00
|
|
|
extra_build_depends="$extra_build_depends, $(if_enabled_echo CONFIG_SYSTEM_TRUSTED_KEYRING libssl-dev:native)"
|
2018-04-05 19:22:29 +08:00
|
|
|
|
|
|
|
# Generate a simple changelog template
|
|
|
|
cat <<EOF > debian/changelog
|
|
|
|
$sourcename ($packageversion) $distribution; urgency=low
|
|
|
|
|
|
|
|
* Custom built Linux kernel.
|
|
|
|
|
|
|
|
-- $maintainer $(date -R)
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Generate copyright file
|
|
|
|
cat <<EOF > debian/copyright
|
2023-03-31 22:15:40 +08:00
|
|
|
This is a packaged upstream version of the Linux kernel.
|
2018-04-05 19:22:29 +08:00
|
|
|
|
|
|
|
The sources may be found at most Linux archive sites, including:
|
|
|
|
https://www.kernel.org/pub/linux/kernel
|
|
|
|
|
|
|
|
Copyright: 1991 - 2018 Linus Torvalds and others.
|
|
|
|
|
|
|
|
The git repository for mainline kernel development is at:
|
|
|
|
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; version 2 dated June, 1991.
|
|
|
|
|
|
|
|
On Debian GNU/Linux systems, the complete text of the GNU General Public
|
|
|
|
License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# Generate a control file
|
|
|
|
cat <<EOF > debian/control
|
|
|
|
Source: $sourcename
|
|
|
|
Section: kernel
|
|
|
|
Priority: optional
|
|
|
|
Maintainer: $maintainer
|
2020-09-21 06:25:54 +08:00
|
|
|
Rules-Requires-Root: no
|
2023-03-13 04:07:30 +08:00
|
|
|
Build-Depends: bc, debhelper, rsync, kmod, cpio, bison, flex $extra_build_depends
|
2020-07-20 03:46:02 +08:00
|
|
|
Homepage: https://www.kernel.org/
|
2018-04-05 19:22:29 +08:00
|
|
|
|
2020-10-14 02:38:20 +08:00
|
|
|
Package: $packagename-$version
|
2018-04-05 19:22:29 +08:00
|
|
|
Architecture: $debarch
|
|
|
|
Description: Linux kernel, version $version
|
|
|
|
This package contains the Linux kernel, modules and corresponding other
|
|
|
|
files, version: $version.
|
2023-03-13 04:07:30 +08:00
|
|
|
EOF
|
|
|
|
|
|
|
|
if [ "${SRCARCH}" != um ]; then
|
|
|
|
cat <<EOF >> debian/control
|
2018-04-05 19:22:29 +08:00
|
|
|
|
|
|
|
Package: linux-libc-dev
|
|
|
|
Section: devel
|
|
|
|
Provides: linux-kernel-headers
|
|
|
|
Architecture: $debarch
|
|
|
|
Description: Linux support headers for userspace development
|
|
|
|
This package provides userspaces headers from the Linux kernel. These headers
|
|
|
|
are used by the installed headers for GNU glibc and other system libraries.
|
2019-07-09 15:43:35 +08:00
|
|
|
Multi-Arch: same
|
2020-03-24 18:24:47 +08:00
|
|
|
EOF
|
|
|
|
|
2020-10-14 02:38:19 +08:00
|
|
|
if is_enabled CONFIG_MODULES; then
|
|
|
|
cat <<EOF >> debian/control
|
|
|
|
|
2020-10-14 02:38:20 +08:00
|
|
|
Package: linux-headers-$version
|
2020-10-14 02:38:19 +08:00
|
|
|
Architecture: $debarch
|
|
|
|
Description: Linux kernel headers for $version on $debarch
|
|
|
|
This package provides kernel header files for $version on $debarch
|
|
|
|
.
|
|
|
|
This is useful for people who need to build external modules
|
|
|
|
EOF
|
|
|
|
fi
|
2023-03-13 04:07:30 +08:00
|
|
|
fi
|
2020-10-14 02:38:19 +08:00
|
|
|
|
2020-03-24 18:24:47 +08:00
|
|
|
if is_enabled CONFIG_DEBUG_INFO; then
|
|
|
|
cat <<EOF >> debian/control
|
2018-04-05 19:22:29 +08:00
|
|
|
|
2020-10-14 02:38:20 +08:00
|
|
|
Package: linux-image-$version-dbg
|
2018-04-05 19:22:29 +08:00
|
|
|
Section: debug
|
|
|
|
Architecture: $debarch
|
|
|
|
Description: Linux kernel debugging symbols for $version
|
|
|
|
This package will come in handy if you need to debug the kernel. It provides
|
|
|
|
all the necessary debug symbols for the kernel and its modules.
|
|
|
|
EOF
|
2020-03-24 18:24:47 +08:00
|
|
|
fi
|
2018-04-05 19:22:29 +08:00
|
|
|
|
|
|
|
cat <<EOF > debian/rules
|
|
|
|
#!$(command -v $MAKE) -f
|
|
|
|
|
2019-02-14 11:05:14 +08:00
|
|
|
srctree ?= .
|
2023-03-13 04:07:26 +08:00
|
|
|
KERNELRELEASE = ${KERNELRELEASE}
|
2019-02-14 11:05:14 +08:00
|
|
|
|
2023-04-25 19:08:59 +08:00
|
|
|
.PHONY: clean build build-arch build-indep binary binary-arch binary-indep
|
|
|
|
|
2020-09-21 06:25:53 +08:00
|
|
|
build-indep:
|
|
|
|
build-arch:
|
2023-02-15 09:20:33 +08:00
|
|
|
\$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} \
|
2023-03-13 04:07:27 +08:00
|
|
|
KERNELRELEASE=\$(KERNELRELEASE) \
|
2023-02-15 09:20:33 +08:00
|
|
|
\$(shell \$(srctree)/scripts/package/deb-build-option) \
|
|
|
|
olddefconfig all
|
2018-04-05 19:22:29 +08:00
|
|
|
|
2020-09-21 06:25:53 +08:00
|
|
|
build: build-arch
|
|
|
|
|
|
|
|
binary-indep:
|
|
|
|
binary-arch: build-arch
|
2023-03-13 04:07:26 +08:00
|
|
|
\$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} \
|
|
|
|
KERNELRELEASE=\$(KERNELRELEASE) intdeb-pkg
|
|
|
|
|
2018-04-05 19:22:29 +08:00
|
|
|
clean:
|
2021-05-26 07:01:37 +08:00
|
|
|
rm -rf debian/files debian/linux-*
|
2023-02-15 09:20:32 +08:00
|
|
|
\$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} clean
|
2018-04-05 19:22:29 +08:00
|
|
|
|
|
|
|
binary: binary-arch
|
|
|
|
EOF
|
2019-03-09 23:43:06 +08:00
|
|
|
chmod +x debian/rules
|
2018-04-05 19:22:29 +08:00
|
|
|
|
|
|
|
exit 0
|