Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 1 | #!/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 | |
| 7 | set -e |
| 8 | |
Ben Hutchings | 08d3892 | 2018-07-26 11:21:01 +0100 | [diff] [blame^] | 9 | is_enabled() { |
| 10 | grep -q "^CONFIG_$1=y" $KCONFIG_CONFIG |
| 11 | } |
| 12 | |
| 13 | if_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 Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 21 | set_debarch() { |
Ben Hutchings | f2abcc1 | 2018-07-26 11:20:28 +0100 | [diff] [blame] | 22 | if [ -n "$KBUILD_DEBARCH" ] ; then |
| 23 | debarch="$KBUILD_DEBARCH" |
| 24 | return |
| 25 | fi |
| 26 | |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 27 | # 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 Hutchings | 4260ecd | 2018-07-26 11:20:54 +0100 | [diff] [blame] | 36 | debarch=s390x ;; |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 37 | ppc*) |
Ben Hutchings | 08d3892 | 2018-07-26 11:21:01 +0100 | [diff] [blame^] | 38 | debarch=$(if_enabled_echo CPU_LITTLE_ENDIAN ppc64el powerpc) ;; |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 39 | parisc*) |
| 40 | debarch=hppa ;; |
| 41 | mips*) |
Ben Hutchings | 08d3892 | 2018-07-26 11:21:01 +0100 | [diff] [blame^] | 42 | debarch=mips$(if_enabled_echo CPU_LITTLE_ENDIAN el) ;; |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 43 | aarch64|arm64) |
| 44 | debarch=arm64 ;; |
| 45 | arm*) |
Ben Hutchings | 08d3892 | 2018-07-26 11:21:01 +0100 | [diff] [blame^] | 46 | if is_enabled AEABI; then |
| 47 | debarch=arm$(if_enabled_echo VFP hf el) |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 48 | else |
Ben Hutchings | 08d3892 | 2018-07-26 11:21:01 +0100 | [diff] [blame^] | 49 | debarch=arm |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 50 | fi |
| 51 | ;; |
| 52 | *) |
Ben Hutchings | 091d30a | 2018-07-26 11:20:45 +0100 | [diff] [blame] | 53 | debarch=$(dpkg-architecture -qDEB_HOST_ARCH) |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 54 | 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 Hutchings | 091d30a | 2018-07-26 11:20:45 +0100 | [diff] [blame] | 59 | echo "Falling back to the current host architecture ($debarch)." >&2 |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 60 | echo "Please add support for $UTS_MACHINE to ${0} ..." >&2 |
| 61 | echo "" >&2 |
Ben Hutchings | f2abcc1 | 2018-07-26 11:20:28 +0100 | [diff] [blame] | 62 | ;; |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 63 | esac |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | # Some variables and settings used throughout the script |
| 67 | version=$KERNELRELEASE |
| 68 | if [ -n "$KDEB_PKGVERSION" ]; then |
| 69 | packageversion=$KDEB_PKGVERSION |
| 70 | else |
| 71 | revision=$(cat .version 2>/dev/null||echo 1) |
| 72 | packageversion=$version-$revision |
| 73 | fi |
| 74 | sourcename=$KDEB_SOURCENAME |
| 75 | packagename=linux-image-$version |
| 76 | kernel_headers_packagename=linux-headers-$version |
| 77 | dbg_packagename=$packagename-dbg |
| 78 | debarch= |
| 79 | set_debarch |
| 80 | |
| 81 | if [ "$ARCH" = "um" ] ; then |
| 82 | packagename=user-mode-linux-$version |
| 83 | fi |
| 84 | |
Riku Voipio | d5940c60 | 2018-05-07 10:11:34 +0300 | [diff] [blame] | 85 | email=${DEBEMAIL-$EMAIL} |
| 86 | |
| 87 | # use email string directly if it contains <email> |
| 88 | if echo $email | grep -q '<.*>'; then |
| 89 | maintainer=$email |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 90 | else |
Riku Voipio | d5940c60 | 2018-05-07 10:11:34 +0300 | [diff] [blame] | 91 | # 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 Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 99 | fi |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 100 | |
| 101 | # Try to determine distribution |
| 102 | if [ -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 |
| 105 | elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then |
| 106 | : # nothing to do in this case |
| 107 | else |
| 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" |
| 111 | fi |
| 112 | |
| 113 | mkdir -p debian/ |
| 114 | echo $debarch > debian/arch |
| 115 | |
| 116 | # Generate a simple changelog template |
| 117 | cat <<EOF > debian/changelog |
| 118 | $sourcename ($packageversion) $distribution; urgency=low |
| 119 | |
| 120 | * Custom built Linux kernel. |
| 121 | |
| 122 | -- $maintainer $(date -R) |
| 123 | EOF |
| 124 | |
| 125 | # Generate copyright file |
| 126 | cat <<EOF > debian/copyright |
| 127 | This is a packacked upstream version of the Linux kernel. |
| 128 | |
| 129 | The sources may be found at most Linux archive sites, including: |
| 130 | https://www.kernel.org/pub/linux/kernel |
| 131 | |
| 132 | Copyright: 1991 - 2018 Linus Torvalds and others. |
| 133 | |
| 134 | The git repository for mainline kernel development is at: |
| 135 | git://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 | |
| 141 | On Debian GNU/Linux systems, the complete text of the GNU General Public |
| 142 | License version 2 can be found in \`/usr/share/common-licenses/GPL-2'. |
| 143 | EOF |
| 144 | |
| 145 | # Generate a control file |
| 146 | cat <<EOF > debian/control |
| 147 | Source: $sourcename |
| 148 | Section: kernel |
| 149 | Priority: optional |
| 150 | Maintainer: $maintainer |
| 151 | Build-Depends: bc, kmod, cpio |
| 152 | Homepage: http://www.kernel.org/ |
| 153 | |
| 154 | Package: $packagename |
| 155 | Architecture: $debarch |
| 156 | Description: Linux kernel, version $version |
| 157 | This package contains the Linux kernel, modules and corresponding other |
| 158 | files, version: $version. |
| 159 | |
| 160 | Package: $kernel_headers_packagename |
| 161 | Architecture: $debarch |
| 162 | Description: 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 | |
| 167 | Package: linux-libc-dev |
| 168 | Section: devel |
| 169 | Provides: linux-kernel-headers |
| 170 | Architecture: $debarch |
| 171 | Description: 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 | |
| 175 | Package: $dbg_packagename |
| 176 | Section: debug |
| 177 | Architecture: $debarch |
| 178 | Description: 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. |
| 181 | EOF |
| 182 | |
| 183 | cat <<EOF > debian/rules |
| 184 | #!$(command -v $MAKE) -f |
| 185 | |
| 186 | build: |
| 187 | \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC= |
| 188 | |
| 189 | binary-arch: |
| 190 | \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC= intdeb-pkg |
| 191 | |
| 192 | clean: |
| 193 | rm -rf debian/*tmp debian/files |
| 194 | \$(MAKE) clean |
| 195 | |
| 196 | binary: binary-arch |
| 197 | EOF |
| 198 | |
| 199 | exit 0 |