18c2ecf20Sopenharmony_ci#!/bin/sh 28c2ecf20Sopenharmony_ci# 38c2ecf20Sopenharmony_ci# Copyright 2003 Wichert Akkerman <wichert@wiggy.net> 48c2ecf20Sopenharmony_ci# 58c2ecf20Sopenharmony_ci# Simple script to generate a debian/ directory for a Linux kernel. 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciset -e 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciis_enabled() { 108c2ecf20Sopenharmony_ci grep -q "^$1=y" include/config/auto.conf 118c2ecf20Sopenharmony_ci} 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciif_enabled_echo() { 148c2ecf20Sopenharmony_ci if is_enabled "$1"; then 158c2ecf20Sopenharmony_ci echo -n "$2" 168c2ecf20Sopenharmony_ci elif [ $# -ge 3 ]; then 178c2ecf20Sopenharmony_ci echo -n "$3" 188c2ecf20Sopenharmony_ci fi 198c2ecf20Sopenharmony_ci} 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ciset_debarch() { 228c2ecf20Sopenharmony_ci if [ -n "$KBUILD_DEBARCH" ] ; then 238c2ecf20Sopenharmony_ci debarch="$KBUILD_DEBARCH" 248c2ecf20Sopenharmony_ci return 258c2ecf20Sopenharmony_ci fi 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci # Attempt to find the correct Debian architecture 288c2ecf20Sopenharmony_ci case "$UTS_MACHINE" in 298c2ecf20Sopenharmony_ci i386|ia64|alpha|m68k|riscv*) 308c2ecf20Sopenharmony_ci debarch="$UTS_MACHINE" ;; 318c2ecf20Sopenharmony_ci x86_64) 328c2ecf20Sopenharmony_ci debarch=amd64 ;; 338c2ecf20Sopenharmony_ci sparc*) 348c2ecf20Sopenharmony_ci debarch=sparc$(if_enabled_echo CONFIG_64BIT 64) ;; 358c2ecf20Sopenharmony_ci s390*) 368c2ecf20Sopenharmony_ci debarch=s390x ;; 378c2ecf20Sopenharmony_ci ppc*) 388c2ecf20Sopenharmony_ci if is_enabled CONFIG_64BIT; then 398c2ecf20Sopenharmony_ci debarch=ppc64$(if_enabled_echo CONFIG_CPU_LITTLE_ENDIAN el) 408c2ecf20Sopenharmony_ci else 418c2ecf20Sopenharmony_ci debarch=powerpc$(if_enabled_echo CONFIG_SPE spe) 428c2ecf20Sopenharmony_ci fi 438c2ecf20Sopenharmony_ci ;; 448c2ecf20Sopenharmony_ci parisc*) 458c2ecf20Sopenharmony_ci debarch=hppa ;; 468c2ecf20Sopenharmony_ci mips*) 478c2ecf20Sopenharmony_ci if is_enabled CONFIG_CPU_LITTLE_ENDIAN; then 488c2ecf20Sopenharmony_ci debarch=mips$(if_enabled_echo CONFIG_64BIT 64)$(if_enabled_echo CONFIG_CPU_MIPSR6 r6)el 498c2ecf20Sopenharmony_ci elif is_enabled CONFIG_CPU_MIPSR6; then 508c2ecf20Sopenharmony_ci debarch=mips$(if_enabled_echo CONFIG_64BIT 64)r6 518c2ecf20Sopenharmony_ci else 528c2ecf20Sopenharmony_ci debarch=mips 538c2ecf20Sopenharmony_ci fi 548c2ecf20Sopenharmony_ci ;; 558c2ecf20Sopenharmony_ci aarch64|arm64) 568c2ecf20Sopenharmony_ci debarch=arm64 ;; 578c2ecf20Sopenharmony_ci arm*) 588c2ecf20Sopenharmony_ci if is_enabled CONFIG_AEABI; then 598c2ecf20Sopenharmony_ci debarch=arm$(if_enabled_echo CONFIG_VFP hf el) 608c2ecf20Sopenharmony_ci else 618c2ecf20Sopenharmony_ci debarch=arm 628c2ecf20Sopenharmony_ci fi 638c2ecf20Sopenharmony_ci ;; 648c2ecf20Sopenharmony_ci openrisc) 658c2ecf20Sopenharmony_ci debarch=or1k ;; 668c2ecf20Sopenharmony_ci sh) 678c2ecf20Sopenharmony_ci if is_enabled CONFIG_CPU_SH3; then 688c2ecf20Sopenharmony_ci debarch=sh3$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb) 698c2ecf20Sopenharmony_ci elif is_enabled CONFIG_CPU_SH4; then 708c2ecf20Sopenharmony_ci debarch=sh4$(if_enabled_echo CONFIG_CPU_BIG_ENDIAN eb) 718c2ecf20Sopenharmony_ci fi 728c2ecf20Sopenharmony_ci ;; 738c2ecf20Sopenharmony_ci esac 748c2ecf20Sopenharmony_ci if [ -z "$debarch" ]; then 758c2ecf20Sopenharmony_ci debarch=$(dpkg-architecture -qDEB_HOST_ARCH) 768c2ecf20Sopenharmony_ci echo "" >&2 778c2ecf20Sopenharmony_ci echo "** ** ** WARNING ** ** **" >&2 788c2ecf20Sopenharmony_ci echo "" >&2 798c2ecf20Sopenharmony_ci echo "Your architecture doesn't have its equivalent" >&2 808c2ecf20Sopenharmony_ci echo "Debian userspace architecture defined!" >&2 818c2ecf20Sopenharmony_ci echo "Falling back to the current host architecture ($debarch)." >&2 828c2ecf20Sopenharmony_ci echo "Please add support for $UTS_MACHINE to ${0} ..." >&2 838c2ecf20Sopenharmony_ci echo "" >&2 848c2ecf20Sopenharmony_ci fi 858c2ecf20Sopenharmony_ci} 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci# Some variables and settings used throughout the script 888c2ecf20Sopenharmony_civersion=$KERNELRELEASE 898c2ecf20Sopenharmony_ciif [ -n "$KDEB_PKGVERSION" ]; then 908c2ecf20Sopenharmony_ci packageversion=$KDEB_PKGVERSION 918c2ecf20Sopenharmony_ci revision=${packageversion##*-} 928c2ecf20Sopenharmony_cielse 938c2ecf20Sopenharmony_ci revision=$(cat .version 2>/dev/null||echo 1) 948c2ecf20Sopenharmony_ci packageversion=$version-$revision 958c2ecf20Sopenharmony_cifi 968c2ecf20Sopenharmony_cisourcename=$KDEB_SOURCENAME 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ciif [ "$ARCH" = "um" ] ; then 998c2ecf20Sopenharmony_ci packagename=user-mode-linux 1008c2ecf20Sopenharmony_cielse 1018c2ecf20Sopenharmony_ci packagename=linux-image 1028c2ecf20Sopenharmony_cifi 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cidebarch= 1058c2ecf20Sopenharmony_ciset_debarch 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ciemail=${DEBEMAIL-$EMAIL} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci# use email string directly if it contains <email> 1108c2ecf20Sopenharmony_ciif echo $email | grep -q '<.*>'; then 1118c2ecf20Sopenharmony_ci maintainer=$email 1128c2ecf20Sopenharmony_cielse 1138c2ecf20Sopenharmony_ci # or construct the maintainer string 1148c2ecf20Sopenharmony_ci user=${KBUILD_BUILD_USER-$(id -nu)} 1158c2ecf20Sopenharmony_ci name=${DEBFULLNAME-$user} 1168c2ecf20Sopenharmony_ci if [ -z "$email" ]; then 1178c2ecf20Sopenharmony_ci buildhost=${KBUILD_BUILD_HOST-$(hostname -f 2>/dev/null || hostname)} 1188c2ecf20Sopenharmony_ci email="$user@$buildhost" 1198c2ecf20Sopenharmony_ci fi 1208c2ecf20Sopenharmony_ci maintainer="$name <$email>" 1218c2ecf20Sopenharmony_cifi 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci# Try to determine distribution 1248c2ecf20Sopenharmony_ciif [ -n "$KDEB_CHANGELOG_DIST" ]; then 1258c2ecf20Sopenharmony_ci distribution=$KDEB_CHANGELOG_DIST 1268c2ecf20Sopenharmony_ci# In some cases lsb_release returns the codename as n/a, which breaks dpkg-parsechangelog 1278c2ecf20Sopenharmony_cielif distribution=$(lsb_release -cs 2>/dev/null) && [ -n "$distribution" ] && [ "$distribution" != "n/a" ]; then 1288c2ecf20Sopenharmony_ci : # nothing to do in this case 1298c2ecf20Sopenharmony_cielse 1308c2ecf20Sopenharmony_ci distribution="unstable" 1318c2ecf20Sopenharmony_ci echo >&2 "Using default distribution of 'unstable' in the changelog" 1328c2ecf20Sopenharmony_ci echo >&2 "Install lsb-release or set \$KDEB_CHANGELOG_DIST explicitly" 1338c2ecf20Sopenharmony_cifi 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cimkdir -p debian/source/ 1368c2ecf20Sopenharmony_ciecho "1.0" > debian/source/format 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ciecho $debarch > debian/arch 1398c2ecf20Sopenharmony_ciextra_build_depends=", $(if_enabled_echo CONFIG_UNWINDER_ORC libelf-dev:native)" 1408c2ecf20Sopenharmony_ciextra_build_depends="$extra_build_depends, $(if_enabled_echo CONFIG_SYSTEM_TRUSTED_KEYRING libssl-dev:native)" 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci# Generate a simple changelog template 1438c2ecf20Sopenharmony_cicat <<EOF > debian/changelog 1448c2ecf20Sopenharmony_ci$sourcename ($packageversion) $distribution; urgency=low 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci * Custom built Linux kernel. 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci -- $maintainer $(date -R) 1498c2ecf20Sopenharmony_ciEOF 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci# Generate copyright file 1528c2ecf20Sopenharmony_cicat <<EOF > debian/copyright 1538c2ecf20Sopenharmony_ciThis is a packacked upstream version of the Linux kernel. 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ciThe sources may be found at most Linux archive sites, including: 1568c2ecf20Sopenharmony_cihttps://www.kernel.org/pub/linux/kernel 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ciCopyright: 1991 - 2018 Linus Torvalds and others. 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ciThe git repository for mainline kernel development is at: 1618c2ecf20Sopenharmony_cigit://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci This program is free software; you can redistribute it and/or modify 1648c2ecf20Sopenharmony_ci it under the terms of the GNU General Public License as published by 1658c2ecf20Sopenharmony_ci the Free Software Foundation; version 2 dated June, 1991. 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ciOn Debian GNU/Linux systems, the complete text of the GNU General Public 1688c2ecf20Sopenharmony_ciLicense version 2 can be found in \`/usr/share/common-licenses/GPL-2'. 1698c2ecf20Sopenharmony_ciEOF 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci# Generate a control file 1728c2ecf20Sopenharmony_cicat <<EOF > debian/control 1738c2ecf20Sopenharmony_ciSource: $sourcename 1748c2ecf20Sopenharmony_ciSection: kernel 1758c2ecf20Sopenharmony_ciPriority: optional 1768c2ecf20Sopenharmony_ciMaintainer: $maintainer 1778c2ecf20Sopenharmony_ciRules-Requires-Root: no 1788c2ecf20Sopenharmony_ciBuild-Depends: bc, rsync, kmod, cpio, bison, flex | flex:native $extra_build_depends 1798c2ecf20Sopenharmony_ciHomepage: https://www.kernel.org/ 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ciPackage: $packagename-$version 1828c2ecf20Sopenharmony_ciArchitecture: $debarch 1838c2ecf20Sopenharmony_ciDescription: Linux kernel, version $version 1848c2ecf20Sopenharmony_ci This package contains the Linux kernel, modules and corresponding other 1858c2ecf20Sopenharmony_ci files, version: $version. 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ciPackage: linux-libc-dev 1888c2ecf20Sopenharmony_ciSection: devel 1898c2ecf20Sopenharmony_ciProvides: linux-kernel-headers 1908c2ecf20Sopenharmony_ciArchitecture: $debarch 1918c2ecf20Sopenharmony_ciDescription: Linux support headers for userspace development 1928c2ecf20Sopenharmony_ci This package provides userspaces headers from the Linux kernel. These headers 1938c2ecf20Sopenharmony_ci are used by the installed headers for GNU glibc and other system libraries. 1948c2ecf20Sopenharmony_ciMulti-Arch: same 1958c2ecf20Sopenharmony_ciEOF 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ciif is_enabled CONFIG_MODULES; then 1988c2ecf20Sopenharmony_cicat <<EOF >> debian/control 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ciPackage: linux-headers-$version 2018c2ecf20Sopenharmony_ciArchitecture: $debarch 2028c2ecf20Sopenharmony_ciDescription: Linux kernel headers for $version on $debarch 2038c2ecf20Sopenharmony_ci This package provides kernel header files for $version on $debarch 2048c2ecf20Sopenharmony_ci . 2058c2ecf20Sopenharmony_ci This is useful for people who need to build external modules 2068c2ecf20Sopenharmony_ciEOF 2078c2ecf20Sopenharmony_cifi 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_ciif is_enabled CONFIG_DEBUG_INFO; then 2108c2ecf20Sopenharmony_cicat <<EOF >> debian/control 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ciPackage: linux-image-$version-dbg 2138c2ecf20Sopenharmony_ciSection: debug 2148c2ecf20Sopenharmony_ciArchitecture: $debarch 2158c2ecf20Sopenharmony_ciDescription: Linux kernel debugging symbols for $version 2168c2ecf20Sopenharmony_ci This package will come in handy if you need to debug the kernel. It provides 2178c2ecf20Sopenharmony_ci all the necessary debug symbols for the kernel and its modules. 2188c2ecf20Sopenharmony_ciEOF 2198c2ecf20Sopenharmony_cifi 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_cicat <<EOF > debian/rules 2228c2ecf20Sopenharmony_ci#!$(command -v $MAKE) -f 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_cisrctree ?= . 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_cibuild-indep: 2278c2ecf20Sopenharmony_cibuild-arch: 2288c2ecf20Sopenharmony_ci \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \ 2298c2ecf20Sopenharmony_ci KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_cibuild: build-arch 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_cibinary-indep: 2348c2ecf20Sopenharmony_cibinary-arch: build-arch 2358c2ecf20Sopenharmony_ci \$(MAKE) KERNELRELEASE=${version} ARCH=${ARCH} \ 2368c2ecf20Sopenharmony_ci KBUILD_BUILD_VERSION=${revision} -f \$(srctree)/Makefile intdeb-pkg 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ciclean: 2398c2ecf20Sopenharmony_ci rm -rf debian/files debian/linux-* 2408c2ecf20Sopenharmony_ci \$(MAKE) clean 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_cibinary: binary-arch 2438c2ecf20Sopenharmony_ciEOF 2448c2ecf20Sopenharmony_cichmod +x debian/rules 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_ciexit 0 247