1b41d920aSRiku Voipio#!/bin/sh 2b41d920aSRiku Voipio# 3b41d920aSRiku Voipio# Copyright 2003 Wichert Akkerman <wichert@wiggy.net> 4b41d920aSRiku Voipio# 5b41d920aSRiku Voipio# Simple script to generate a debian/ directory for a Linux kernel. 6b41d920aSRiku Voipio 7b41d920aSRiku Voipioset -e 8b41d920aSRiku Voipio 908d3892cSBen Hutchingsis_enabled() { 106fb7ef5aSMasahiro Yamada grep -q "^$1=y" include/config/auto.conf 1108d3892cSBen Hutchings} 1208d3892cSBen Hutchings 1308d3892cSBen Hutchingsif_enabled_echo() { 1408d3892cSBen Hutchings if is_enabled "$1"; then 1508d3892cSBen Hutchings echo -n "$2" 1608d3892cSBen Hutchings elif [ $# -ge 3 ]; then 1708d3892cSBen Hutchings echo -n "$3" 1808d3892cSBen Hutchings fi 1908d3892cSBen Hutchings} 2008d3892cSBen Hutchings 21b41d920aSRiku Voipioset_debarch() { 22f2abcc13SBen Hutchings if [ -n "$KBUILD_DEBARCH" ] ; then 23f2abcc13SBen Hutchings debarch="$KBUILD_DEBARCH" 24f2abcc13SBen Hutchings return 25f2abcc13SBen Hutchings fi 26f2abcc13SBen Hutchings 27b41d920aSRiku Voipio # Attempt to find the correct Debian architecture 28b41d920aSRiku Voipio case "$UTS_MACHINE" in 2975ebcee7SBen Hutchings i386|ia64|alpha|m68k|riscv*) 30b41d920aSRiku Voipio debarch="$UTS_MACHINE" ;; 31b41d920aSRiku Voipio x86_64) 32b41d920aSRiku Voipio debarch=amd64 ;; 33b41d920aSRiku Voipio sparc*) 347e548e9aSMasahiro Yamada debarch=sparc$(if_enabled_echo CONFIG_64BIT 64) ;; 35b41d920aSRiku Voipio s390*) 364260ecd0SBen Hutchings debarch=s390x ;; 37b41d920aSRiku Voipio ppc*) 387e548e9aSMasahiro Yamada if is_enabled CONFIG_64BIT; then 397e548e9aSMasahiro Yamada debarch=ppc64$(if_enabled_echo CONFIG_CPU_LITTLE_ENDIAN el) 4050d511baSBen Hutchings else 417e548e9aSMasahiro Yamada debarch=powerpc$(if_enabled_echo CONFIG_SPE spe) 4250d511baSBen Hutchings fi 4350d511baSBen Hutchings ;; 44b41d920aSRiku Voipio parisc*) 45b41d920aSRiku Voipio debarch=hppa ;; 46b41d920aSRiku Voipio mips*) 477e548e9aSMasahiro Yamada if is_enabled CONFIG_CPU_LITTLE_ENDIAN; then 487e548e9aSMasahiro Yamada debarch=mips$(if_enabled_echo CONFIG_64BIT 64)$(if_enabled_echo CONFIG_CPU_MIPSR6 r6)el 497e548e9aSMasahiro Yamada elif is_enabled CONFIG_CPU_MIPSR6; then 507e548e9aSMasahiro Yamada debarch=mips$(if_enabled_echo CONFIG_64BIT 64)r6 51159b3794SBen Hutchings else 52159b3794SBen Hutchings debarch=mips 53159b3794SBen Hutchings fi 54159b3794SBen Hutchings ;; 55b41d920aSRiku Voipio aarch64|arm64) 56b41d920aSRiku Voipio debarch=arm64 ;; 57b41d920aSRiku Voipio arm*) 587e548e9aSMasahiro Yamada if is_enabled CONFIG_AEABI; then 597e548e9aSMasahiro Yamada debarch=arm$(if_enabled_echo CONFIG_VFP hf el) 60b41d920aSRiku Voipio else 61b41d920aSRiku Voipio debarch=arm 62b41d920aSRiku Voipio fi 63b41d920aSRiku Voipio ;; 64822f44fbSBen Hutchings openrisc) 65822f44fbSBen Hutchings debarch=or1k ;; 6679a85b55SBen Hutchings sh) 677e548e9aSMasahiro Yamada if is_enabled CONFIG_CPU_SH3; then 687e548e9aSMasahiro Yamada debarch=sh3$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb) 697e548e9aSMasahiro Yamada elif is_enabled CONFIG_CPU_SH4; then 707e548e9aSMasahiro Yamada debarch=sh4$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb) 7179a85b55SBen Hutchings fi 7279a85b55SBen Hutchings ;; 7379a85b55SBen Hutchings esac 7479a85b55SBen Hutchings if [ -z "$debarch" ]; then 75091d30aeSBen Hutchings debarch=$(dpkg-architecture -qDEB_HOST_ARCH) 76b41d920aSRiku Voipio echo "" >&2 77b41d920aSRiku Voipio echo "** ** ** WARNING ** ** **" >&2 78b41d920aSRiku Voipio echo "" >&2 79b41d920aSRiku Voipio echo "Your architecture doesn't have its equivalent" >&2 80b41d920aSRiku Voipio echo "Debian userspace architecture defined!" >&2 81091d30aeSBen Hutchings echo "Falling back to the current host architecture ($debarch)." >&2 82b41d920aSRiku Voipio echo "Please add support for $UTS_MACHINE to ${0} ..." >&2 83b41d920aSRiku Voipio echo "" >&2 8479a85b55SBen Hutchings fi 85b41d920aSRiku Voipio} 86b41d920aSRiku Voipio 877bf4582dSMasahiro Yamadarm -rf debian 887bf4582dSMasahiro Yamada 89b41d920aSRiku Voipio# Some variables and settings used throughout the script 90b41d920aSRiku Voipioversion=$KERNELRELEASE 91b41d920aSRiku Voipioif [ -n "$KDEB_PKGVERSION" ]; then 92b41d920aSRiku Voipio packageversion=$KDEB_PKGVERSION 93b41d920aSRiku Voipioelse 94*05e96e96SMasahiro Yamada packageversion=$(${srctree}/scripts/setlocalversion --no-local ${srctree})-$($srctree/init/build-version) 95b41d920aSRiku Voipiofi 966eabebb1SMasahiro Yamadasourcename=${KDEB_SOURCENAME:-linux-upstream} 97b41d920aSRiku Voipio 98b41d920aSRiku Voipioif [ "$ARCH" = "um" ] ; then 990fa21cf4SMasahiro Yamada packagename=user-mode-linux 1000fa21cf4SMasahiro Yamadaelse 1010fa21cf4SMasahiro Yamada packagename=linux-image 102b41d920aSRiku Voipiofi 103b41d920aSRiku Voipio 1040fa21cf4SMasahiro Yamadadebarch= 1050fa21cf4SMasahiro Yamadaset_debarch 1060fa21cf4SMasahiro Yamada 107d5940c60SRiku Voipioemail=${DEBEMAIL-$EMAIL} 108d5940c60SRiku Voipio 109d5940c60SRiku Voipio# use email string directly if it contains <email> 110d5940c60SRiku Voipioif echo $email | grep -q '<.*>'; then 111d5940c60SRiku Voipio maintainer=$email 112b41d920aSRiku Voipioelse 113d5940c60SRiku Voipio # or construct the maintainer string 114d5940c60SRiku Voipio user=${KBUILD_BUILD_USER-$(id -nu)} 115d5940c60SRiku Voipio name=${DEBFULLNAME-$user} 116d5940c60SRiku Voipio if [ -z "$email" ]; then 117d5940c60SRiku Voipio buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)} 118d5940c60SRiku Voipio email="$user@$buildhost" 119b41d920aSRiku Voipio fi 120b41d920aSRiku Voipio maintainer="$name <$email>" 121d5940c60SRiku Voipiofi 122b41d920aSRiku Voipio 123b41d920aSRiku Voipio# Try to determine distribution 124b41d920aSRiku Voipioif [ -n "$KDEB_CHANGELOG_DIST" ]; then 125b41d920aSRiku Voipio distribution=$KDEB_CHANGELOG_DIST 126b41d920aSRiku Voipio# In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog 127b41d920aSRiku Voipioelif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then 128b41d920aSRiku Voipio : # nothing to do in this case 129b41d920aSRiku Voipioelse 130b41d920aSRiku Voipio distribution="unstable" 131b41d920aSRiku Voipio echo >&2 "Using default distribution of 'unstable' in the changelog" 132b41d920aSRiku Voipio echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly" 133b41d920aSRiku Voipiofi 134b41d920aSRiku Voipio 135f6d9db63SArseny Maslennikovmkdir -p debian/source/ 136e7853995SMasahiro Yamadaecho "3.0 (quilt)" > debian/source/format 137f6d9db63SArseny Maslennikov 138e7853995SMasahiro Yamada{ 139e7853995SMasahiro Yamada echo "diff-ignore" 140e7853995SMasahiro Yamada echo "extend-diff-ignore = .*" 141e7853995SMasahiro Yamada} > debian/source/local-options 1427bf4582dSMasahiro Yamada 143e7853995SMasahiro Yamada# Add .config as a patch 144e7853995SMasahiro Yamadamkdir -p debian/patches 145e7853995SMasahiro Yamada{ 146e7853995SMasahiro Yamada echo "Subject: Add .config" 147e7853995SMasahiro Yamada echo "Author: ${maintainer}" 148e7853995SMasahiro Yamada echo 149e7853995SMasahiro Yamada echo "--- /dev/null" 150e7853995SMasahiro Yamada echo "+++ linux/.config" 151e7853995SMasahiro Yamada diff -u /dev/null "${KCONFIG_CONFIG}" | tail -n +3 152e7853995SMasahiro Yamada} > debian/patches/config 153e7853995SMasahiro Yamadaecho config > debian/patches/series 1547bf4582dSMasahiro Yamada 155*05e96e96SMasahiro Yamada$(dirname $0)/gen-diff-patch debian/patches/diff.patch debian/patches/untracked.patch 156*05e96e96SMasahiro Yamadaif [ -f debian/patches/diff.patch ]; then 157*05e96e96SMasahiro Yamada echo diff.patch >> debian/patches/series 158*05e96e96SMasahiro Yamadafi 159*05e96e96SMasahiro Yamadaif [ -f debian/patches/untracked.patch ]; then 160*05e96e96SMasahiro Yamada echo untracked.patch >> debian/patches/series 161*05e96e96SMasahiro Yamadafi 162*05e96e96SMasahiro Yamada 163b41d920aSRiku Voipioecho $debarch > debian/arch 1648ffdc54bSArd Biesheuvelextra_build_depends=", $(if_enabled_echo CONFIG_UNWINDER_ORC libelf-dev:native)" 1657e548e9aSMasahiro Yamadaextra_build_depends="$extra_build_depends, $(if_enabled_echo CONFIG_SYSTEM_TRUSTED_KEYRING libssl-dev:native)" 166b41d920aSRiku Voipio 167b41d920aSRiku Voipio# Generate a simple changelog template 168b41d920aSRiku Voipiocat <<EOF > debian/changelog 169b41d920aSRiku Voipio$sourcename ($packageversion) $distribution; urgency=low 170b41d920aSRiku Voipio 171b41d920aSRiku Voipio * Custom built Linux kernel. 172b41d920aSRiku Voipio 173b41d920aSRiku Voipio -- $maintainer $(date -R) 174b41d920aSRiku VoipioEOF 175b41d920aSRiku Voipio 176b41d920aSRiku Voipio# Generate copyright file 177b41d920aSRiku Voipiocat <<EOF > debian/copyright 178b41d920aSRiku VoipioThis is a packacked upstream version of the Linux kernel. 179b41d920aSRiku Voipio 180b41d920aSRiku VoipioThe sources may be found at most Linux archive sites, including: 181b41d920aSRiku Voipiohttps://www.kernel.org/pub/linux/kernel 182b41d920aSRiku Voipio 183b41d920aSRiku VoipioCopyright: 1991 - 2018 Linus Torvalds and others. 184b41d920aSRiku Voipio 185b41d920aSRiku VoipioThe git repository for mainline kernel development is at: 186b41d920aSRiku Voipiogit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 187b41d920aSRiku Voipio 188b41d920aSRiku Voipio This program is free software; you can redistribute it and/or modify 189b41d920aSRiku Voipio it under the terms of the GNU General Public License as published by 190b41d920aSRiku Voipio the Free Software Foundation; version 2 dated June, 1991. 191b41d920aSRiku Voipio 192b41d920aSRiku VoipioOn Debian GNU/Linux systems, the complete text of the GNU General Public 193b41d920aSRiku VoipioLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'. 194b41d920aSRiku VoipioEOF 195b41d920aSRiku Voipio 196b41d920aSRiku Voipio# Generate a control file 197b41d920aSRiku Voipiocat <<EOF > debian/control 198b41d920aSRiku VoipioSource: $sourcename 199b41d920aSRiku VoipioSection: kernel 200b41d920aSRiku VoipioPriority: optional 201b41d920aSRiku VoipioMaintainer: $maintainer 2023e854180SGuillem JoverRules-Requires-Root: no 20336862e14SMasahiro YamadaBuild-Depends: bc, debhelper, rsync, kmod, cpio, bison, flex $extra_build_depends 20416a122c7SAlexander A. KlimovHomepage: https://www.kernel.org/ 205b41d920aSRiku Voipio 2060fa21cf4SMasahiro YamadaPackage: $packagename-$version 207b41d920aSRiku VoipioArchitecture: $debarch 208b41d920aSRiku VoipioDescription: Linux kernel, version $version 209b41d920aSRiku Voipio This package contains the Linux kernel, modules and corresponding other 210b41d920aSRiku Voipio files, version: $version. 21136862e14SMasahiro YamadaEOF 21236862e14SMasahiro Yamada 21336862e14SMasahiro Yamadaif [ "${SRCARCH}" != um ]; then 21436862e14SMasahiro Yamadacat <<EOF >> debian/control 215b41d920aSRiku Voipio 216b41d920aSRiku VoipioPackage: linux-libc-dev 217b41d920aSRiku VoipioSection: devel 218b41d920aSRiku VoipioProvides: linux-kernel-headers 219b41d920aSRiku VoipioArchitecture: $debarch 220b41d920aSRiku VoipioDescription: Linux support headers for userspace development 221b41d920aSRiku Voipio This package provides userspaces headers from the Linux kernel. These headers 222b41d920aSRiku Voipio are used by the installed headers for GNU glibc and other system libraries. 2235a464217SCedric HombourgerMulti-Arch: same 224d9dac147SReinhard KarcherEOF 225d9dac147SReinhard Karcher 226bac977cbSMasahiro Yamadaif is_enabled CONFIG_MODULES; then 227bac977cbSMasahiro Yamadacat <<EOF >> debian/control 228bac977cbSMasahiro Yamada 2290fa21cf4SMasahiro YamadaPackage: linux-headers-$version 230bac977cbSMasahiro YamadaArchitecture: $debarch 231bac977cbSMasahiro YamadaDescription: Linux kernel headers for $version on $debarch 232bac977cbSMasahiro Yamada This package provides kernel header files for $version on $debarch 233bac977cbSMasahiro Yamada . 234bac977cbSMasahiro Yamada This is useful for people who need to build external modules 235bac977cbSMasahiro YamadaEOF 236bac977cbSMasahiro Yamadafi 23736862e14SMasahiro Yamadafi 238bac977cbSMasahiro Yamada 239d9dac147SReinhard Karcherif is_enabled CONFIG_DEBUG_INFO; then 240d9dac147SReinhard Karchercat <<EOF >> debian/control 241b41d920aSRiku Voipio 2420fa21cf4SMasahiro YamadaPackage: linux-image-$version-dbg 243b41d920aSRiku VoipioSection: debug 244b41d920aSRiku VoipioArchitecture: $debarch 245b41d920aSRiku VoipioDescription: Linux kernel debugging symbols for $version 246b41d920aSRiku Voipio This package will come in handy if you need to debug the kernel. It provides 247b41d920aSRiku Voipio all the necessary debug symbols for the kernel and its modules. 248b41d920aSRiku VoipioEOF 249d9dac147SReinhard Karcherfi 250b41d920aSRiku Voipio 251b41d920aSRiku Voipiocat <<EOF > debian/rules 252b41d920aSRiku Voipio#!$(command -v $MAKE) -f 253b41d920aSRiku Voipio 254175209ccSMasahiro Yamadasrctree ?= . 2552fd6c455SMasahiro YamadaKERNELRELEASE = ${KERNELRELEASE} 256175209ccSMasahiro Yamada 25776c37668SGuillem Joverbuild-indep: 25876c37668SGuillem Joverbuild-arch: 2593ab18a62SMasahiro Yamada \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} \ 2607a531c21SMasahiro Yamada KERNELRELEASE=\$(KERNELRELEASE) \ 2613ab18a62SMasahiro Yamada \$(shell \$(srctree)/scripts/package/deb-build-option) \ 2623ab18a62SMasahiro Yamada olddefconfig all 263b41d920aSRiku Voipio 26476c37668SGuillem Joverbuild: build-arch 26576c37668SGuillem Jover 26676c37668SGuillem Joverbinary-indep: 26776c37668SGuillem Joverbinary-arch: build-arch 2682fd6c455SMasahiro Yamada \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} \ 2692fd6c455SMasahiro Yamada KERNELRELEASE=\$(KERNELRELEASE) intdeb-pkg 2702fd6c455SMasahiro Yamada 271b41d920aSRiku Voipioclean: 272c9f9cf25SBastian Germann rm -rf debian/files debian/linux-* 273c5bf2efbSMasahiro Yamada \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} clean 274b41d920aSRiku Voipio 275b41d920aSRiku Voipiobinary: binary-arch 276b41d920aSRiku VoipioEOF 277f6d9db63SArseny Maslennikovchmod +x debian/rules 278b41d920aSRiku Voipio 279b41d920aSRiku Voipioexit 0 280