5 # Simple script to generate a debian/ directory for a Linux kernel.
10 grep -q "^$1=y" include/config/auto.conf
14 if is_enabled "$1"; then
16 elif [ $# -ge 3 ]; then
22 if [ "${KBUILD_DEBARCH:+set}" ]; then
23 debarch="$KBUILD_DEBARCH"
27 # Attempt to find the correct Debian architecture
28 case "$UTS_MACHINE" in
29 i386|alpha|m68k|riscv*)
30 debarch="$UTS_MACHINE" ;;
34 debarch=sparc$(if_enabled_echo CONFIG_64BIT 64) ;;
38 if is_enabled CONFIG_64BIT; then
39 debarch=ppc64$(if_enabled_echo CONFIG_CPU_LITTLE_ENDIAN el)
41 debarch=powerpc$(if_enabled_echo CONFIG_SPE spe)
47 if is_enabled CONFIG_CPU_LITTLE_ENDIAN; then
48 debarch=mips$(if_enabled_echo CONFIG_64BIT 64)$(if_enabled_echo CONFIG_CPU_MIPSR6 r6)el
49 elif is_enabled CONFIG_CPU_MIPSR6; then
50 debarch=mips$(if_enabled_echo CONFIG_64BIT 64)r6
58 if is_enabled CONFIG_AEABI; then
59 debarch=arm$(if_enabled_echo CONFIG_VFP hf el)
67 if is_enabled CONFIG_CPU_SH3; then
68 debarch=sh3$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb)
69 elif is_enabled CONFIG_CPU_SH4; then
70 debarch=sh4$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb)
74 if is_enabled CONFIG_64BIT; then
81 if [ -z "$debarch" ]; then
82 debarch=$(dpkg-architecture -qDEB_HOST_ARCH)
84 echo "** ** ** WARNING ** ** **" >&2
86 echo "Your architecture doesn't have its equivalent" >&2
87 echo "Debian userspace architecture defined!" >&2
88 echo "Falling back to the current host architecture ($debarch)." >&2
89 echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
94 # Create debian/source/ if it is a source package build
97 mkdir -p debian/source
99 echo "3.0 (quilt)" > debian/source/format
103 echo "extend-diff-ignore = .*"
104 } > debian/source/local-options
106 # Add .config as a patch
107 mkdir -p debian/patches
109 echo "Subject: Add .config"
110 echo "Author: ${maintainer}"
113 echo "+++ linux/.config"
114 diff -u /dev/null "${KCONFIG_CONFIG}" | tail -n +3
115 } > debian/patches/config.patch
116 echo config.patch > debian/patches/series
118 "${srctree}/scripts/package/gen-diff-patch" debian/patches/diff.patch
119 if [ -s debian/patches/diff.patch ]; then
121 1iSubject: Add local diff
122 1iAuthor: ${maintainer}
124 " debian/patches/diff.patch
126 echo diff.patch >> debian/patches/series
128 rm -f debian/patches/diff.patch
135 user=${KBUILD_BUILD_USER:-$(id -nu)}
136 name=${DEBFULLNAME:-${user}}
137 if [ "${DEBEMAIL:+set}" ]; then
140 buildhost=${KBUILD_BUILD_HOST:-$(hostname -f 2>/dev/null || hostname)}
141 email="${user}@${buildhost}"
143 maintainer="${name} <${email}>"
145 while [ $# -gt 0 ]; do
157 # Some variables and settings used throughout the script
158 version=$KERNELRELEASE
159 if [ "${KDEB_PKGVERSION:+set}" ]; then
160 packageversion=$KDEB_PKGVERSION
162 packageversion=$(${srctree}/scripts/setlocalversion --no-local ${srctree})-$($srctree/scripts/build-version)
164 sourcename=${KDEB_SOURCENAME:-linux-upstream}
166 if [ "$ARCH" = "um" ] ; then
167 packagename=user-mode-linux
169 packagename=linux-image
175 # Try to determine distribution
176 if [ "${KDEB_CHANGELOG_DIST:+set}" ]; then
177 distribution=$KDEB_CHANGELOG_DIST
178 # In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
179 elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then
180 : # nothing to do in this case
182 distribution="unstable"
183 echo >&2 "Using default distribution of 'unstable' in the changelog"
184 echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
187 echo $debarch > debian/arch
189 host_gnu=$(dpkg-architecture -a "${debarch}" -q DEB_HOST_GNU_TYPE | sed 's/_/-/g')
191 # Generate a simple changelog template
192 cat <<EOF > debian/changelog
193 $sourcename ($packageversion) $distribution; urgency=low
195 * Custom built Linux kernel.
197 -- $maintainer $(date -R)
200 # Generate a control file
201 cat <<EOF > debian/control
205 Maintainer: $maintainer
206 Rules-Requires-Root: no
207 Build-Depends: debhelper-compat (= 12)
208 Build-Depends-Arch: bc, bison, cpio, flex,
209 gcc-${host_gnu} <!pkg.${sourcename}.nokernelheaders>,
210 kmod, libelf-dev:native,
211 libssl-dev:native, libssl-dev <!pkg.${sourcename}.nokernelheaders>,
212 python3:native, rsync
213 Homepage: https://www.kernel.org/
215 Package: $packagename-$version
216 Architecture: $debarch
217 Description: Linux kernel, version $version
218 This package contains the Linux kernel, modules and corresponding other
219 files, version: $version.
222 if [ "${SRCARCH}" != um ]; then
223 cat <<EOF >> debian/control
225 Package: linux-libc-dev
227 Provides: linux-kernel-headers
228 Architecture: $debarch
229 Description: Linux support headers for userspace development
230 This package provides userspaces headers from the Linux kernel. These headers
231 are used by the installed headers for GNU glibc and other system libraries.
235 if is_enabled CONFIG_MODULES; then
236 cat <<EOF >> debian/control
238 Package: linux-headers-$version
239 Architecture: $debarch
240 Build-Profiles: <!pkg.${sourcename}.nokernelheaders>
241 Description: Linux kernel headers for $version on $debarch
242 This package provides kernel header files for $version on $debarch
244 This is useful for people who need to build external modules
249 if is_enabled CONFIG_DEBUG_INFO; then
250 cat <<EOF >> debian/control
252 Package: linux-image-$version-dbg
254 Architecture: $debarch
255 Build-Profiles: <!pkg.${sourcename}.nokerneldbg>
256 Description: Linux kernel debugging symbols for $version
257 This package will come in handy if you need to debug the kernel. It provides
258 all the necessary debug symbols for the kernel and its modules.
262 cat <<EOF > debian/rules.vars
264 KERNELRELEASE := ${KERNELRELEASE}
267 cp "${srctree}/scripts/package/debian/copyright" debian/
268 cp "${srctree}/scripts/package/debian/rules" debian/