Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 #
0003 # Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
0004 #
0005 # Simple script to generate a debian/ directory for a Linux kernel.
0006 
0007 set -e
0008 
0009 is_enabled() {
0010         grep -q "^$1=y" include/config/auto.conf
0011 }
0012 
0013 if_enabled_echo() {
0014         if is_enabled "$1"; then
0015                 echo -n "$2"
0016         elif [ $# -ge 3 ]; then
0017                 echo -n "$3"
0018         fi
0019 }
0020 
0021 set_debarch() {
0022         if [ -n "$KBUILD_DEBARCH" ] ; then
0023                 debarch="$KBUILD_DEBARCH"
0024                 return
0025         fi
0026 
0027         # Attempt to find the correct Debian architecture
0028         case "$UTS_MACHINE" in
0029         i386|ia64|alpha|m68k|riscv*)
0030                 debarch="$UTS_MACHINE" ;;
0031         x86_64)
0032                 debarch=amd64 ;;
0033         sparc*)
0034                 debarch=sparc$(if_enabled_echo CONFIG_64BIT 64) ;;
0035         s390*)
0036                 debarch=s390x ;;
0037         ppc*)
0038                 if is_enabled CONFIG_64BIT; then
0039                         debarch=ppc64$(if_enabled_echo CONFIG_CPU_LITTLE_ENDIAN el)
0040                 else
0041                         debarch=powerpc$(if_enabled_echo CONFIG_SPE spe)
0042                 fi
0043                 ;;
0044         parisc*)
0045                 debarch=hppa ;;
0046         mips*)
0047                 if is_enabled CONFIG_CPU_LITTLE_ENDIAN; then
0048                         debarch=mips$(if_enabled_echo CONFIG_64BIT 64)$(if_enabled_echo CONFIG_CPU_MIPSR6 r6)el
0049                 elif is_enabled CONFIG_CPU_MIPSR6; then
0050                         debarch=mips$(if_enabled_echo CONFIG_64BIT 64)r6
0051                 else
0052                         debarch=mips
0053                 fi
0054                 ;;
0055         aarch64|arm64)
0056                 debarch=arm64 ;;
0057         arm*)
0058                 if is_enabled CONFIG_AEABI; then
0059                         debarch=arm$(if_enabled_echo CONFIG_VFP hf el)
0060                 else
0061                         debarch=arm
0062                 fi
0063                 ;;
0064         openrisc)
0065                 debarch=or1k ;;
0066         sh)
0067                 if is_enabled CONFIG_CPU_SH3; then
0068                         debarch=sh3$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb)
0069                 elif is_enabled CONFIG_CPU_SH4; then
0070                         debarch=sh4$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb)
0071                 fi
0072                 ;;
0073         esac
0074         if [ -z "$debarch" ]; then
0075                 debarch=$(dpkg-architecture -qDEB_HOST_ARCH)
0076                 echo "" >&2
0077                 echo "** ** **  WARNING  ** ** **" >&2
0078                 echo "" >&2
0079                 echo "Your architecture doesn't have its equivalent" >&2
0080                 echo "Debian userspace architecture defined!" >&2
0081                 echo "Falling back to the current host architecture ($debarch)." >&2
0082                 echo "Please add support for $UTS_MACHINE to ${0} ..." >&2
0083                 echo "" >&2
0084         fi
0085 }
0086 
0087 # Some variables and settings used throughout the script
0088 version=$KERNELRELEASE
0089 if [ -n "$KDEB_PKGVERSION" ]; then
0090         packageversion=$KDEB_PKGVERSION
0091         revision=${packageversion##*-}
0092 else
0093         revision=$(cat .version 2>/dev/null||echo 1)
0094         packageversion=$version-$revision
0095 fi
0096 sourcename=$KDEB_SOURCENAME
0097 
0098 if [ "$ARCH" = "um" ] ; then
0099         packagename=user-mode-linux
0100 else
0101         packagename=linux-image
0102 fi
0103 
0104 debarch=
0105 set_debarch
0106 
0107 email=${DEBEMAIL-$EMAIL}
0108 
0109 # use email string directly if it contains <email>
0110 if echo $email | grep -q '<.*>'; then
0111         maintainer=$email
0112 else
0113         # or construct the maintainer string
0114         user=${KBUILD_BUILD_USER-$(id -nu)}
0115         name=${DEBFULLNAME-$user}
0116         if [ -z "$email" ]; then
0117                 buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)}
0118                 email="$user@$buildhost"
0119         fi
0120         maintainer="$name <$email>"
0121 fi
0122 
0123 # Try to determine distribution
0124 if [ -n "$KDEB_CHANGELOG_DIST" ]; then
0125         distribution=$KDEB_CHANGELOG_DIST
0126 # In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog
0127 elif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then
0128         : # nothing to do in this case
0129 else
0130         distribution="unstable"
0131         echo >&2 "Using default distribution of 'unstable' in the changelog"
0132         echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly"
0133 fi
0134 
0135 mkdir -p debian/source/
0136 echo "1.0" > debian/source/format
0137 
0138 echo $debarch > debian/arch
0139 extra_build_depends=", $(if_enabled_echo CONFIG_UNWINDER_ORC libelf-dev:native)"
0140 extra_build_depends="$extra_build_depends, $(if_enabled_echo CONFIG_SYSTEM_TRUSTED_KEYRING libssl-dev:native)"
0141 
0142 # Generate a simple changelog template
0143 cat <<EOF > debian/changelog
0144 $sourcename ($packageversion) $distribution; urgency=low
0145 
0146   * Custom built Linux kernel.
0147 
0148  -- $maintainer  $(date -R)
0149 EOF
0150 
0151 # Generate copyright file
0152 cat <<EOF > debian/copyright
0153 This is a packacked upstream version of the Linux kernel.
0154 
0155 The sources may be found at most Linux archive sites, including:
0156 https://www.kernel.org/pub/linux/kernel
0157 
0158 Copyright: 1991 - 2018 Linus Torvalds and others.
0159 
0160 The git repository for mainline kernel development is at:
0161 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
0162 
0163     This program is free software; you can redistribute it and/or modify
0164     it under the terms of the GNU General Public License as published by
0165     the Free Software Foundation; version 2 dated June, 1991.
0166 
0167 On Debian GNU/Linux systems, the complete text of the GNU General Public
0168 License version 2 can be found in \`/usr/share/common-licenses/GPL-2'.
0169 EOF
0170 
0171 # Generate a control file
0172 cat <<EOF > debian/control
0173 Source: $sourcename
0174 Section: kernel
0175 Priority: optional
0176 Maintainer: $maintainer
0177 Rules-Requires-Root: no
0178 Build-Depends: bc, rsync, kmod, cpio, bison, flex | flex:native $extra_build_depends
0179 Homepage: https://www.kernel.org/
0180 
0181 Package: $packagename-$version
0182 Architecture: $debarch
0183 Description: Linux kernel, version $version
0184  This package contains the Linux kernel, modules and corresponding other
0185  files, version: $version.
0186 
0187 Package: linux-libc-dev
0188 Section: devel
0189 Provides: linux-kernel-headers
0190 Architecture: $debarch
0191 Description: Linux support headers for userspace development
0192  This package provides userspaces headers from the Linux kernel.  These headers
0193  are used by the installed headers for GNU glibc and other system libraries.
0194 Multi-Arch: same
0195 EOF
0196 
0197 if is_enabled CONFIG_MODULES; then
0198 cat <<EOF >> debian/control
0199 
0200 Package: linux-headers-$version
0201 Architecture: $debarch
0202 Description: Linux kernel headers for $version on $debarch
0203  This package provides kernel header files for $version on $debarch
0204  .
0205  This is useful for people who need to build external modules
0206 EOF
0207 fi
0208 
0209 if is_enabled CONFIG_DEBUG_INFO; then
0210 cat <<EOF >> debian/control
0211 
0212 Package: linux-image-$version-dbg
0213 Section: debug
0214 Architecture: $debarch
0215 Description: Linux kernel debugging symbols for $version
0216  This package will come in handy if you need to debug the kernel. It provides
0217  all the necessary debug symbols for the kernel and its modules.
0218 EOF
0219 fi
0220 
0221 cat <<EOF > debian/rules
0222 #!$(command -v $MAKE) -f
0223 
0224 srctree ?= .
0225 
0226 build-indep:
0227 build-arch:
0228         \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \
0229         KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile
0230 
0231 build: build-arch
0232 
0233 binary-indep:
0234 binary-arch: build-arch
0235         \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \
0236         KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile intdeb-pkg
0237 
0238 clean:
0239         rm -rf debian/*tmp debian/files
0240         \$(MAKE) clean
0241 
0242 binary: binary-arch
0243 EOF
0244 chmod +x debian/rules
0245 
0246 exit 0