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() { 1008d3892cSBen Hutchings grep -q "^CONFIG_$1=y" $KCONFIG_CONFIG 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 29b41d920aSRiku Voipio i386|ia64|alpha) 30b41d920aSRiku Voipio debarch="$UTS_MACHINE" ;; 31b41d920aSRiku Voipio x86_64) 32b41d920aSRiku Voipio debarch=amd64 ;; 33b41d920aSRiku Voipio sparc*) 34b41d920aSRiku Voipio debarch=sparc ;; 35b41d920aSRiku Voipio s390*) 364260ecd0SBen Hutchings debarch=s390x ;; 37b41d920aSRiku Voipio ppc*) 3850d511baSBen Hutchings if is_enabled 64BIT; then 3950d511baSBen Hutchings debarch=ppc64$(if_enabled_echo CPU_LITTLE_ENDIAN el) 4050d511baSBen Hutchings else 4150d511baSBen Hutchings debarch=powerpc$(if_enabled_echo SPE spe) 4250d511baSBen Hutchings fi 4350d511baSBen Hutchings ;; 44b41d920aSRiku Voipio parisc*) 45b41d920aSRiku Voipio debarch=hppa ;; 46b41d920aSRiku Voipio mips*) 4708d3892cSBen Hutchings debarch=mips$(if_enabled_echo CPU_LITTLE_ENDIAN el) ;; 48b41d920aSRiku Voipio aarch64|arm64) 49b41d920aSRiku Voipio debarch=arm64 ;; 50b41d920aSRiku Voipio arm*) 5108d3892cSBen Hutchings if is_enabled AEABI; then 5208d3892cSBen Hutchings debarch=arm$(if_enabled_echo VFP hf el) 53b41d920aSRiku Voipio else 54b41d920aSRiku Voipio debarch=arm 55b41d920aSRiku Voipio fi 56b41d920aSRiku Voipio ;; 57b41d920aSRiku Voipio *) 58091d30aeSBen Hutchings debarch=$(dpkg-architecture -qDEB_HOST_ARCH) 59b41d920aSRiku Voipio echo "" >&2 60b41d920aSRiku Voipio echo "** ** ** WARNING ** ** **" >&2 61b41d920aSRiku Voipio echo "" >&2 62b41d920aSRiku Voipio echo "Your architecture doesn't have its equivalent" >&2 63b41d920aSRiku Voipio echo "Debian userspace architecture defined!" >&2 64091d30aeSBen Hutchings echo "Falling back to the current host architecture ($debarch)." >&2 65b41d920aSRiku Voipio echo "Please add support for $UTS_MACHINE to ${0} ..." >&2 66b41d920aSRiku Voipio echo "" >&2 67f2abcc13SBen Hutchings ;; 68b41d920aSRiku Voipio esac 69b41d920aSRiku Voipio} 70b41d920aSRiku Voipio 71b41d920aSRiku Voipio# Some variables and settings used throughout the script 72b41d920aSRiku Voipioversion=$KERNELRELEASE 73b41d920aSRiku Voipioif [ -n "$KDEB_PKGVERSION" ]; then 74b41d920aSRiku Voipio packageversion=$KDEB_PKGVERSION 75b41d920aSRiku Voipioelse 76b41d920aSRiku Voipio revision=$(cat .version 2>/dev/null||echo 1) 77b41d920aSRiku Voipio packageversion=$version-$revision 78b41d920aSRiku Voipiofi 79b41d920aSRiku Voipiosourcename=$KDEB_SOURCENAME 80b41d920aSRiku Voipiopackagename=linux-image-$version 81b41d920aSRiku Voipiokernel_headers_packagename=linux-headers-$version 82b41d920aSRiku Voipiodbg_packagename=$packagename-dbg 83b41d920aSRiku Voipiodebarch= 84b41d920aSRiku Voipioset_debarch 85b41d920aSRiku Voipio 86b41d920aSRiku Voipioif [ "$ARCH" = "um" ] ; then 87b41d920aSRiku Voipio packagename=user-mode-linux-$version 88b41d920aSRiku Voipiofi 89b41d920aSRiku Voipio 90d5940c60SRiku Voipioemail=${DEBEMAIL-$EMAIL} 91d5940c60SRiku Voipio 92d5940c60SRiku Voipio# use email string directly if it contains <email> 93d5940c60SRiku Voipioif echo $email | grep -q '<.*>'; then 94d5940c60SRiku Voipio maintainer=$email 95b41d920aSRiku Voipioelse 96d5940c60SRiku Voipio # or construct the maintainer string 97d5940c60SRiku Voipio user=${KBUILD_BUILD_USER-$(id -nu)} 98d5940c60SRiku Voipio name=${DEBFULLNAME-$user} 99d5940c60SRiku Voipio if [ -z "$email" ]; then 100d5940c60SRiku Voipio buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)} 101d5940c60SRiku Voipio email="$user@$buildhost" 102b41d920aSRiku Voipio fi 103b41d920aSRiku Voipio maintainer="$name <$email>" 104d5940c60SRiku Voipiofi 105b41d920aSRiku Voipio 106b41d920aSRiku Voipio# Try to determine distribution 107b41d920aSRiku Voipioif [ -n "$KDEB_CHANGELOG_DIST" ]; then 108b41d920aSRiku Voipio distribution=$KDEB_CHANGELOG_DIST 109b41d920aSRiku Voipio# In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog 110b41d920aSRiku Voipioelif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then 111b41d920aSRiku Voipio : # nothing to do in this case 112b41d920aSRiku Voipioelse 113b41d920aSRiku Voipio distribution="unstable" 114b41d920aSRiku Voipio echo >&2 "Using default distribution of 'unstable' in the changelog" 115b41d920aSRiku Voipio echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly" 116b41d920aSRiku Voipiofi 117b41d920aSRiku Voipio 118b41d920aSRiku Voipiomkdir -p debian/ 119b41d920aSRiku Voipioecho $debarch > debian/arch 120b41d920aSRiku Voipio 121b41d920aSRiku Voipio# Generate a simple changelog template 122b41d920aSRiku Voipiocat <<EOF > debian/changelog 123b41d920aSRiku Voipio$sourcename ($packageversion) $distribution; urgency=low 124b41d920aSRiku Voipio 125b41d920aSRiku Voipio * Custom built Linux kernel. 126b41d920aSRiku Voipio 127b41d920aSRiku Voipio -- $maintainer $(date -R) 128b41d920aSRiku VoipioEOF 129b41d920aSRiku Voipio 130b41d920aSRiku Voipio# Generate copyright file 131b41d920aSRiku Voipiocat <<EOF > debian/copyright 132b41d920aSRiku VoipioThis is a packacked upstream version of the Linux kernel. 133b41d920aSRiku Voipio 134b41d920aSRiku VoipioThe sources may be found at most Linux archive sites, including: 135b41d920aSRiku Voipiohttps://www.kernel.org/pub/linux/kernel 136b41d920aSRiku Voipio 137b41d920aSRiku VoipioCopyright: 1991 - 2018 Linus Torvalds and others. 138b41d920aSRiku Voipio 139b41d920aSRiku VoipioThe git repository for mainline kernel development is at: 140b41d920aSRiku Voipiogit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 141b41d920aSRiku Voipio 142b41d920aSRiku Voipio This program is free software; you can redistribute it and/or modify 143b41d920aSRiku Voipio it under the terms of the GNU General Public License as published by 144b41d920aSRiku Voipio the Free Software Foundation; version 2 dated June, 1991. 145b41d920aSRiku Voipio 146b41d920aSRiku VoipioOn Debian GNU/Linux systems, the complete text of the GNU General Public 147b41d920aSRiku VoipioLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'. 148b41d920aSRiku VoipioEOF 149b41d920aSRiku Voipio 150b41d920aSRiku Voipio# Generate a control file 151b41d920aSRiku Voipiocat <<EOF > debian/control 152b41d920aSRiku VoipioSource: $sourcename 153b41d920aSRiku VoipioSection: kernel 154b41d920aSRiku VoipioPriority: optional 155b41d920aSRiku VoipioMaintainer: $maintainer 156b41d920aSRiku VoipioBuild-Depends: bc, kmod, cpio 157b41d920aSRiku VoipioHomepage: http://www.kernel.org/ 158b41d920aSRiku Voipio 159b41d920aSRiku VoipioPackage: $packagename 160b41d920aSRiku VoipioArchitecture: $debarch 161b41d920aSRiku VoipioDescription: Linux kernel, version $version 162b41d920aSRiku Voipio This package contains the Linux kernel, modules and corresponding other 163b41d920aSRiku Voipio files, version: $version. 164b41d920aSRiku Voipio 165b41d920aSRiku VoipioPackage: $kernel_headers_packagename 166b41d920aSRiku VoipioArchitecture: $debarch 167b41d920aSRiku VoipioDescription: Linux kernel headers for $version on $debarch 168b41d920aSRiku Voipio This package provides kernel header files for $version on $debarch 169b41d920aSRiku Voipio . 170b41d920aSRiku Voipio This is useful for people who need to build external modules 171b41d920aSRiku Voipio 172b41d920aSRiku VoipioPackage: linux-libc-dev 173b41d920aSRiku VoipioSection: devel 174b41d920aSRiku VoipioProvides: linux-kernel-headers 175b41d920aSRiku VoipioArchitecture: $debarch 176b41d920aSRiku VoipioDescription: Linux support headers for userspace development 177b41d920aSRiku Voipio This package provides userspaces headers from the Linux kernel. These headers 178b41d920aSRiku Voipio are used by the installed headers for GNU glibc and other system libraries. 179b41d920aSRiku Voipio 180b41d920aSRiku VoipioPackage: $dbg_packagename 181b41d920aSRiku VoipioSection: debug 182b41d920aSRiku VoipioArchitecture: $debarch 183b41d920aSRiku VoipioDescription: Linux kernel debugging symbols for $version 184b41d920aSRiku Voipio This package will come in handy if you need to debug the kernel. It provides 185b41d920aSRiku Voipio all the necessary debug symbols for the kernel and its modules. 186b41d920aSRiku VoipioEOF 187b41d920aSRiku Voipio 188b41d920aSRiku Voipiocat <<EOF > debian/rules 189b41d920aSRiku Voipio#!$(command -v $MAKE) -f 190b41d920aSRiku Voipio 191b41d920aSRiku Voipiobuild: 192b41d920aSRiku Voipio \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC= 193b41d920aSRiku Voipio 194b41d920aSRiku Voipiobinary-arch: 195b41d920aSRiku Voipio \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} KBUILD_SRC= intdeb-pkg 196b41d920aSRiku Voipio 197b41d920aSRiku Voipioclean: 198b41d920aSRiku Voipio rm -rf debian/*tmp debian/files 199b41d920aSRiku Voipio \$(MAKE) clean 200b41d920aSRiku Voipio 201b41d920aSRiku Voipiobinary: binary-arch 202b41d920aSRiku VoipioEOF 203b41d920aSRiku Voipio 204b41d920aSRiku Voipioexit 0 205