Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 #
0003 # builddeb 1.3
0004 # Copyright 2003 Wichert Akkerman <wichert@wiggy.net>
0005 #
0006 # Simple script to generate a deb package for a Linux kernel. All the
0007 # complexity of what to do with a kernel after it is installed or removed
0008 # is left to other scripts and packages: they can install scripts in the
0009 # /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
0010 # specified in KDEB_HOOKDIR) that will be called on package install and
0011 # removal.
0012 
0013 set -e
0014 
0015 is_enabled() {
0016         grep -q "^$1=y" include/config/auto.conf
0017 }
0018 
0019 if_enabled_echo() {
0020         if is_enabled "$1"; then
0021                 echo -n "$2"
0022         elif [ $# -ge 3 ]; then
0023                 echo -n "$3"
0024         fi
0025 }
0026 
0027 create_package() {
0028         local pname="$1" pdir="$2"
0029         local dpkg_deb_opts
0030 
0031         mkdir -m 755 -p "$pdir/DEBIAN"
0032         mkdir -p "$pdir/usr/share/doc/$pname"
0033         cp debian/copyright "$pdir/usr/share/doc/$pname/"
0034         cp debian/changelog "$pdir/usr/share/doc/$pname/changelog.Debian"
0035         gzip -n -9 "$pdir/usr/share/doc/$pname/changelog.Debian"
0036         sh -c "cd '$pdir'; find . -type f ! -path './DEBIAN/*' -printf '%P\0' \
0037                 | xargs -r0 md5sum > DEBIAN/md5sums"
0038 
0039         # Fix ownership and permissions
0040         if [ "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
0041                 dpkg_deb_opts="--root-owner-group"
0042         else
0043                 chown -R root:root "$pdir"
0044         fi
0045         chmod -R go-w "$pdir"
0046         # in case we are in a restrictive umask environment like 0077
0047         chmod -R a+rX "$pdir"
0048         # in case we build in a setuid/setgid directory
0049         chmod -R ug-s "$pdir"
0050 
0051         # Create the package
0052         dpkg-gencontrol -p$pname -P"$pdir"
0053         dpkg-deb $dpkg_deb_opts ${KDEB_COMPRESS:+-Z$KDEB_COMPRESS} --build "$pdir" ..
0054 }
0055 
0056 deploy_kernel_headers () {
0057         pdir=$1
0058 
0059         rm -rf $pdir
0060 
0061         (
0062                 cd $srctree
0063                 find . arch/$SRCARCH -maxdepth 1 -name Makefile\*
0064                 find include scripts -type f -o -type l
0065                 find arch/$SRCARCH -name Kbuild.platforms -o -name Platform
0066                 find $(find arch/$SRCARCH -name include -o -name scripts -type d) -type f
0067         ) > debian/hdrsrcfiles
0068 
0069         {
0070                 if is_enabled CONFIG_OBJTOOL; then
0071                         echo tools/objtool/objtool
0072                 fi
0073 
0074                 find arch/$SRCARCH/include Module.symvers include scripts -type f
0075 
0076                 if is_enabled CONFIG_GCC_PLUGINS; then
0077                         find scripts/gcc-plugins -name \*.so
0078                 fi
0079         } > debian/hdrobjfiles
0080 
0081         destdir=$pdir/usr/src/linux-headers-$version
0082         mkdir -p $destdir
0083         tar -c -f - -C $srctree -T debian/hdrsrcfiles | tar -xf - -C $destdir
0084         tar -c -f - -T debian/hdrobjfiles | tar -xf - -C $destdir
0085         rm -f debian/hdrsrcfiles debian/hdrobjfiles
0086 
0087         # copy .config manually to be where it's expected to be
0088         cp $KCONFIG_CONFIG $destdir/.config
0089 
0090         mkdir -p $pdir/lib/modules/$version/
0091         ln -s /usr/src/linux-headers-$version $pdir/lib/modules/$version/build
0092 }
0093 
0094 deploy_libc_headers () {
0095         pdir=$1
0096 
0097         rm -rf $pdir
0098 
0099         $MAKE -f $srctree/Makefile headers
0100         $MAKE -f $srctree/Makefile headers_install INSTALL_HDR_PATH=$pdir/usr
0101 
0102         # move asm headers to /usr/include/<libc-machine>/asm to match the structure
0103         # used by Debian-based distros (to support multi-arch)
0104         host_arch=$(dpkg-architecture -a$(cat debian/arch) -qDEB_HOST_MULTIARCH)
0105         mkdir $pdir/usr/include/$host_arch
0106         mv $pdir/usr/include/asm $pdir/usr/include/$host_arch/
0107 }
0108 
0109 version=$KERNELRELEASE
0110 tmpdir=debian/linux-image
0111 dbg_dir=debian/linux-image-dbg
0112 packagename=linux-image-$version
0113 dbg_packagename=$packagename-dbg
0114 
0115 if [ "$ARCH" = "um" ] ; then
0116         packagename=user-mode-linux-$version
0117 fi
0118 
0119 # Not all arches have the same installed path in debian
0120 # XXX: have each arch Makefile export a variable of the canonical image install
0121 # path instead
0122 case $ARCH in
0123 um)
0124         installed_image_path="usr/bin/linux-$version"
0125         ;;
0126 parisc|mips|powerpc)
0127         installed_image_path="boot/vmlinux-$version"
0128         ;;
0129 *)
0130         installed_image_path="boot/vmlinuz-$version"
0131 esac
0132 
0133 BUILD_DEBUG=$(if_enabled_echo CONFIG_DEBUG_INFO Yes)
0134 
0135 # Setup the directory structure
0136 rm -rf "$tmpdir" "$dbg_dir" debian/files
0137 mkdir -m 755 -p "$tmpdir/DEBIAN"
0138 mkdir -p "$tmpdir/lib" "$tmpdir/boot"
0139 
0140 # Install the kernel
0141 if [ "$ARCH" = "um" ] ; then
0142         mkdir -p "$tmpdir/usr/lib/uml/modules/$version" "$tmpdir/usr/bin" "$tmpdir/usr/share/doc/$packagename"
0143         cp System.map "$tmpdir/usr/lib/uml/modules/$version/System.map"
0144         cp $KCONFIG_CONFIG "$tmpdir/usr/share/doc/$packagename/config"
0145         gzip "$tmpdir/usr/share/doc/$packagename/config"
0146 else
0147         cp System.map "$tmpdir/boot/System.map-$version"
0148         cp $KCONFIG_CONFIG "$tmpdir/boot/config-$version"
0149 fi
0150 cp "$($MAKE -s -f $srctree/Makefile image_name)" "$tmpdir/$installed_image_path"
0151 
0152 if is_enabled CONFIG_OF_EARLY_FLATTREE; then
0153         # Only some architectures with OF support have this target
0154         if [ -d "${srctree}/arch/$SRCARCH/boot/dts" ]; then
0155                 $MAKE -f $srctree/Makefile INSTALL_DTBS_PATH="$tmpdir/usr/lib/$packagename" dtbs_install
0156         fi
0157 fi
0158 
0159 if is_enabled CONFIG_MODULES; then
0160         INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_install
0161         rm -f "$tmpdir/lib/modules/$version/build"
0162         rm -f "$tmpdir/lib/modules/$version/source"
0163         if [ "$ARCH" = "um" ] ; then
0164                 mv "$tmpdir/lib/modules/$version"/* "$tmpdir/usr/lib/uml/modules/$version/"
0165                 rmdir "$tmpdir/lib/modules/$version"
0166         fi
0167         if [ -n "$BUILD_DEBUG" ] ; then
0168                 for module in $(find $tmpdir/lib/modules/ -name *.ko -printf '%P\n'); do
0169                         module=lib/modules/$module
0170                         mkdir -p $(dirname $dbg_dir/usr/lib/debug/$module)
0171                         # only keep debug symbols in the debug file
0172                         $OBJCOPY --only-keep-debug $tmpdir/$module $dbg_dir/usr/lib/debug/$module
0173                         # strip original module from debug symbols
0174                         $OBJCOPY --strip-debug $tmpdir/$module
0175                         # then add a link to those
0176                         $OBJCOPY --add-gnu-debuglink=$dbg_dir/usr/lib/debug/$module $tmpdir/$module
0177                 done
0178 
0179                 # resign stripped modules
0180                 if is_enabled CONFIG_MODULE_SIG_ALL; then
0181                         INSTALL_MOD_PATH="$tmpdir" $MAKE -f $srctree/Makefile modules_sign
0182                 fi
0183         fi
0184 fi
0185 
0186 # Install the maintainer scripts
0187 # Note: hook scripts under /etc/kernel are also executed by official Debian
0188 # kernel packages, as well as kernel packages built using make-kpkg.
0189 # make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
0190 # so do we; recent versions of dracut and initramfs-tools will obey this.
0191 debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
0192 for script in postinst postrm preinst prerm ; do
0193         mkdir -p "$tmpdir$debhookdir/$script.d"
0194         cat <<EOF > "$tmpdir/DEBIAN/$script"
0195 #!/bin/sh
0196 
0197 set -e
0198 
0199 # Pass maintainer script parameters to hook scripts
0200 export DEB_MAINT_PARAMS="\$*"
0201 
0202 # Tell initramfs builder whether it's wanted
0203 export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
0204 
0205 test -d $debhookdir/$script.d && run-parts --arg="$version" --arg="/$installed_image_path" $debhookdir/$script.d
0206 exit 0
0207 EOF
0208         chmod 755 "$tmpdir/DEBIAN/$script"
0209 done
0210 
0211 if [ "$ARCH" != "um" ]; then
0212         if is_enabled CONFIG_MODULES; then
0213                 deploy_kernel_headers debian/linux-headers
0214                 create_package linux-headers-$version debian/linux-headers
0215         fi
0216 
0217         deploy_libc_headers debian/linux-libc-dev
0218         create_package linux-libc-dev debian/linux-libc-dev
0219 fi
0220 
0221 create_package "$packagename" "$tmpdir"
0222 
0223 if [ -n "$BUILD_DEBUG" ] ; then
0224         # Build debug package
0225         # Different tools want the image in different locations
0226         # perf
0227         mkdir -p $dbg_dir/usr/lib/debug/lib/modules/$version/
0228         cp vmlinux $dbg_dir/usr/lib/debug/lib/modules/$version/
0229         # systemtap
0230         mkdir -p $dbg_dir/usr/lib/debug/boot/
0231         ln -s ../lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/boot/vmlinux-$version
0232         # kdump-tools
0233         ln -s lib/modules/$version/vmlinux $dbg_dir/usr/lib/debug/vmlinux-$version
0234         create_package "$dbg_packagename" "$dbg_dir"
0235 fi
0236 
0237 exit 0