mkdebian 6.2 KB
Newer Older
1 2 3 4 5 6 7 8
#!/bin/sh
#
# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
#
# Simple script to generate a debian/ directory for a Linux kernel.

set -e

9
is_enabled() {
10
	grep -q "^$1=y" include/config/auto.conf
11 12 13 14 15 16 17 18 19 20
}

if_enabled_echo() {
	if is_enabled "$1"; then
		echo -n "$2"
	elif [ $# -ge 3 ]; then
		echo -n "$3"
	fi
}

21
set_debarch() {
22 23 24 25 26
	if [ -n "$KBUILD_DEBARCH" ] ; then
		debarch="$KBUILD_DEBARCH"
		return
	fi

27 28
	# Attempt to find the correct Debian architecture
	case "$UTS_MACHINE" in
29
	i386|ia64|alpha|m68k|riscv*)
30 31 32 33
		debarch="$UTS_MACHINE" ;;
	x86_64)
		debarch=amd64 ;;
	sparc*)
34
		debarch=sparc$(if_enabled_echo CONFIG_64BIT 64) ;;
35
	s390*)
36
		debarch=s390x ;;
37
	ppc*)
38 39
		if is_enabled CONFIG_64BIT; then
			debarch=ppc64$(if_enabled_echo CONFIG_CPU_LITTLE_ENDIAN el)
40
		else
41
			debarch=powerpc$(if_enabled_echo CONFIG_SPE spe)
42 43
		fi
		;;
44 45 46
	parisc*)
		debarch=hppa ;;
	mips*)
47 48 49 50
		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
51 52 53 54
		else
			debarch=mips
		fi
		;;
55 56 57
	aarch64|arm64)
		debarch=arm64 ;;
	arm*)
58 59
		if is_enabled CONFIG_AEABI; then
			debarch=arm$(if_enabled_echo CONFIG_VFP hf el)
60
		else
61
			debarch=arm
62 63
		fi
		;;
64 65
	openrisc)
		debarch=or1k ;;
66
	sh)
67 68 69 70
		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)
71 72 73 74
		fi
		;;
	esac
	if [ -z "$debarch" ]; then
75
		debarch=$(dpkg-architecture -qDEB_HOST_ARCH)
76 77 78 79 80
		echo "" >&2
		echo "** ** **  WARNING  ** ** **" >&2
		echo "" >&2
		echo "Your architecture doesn't have its equivalent" >&2
		echo "Debian userspace architecture defined!" >&2
81
		echo "Falling back to the current host architecture ($debarch)." >&2
82 83
		echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
		echo "" >&2
84
	fi
85 86 87 88 89 90
}

# Some variables and settings used throughout the script
version=$KERNELRELEASE
if [ -n "$KDEB_PKGVERSION" ]; then
	packageversion=$KDEB_PKGVERSION
91
	revision=${packageversion##*-}
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
else
	revision=$(cat .version 2>/dev/null||echo 1)
	packageversion=$version-$revision
fi
sourcename=$KDEB_SOURCENAME
packagename=linux-image-$version
kernel_headers_packagename=linux-headers-$version
dbg_packagename=$packagename-dbg
debarch=
set_debarch

if [ "$ARCH" = "um" ] ; then
	packagename=user-mode-linux-$version
fi

107 108 109 110 111
email=${DEBEMAIL-$EMAIL}

# use email string directly if it contains <email>
if echo $email | grep -q '<.*>'; then
	maintainer=$email
112
else
113 114 115 116 117 118 119 120
	# 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>"
121 122 123 124 125 126 127 128 129 130 131 132 133 134
fi

# 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

135 136 137
mkdir -p debian/source/
echo "1.0" > debian/source/format

138
echo $debarch > debian/arch
139
extra_build_depends=", $(if_enabled_echo CONFIG_UNWINDER_ORC libelf-dev:native)"
140
extra_build_depends="$extra_build_depends, $(if_enabled_echo CONFIG_SYSTEM_TRUSTED_KEYRING libssl-dev:native)"
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

# 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
This is a packacked upstream version of the Linux kernel.

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
177
Build-Depends: bc, rsync, kmod, cpio, bison, flex | flex:native $extra_build_depends
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
Homepage: http://www.kernel.org/

Package: $packagename
Architecture: $debarch
Description: Linux kernel, version $version
 This package contains the Linux kernel, modules and corresponding other
 files, version: $version.

Package: $kernel_headers_packagename
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

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.
200
Multi-Arch: same
201 202 203 204 205 206 207 208 209 210 211 212

Package: $dbg_packagename
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

cat <<EOF > debian/rules
#!$(command -v $MAKE) -f

213 214
srctree ?= .

215
build:
216
	\$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \
217
	KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile
218 219

binary-arch:
220
	\$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \
221
	KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile intdeb-pkg
222 223 224 225 226 227 228

clean:
	rm -rf debian/*tmp debian/files
	\$(MAKE) clean

binary: binary-arch
EOF
229
chmod +x debian/rules
230 231

exit 0