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 | |
| 9 | set_debarch() { |
Ben Hutchings | f2abcc1 | 2018-07-26 11:20:28 +0100 | [diff] [blame] | 10 | if [ -n "$KBUILD_DEBARCH" ] ; then |
| 11 | debarch="$KBUILD_DEBARCH" |
| 12 | return |
| 13 | fi |
| 14 | |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 15 | # 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 Hutchings | 4260ecd | 2018-07-26 11:20:54 +0100 | [diff] [blame^] | 24 | debarch=s390x ;; |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 25 | 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 Hutchings | 091d30a | 2018-07-26 11:20:45 +0100 | [diff] [blame] | 45 | debarch=$(dpkg-architecture -qDEB_HOST_ARCH) |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 46 | 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 Hutchings | 091d30a | 2018-07-26 11:20:45 +0100 | [diff] [blame] | 51 | echo "Falling back to the current host architecture ($debarch)." >&2 |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 52 | echo "Please add support for $UTS_MACHINE to ${0} ..." >&2 |
| 53 | echo "" >&2 |
Ben Hutchings | f2abcc1 | 2018-07-26 11:20:28 +0100 | [diff] [blame] | 54 | ;; |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 55 | esac |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | # Some variables and settings used throughout the script |
| 59 | version=$KERNELRELEASE |
| 60 | if [ -n "$KDEB_PKGVERSION" ]; then |
| 61 | packageversion=$KDEB_PKGVERSION |
| 62 | else |
| 63 | revision=$(cat .version 2>/dev/null||echo 1) |
| 64 | packageversion=$version-$revision |
| 65 | fi |
| 66 | sourcename=$KDEB_SOURCENAME |
| 67 | packagename=linux-image-$version |
| 68 | kernel_headers_packagename=linux-headers-$version |
| 69 | dbg_packagename=$packagename-dbg |
| 70 | debarch= |
| 71 | set_debarch |
| 72 | |
| 73 | if [ "$ARCH" = "um" ] ; then |
| 74 | packagename=user-mode-linux-$version |
| 75 | fi |
| 76 | |
Riku Voipio | d5940c60 | 2018-05-07 10:11:34 +0300 | [diff] [blame] | 77 | email=${DEBEMAIL-$EMAIL} |
| 78 | |
| 79 | # use email string directly if it contains <email> |
| 80 | if echo $email | grep -q '<.*>'; then |
| 81 | maintainer=$email |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 82 | else |
Riku Voipio | d5940c60 | 2018-05-07 10:11:34 +0300 | [diff] [blame] | 83 | # 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 Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 91 | fi |
Riku Voipio | b41d920 | 2018-04-05 14:22:29 +0300 | [diff] [blame] | 92 | |
| 93 | # Try to determine distribution |
| 94 | if [ -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 |
| 97 | elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then |
| 98 | : # nothing to do in this case |
| 99 | else |
| 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" |
| 103 | fi |
| 104 | |
| 105 | mkdir -p debian/ |
| 106 | echo $debarch > debian/arch |
| 107 | |
| 108 | # Generate a simple changelog template |
| 109 | cat <<EOF > debian/changelog |
| 110 | $sourcename ($packageversion) $distribution; urgency=low |
| 111 | |
| 112 | * Custom built Linux kernel. |
| 113 | |
| 114 | -- $maintainer $(date -R) |
| 115 | EOF |
| 116 | |
| 117 | # Generate copyright file |
| 118 | cat <<EOF > debian/copyright |
| 119 | This is a packacked upstream version of the Linux kernel. |
| 120 | |
| 121 | The sources may be found at most Linux archive sites, including: |
| 122 | https://www.kernel.org/pub/linux/kernel |
| 123 | |
| 124 | Copyright: 1991 - 2018 Linus Torvalds and others. |
| 125 | |
| 126 | The git repository for mainline kernel development is at: |
| 127 | git://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 | |
| 133 | On Debian GNU/Linux systems, the complete text of the GNU General Public |
| 134 | License version 2 can be found in \`/usr/share/common-licenses/GPL-2'. |
| 135 | EOF |
| 136 | |
| 137 | # Generate a control file |
| 138 | cat <<EOF > debian/control |
| 139 | Source: $sourcename |
| 140 | Section: kernel |
| 141 | Priority: optional |
| 142 | Maintainer: $maintainer |
| 143 | Build-Depends: bc, kmod, cpio |
| 144 | Homepage: http://www.kernel.org/ |
| 145 | |
| 146 | Package: $packagename |
| 147 | Architecture: $debarch |
| 148 | Description: Linux kernel, version $version |
| 149 | This package contains the Linux kernel, modules and corresponding other |
| 150 | files, version: $version. |
| 151 | |
| 152 | Package: $kernel_headers_packagename |
| 153 | Architecture: $debarch |
| 154 | Description: 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 | |
| 159 | Package: linux-libc-dev |
| 160 | Section: devel |
| 161 | Provides: linux-kernel-headers |
| 162 | Architecture: $debarch |
| 163 | Description: 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 | |
| 167 | Package: $dbg_packagename |
| 168 | Section: debug |
| 169 | Architecture: $debarch |
| 170 | Description: 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. |
| 173 | EOF |
| 174 | |
| 175 | cat <<EOF > debian/rules |
| 176 | #!$(command -v $MAKE) -f |
| 177 | |
| 178 | build: |
| 179 | \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC= |
| 180 | |
| 181 | binary-arch: |
| 182 | \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC= intdeb-pkg |
| 183 | |
| 184 | clean: |
| 185 | rm -rf debian/*tmp debian/files |
| 186 | \$(MAKE) clean |
| 187 | |
| 188 | binary: binary-arch |
| 189 | EOF |
| 190 | |
| 191 | exit 0 |