4 # Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
6 # Simple script to generate a deb package for a Linux kernel. All the
7 # complexity of what to do with a kernel after it is installed or removed
8 # is left to other scripts and packages: they can install scripts in the
9 # /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
10 # specified in KDEB_HOOKDIR) that will be called on package install and
16 grep -q "^$1=y" include/config/auto.conf
20 if is_enabled "$1"; then
22 elif [ $# -ge 3 ]; then
28 local pname="$1" pdir="$2"
31 mkdir -m 755 -p "$pdir/DEBIAN"
32 mkdir -p "$pdir/usr/share/doc/$pname"
33 cp debian/copyright "$pdir/usr/share/doc/$pname/"
34 cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
35 gzip -n -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
36 sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
37 | xargs -r0 md5sum > DEBIAN/md5sums"
39 # Fix ownership and permissions
40 if [ "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
41 dpkg_deb_opts="--root-owner-group"
43 chown -R root:root "$pdir"
45 # a+rX in case we are in a restrictive umask environment like 0077
46 # ug-s in case we build in a setuid/setgid directory
47 chmod -R go-w,a+rX,ug-s "$pdir"
50 dpkg-gencontrol -p$pname -P"$pdir"
51 dpkg-deb $dpkg_deb_opts ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" ..
54 install_linux_image () {
60 # Only some architectures with OF support have this target
61 if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then
62 ${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install
65 ${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" modules_install
66 rm -f "${pdir}/lib/modules/${KERNELRELEASE}/build"
69 if [ "${ARCH}" = um ] ; then
70 mkdir -p "${pdir}/usr/lib/uml/modules"
71 mv "${pdir}/lib/modules/${KERNELRELEASE}" "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}"
72 mkdir -p "${pdir}/usr/bin" "${pdir}/usr/share/doc/${pname}"
73 cp System.map "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}/System.map"
74 cp ${KCONFIG_CONFIG} "${pdir}/usr/share/doc/${pname}/config"
75 gzip "${pdir}/usr/share/doc/${pname}/config"
77 mkdir -p "${pdir}/boot"
78 cp System.map "${pdir}/boot/System.map-${KERNELRELEASE}"
79 cp ${KCONFIG_CONFIG} "${pdir}/boot/config-${KERNELRELEASE}"
82 # Not all arches have the same installed path in debian
83 # XXX: have each arch Makefile export a variable of the canonical image install
87 installed_image_path="usr/bin/linux-${KERNELRELEASE}";;
89 installed_image_path="boot/vmlinux-${KERNELRELEASE}";;
91 installed_image_path="boot/vmlinuz-${KERNELRELEASE}";;
93 cp "$(${MAKE} -s -f ${srctree}/Makefile image_name)" "${pdir}/${installed_image_path}"
95 # Install the maintainer scripts
96 # Note: hook scripts under /etc/kernel are also executed by official Debian
97 # kernel packages, as well as kernel packages built using make-kpkg.
98 # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
99 # so do we; recent versions of dracut and initramfs-tools will obey this.
100 debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
101 for script in postinst postrm preinst prerm; do
102 mkdir -p "${pdir}${debhookdir}/${script}.d"
104 mkdir -p "${pdir}/DEBIAN"
105 cat <<-EOF > "${pdir}/DEBIAN/${script}"
111 # Pass maintainer script parameters to hook scripts
112 export DEB_MAINT_PARAMS="\$*"
114 # Tell initramfs builder whether it's wanted
115 export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
117 test -d ${debhookdir}/${script}.d && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" ${debhookdir}/${script}.d
120 chmod 755 "${pdir}/DEBIAN/${script}"
124 install_linux_image_dbg () {
130 for module in $(find ${image_pdir}/lib/modules/ -name *.ko -printf '%P\n'); do
131 module=lib/modules/${module}
132 mkdir -p $(dirname ${pdir}/usr/lib/debug/${module})
133 # only keep debug symbols in the debug file
134 ${OBJCOPY} --only-keep-debug ${image_pdir}/${module} ${pdir}/usr/lib/debug/${module}
135 # strip original module from debug symbols
136 ${OBJCOPY} --strip-debug ${image_pdir}/${module}
137 # then add a link to those
138 ${OBJCOPY} --add-gnu-debuglink=${pdir}/usr/lib/debug/${module} ${image_pdir}/${module}
141 # re-sign stripped modules
142 if is_enabled CONFIG_MODULE_SIG_ALL; then
143 ${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${image_pdir}" modules_sign
146 # Build debug package
147 # Different tools want the image in different locations
149 mkdir -p ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
150 cp vmlinux ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/
152 mkdir -p ${pdir}/usr/lib/debug/boot/
153 ln -s ../lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/boot/vmlinux-${KERNELRELEASE}
155 ln -s lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/vmlinux-${KERNELRELEASE}
158 install_kernel_headers () {
164 "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}"
166 mkdir -p $pdir/lib/modules/$version/
167 ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build
170 install_libc_headers () {
175 $MAKE -f $srctree/Makefile headers
176 $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr
178 # move asm headers to /usr/include/<libc-machine>/asm to match the structure
179 # used by Debian-based distros (to support multi-arch)
180 host_arch=$(dpkg-architecture -a$DEB_HOST_ARCH -qDEB_HOST_MULTIARCH)
181 mkdir $pdir/usr/include/$host_arch
182 mv $pdir/usr/include/asm $pdir/usr/include/$host_arch/
187 packages_enabled=$(dh_listpackages)
189 for package in ${packages_enabled}
193 # This must be done after linux-image, that is, we expect the
194 # debug package appears after linux-image in debian/control.
195 install_linux_image_dbg debian/linux-image-dbg debian/linux-image;;
196 linux-image-*|user-mode-linux-*)
197 install_linux_image debian/linux-image ${package};;
199 install_libc_headers debian/linux-libc-dev;;
201 install_kernel_headers debian/linux-headers ${package#linux-headers-};;
205 for package in ${packages_enabled}
209 create_package ${package} debian/linux-image-dbg;;
210 linux-image-*|user-mode-linux-*)
211 create_package ${package} debian/linux-image;;
213 create_package ${package} debian/linux-libc-dev;;
215 create_package ${package} debian/linux-headers;;