| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #!/bin/sh
- #
- # builddeb 1.3
- # Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
- #
- # Simple script to generate a deb package for a Linux kernel. All the
- # complexity of what to do with a kernel after it is installed or removed
- # is left to other scripts and packages. Scripts can be placed into the
- # preinst, postinst, prerm and postrm directories in /etc/kernel or
- # /usr/share/kernel. A different list of search directories can be given
- # via KDEB_HOOKDIR. Scripts in directories earlier in the list will
- # override scripts of the same name in later directories. The script will
- # be called on package installation and removal.
- set -eu
- is_enabled() {
- grep -q "^$1=y" include/config/auto.conf
- }
- if_enabled_echo() {
- if is_enabled "$1"; then
- echo -n "$2"
- elif [ $# -ge 3 ]; then
- echo -n "$3"
- fi
- }
- install_linux_image () {
- pname=$1
- pdir=debian/$1
- # Only some architectures with OF support have this target
- if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then
- ${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install
- fi
- ${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" INSTALL_MOD_STRIP=1 modules_install
- rm -f "${pdir}/lib/modules/${KERNELRELEASE}/build"
- # Install the kernel
- if [ "${ARCH}" = um ] ; then
- mkdir -p "${pdir}/usr/lib/uml/modules"
- mv "${pdir}/lib/modules/${KERNELRELEASE}" "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}"
- mkdir -p "${pdir}/usr/bin" "${pdir}/usr/share/doc/${pname}"
- cp System.map "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}/System.map"
- cp ${KCONFIG_CONFIG} "${pdir}/usr/share/doc/${pname}/config"
- gzip "${pdir}/usr/share/doc/${pname}/config"
- else
- mkdir -p "${pdir}/boot"
- cp System.map "${pdir}/boot/System.map-${KERNELRELEASE}"
- cp ${KCONFIG_CONFIG} "${pdir}/boot/config-${KERNELRELEASE}"
- fi
- # Not all arches have the same installed path in debian
- # XXX: have each arch Makefile export a variable of the canonical image install
- # path instead
- case "${SRCARCH}" in
- um)
- installed_image_path="usr/bin/linux-${KERNELRELEASE}";;
- parisc|mips|powerpc)
- installed_image_path="boot/vmlinux-${KERNELRELEASE}";;
- *)
- installed_image_path="boot/vmlinuz-${KERNELRELEASE}";;
- esac
- cp "$(${MAKE} -s -f ${srctree}/Makefile image_name)" "${pdir}/${installed_image_path}"
- if [ "${ARCH}" != um ]; then
- install_maint_scripts "${pdir}"
- fi
- }
- install_maint_scripts () {
- # Install the maintainer scripts
- # Note: hook scripts under /etc/kernel are also executed by official Debian
- # kernel packages, as well as kernel packages built using make-kpkg.
- # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
- # so do we; recent versions of dracut and initramfs-tools will obey this.
- debhookdir=${KDEB_HOOKDIR:-/etc/kernel /usr/share/kernel}
- for script in postinst postrm preinst prerm; do
- mkdir -p "${pdir}/DEBIAN"
- cat <<-EOF > "${pdir}/DEBIAN/${script}"
- #!/bin/sh
- set -e
- # Pass maintainer script parameters to hook scripts
- export DEB_MAINT_PARAMS="\$*"
- # Tell initramfs builder whether it's wanted
- export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
- # run-parts will error out if one of its directory arguments does not
- # exist, so filter the list of hook directories accordingly.
- hookdirs=
- for dir in ${debhookdir}; do
- test -d "\$dir/${script}.d" || continue
- hookdirs="\$hookdirs \$dir/${script}.d"
- done
- hookdirs="\${hookdirs# }"
- test -n "\$hookdirs" && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" \$hookdirs
- exit 0
- EOF
- chmod 755 "${pdir}/DEBIAN/${script}"
- done
- }
- install_linux_image_dbg () {
- pdir=debian/$1
- # Parse modules.order directly because 'make modules_install' may sign,
- # compress modules, and then run unneeded depmod.
- if is_enabled CONFIG_MODULES; then
- while read -r mod; do
- mod="${mod%.o}.ko"
- dbg="${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/kernel/${mod}"
- buildid=$("${READELF}" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p')
- link="${pdir}/usr/lib/debug/.build-id/${buildid}.debug"
- mkdir -p "${dbg%/*}" "${link%/*}"
- "${OBJCOPY}" --only-keep-debug "${mod}" "${dbg}"
- ln -sf --relative "${dbg}" "${link}"
- done < modules.order
- fi
- # Build debug package
- # Different tools want the image in different locations
- # perf
- mkdir -p ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
- cp vmlinux ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
- # systemtap
- mkdir -p ${pdir}/usr/lib/debug/boot/
- ln -s ../lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/boot/vmlinux-${KERNELRELEASE}
- # kdump-tools
- ln -s lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/vmlinux-${KERNELRELEASE}
- }
- install_kernel_headers () {
- pdir=debian/$1
- version=${1#linux-headers-}
- CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
- mkdir -p $pdir/lib/modules/$version/
- ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build
- }
- install_libc_headers () {
- pdir=debian/$1
- $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr
- # move asm headers to /usr/include/<libc-machine>/asm to match the structure
- # used by Debian-based distros (to support multi-arch)
- mkdir "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
- mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}"
- }
- package=$1
- case "${package}" in
- *-dbg)
- install_linux_image_dbg "${package}";;
- linux-image-*|user-mode-linux-*)
- install_linux_image "${package}";;
- linux-libc-dev)
- install_libc_headers "${package}";;
- linux-headers-*)
- install_kernel_headers "${package}";;
- esac
|