blob: f4449b5753796f1f189c906308fe5112bf675867 [file] [log] [blame]
Riku Voipiob41d9202018-04-05 14:22:29 +03001#!/bin/sh
2#
3# Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
4#
5# Simple script to generate a debian/ directory for a Linux kernel.
6
7set -e
8
9set_debarch() {
Ben Hutchingsf2abcc12018-07-26 11:20:28 +010010 if [ -n "$KBUILD_DEBARCH" ] ; then
11 debarch="$KBUILD_DEBARCH"
12 return
13 fi
14
Riku Voipiob41d9202018-04-05 14:22:29 +030015 # Attempt to find the correct Debian architecture
16 case "$UTS_MACHINE" in
17 i386|ia64|alpha)
18 debarch="$UTS_MACHINE" ;;
19 x86_64)
20 debarch=amd64 ;;
21 sparc*)
22 debarch=sparc ;;
23 s390*)
Ben Hutchings4260ecd2018-07-26 11:20:54 +010024 debarch=s390x ;;
Riku Voipiob41d9202018-04-05 14:22:29 +030025 ppc*)
26 debarch=$(grep -q CPU_LITTLE_ENDIAN=y $KCONFIG_CONFIG && echo ppc64el || echo powerpc) ;;
27 parisc*)
28 debarch=hppa ;;
29 mips*)
30 debarch=mips$(grep -q CPU_LITTLE_ENDIAN=y $KCONFIG_CONFIG && echo el || true) ;;
31 aarch64|arm64)
32 debarch=arm64 ;;
33 arm*)
34 if grep -q CONFIG_AEABI=y $KCONFIG_CONFIG; then
35 if grep -q CONFIG_VFP=y $KCONFIG_CONFIG; then
36 debarch=armhf
37 else
38 debarch=armel
39 fi
40 else
41 debarch=arm
42 fi
43 ;;
44 *)
Ben Hutchings091d30a2018-07-26 11:20:45 +010045 debarch=$(dpkg-architecture -qDEB_HOST_ARCH)
Riku Voipiob41d9202018-04-05 14:22:29 +030046 echo "" >&2
47 echo "** ** ** WARNING ** ** **" >&2
48 echo "" >&2
49 echo "Your architecture doesn't have its equivalent" >&2
50 echo "Debian userspace architecture defined!" >&2
Ben Hutchings091d30a2018-07-26 11:20:45 +010051 echo "Falling back to the current host architecture ($debarch)." >&2
Riku Voipiob41d9202018-04-05 14:22:29 +030052 echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
53 echo "" >&2
Ben Hutchingsf2abcc12018-07-26 11:20:28 +010054 ;;
Riku Voipiob41d9202018-04-05 14:22:29 +030055 esac
Riku Voipiob41d9202018-04-05 14:22:29 +030056}
57
58# Some variables and settings used throughout the script
59version=$KERNELRELEASE
60if [ -n "$KDEB_PKGVERSION" ]; then
61 packageversion=$KDEB_PKGVERSION
62else
63 revision=$(cat .version 2>/dev/null||echo 1)
64 packageversion=$version-$revision
65fi
66sourcename=$KDEB_SOURCENAME
67packagename=linux-image-$version
68kernel_headers_packagename=linux-headers-$version
69dbg_packagename=$packagename-dbg
70debarch=
71set_debarch
72
73if [ "$ARCH" = "um" ] ; then
74 packagename=user-mode-linux-$version
75fi
76
Riku Voipiod5940c602018-05-07 10:11:34 +030077email=${DEBEMAIL-$EMAIL}
78
79# use email string directly if it contains <email>
80if echo $email | grep -q '<.*>'; then
81 maintainer=$email
Riku Voipiob41d9202018-04-05 14:22:29 +030082else
Riku Voipiod5940c602018-05-07 10:11:34 +030083 # or construct the maintainer string
84 user=${KBUILD_BUILD_USER-$(id -nu)}
85 name=${DEBFULLNAME-$user}
86 if [ -z "$email" ]; then
87 buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)}
88 email="$user@$buildhost"
89 fi
90 maintainer="$name <$email>"
Riku Voipiob41d9202018-04-05 14:22:29 +030091fi
Riku Voipiob41d9202018-04-05 14:22:29 +030092
93# Try to determine distribution
94if [ -n "$KDEB_CHANGELOG_DIST" ]; then
95 distribution=$KDEB_CHANGELOG_DIST
96# In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
97elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then
98 : # nothing to do in this case
99else
100 distribution="unstable"
101 echo >&2 "Using default distribution of 'unstable' in the changelog"
102 echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
103fi
104
105mkdir -p debian/
106echo $debarch > debian/arch
107
108# Generate a simple changelog template
109cat <<EOF > debian/changelog
110$sourcename ($packageversion) $distribution; urgency=low
111
112 * Custom built Linux kernel.
113
114 -- $maintainer $(date -R)
115EOF
116
117# Generate copyright file
118cat <<EOF > debian/copyright
119This is a packacked upstream version of the Linux kernel.
120
121The sources may be found at most Linux archive sites, including:
122https://www.kernel.org/pub/linux/kernel
123
124Copyright: 1991 - 2018 Linus Torvalds and others.
125
126The git repository for mainline kernel development is at:
127git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
128
129 This program is free software; you can redistribute it and/or modify
130 it under the terms of the GNU General Public License as published by
131 the Free Software Foundation; version 2 dated June, 1991.
132
133On Debian GNU/Linux systems, the complete text of the GNU General Public
134License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
135EOF
136
137# Generate a control file
138cat <<EOF > debian/control
139Source: $sourcename
140Section: kernel
141Priority: optional
142Maintainer: $maintainer
143Build-Depends: bc, kmod, cpio
144Homepage: http://www.kernel.org/
145
146Package: $packagename
147Architecture: $debarch
148Description: Linux kernel, version $version
149 This package contains the Linux kernel, modules and corresponding other
150 files, version: $version.
151
152Package: $kernel_headers_packagename
153Architecture: $debarch
154Description: Linux kernel headers for $version on $debarch
155 This package provides kernel header files for $version on $debarch
156 .
157 This is useful for people who need to build external modules
158
159Package: linux-libc-dev
160Section: devel
161Provides: linux-kernel-headers
162Architecture: $debarch
163Description: Linux support headers for userspace development
164 This package provides userspaces headers from the Linux kernel. These headers
165 are used by the installed headers for GNU glibc and other system libraries.
166
167Package: $dbg_packagename
168Section: debug
169Architecture: $debarch
170Description: Linux kernel debugging symbols for $version
171 This package will come in handy if you need to debug the kernel. It provides
172 all the necessary debug symbols for the kernel and its modules.
173EOF
174
175cat <<EOF > debian/rules
176#!$(command -v $MAKE) -f
177
178build:
179 \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC=
180
181binary-arch:
182 \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC= intdeb-pkg
183
184clean:
185 rm -rf debian/*tmp debian/files
186 \$(MAKE) clean
187
188binary: binary-arch
189EOF
190
191exit 0