Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #!/bin/sh |
2 | # | |
4964451a | 3 | # builddeb 1.3 |
1da177e4 LT |
4 | # Copyright 2003 Wichert Akkerman <wichert@wiggy.net> |
5 | # | |
6 | # Simple script to generate a deb package for a Linux kernel. All the | |
4f66199b | 7 | # complexity of what to do with a kernel after it is installed or removed |
ac2c30f9 JSMR |
8 | # is left to other scripts and packages. Scripts can be placed into the |
9 | # preinst, postinst, prerm and postrm directories in /etc/kernel or | |
10 | # /usr/share/kernel. A different list of search directories can be given | |
11 | # via KDEB_HOOKDIR. Scripts in directories earlier in the list will | |
12 | # override scripts of the same name in later directories. The script will | |
13 | # be called on package installation and removal. | |
1da177e4 | 14 | |
c0414419 | 15 | set -eu |
1da177e4 | 16 | |
515f4c63 | 17 | is_enabled() { |
6fb7ef5a | 18 | grep -q "^$1=y" include/config/auto.conf |
515f4c63 MY |
19 | } |
20 | ||
21 | if_enabled_echo() { | |
22 | if is_enabled "$1"; then | |
23 | echo -n "$2" | |
24 | elif [ $# -ge 3 ]; then | |
25 | echo -n "$3" | |
26 | fi | |
27 | } | |
28 | ||
b611daae | 29 | install_linux_image () { |
6185d321 MY |
30 | pname=$1 |
31 | pdir=debian/$1 | |
b611daae | 32 | |
b611daae MY |
33 | # Only some architectures with OF support have this target |
34 | if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then | |
35 | ${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install | |
36 | fi | |
37 | ||
16c36f88 | 38 | ${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" INSTALL_MOD_STRIP=1 modules_install |
1240dabe | 39 | rm -f "${pdir}/lib/modules/${KERNELRELEASE}/build" |
b611daae MY |
40 | |
41 | # Install the kernel | |
42 | if [ "${ARCH}" = um ] ; then | |
1240dabe MY |
43 | mkdir -p "${pdir}/usr/lib/uml/modules" |
44 | mv "${pdir}/lib/modules/${KERNELRELEASE}" "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}" | |
b611daae MY |
45 | mkdir -p "${pdir}/usr/bin" "${pdir}/usr/share/doc/${pname}" |
46 | cp System.map "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}/System.map" | |
47 | cp ${KCONFIG_CONFIG} "${pdir}/usr/share/doc/${pname}/config" | |
48 | gzip "${pdir}/usr/share/doc/${pname}/config" | |
49 | else | |
50 | mkdir -p "${pdir}/boot" | |
51 | cp System.map "${pdir}/boot/System.map-${KERNELRELEASE}" | |
52 | cp ${KCONFIG_CONFIG} "${pdir}/boot/config-${KERNELRELEASE}" | |
53 | fi | |
54 | ||
55 | # Not all arches have the same installed path in debian | |
56 | # XXX: have each arch Makefile export a variable of the canonical image install | |
57 | # path instead | |
58 | case "${SRCARCH}" in | |
59 | um) | |
60 | installed_image_path="usr/bin/linux-${KERNELRELEASE}";; | |
61 | parisc|mips|powerpc) | |
62 | installed_image_path="boot/vmlinux-${KERNELRELEASE}";; | |
63 | *) | |
64 | installed_image_path="boot/vmlinuz-${KERNELRELEASE}";; | |
65 | esac | |
66 | cp "$(${MAKE} -s -f ${srctree}/Makefile image_name)" "${pdir}/${installed_image_path}" | |
67 | ||
54956567 NS |
68 | if [ "${ARCH}" != um ]; then |
69 | install_maint_scripts "${pdir}" | |
70 | fi | |
71 | } | |
72 | ||
73 | install_maint_scripts () { | |
b611daae MY |
74 | # Install the maintainer scripts |
75 | # Note: hook scripts under /etc/kernel are also executed by official Debian | |
76 | # kernel packages, as well as kernel packages built using make-kpkg. | |
77 | # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and | |
78 | # so do we; recent versions of dracut and initramfs-tools will obey this. | |
ac2c30f9 | 79 | debhookdir=${KDEB_HOOKDIR:-/etc/kernel /usr/share/kernel} |
b611daae | 80 | for script in postinst postrm preinst prerm; do |
b611daae MY |
81 | mkdir -p "${pdir}/DEBIAN" |
82 | cat <<-EOF > "${pdir}/DEBIAN/${script}" | |
b611daae MY |
83 | #!/bin/sh |
84 | ||
85 | set -e | |
86 | ||
87 | # Pass maintainer script parameters to hook scripts | |
88 | export DEB_MAINT_PARAMS="\$*" | |
89 | ||
90 | # Tell initramfs builder whether it's wanted | |
91 | export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No) | |
92 | ||
ac2c30f9 JSMR |
93 | # run-parts will error out if one of its directory arguments does not |
94 | # exist, so filter the list of hook directories accordingly. | |
95 | hookdirs= | |
96 | for dir in ${debhookdir}; do | |
97 | test -d "\$dir/${script}.d" || continue | |
98 | hookdirs="\$hookdirs \$dir/${script}.d" | |
99 | done | |
100 | hookdirs="\${hookdirs# }" | |
101 | test -n "\$hookdirs" && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" \$hookdirs | |
b611daae MY |
102 | exit 0 |
103 | EOF | |
104 | chmod 755 "${pdir}/DEBIAN/${script}" | |
105 | done | |
106 | } | |
107 | ||
108 | install_linux_image_dbg () { | |
6185d321 | 109 | pdir=debian/$1 |
b611daae | 110 | |
16c36f88 MY |
111 | # Parse modules.order directly because 'make modules_install' may sign, |
112 | # compress modules, and then run unneeded depmod. | |
bcbbf493 MF |
113 | if is_enabled CONFIG_MODULES; then |
114 | while read -r mod; do | |
115 | mod="${mod%.o}.ko" | |
116 | dbg="${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/kernel/${mod}" | |
117 | buildid=$("${READELF}" -n "${mod}" | sed -n 's@^.*Build ID: \(..\)\(.*\)@\1/\2@p') | |
118 | link="${pdir}/usr/lib/debug/.build-id/${buildid}.debug" | |
119 | ||
120 | mkdir -p "${dbg%/*}" "${link%/*}" | |
121 | "${OBJCOPY}" --only-keep-debug "${mod}" "${dbg}" | |
122 | ln -sf --relative "${dbg}" "${link}" | |
123 | done < modules.order | |
124 | fi | |
b611daae MY |
125 | |
126 | # Build debug package | |
127 | # Different tools want the image in different locations | |
128 | # perf | |
129 | mkdir -p ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/ | |
130 | cp vmlinux ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/ | |
131 | # systemtap | |
132 | mkdir -p ${pdir}/usr/lib/debug/boot/ | |
133 | ln -s ../lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/boot/vmlinux-${KERNELRELEASE} | |
134 | # kdump-tools | |
135 | ln -s lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/vmlinux-${KERNELRELEASE} | |
136 | } | |
137 | ||
36862e14 | 138 | install_kernel_headers () { |
6185d321 MY |
139 | pdir=debian/$1 |
140 | version=${1#linux-headers-} | |
3126c17d | 141 | |
e2c31822 | 142 | CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}" |
3126c17d MY |
143 | |
144 | mkdir -p $pdir/lib/modules/$version/ | |
145 | ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build | |
146 | } | |
147 | ||
36862e14 | 148 | install_libc_headers () { |
6185d321 | 149 | pdir=debian/$1 |
451dff37 | 150 | |
451dff37 MY |
151 | $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr |
152 | ||
153 | # move asm headers to /usr/include/<libc-machine>/asm to match the structure | |
154 | # used by Debian-based distros (to support multi-arch) | |
159956f3 MY |
155 | mkdir "$pdir/usr/include/${DEB_HOST_MULTIARCH}" |
156 | mv "$pdir/usr/include/asm" "$pdir/usr/include/${DEB_HOST_MULTIARCH}" | |
451dff37 MY |
157 | } |
158 | ||
1d7bae8f MY |
159 | package=$1 |
160 | ||
161 | case "${package}" in | |
162 | *-dbg) | |
163 | install_linux_image_dbg "${package}";; | |
164 | linux-image-*|user-mode-linux-*) | |
165 | install_linux_image "${package}";; | |
166 | linux-libc-dev) | |
167 | install_libc_headers "${package}";; | |
168 | linux-headers-*) | |
169 | install_kernel_headers "${package}";; | |
170 | esac |