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" 38 67 39 # Install the kernel 68 # Install the kernel 40 if [ "${ARCH}" = um ] ; then 69 if [ "${ARCH}" = um ] ; then 41 mkdir -p "${pdir}/usr/lib/uml/ 70 mkdir -p "${pdir}/usr/lib/uml/modules" 42 mv "${pdir}/lib/modules/${KERN 71 mv "${pdir}/lib/modules/${KERNELRELEASE}" "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}" 43 mkdir -p "${pdir}/usr/bin" "${ 72 mkdir -p "${pdir}/usr/bin" "${pdir}/usr/share/doc/${pname}" 44 cp System.map "${pdir}/usr/lib 73 cp System.map "${pdir}/usr/lib/uml/modules/${KERNELRELEASE}/System.map" 45 cp ${KCONFIG_CONFIG} "${pdir}/ 74 cp ${KCONFIG_CONFIG} "${pdir}/usr/share/doc/${pname}/config" 46 gzip "${pdir}/usr/share/doc/${ 75 gzip "${pdir}/usr/share/doc/${pname}/config" 47 else 76 else 48 mkdir -p "${pdir}/boot" 77 mkdir -p "${pdir}/boot" 49 cp System.map "${pdir}/boot/Sy 78 cp System.map "${pdir}/boot/System.map-${KERNELRELEASE}" 50 cp ${KCONFIG_CONFIG} "${pdir}/ 79 cp ${KCONFIG_CONFIG} "${pdir}/boot/config-${KERNELRELEASE}" 51 fi 80 fi 52 81 53 # Not all arches have the same install 82 # Not all arches have the same installed path in debian 54 # XXX: have each arch Makefile export 83 # XXX: have each arch Makefile export a variable of the canonical image install 55 # path instead 84 # path instead 56 case "${SRCARCH}" in 85 case "${SRCARCH}" in 57 um) 86 um) 58 installed_image_path="usr/bin/ 87 installed_image_path="usr/bin/linux-${KERNELRELEASE}";; 59 parisc|mips|powerpc) 88 parisc|mips|powerpc) 60 installed_image_path="boot/vml 89 installed_image_path="boot/vmlinux-${KERNELRELEASE}";; 61 *) 90 *) 62 installed_image_path="boot/vml 91 installed_image_path="boot/vmlinuz-${KERNELRELEASE}";; 63 esac 92 esac 64 cp "$(${MAKE} -s -f ${srctree}/Makefil 93 cp "$(${MAKE} -s -f ${srctree}/Makefile image_name)" "${pdir}/${installed_image_path}" 65 94 66 # Install the maintainer scripts 95 # Install the maintainer scripts 67 # Note: hook scripts under /etc/kernel 96 # Note: hook scripts under /etc/kernel are also executed by official Debian 68 # kernel packages, as well as kernel p 97 # kernel packages, as well as kernel packages built using make-kpkg. 69 # make-kpkg sets $INITRD to indicate w 98 # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and 70 # so do we; recent versions of dracut 99 # so do we; recent versions of dracut and initramfs-tools will obey this. 71 debhookdir=${KDEB_HOOKDIR:-/etc/kernel 100 debhookdir=${KDEB_HOOKDIR:-/etc/kernel} 72 for script in postinst postrm preinst 101 for script in postinst postrm preinst prerm; do 73 mkdir -p "${pdir}${debhookdir} 102 mkdir -p "${pdir}${debhookdir}/${script}.d" 74 103 75 mkdir -p "${pdir}/DEBIAN" 104 mkdir -p "${pdir}/DEBIAN" 76 cat <<-EOF > "${pdir}/DEBIAN/$ 105 cat <<-EOF > "${pdir}/DEBIAN/${script}" >> 106 77 #!/bin/sh 107 #!/bin/sh 78 108 79 set -e 109 set -e 80 110 81 # Pass maintainer script param 111 # Pass maintainer script parameters to hook scripts 82 export DEB_MAINT_PARAMS="\$*" 112 export DEB_MAINT_PARAMS="\$*" 83 113 84 # Tell initramfs builder wheth 114 # Tell initramfs builder whether it's wanted 85 export INITRD=$(if_enabled_ech 115 export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No) 86 116 87 test -d ${debhookdir}/${script 117 test -d ${debhookdir}/${script}.d && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" ${debhookdir}/${script}.d 88 exit 0 118 exit 0 89 EOF 119 EOF 90 chmod 755 "${pdir}/DEBIAN/${sc 120 chmod 755 "${pdir}/DEBIAN/${script}" 91 done 121 done 92 } 122 } 93 123 94 install_linux_image_dbg () { 124 install_linux_image_dbg () { 95 pdir=debian/$1 !! 125 pdir=$1 >> 126 image_pdir=$2 96 127 97 # Parse modules.order directly because !! 128 rm -rf ${pdir} 98 # compress modules, and then run unnee !! 129 99 while read -r mod; do !! 130 for module in $(find ${image_pdir}/lib/modules/ -name *.ko -printf '%P\n'); do 100 mod="${mod%.o}.ko" !! 131 module=lib/modules/${module} 101 dbg="${pdir}/usr/lib/debug/lib !! 132 mkdir -p $(dirname ${pdir}/usr/lib/debug/${module}) 102 buildid=$("${READELF}" -n "${m !! 133 # only keep debug symbols in the debug file 103 link="${pdir}/usr/lib/debug/.b !! 134 ${OBJCOPY} --only-keep-debug ${image_pdir}/${module} ${pdir}/usr/lib/debug/${module} 104 !! 135 # strip original module from debug symbols 105 mkdir -p "${dbg%/*}" "${link%/ !! 136 ${OBJCOPY} --strip-debug ${image_pdir}/${module} 106 "${OBJCOPY}" --only-keep-debug !! 137 # then add a link to those 107 ln -sf --relative "${dbg}" "${ !! 138 ${OBJCOPY} --add-gnu-debuglink=${pdir}/usr/lib/debug/${module} ${image_pdir}/${module} 108 done < modules.order !! 139 done >> 140 >> 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 >> 144 fi 109 145 110 # Build debug package 146 # Build debug package 111 # Different tools want the image in di 147 # Different tools want the image in different locations 112 # perf 148 # perf 113 mkdir -p ${pdir}/usr/lib/debug/lib/mod 149 mkdir -p ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/ 114 cp vmlinux ${pdir}/usr/lib/debug/lib/m 150 cp vmlinux ${pdir}/usr/lib/debug/lib/modules/${KERNELRELEASE}/ 115 # systemtap 151 # systemtap 116 mkdir -p ${pdir}/usr/lib/debug/boot/ 152 mkdir -p ${pdir}/usr/lib/debug/boot/ 117 ln -s ../lib/modules/${KERNELRELEASE}/ 153 ln -s ../lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/boot/vmlinux-${KERNELRELEASE} 118 # kdump-tools 154 # kdump-tools 119 ln -s lib/modules/${KERNELRELEASE}/vml 155 ln -s lib/modules/${KERNELRELEASE}/vmlinux ${pdir}/usr/lib/debug/vmlinux-${KERNELRELEASE} 120 } 156 } 121 157 122 install_kernel_headers () { 158 install_kernel_headers () { 123 pdir=debian/$1 !! 159 pdir=$1 124 version=${1#linux-headers-} !! 160 version=$2 125 161 126 CC="${DEB_HOST_GNU_TYPE}-gcc" "${srctr !! 162 rm -rf $pdir >> 163 >> 164 "${srctree}/scripts/package/install-extmod-build" "${pdir}/usr/src/linux-headers-${version}" 127 165 128 mkdir -p $pdir/lib/modules/$version/ 166 mkdir -p $pdir/lib/modules/$version/ 129 ln -s /usr/src/linux-headers-$version 167 ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build 130 } 168 } 131 169 132 install_libc_headers () { 170 install_libc_headers () { 133 pdir=debian/$1 !! 171 pdir=$1 >> 172 >> 173 rm -rf $pdir 134 174 >> 175 $MAKE -f $srctree/Makefile headers 135 $MAKE -f $srctree/Makefile headers_ins 176 $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr 136 177 137 # move asm headers to /usr/include/<li 178 # move asm headers to /usr/include/<libc-machine>/asm to match the structure 138 # used by Debian-based distros (to sup 179 # used by Debian-based distros (to support multi-arch) 139 mkdir "$pdir/usr/include/${DEB_HOST_MU !! 180 host_arch=$(dpkg-architecture -a$DEB_HOST_ARCH -qDEB_HOST_MULTIARCH) 140 mv "$pdir/usr/include/asm" "$pdir/usr/ !! 181 mkdir $pdir/usr/include/$host_arch 141 } !! 182 mv $pdir/usr/include/asm $pdir/usr/include/$host_arch/ >> 183 } >> 184 >> 185 rm -f debian/files >> 186 >> 187 packages_enabled=$(dh_listpackages) >> 188 >> 189 for package in ${packages_enabled} >> 190 do >> 191 case ${package} in >> 192 *-dbg) >> 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};; >> 198 linux-libc-dev) >> 199 install_libc_headers debian/linux-libc-dev;; >> 200 linux-headers-*) >> 201 install_kernel_headers debian/linux-headers ${package#linux-headers-};; >> 202 esac >> 203 done 142 204 143 package=$1 !! 205 for package in ${packages_enabled} >> 206 do >> 207 case ${package} in >> 208 *-dbg) >> 209 create_package ${package} debian/linux-image-dbg;; >> 210 linux-image-*|user-mode-linux-*) >> 211 create_package ${package} debian/linux-image;; >> 212 linux-libc-dev) >> 213 create_package ${package} debian/linux-libc-dev;; >> 214 linux-headers-*) >> 215 create_package ${package} debian/linux-headers;; >> 216 esac >> 217 done 144 218 145 case "${package}" in !! 219 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.