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 7*c0414419SMasahiro Yamadaset -eu 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() { 22*c0414419SMasahiro Yamada if [ "${KBUILD_DEBARCH:+set}" ]; 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 290df8e970SMasahiro Yamada i386|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 87aa7d233fSMasahiro Yamada# Create debian/source/ if it is a source package build 88aa7d233fSMasahiro Yamadagen_source () 89aa7d233fSMasahiro Yamada{ 90aa7d233fSMasahiro Yamada mkdir -p debian/source 91aa7d233fSMasahiro Yamada 92aa7d233fSMasahiro Yamada echo "3.0 (quilt)" > debian/source/format 93aa7d233fSMasahiro Yamada 94aa7d233fSMasahiro Yamada { 95aa7d233fSMasahiro Yamada echo "diff-ignore" 96aa7d233fSMasahiro Yamada echo "extend-diff-ignore = .*" 97aa7d233fSMasahiro Yamada } > debian/source/local-options 98aa7d233fSMasahiro Yamada 99aa7d233fSMasahiro Yamada # Add .config as a patch 100aa7d233fSMasahiro Yamada mkdir -p debian/patches 101aa7d233fSMasahiro Yamada { 102aa7d233fSMasahiro Yamada echo "Subject: Add .config" 103aa7d233fSMasahiro Yamada echo "Author: ${maintainer}" 104aa7d233fSMasahiro Yamada echo 105aa7d233fSMasahiro Yamada echo "--- /dev/null" 106aa7d233fSMasahiro Yamada echo "+++ linux/.config" 107aa7d233fSMasahiro Yamada diff -u /dev/null "${KCONFIG_CONFIG}" | tail -n +3 108aa7d233fSMasahiro Yamada } > debian/patches/config.patch 109aa7d233fSMasahiro Yamada echo config.patch > debian/patches/series 110aa7d233fSMasahiro Yamada 111aa7d233fSMasahiro Yamada "${srctree}/scripts/package/gen-diff-patch" debian/patches/diff.patch 112aa7d233fSMasahiro Yamada if [ -s debian/patches/diff.patch ]; then 113aa7d233fSMasahiro Yamada sed -i " 114aa7d233fSMasahiro Yamada 1iSubject: Add local diff 115aa7d233fSMasahiro Yamada 1iAuthor: ${maintainer} 116aa7d233fSMasahiro Yamada 1i 117aa7d233fSMasahiro Yamada " debian/patches/diff.patch 118aa7d233fSMasahiro Yamada 119aa7d233fSMasahiro Yamada echo diff.patch >> debian/patches/series 120aa7d233fSMasahiro Yamada else 121aa7d233fSMasahiro Yamada rm -f debian/patches/diff.patch 122aa7d233fSMasahiro Yamada fi 123aa7d233fSMasahiro Yamada} 124aa7d233fSMasahiro Yamada 1257bf4582dSMasahiro Yamadarm -rf debian 126aa7d233fSMasahiro Yamadamkdir debian 127aa7d233fSMasahiro Yamada 128aa7d233fSMasahiro Yamadauser=${KBUILD_BUILD_USER-$(id -nu)} 129aa7d233fSMasahiro Yamadaname=${DEBFULLNAME-${user}} 130c5209080SMasahiro Yamadaif [ "${DEBEMAIL:+set}" ]; then 131c5209080SMasahiro Yamada email=${DEBEMAIL} 132c5209080SMasahiro Yamadaelse 133aa7d233fSMasahiro Yamada buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)} 134aa7d233fSMasahiro Yamada email="${user}@${buildhost}" 135aa7d233fSMasahiro Yamadafi 136aa7d233fSMasahiro Yamadamaintainer="${name} <${email}>" 137aa7d233fSMasahiro Yamada 138*c0414419SMasahiro Yamadawhile [ $# -gt 0 ]; do 139*c0414419SMasahiro Yamada case "$1" in 140*c0414419SMasahiro Yamada --need-source) 141aa7d233fSMasahiro Yamada gen_source 142*c0414419SMasahiro Yamada shift 143*c0414419SMasahiro Yamada ;; 144*c0414419SMasahiro Yamada *) 145*c0414419SMasahiro Yamada break 146*c0414419SMasahiro Yamada ;; 147*c0414419SMasahiro Yamada esac 148*c0414419SMasahiro Yamadadone 1497bf4582dSMasahiro Yamada 150b41d920aSRiku Voipio# Some variables and settings used throughout the script 151b41d920aSRiku Voipioversion=$KERNELRELEASE 152*c0414419SMasahiro Yamadaif [ "${KDEB_PKGVERSION:+set}" ]; then 153b41d920aSRiku Voipio packageversion=$KDEB_PKGVERSION 154b41d920aSRiku Voipioelse 155ae4c4ceeSMasahiro Yamada packageversion=$(${srctree}/scripts/setlocalversion --no-local ${srctree})-$($srctree/scripts/build-version) 156b41d920aSRiku Voipiofi 1576eabebb1SMasahiro Yamadasourcename=${KDEB_SOURCENAME:-linux-upstream} 158b41d920aSRiku Voipio 159b41d920aSRiku Voipioif [ "$ARCH" = "um" ] ; then 1600fa21cf4SMasahiro Yamada packagename=user-mode-linux 1610fa21cf4SMasahiro Yamadaelse 1620fa21cf4SMasahiro Yamada packagename=linux-image 163b41d920aSRiku Voipiofi 164b41d920aSRiku Voipio 1650fa21cf4SMasahiro Yamadadebarch= 1660fa21cf4SMasahiro Yamadaset_debarch 1670fa21cf4SMasahiro Yamada 168b41d920aSRiku Voipio# Try to determine distribution 169*c0414419SMasahiro Yamadaif [ "${KDEB_CHANGELOG_DIST:+set}" ]; then 170b41d920aSRiku Voipio distribution=$KDEB_CHANGELOG_DIST 171b41d920aSRiku Voipio# In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog 172b41d920aSRiku Voipioelif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then 173b41d920aSRiku Voipio : # nothing to do in this case 174b41d920aSRiku Voipioelse 175b41d920aSRiku Voipio distribution="unstable" 176b41d920aSRiku Voipio echo >&2 "Using default distribution of 'unstable' in the changelog" 177b41d920aSRiku Voipio echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly" 178b41d920aSRiku Voipiofi 179b41d920aSRiku Voipio 180b41d920aSRiku Voipioecho $debarch > debian/arch 181b41d920aSRiku Voipio 182b41d920aSRiku Voipio# Generate a simple changelog template 183b41d920aSRiku Voipiocat <<EOF > debian/changelog 184b41d920aSRiku Voipio$sourcename ($packageversion) $distribution; urgency=low 185b41d920aSRiku Voipio 186b41d920aSRiku Voipio * Custom built Linux kernel. 187b41d920aSRiku Voipio 188b41d920aSRiku Voipio -- $maintainer $(date -R) 189b41d920aSRiku VoipioEOF 190b41d920aSRiku Voipio 191b41d920aSRiku Voipio# Generate a control file 192b41d920aSRiku Voipiocat <<EOF > debian/control 193b41d920aSRiku VoipioSource: $sourcename 194b41d920aSRiku VoipioSection: kernel 195b41d920aSRiku VoipioPriority: optional 196b41d920aSRiku VoipioMaintainer: $maintainer 1973e854180SGuillem JoverRules-Requires-Root: no 1985e73758bSMasahiro YamadaBuild-Depends: debhelper-compat (= 12) 199b88365b6SMasahiro YamadaBuild-Depends-Arch: bc, bison, cpio, flex, kmod, libelf-dev:native, libssl-dev:native, rsync 20016a122c7SAlexander A. KlimovHomepage: https://www.kernel.org/ 201b41d920aSRiku Voipio 2020fa21cf4SMasahiro YamadaPackage: $packagename-$version 203b41d920aSRiku VoipioArchitecture: $debarch 204b41d920aSRiku VoipioDescription: Linux kernel, version $version 205b41d920aSRiku Voipio This package contains the Linux kernel, modules and corresponding other 206b41d920aSRiku Voipio files, version: $version. 20736862e14SMasahiro YamadaEOF 20836862e14SMasahiro Yamada 20936862e14SMasahiro Yamadaif [ "${SRCARCH}" != um ]; then 21036862e14SMasahiro Yamadacat <<EOF >> debian/control 211b41d920aSRiku Voipio 212b41d920aSRiku VoipioPackage: linux-libc-dev 213b41d920aSRiku VoipioSection: devel 214b41d920aSRiku VoipioProvides: linux-kernel-headers 215b41d920aSRiku VoipioArchitecture: $debarch 216b41d920aSRiku VoipioDescription: Linux support headers for userspace development 217b41d920aSRiku Voipio This package provides userspaces headers from the Linux kernel. These headers 218b41d920aSRiku Voipio are used by the installed headers for GNU glibc and other system libraries. 2195a464217SCedric HombourgerMulti-Arch: same 220d9dac147SReinhard KarcherEOF 221d9dac147SReinhard Karcher 222bac977cbSMasahiro Yamadaif is_enabled CONFIG_MODULES; then 223bac977cbSMasahiro Yamadacat <<EOF >> debian/control 224bac977cbSMasahiro Yamada 2250fa21cf4SMasahiro YamadaPackage: linux-headers-$version 226bac977cbSMasahiro YamadaArchitecture: $debarch 227bac977cbSMasahiro YamadaDescription: Linux kernel headers for $version on $debarch 228bac977cbSMasahiro Yamada This package provides kernel header files for $version on $debarch 229bac977cbSMasahiro Yamada . 230bac977cbSMasahiro Yamada This is useful for people who need to build external modules 231bac977cbSMasahiro YamadaEOF 232bac977cbSMasahiro Yamadafi 23336862e14SMasahiro Yamadafi 234bac977cbSMasahiro Yamada 235d9dac147SReinhard Karcherif is_enabled CONFIG_DEBUG_INFO; then 236d9dac147SReinhard Karchercat <<EOF >> debian/control 237b41d920aSRiku Voipio 2380fa21cf4SMasahiro YamadaPackage: linux-image-$version-dbg 239b41d920aSRiku VoipioSection: debug 240b41d920aSRiku VoipioArchitecture: $debarch 241b41d920aSRiku VoipioDescription: Linux kernel debugging symbols for $version 242b41d920aSRiku Voipio This package will come in handy if you need to debug the kernel. It provides 243b41d920aSRiku Voipio all the necessary debug symbols for the kernel and its modules. 244b41d920aSRiku VoipioEOF 245d9dac147SReinhard Karcherfi 246b41d920aSRiku Voipio 247d9287ea8SMasahiro Yamadacat <<EOF > debian/rules.vars 248d9287ea8SMasahiro YamadaARCH := ${ARCH} 249d9287ea8SMasahiro YamadaKERNELRELEASE := ${KERNELRELEASE} 250b41d920aSRiku VoipioEOF 251d9287ea8SMasahiro Yamada 2529c65810cSMasahiro Yamadacp "${srctree}/scripts/package/debian/copyright" debian/ 253d9287ea8SMasahiro Yamadacp "${srctree}/scripts/package/debian/rules" debian/ 254b41d920aSRiku Voipio 255b41d920aSRiku Voipioexit 0 256