1 #!/bin/sh 1 #!/bin/sh 2 # 2 # 3 # builddeb 1.3 3 # builddeb 1.3 4 # Copyright 2003 Wichert Akkerman <wichert@wigg 4 # Copyright 2003 Wichert Akkerman <wichert@wiggy.net> 5 # 5 # 6 # Simple script to generate a deb package for 6 # Simple script to generate a deb package for a Linux kernel. All the 7 # complexity of what to do with a kernel after 7 # complexity of what to do with a kernel after it is installed or removed 8 # is left to other scripts and packages: they 8 # is left to other scripts and packages: they can install scripts in the 9 # /etc/kernel/{pre,post}{inst,rm}.d/ directori 9 # /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location 10 # specified in KDEB_HOOKDIR) that will be call 10 # specified in KDEB_HOOKDIR) that will be called on package install and 11 # removal. 11 # removal. 12 12 13 set -eu !! 13 set -e 14 14 15 is_enabled() { 15 is_enabled() { 16 grep -q "^$1=y" include/config/auto.co 16 grep -q "^$1=y" include/config/auto.conf 17 } 17 } 18 18 19 if_enabled_echo() { 19 if_enabled_echo() { 20 if is_enabled "$1"; then 20 if is_enabled "$1"; then 21 echo -n "$2" 21 echo -n "$2" 22 elif [ $# -ge 3 ]; then 22 elif [ $# -ge 3 ]; then 23 echo -n "$3" 23 echo -n "$3" 24 fi 24 fi 25 } 25 } 26 26 >> 27 create_package() { >> 28 local pname="$1" pdir="$2" >> 29 local dpkg_deb_opts >> 30 >> 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" >> 38 >> 39 # Fix ownership and permissions >> 40 if [ "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then >> 41 dpkg_deb_opts="--root-owner-group" >> 42 else >> 43 chown -R root:root "$pdir" >> 44 fi >> 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" >> 48 >> 49 # Create the package >> 50 dpkg-gencontrol -p$pname -P"$pdir" >> 51 dpkg-deb $dpkg_deb_opts ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" .. >> 52 } >> 53 27 install_linux_image () { 54 install_linux_image () { 28 pname=$1 !! 55 pdir=$1 29 pdir=debian/$1 !! 56 pname=$2 >> 57 >> 58 rm -rf ${pdir} 30 59 31 # Only some architectures with OF supp 60 # Only some architectures with OF support have this target 32 if is_enabled CONFIG_OF_EARLY_FLATTREE 61 if is_enabled CONFIG_OF_EARLY_FLATTREE && [ -d "${srctree}/arch/${SRCARCH}/boot/dts" ]; then 33 ${MAKE} -f ${srctree}/Makefile 62 ${MAKE} -f ${srctree}/Makefile INSTALL_DTBS_PATH="${pdir}/usr/lib/linux-image-${KERNELRELEASE}" dtbs_install 34 fi 63 fi 35 64 36 ${MAKE} -f ${srctree}/Makefile INSTALL !! 65 ${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${pdir}" modules_install 37 rm -f "${pdir}/lib/modules/${KERNELREL 66 rm -f "${pdir}/lib/modules/${KERNELRELEASE}/build" >> 67 rm -f "${pdir}/lib/modules/${KERNELRELEASE}/source" 38 68 39 # Install the kernel 69 # Install the kernel 40 if [ "${ARCH}" = um ] ; then 70 if [ "${ARCH}" = um ] ; then 41 mkdir -p "${pdir}/usr/lib/uml/ 71 mkdir -p "${pdir}/usr/lib/uml/modules" 42 mv "${pdir}/lib/modules/${KERN 72 mv "${pdir}/lib/modules/${KERNELRELEASE}" "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}" 43 mkdir -p "${pdir}/usr/bin" "${ 73 mkdir -p "${pdir}/usr/bin" "${pdir}/usr/share/doc/${pname}" 44 cp System.map "${pdir}/usr/lib 74 cp System.map "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}/System.map" 45 cp ${KCONFIG_CONFIG} "${pdir}/ 75 cp ${KCONFIG_CONFIG} "${pdir}/usr/share/doc/${pname}/config" 46 gzip "${pdir}/usr/share/doc/${ 76 gzip "${pdir}/usr/share/doc/${pname}/config" 47 else 77 else 48 mkdir -p "${pdir}/boot" 78 mkdir -p "${pdir}/boot" 49 cp System.map "${pdir}/boot/Sy 79 cp System.map "${pdir}/boot/System.map-${KERNELRELEASE}" 50 cp ${KCONFIG_CONFIG} "${pdir}/ 80 cp ${KCONFIG_CONFIG} "${pdir}/boot/config-${KERNELRELEASE}" 51 fi 81 fi 52 82 53 # Not all arches have the same install 83 # Not all arches have the same installed path in debian 54 # XXX: have each arch Makefile export 84 # XXX: have each arch Makefile export a variable of the canonical image install 55 # path instead 85 # path instead 56 case "${SRCARCH}" in 86 case "${SRCARCH}" in 57 um) 87 um) 58 installed_image_path="usr/bin/ 88 installed_image_path="usr/bin/linux-${KERNELRELEASE}";; 59 parisc|mips|powerpc) 89 parisc|mips|powerpc) 60 installed_image_path="boot/vml 90 installed_image_path="boot/vmlinux-${KERNELRELEASE}";; 61 *) 91 *) 62 installed_image_path="boot/vml 92 installed_image_path="boot/vmlinuz-${KERNELRELEASE}";; 63 esac 93 esac 64 cp "$(${MAKE} -s -f ${srctree}/Makefil 94 cp "$(${MAKE} -s -f ${srctree}/Makefile image_name)" "${pdir}/${installed_image_path}" 65 95 66 # Install the maintainer scripts 96 # Install the maintainer scripts 67 # Note: hook scripts under /etc/kernel 97 # Note: hook scripts under /etc/kernel are also executed by official Debian 68 # kernel packages, as well as kernel p 98 # kernel packages, as well as kernel packages built using make-kpkg. 69 # make-kpkg sets $INITRD to indicate w 99 # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and 70 # so do we; recent versions of dracut 100 # so do we; recent versions of dracut and initramfs-tools will obey this. 71 debhookdir=${KDEB_HOOKDIR:-/etc/kernel 101 debhookdir=${KDEB_HOOKDIR:-/etc/kernel} 72 for script in postinst postrm preinst 102 for script in postinst postrm preinst prerm; do 73 mkdir -p "${pdir}${debhookdir} 103 mkdir -p "${pdir}${debhookdir}/${script}.d" 74 104 75 mkdir -p "${pdir}/DEBIAN" 105 mkdir -p "${pdir}/DEBIAN" 76 cat <<-EOF > "${pdir}/DEBIAN/$ 106 cat <<-EOF > "${pdir}/DEBIAN/${script}" >> 107 77 #!/bin/sh 108 #!/bin/sh 78 109 79 set -e 110 set -e 80 111 81 # Pass maintainer script param 112 # Pass maintainer script parameters to hook scripts 82 export DEB_MAINT_PARAMS="\$*" 113 export DEB_MAINT_PARAMS="\$*" 83 114 84 # Tell initramfs builder wheth 115 # Tell initramfs builder whether it's wanted 85 export INITRD=$(if_enabled_ech 116 export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No) 86 117 87 test -d ${debhookdir}/${script 118 test -d ${debhookdir}/${script}.d && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" ${debhookdir}/${script}.d 88 exit 0 119 exit 0 89 EOF 120 EOF 90 chmod 755 "${pdir}/DEBIAN/${sc 121 chmod 755 "${pdir}/DEBIAN/${script}" 91 done 122 done 92 } 123 } 93 124 94 install_linux_image_dbg () { 125 install_linux_image_dbg () { 95 pdir=debian/$1 !! 126 pdir=$1 >> 127 image_pdir=$2 >> 128 >> 129 rm -rf ${pdir} >> 130 >> 131 for module in $(find ${image_pdir}/lib/modules/ -name *.ko -printf '%P\n'); do >> 132 module=lib/modules/${module} >> 133 mkdir -p $(dirname ${pdir}/usr/lib/debug/${module}) >> 134 # only keep debug symbols in the debug file >> 135 ${OBJCOPY} --only-keep-debug ${image_pdir}/${module} ${pdir}/usr/lib/debug/${module} >> 136 # strip original module from debug symbols >> 137 ${OBJCOPY} --strip-debug ${image_pdir}/${module} >> 138 # then add a link to those >> 139 ${OBJCOPY} --add-gnu-debuglink=${pdir}/usr/lib/debug/${module} ${image_pdir}/${module} >> 140 done 96 141 97 # Parse modules.order directly because !! 142 # re-sign stripped modules 98 # compress modules, and then run unnee !! 143 if is_enabled CONFIG_MODULE_SIG_ALL; then 99 while read -r mod; do !! 144 ${MAKE} -f ${srctree}/Makefile INSTALL_MOD_PATH="${image_pdir}" modules_sign 100 mod="${mod%.o}.ko" !! 145 fi 101 dbg="${pdir}/usr/lib/debug/lib << 102 buildid=$("${READELF}" -n "${m << 103 link="${pdir}/usr/lib/debug/.b << 104 << 105 mkdir -p "${dbg%/*}" "${link%/ << 106 "${OBJCOPY}" --only-keep-debug << 107 ln -sf --relative "${dbg}" "${ << 108 done < modules.order << 109 146 110 # Build debug package 147 # Build debug package 111 # Different tools want the image in di 148 # Different tools want the image in different locations 112 # perf 149 # perf 113 mkdir -p ${pdir}/usr/lib/debug/lib/mod 150 mkdir -p ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/ 114 cp vmlinux ${pdir}/usr/lib/debug/lib/m 151 cp vmlinux ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/ 115 # systemtap 152 # systemtap 116 mkdir -p ${pdir}/usr/lib/debug/boot/ 153 mkdir -p ${pdir}/usr/lib/debug/boot/ 117 ln -s ../lib/modules/${KERNELRELEASE}/ 154 ln -s ../lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/boot/vmlinux-${KERNELRELEASE} 118 # kdump-tools 155 # kdump-tools 119 ln -s lib/modules/${KERNELRELEASE}/vml 156 ln -s lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/vmlinux-${KERNELRELEASE} 120 } 157 } 121 158 122 install_kernel_headers () { 159 install_kernel_headers () { 123 pdir=debian/$1 !! 160 pdir=$1 124 version=${1#linux-headers-} !! 161 version=$2 >> 162 >> 163 rm -rf $pdir >> 164 >> 165 ( >> 166 cd $srctree >> 167 find . arch/$SRCARCH -maxdepth 1 -name Makefile\* >> 168 find include scripts -type f -o -type l >> 169 find arch/$SRCARCH -name Kbuild.platforms -o -name Platform >> 170 find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f >> 171 ) > debian/hdrsrcfiles >> 172 >> 173 { >> 174 if is_enabled CONFIG_OBJTOOL; then >> 175 echo tools/objtool/objtool >> 176 fi >> 177 >> 178 find arch/$SRCARCH/include Module.symvers include scripts -type f >> 179 >> 180 if is_enabled CONFIG_GCC_PLUGINS; then >> 181 find scripts/gcc-plugins -name \*.so >> 182 fi >> 183 } > debian/hdrobjfiles >> 184 >> 185 destdir=$pdir/usr/src/linux-headers-$version >> 186 mkdir -p $destdir >> 187 tar -c -f - -C $srctree -T debian/hdrsrcfiles | tar -xf - -C $destdir >> 188 tar -c -f - -T debian/hdrobjfiles | tar -xf - -C $destdir >> 189 rm -f debian/hdrsrcfiles debian/hdrobjfiles 125 190 126 CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctr !! 191 # copy .config manually to be where it's expected to be >> 192 cp $KCONFIG_CONFIG $destdir/.config 127 193 128 mkdir -p $pdir/lib/modules/$version/ 194 mkdir -p $pdir/lib/modules/$version/ 129 ln -s /usr/src/linux-headers-$version 195 ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build 130 } 196 } 131 197 132 install_libc_headers () { 198 install_libc_headers () { 133 pdir=debian/$1 !! 199 pdir=$1 134 200 >> 201 rm -rf $pdir >> 202 >> 203 $MAKE -f $srctree/Makefile headers 135 $MAKE -f $srctree/Makefile headers_ins 204 $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr 136 205 137 # move asm headers to /usr/include/<li 206 # move asm headers to /usr/include/<libc-machine>/asm to match the structure 138 # used by Debian-based distros (to sup 207 # used by Debian-based distros (to support multi-arch) 139 mkdir "$pdir/usr/include/${DEB_HOST_MU !! 208 host_arch=$(dpkg-architecture -a$(cat debian/arch) -qDEB_HOST_MULTIARCH) 140 mv "$pdir/usr/include/asm" "$pdir/usr/ !! 209 mkdir $pdir/usr/include/$host_arch 141 } !! 210 mv $pdir/usr/include/asm $pdir/usr/include/$host_arch/ >> 211 } >> 212 >> 213 rm -f debian/files >> 214 >> 215 packages_enabled=$(dh_listpackages) >> 216 >> 217 for package in ${packages_enabled} >> 218 do >> 219 case ${package} in >> 220 *-dbg) >> 221 # This must be done after linux-image, that is, we expect the >> 222 # debug package appears after linux-image in debian/control. >> 223 install_linux_image_dbg debian/linux-image-dbg debian/linux-image;; >> 224 linux-image-*|user-mode-linux-*) >> 225 install_linux_image debian/linux-image ${package};; >> 226 linux-libc-dev) >> 227 install_libc_headers debian/linux-libc-dev;; >> 228 linux-headers-*) >> 229 install_kernel_headers debian/linux-headers ${package#linux-headers-};; >> 230 esac >> 231 done 142 232 143 package=$1 !! 233 for package in ${packages_enabled} >> 234 do >> 235 case ${package} in >> 236 *-dbg) >> 237 create_package ${package} debian/linux-image-dbg;; >> 238 linux-image-*|user-mode-linux-*) >> 239 create_package ${package} debian/linux-image;; >> 240 linux-libc-dev) >> 241 create_package ${package} debian/linux-libc-dev;; >> 242 linux-headers-*) >> 243 create_package ${package} debian/linux-headers;; >> 244 esac >> 245 done 144 246 145 case "${package}" in !! 247 exit 0 146 *-dbg) << 147 install_linux_image_dbg "${package}";; << 148 linux-image-*|user-mode-linux-*) << 149 install_linux_image "${package}";; << 150 linux-libc-dev) << 151 install_libc_headers "${package}";; << 152 linux-headers-*) << 153 install_kernel_headers "${package}";; << 154 esac <<
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.