blob: ada3c73d1493322eb2834ed26434d747606d8e68 [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
Ben Hutchings08d38922018-07-26 11:21:01 +01009is_enabled() {
10 grep -q "^CONFIG_$1=y" $KCONFIG_CONFIG
11}
12
13if_enabled_echo() {
14 if is_enabled "$1"; then
15 echo -n "$2"
16 elif [ $# -ge 3 ]; then
17 echo -n "$3"
18 fi
19}
20
Riku Voipiob41d9202018-04-05 14:22:29 +030021set_debarch() {
Ben Hutchingsf2abcc12018-07-26 11:20:28 +010022 if [ -n "$KBUILD_DEBARCH" ] ; then
23 debarch="$KBUILD_DEBARCH"
24 return
25 fi
26
Riku Voipiob41d9202018-04-05 14:22:29 +030027 # Attempt to find the correct Debian architecture
28 case "$UTS_MACHINE" in
29 i386|ia64|alpha)
30 debarch="$UTS_MACHINE" ;;
31 x86_64)
32 debarch=amd64 ;;
33 sparc*)
34 debarch=sparc ;;
35 s390*)
Ben Hutchings4260ecd2018-07-26 11:20:54 +010036 debarch=s390x ;;
Riku Voipiob41d9202018-04-05 14:22:29 +030037 ppc*)
Ben Hutchings08d38922018-07-26 11:21:01 +010038 debarch=$(if_enabled_echo CPU_LITTLE_ENDIAN ppc64el powerpc) ;;
Riku Voipiob41d9202018-04-05 14:22:29 +030039 parisc*)
40 debarch=hppa ;;
41 mips*)
Ben Hutchings08d38922018-07-26 11:21:01 +010042 debarch=mips$(if_enabled_echo CPU_LITTLE_ENDIAN el) ;;
Riku Voipiob41d9202018-04-05 14:22:29 +030043 aarch64|arm64)
44 debarch=arm64 ;;
45 arm*)
Ben Hutchings08d38922018-07-26 11:21:01 +010046 if is_enabled AEABI; then
47 debarch=arm$(if_enabled_echo VFP hf el)
Riku Voipiob41d9202018-04-05 14:22:29 +030048 else
Ben Hutchings08d38922018-07-26 11:21:01 +010049 debarch=arm
Riku Voipiob41d9202018-04-05 14:22:29 +030050 fi
51 ;;
52 *)
Ben Hutchings091d30a2018-07-26 11:20:45 +010053 debarch=$(dpkg-architecture -qDEB_HOST_ARCH)
Riku Voipiob41d9202018-04-05 14:22:29 +030054 echo "" >&2
55 echo "** ** ** WARNING ** ** **" >&2
56 echo "" >&2
57 echo "Your architecture doesn't have its equivalent" >&2
58 echo "Debian userspace architecture defined!" >&2
Ben Hutchings091d30a2018-07-26 11:20:45 +010059 echo "Falling back to the current host architecture ($debarch)." >&2
Riku Voipiob41d9202018-04-05 14:22:29 +030060 echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
61 echo "" >&2
Ben Hutchingsf2abcc12018-07-26 11:20:28 +010062 ;;
Riku Voipiob41d9202018-04-05 14:22:29 +030063 esac
Riku Voipiob41d9202018-04-05 14:22:29 +030064}
65
66# Some variables and settings used throughout the script
67version=$KERNELRELEASE
68if [ -n "$KDEB_PKGVERSION" ]; then
69 packageversion=$KDEB_PKGVERSION
70else
71 revision=$(cat .version 2>/dev/null||echo 1)
72 packageversion=$version-$revision
73fi
74sourcename=$KDEB_SOURCENAME
75packagename=linux-image-$version
76kernel_headers_packagename=linux-headers-$version
77dbg_packagename=$packagename-dbg
78debarch=
79set_debarch
80
81if [ "$ARCH" = "um" ] ; then
82 packagename=user-mode-linux-$version
83fi
84
Riku Voipiod5940c602018-05-07 10:11:34 +030085email=${DEBEMAIL-$EMAIL}
86
87# use email string directly if it contains <email>
88if echo $email | grep -q '<.*>'; then
89 maintainer=$email
Riku Voipiob41d9202018-04-05 14:22:29 +030090else
Riku Voipiod5940c602018-05-07 10:11:34 +030091 # or construct the maintainer string
92 user=${KBUILD_BUILD_USER-$(id -nu)}
93 name=${DEBFULLNAME-$user}
94 if [ -z "$email" ]; then
95 buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)}
96 email="$user@$buildhost"
97 fi
98 maintainer="$name <$email>"
Riku Voipiob41d9202018-04-05 14:22:29 +030099fi
Riku Voipiob41d9202018-04-05 14:22:29 +0300100
101# Try to determine distribution
102if [ -n "$KDEB_CHANGELOG_DIST" ]; then
103 distribution=$KDEB_CHANGELOG_DIST
104# In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
105elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then
106 : # nothing to do in this case
107else
108 distribution="unstable"
109 echo >&2 "Using default distribution of 'unstable' in the changelog"
110 echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
111fi
112
113mkdir -p debian/
114echo $debarch > debian/arch
115
116# Generate a simple changelog template
117cat <<EOF > debian/changelog
118$sourcename ($packageversion) $distribution; urgency=low
119
120 * Custom built Linux kernel.
121
122 -- $maintainer $(date -R)
123EOF
124
125# Generate copyright file
126cat <<EOF > debian/copyright
127This is a packacked upstream version of the Linux kernel.
128
129The sources may be found at most Linux archive sites, including:
130https://www.kernel.org/pub/linux/kernel
131
132Copyright: 1991 - 2018 Linus Torvalds and others.
133
134The git repository for mainline kernel development is at:
135git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
136
137 This program is free software; you can redistribute it and/or modify
138 it under the terms of the GNU General Public License as published by
139 the Free Software Foundation; version 2 dated June, 1991.
140
141On Debian GNU/Linux systems, the complete text of the GNU General Public
142License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
143EOF
144
145# Generate a control file
146cat <<EOF > debian/control
147Source: $sourcename
148Section: kernel
149Priority: optional
150Maintainer: $maintainer
151Build-Depends: bc, kmod, cpio
152Homepage: http://www.kernel.org/
153
154Package: $packagename
155Architecture: $debarch
156Description: Linux kernel, version $version
157 This package contains the Linux kernel, modules and corresponding other
158 files, version: $version.
159
160Package: $kernel_headers_packagename
161Architecture: $debarch
162Description: Linux kernel headers for $version on $debarch
163 This package provides kernel header files for $version on $debarch
164 .
165 This is useful for people who need to build external modules
166
167Package: linux-libc-dev
168Section: devel
169Provides: linux-kernel-headers
170Architecture: $debarch
171Description: Linux support headers for userspace development
172 This package provides userspaces headers from the Linux kernel. These headers
173 are used by the installed headers for GNU glibc and other system libraries.
174
175Package: $dbg_packagename
176Section: debug
177Architecture: $debarch
178Description: Linux kernel debugging symbols for $version
179 This package will come in handy if you need to debug the kernel. It provides
180 all the necessary debug symbols for the kernel and its modules.
181EOF
182
183cat <<EOF > debian/rules
184#!$(command -v $MAKE) -f
185
186build:
187 \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC=
188
189binary-arch:
190 \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC= intdeb-pkg
191
192clean:
193 rm -rf debian/*tmp debian/files
194 \$(MAKE) clean
195
196binary: binary-arch
197EOF
198
199exit 0