]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - debian/rules.d/2-binary-arch.mk
KVM: PPC: Use preregistered memory API to access TCE list
[mirror_ubuntu-zesty-kernel.git] / debian / rules.d / 2-binary-arch.mk
index 9ed5f2234c61bd8e2aa5e8d840eccb9e7a8bb173..edda3f3ba845ee66fe2d680cd172234f3673abbf 100644 (file)
@@ -10,6 +10,13 @@ build_cd =
 build_O  = O=$(builddir)/build-$*
 endif
 
+# Typically supplied from the arch makefile, e.g., debian.master/control.d/armhf.mk
+ifneq ($(gcc),)
+kmake += CC=$(CROSS_COMPILE)$(gcc)
+endif
+
+shlibdeps_opts = $(if $(CROSS_COMPILE),-- -l$(CROSS_COMPILE:%-=/usr/%)/lib)
+
 $(stampdir)/stamp-prepare-%: config-prepare-check-%
        @echo Debug: $@
        @touch $@
@@ -32,27 +39,72 @@ prepare-%: $(stampdir)/stamp-prepare-%
 build-%: $(stampdir)/stamp-build-%
        @echo Debug: $@
 
+define build_zfs =
+       #
+       # SPL/ZFS wants a fully built kernel before you can configure and build.
+       # It seems to be impossible to tease out the application configuration
+       # from the modules, but at least one can build just the modules.
+       #
+       install -d $(builddir)/build-$*/spl
+       rsync -a --exclude=dkms.conf --delete spl/ $(builddir)/build-$*/spl/
+       cd $(builddir)/build-$*/spl; sh autogen.sh; sh configure $(splopts)
+       $(kmake) -C $(builddir)/build-$*/spl/module $(conc_level)
+
+       install -d $(builddir)/build-$*/zfs
+       rsync -a --exclude=dkms.conf --delete zfs/ $(builddir)/build-$*/zfs/
+       cd $(builddir)/build-$*/zfs; sh autogen.sh; sh configure $(zfsopts)
+       $(kmake) -C $(builddir)/build-$*/zfs/module $(conc_level)
+endef
+
 # Do the actual build, including image and modules
 $(stampdir)/stamp-build-%: target_flavour = $*
+$(stampdir)/stamp-build-%: splopts  = --with-linux=$(CURDIR)
+$(stampdir)/stamp-build-%: splopts += --with-linux-obj=$(builddir)/build-$*
+$(stampdir)/stamp-build-%: zfsopts  = $(splopts)
+$(stampdir)/stamp-build-%: zfsopts += --with-spl=$(builddir)/build-$*/spl
+$(stampdir)/stamp-build-%: zfsopts += --with-spl-obj=$(builddir)/build-$*/spl
+$(stampdir)/stamp-build-%: zfsopts += --prefix=/usr --with-config=kernel
 $(stampdir)/stamp-build-%: bldimg = $(call custom_override,build_image,$*)
-$(stampdir)/stamp-build-%: dtb_target = $(dtb_files_$*)
+$(stampdir)/stamp-build-%: enable_zfs = $(call custom_override,do_zfs,$*)
 $(stampdir)/stamp-build-%: $(stampdir)/stamp-prepare-%
        @echo Debug: $@ build_image $(build_image) bldimg $(bldimg)
-       $(build_cd) $(kmake) $(build_O) $(conc_level) $(bldimg) modules $(dtb_target)
+       $(build_cd) $(kmake) $(build_O) $(conc_level) $(bldimg) modules $(if $(filter true,$(do_dtbs)),dtbs)
+
+       $(if $(filter true,$(enable_zfs)),$(call build_zfs))
+
        @touch $@
 
+define install_zfs =
+       cd $(builddir)/build-$*/spl/module; \
+               $(kmake) -C $(builddir)/build-$* SUBDIRS=`pwd` modules_install $(splopts)
+       cd $(builddir)/build-$*/zfs/module; \
+               $(kmake) -C $(builddir)/build-$* SUBDIRS=`pwd` modules_install $(zfsopts)
+endef
+
 # Install the finished build
 install-%: pkgdir = $(CURDIR)/debian/$(bin_pkg_name)-$*
 install-%: pkgdir_ex = $(CURDIR)/debian/$(extra_pkg_name)-$*
 install-%: bindoc = $(pkgdir)/usr/share/doc/$(bin_pkg_name)-$*
 install-%: dbgpkgdir = $(CURDIR)/debian/$(bin_pkg_name)-$*-dbgsym
 install-%: signed = $(CURDIR)/debian/$(bin_pkg_name)-signed
+install-%: toolspkgdir = $(CURDIR)/debian/$(tools_flavour_pkg_name)-$*
+install-%: cloudpkgdir = $(CURDIR)/debian/$(cloud_flavour_pkg_name)-$*
 install-%: basepkg = $(hdrs_pkg_name)
+install-%: indeppkg = $(indep_hdrs_pkg_name)
 install-%: kernfile = $(call custom_override,kernel_file,$*)
 install-%: instfile = $(call custom_override,install_file,$*)
 install-%: hdrdir = $(CURDIR)/debian/$(basepkg)-$*/usr/src/$(basepkg)-$*
 install-%: target_flavour = $*
-install-%: dtb_files = $(dtb_files_$*)
+install-%: MODHASHALGO=sha512
+install-%: MODSECKEY=$(builddir)/build-$*/certs/signing_key.pem
+install-%: MODPUBKEY=$(builddir)/build-$*/certs/signing_key.x509
+install-%: build_dir=$(builddir)/build-$*
+install-%: enable_zfs = $(call custom_override,do_zfs,$*)
+install-%: splopts  = INSTALL_MOD_STRIP=1
+install-%: splopts += INSTALL_MOD_PATH=$(pkgdir)/
+install-%: splopts += INSTALL_MOD_DIR=kernel/zfs
+install-%: splopts += $(conc_level)
+install-%: zfsopts  = $(splopts)
 install-%: checks-%
        @echo Debug: $@ kernel_file $(kernel_file) kernfile $(kernfile) install_file $(install_file) instfile $(instfile)
        dh_testdir
@@ -76,17 +128,15 @@ else
        chmod 600 $(pkgdir)/boot/$(instfile)-$(abi_release)-$*
 endif
 
-ifeq ($(arch),amd64)
 ifeq ($(uefi_signed),true)
        install -d $(signed)/$(release)-$(revision)
        # Check to see if this supports handoff, if not do not sign it.
        # Check the identification area magic and version >= 0x020b
-       handoff=`dd if="$(pkgdir)/boot/$(instfile)-$(abi_release)-$*" bs=1 skip=514 count=6 2>/dev/null | od -s | awk '($$1 == 0 && $$2 == 25672 && $$3 == 21362 && $$4 >= 523) { print "GOOD" }'`; \
+       handoff=`dd if="$(pkgdir)/boot/$(instfile)-$(abi_release)-$*" bs=1 skip=514 count=6 2>/dev/null | od -s | gawk '($$1 == 0 && $$2 == 25672 && $$3 == 21362 && $$4 >= 523) { print "GOOD" }'`; \
        if [ "$$handoff" = "GOOD" ]; then \
                cp -p $(pkgdir)/boot/$(instfile)-$(abi_release)-$* \
                        $(signed)/$(release)-$(revision)/$(instfile)-$(abi_release)-$*.efi; \
        fi
-endif
 endif
 
        install -m644 $(builddir)/build-$*/.config \
@@ -95,12 +145,13 @@ endif
                $(pkgdir)/boot/abi-$(abi_release)-$*
        install -m600 $(builddir)/build-$*/System.map \
                $(pkgdir)/boot/System.map-$(abi_release)-$*
-       if [ "$(dtb_files)" ]; then \
-               install -d $(pkgdir)/lib/firmware/$(abi_release)-$*/device-tree; \
-               for dtb_file in $(dtb_files); do \
-                       install -m644 $(builddir)/build-$*/arch/$(build_arch)/boot/dts/$$dtb_file \
-                               $(pkgdir)/lib/firmware/$(abi_release)-$*/device-tree/$$dtb_file; \
-               done \
+       if [ "$(filter true,$(do_dtbs))" ]; then \
+               $(build_cd) $(kmake) $(build_O) $(conc_level) dtbs_install \
+                       INSTALL_DTBS_PATH=$(pkgdir)/lib/firmware/$(abi_release)-$*/device-tree; \
+               ( cd $(pkgdir)/lib/firmware/$(abi_release)-$*/ && find device-tree -print ) | \
+               while read dtb_file; do \
+                       echo "$$dtb_file ?" >> $(DEBIAN)/d-i/firmware/$(arch)/kernel-image; \
+               done; \
        fi
 ifeq ($(no_dumpfile),)
        makedumpfile -g $(pkgdir)/boot/vmcoreinfo-$(abi_release)-$* \
@@ -108,22 +159,48 @@ ifeq ($(no_dumpfile),)
        chmod 0600 $(pkgdir)/boot/vmcoreinfo-$(abi_release)-$*
 endif
 
-       $(build_cd) $(kmake) $(build_O) $(conc_level) modules_install \
+       $(build_cd) $(kmake) $(build_O) $(conc_level) modules_install $(vdso) \
                INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=$(pkgdir)/ \
                INSTALL_FW_PATH=$(pkgdir)/lib/firmware/$(abi_release)-$*
 
+       $(if $(filter true,$(enable_zfs)),$(call install_zfs))
+
+       #
+       # Build module blacklists:
+       #  - blacklist all watchdog drivers (LP:1432837)
+       #
+       install -d $(pkgdir)/lib/modprobe.d
+       echo "# Kernel supplied blacklist for $(src_pkg_name) $(abi_release)-$* $(arch)" \
+               >$(pkgdir)/lib/modprobe.d/blacklist_$(src_pkg_name)_$(abi_release)-$*.conf
+       for conf in $(arch)-$* $(arch) common.conf; do \
+               if [ -f $(DEBIAN)/modprobe.d/$$conf ]; then \
+                       echo "# modprobe.d/$$conf"; \
+                       cat $(DEBIAN)/modprobe.d/$$conf; \
+               fi; \
+       done >>$(pkgdir)/lib/modprobe.d/blacklist_$(src_pkg_name)_$(abi_release)-$*.conf
+       echo "# Autogenerated watchdog blacklist" \
+               >>$(pkgdir)/lib/modprobe.d/blacklist_$(src_pkg_name)_$(abi_release)-$*.conf
+       ls -1 $(pkgdir)/lib/modules/$(abi_release)-$*/kernel/drivers/watchdog/ | \
+               sed -e 's/^/blacklist /' -e 's/.ko$$//' | \
+               sort -u \
+               >>$(pkgdir)/lib/modprobe.d/blacklist_$(src_pkg_name)_$(abi_release)-$*.conf
+
 ifeq ($(do_extras_package),true)
        #
        # Remove all modules not in the inclusion list.
        #
        if [ -f $(DEBIAN)/control.d/$(target_flavour).inclusion-list ] ; then \
+               /sbin/depmod -v -b $(pkgdir) $(abi_release)-$* | \
+                       sed -e "s@$(pkgdir)/lib/modules/$(abi_release)-$*/kernel/@@g" | \
+                       awk '{ print $$1 " " $$NF}' >$(build_dir)/module-inclusion.depmap; \
                mkdir -p $(pkgdir_ex)/lib/modules/$(abi_release)-$*; \
                mv $(pkgdir)/lib/modules/$(abi_release)-$*/kernel \
                        $(pkgdir_ex)/lib/modules/$(abi_release)-$*/kernel; \
                $(SHELL) $(DROOT)/scripts/module-inclusion --master \
                        $(pkgdir_ex)/lib/modules/$(abi_release)-$*/kernel \
                        $(pkgdir)/lib/modules/$(abi_release)-$*/kernel \
-                       $(DEBIAN)/control.d/$(target_flavour).inclusion-list 2>&1 | \
+                       $(DEBIAN)/control.d/$(target_flavour).inclusion-list \
+                       $(build_dir)/module-inclusion.depmap 2>&1 | \
                                tee $(target_flavour).inclusion-list.log; \
                /sbin/depmod -b $(pkgdir) -ea -F $(pkgdir)/boot/System.map-$(abi_release)-$* \
                        $(abi_release)-$* 2>&1 |tee $(target_flavour).depmod.log; \
@@ -145,7 +222,7 @@ endif
        # Some initramfs-tools specific modules
        install -d $(pkgdir)/lib/modules/$(abi_release)-$*/initrd
        if [ -f $(pkgdir)/lib/modules/$(abi_release)-$*/kernel/drivers/video/vesafb.ko ]; then\
-         ln -f $(pkgdir)/lib/modules/$(abi_release)-$*/kernel/drivers/video/vesafb.ko \
+         $(LN) $(pkgdir)/lib/modules/$(abi_release)-$*/kernel/drivers/video/vesafb.ko \
                $(pkgdir)/lib/modules/$(abi_release)-$*/initrd/; \
        fi
 
@@ -164,7 +241,7 @@ ifeq ($(do_extras_package),true)
                for script in postinst postrm ; do                              \
                        sed -e 's/=V/$(abi_release)-$*/g' -e 's/=K/$(instfile)/g'               \
                            -e 's/=L/$(loader)/g'         -e 's@=B@$(build_arch)@g'             \
-                           debian/control-scripts/$$script > $(pkgdir_ex)/DEBIAN/$$script; \
+                           debian/control-scripts/extra-post > $(pkgdir_ex)/DEBIAN/$$script; \
                        chmod 755 $(pkgdir_ex)/DEBIAN/$$script;                 \
                done;                                                           \
        fi
@@ -202,7 +279,7 @@ ifneq ($(skipdbg),true)
        # Debug image is simple
        install -m644 -D $(builddir)/build-$*/vmlinux \
                $(dbgpkgdir)/usr/lib/debug/boot/vmlinux-$(abi_release)-$*
-       $(build_cd) $(kmake) $(build_O) modules_install \
+       $(build_cd) $(kmake) $(build_O) modules_install $(vdso) \
                INSTALL_MOD_PATH=$(dbgpkgdir)/usr/lib/debug
        # Add .gnu_debuglink sections to each stripped .ko
        # pointing to unstripped verson
@@ -211,6 +288,12 @@ ifneq ($(skipdbg),true)
                        $(CROSS_COMPILE)objcopy \
                                --add-gnu-debuglink=$(dbgpkgdir)/usr/lib/debug/$$module \
                                $(pkgdir)/$$module; \
+                       if grep -q CONFIG_MODULE_SIG=y $(builddir)/build-$*/.config; then \
+                               $(builddir)/build-$*/scripts/sign-file $(MODHASHALGO) \
+                                       $(MODSECKEY) \
+                                       $(MODPUBKEY) \
+                                       $(pkgdir)/$$module; \
+                       fi; \
                fi; \
        done
        rm -f $(dbgpkgdir)/usr/lib/debug/lib/modules/$(abi_release)-$*/build
@@ -233,16 +316,18 @@ endif
        # Copy over the compilation version.
        cp "$(builddir)/build-$*/include/generated/compile.h" \
                "$(hdrdir)/include/generated/compile.h"
-       # powerpc seems to need some .o files for external module linking. Add them in.
-ifeq ($(arch),powerpc)
+       # Add UTS_UBUNTU_RELEASE_ABI since UTS_RELEASE is difficult to parse.
+       echo "#define UTS_UBUNTU_RELEASE_ABI $(abinum)" >> $(hdrdir)/include/generated/utsrelease.h
+       # powerpc kernel arch seems to need some .o files for external module linking. Add them in.
+ifeq ($(build_arch),powerpc)
        mkdir -p $(hdrdir)/arch/powerpc/lib
        cp $(builddir)/build-$*/arch/powerpc/lib/*.o $(hdrdir)/arch/powerpc/lib
 endif
        # Script to symlink everything up
-       $(SHELL) $(DROOT)/scripts/link-headers "$(hdrdir)" "$(basepkg)" "$*"
+       $(SHELL) $(DROOT)/scripts/link-headers "$(hdrdir)" "$(indeppkg)" "$*"
        # The build symlink
        install -d debian/$(basepkg)-$*/lib/modules/$(abi_release)-$*
-       ln -s /usr/src/$(basepkg)-$* \
+       $(LN) /usr/src/$(basepkg)-$* \
                debian/$(basepkg)-$*/lib/modules/$(abi_release)-$*/build
        # And finally the symvers
        install -m644 $(builddir)/build-$*/Module.symvers \
@@ -283,6 +368,35 @@ endif
                $(pkgdir)/lib/modules/$(abi_release)-$*
        rmdir $(pkgdir)/lib/modules/$(abi_release)-$*/_
 
+ifeq ($(do_linux_tools),true)
+       # Create the linux-tools tool links
+       install -d $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+ifeq ($(do_tools_usbip),true)
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/usbip $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/usbipd $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+endif
+ifeq ($(do_tools_cpupower),true)
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/cpupower $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+endif
+ifeq ($(do_tools_perf),true)
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/perf $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+endif
+ifeq ($(do_tools_x86),true)
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/x86_energy_perf_policy $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/turbostat $(toolspkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+endif
+endif
+ifeq ($(do_cloud_tools),true)
+ifeq ($(do_tools_hyperv),true)
+       # Create the linux-hyperv tool links
+       install -d $(cloudpkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/hv_kvp_daemon $(cloudpkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/hv_vss_daemon $(cloudpkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/hv_fcopy_daemon $(cloudpkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+       $(LN) ../../$(src_pkg_name)-tools-$(abi_release)/lsvmbus $(cloudpkgdir)/usr/lib/linux-tools/$(abi_release)-$*
+endif
+endif
+
 headers_tmp := $(CURDIR)/debian/tmp-headers
 headers_dir := $(CURDIR)/debian/linux-libc-dev
 
@@ -340,6 +454,9 @@ binary-%: pkgimg_ex = $(extra_pkg_name)-$*
 binary-%: pkghdr = $(hdrs_pkg_name)-$*
 binary-%: dbgpkg = $(bin_pkg_name)-$*-dbgsym
 binary-%: dbgpkgdir = $(CURDIR)/debian/$(bin_pkg_name)-$*-dbgsym
+binary-%: pkgtools = $(tools_flavour_pkg_name)-$*
+binary-%: pkgcloud = $(cloud_flavour_pkg_name)-$*
+binary-%: rprovides = $(if $(filter true,$(call custom_override,do_zfs,$*)),$(comma) spl-modules$(comma) spl-dkms$(comma) zfs-modules$(comma) zfs-dkms)
 binary-%: target_flavour = $*
 binary-%: install-%
        @echo Debug: $@
@@ -351,10 +468,10 @@ binary-%: install-%
        dh_compress -p$(pkgimg)
        dh_fixperms -p$(pkgimg) -X/boot/
        dh_installdeb -p$(pkgimg)
-       dh_shlibdeps -p$(pkgimg)
-       $(lockme) dh_gencontrol -p$(pkgimg)
+       dh_shlibdeps -p$(pkgimg) $(shlibdeps_opts)
+       $(lockme) dh_gencontrol -p$(pkgimg) -- -Vlinux:rprovides='$(rprovides)'
        dh_md5sums -p$(pkgimg)
-       dh_builddeb -p$(pkgimg) -- -Zbzip2 -z9
+       dh_builddeb -p$(pkgimg)
 
 ifeq ($(do_extras_package),true)
        if [ -f $(DEBIAN)/control.d/$(target_flavour).inclusion-list ] ; then \
@@ -363,10 +480,10 @@ ifeq ($(do_extras_package),true)
                dh_compress -p$(pkgimg_ex); \
                dh_fixperms -p$(pkgimg_ex) -X/boot/; \
                dh_installdeb -p$(pkgimg_ex); \
-               dh_shlibdeps -p$(pkgimg_ex); \
+               dh_shlibdeps -p$(pkgimg_ex) $(shlibdeps_opts); \
                $(lockme) dh_gencontrol -p$(pkgimg_ex); \
                dh_md5sums -p$(pkgimg_ex); \
-               dh_builddeb -p$(pkgimg_ex) -- -Zbzip2 -z9; \
+               dh_builddeb -p$(pkgimg_ex); \
        fi
 endif
 
@@ -374,7 +491,7 @@ endif
        dh_installdocs -p$(pkghdr)
        dh_compress -p$(pkghdr)
        dh_fixperms -p$(pkghdr)
-       dh_shlibdeps -p$(pkghdr)
+       dh_shlibdeps -p$(pkghdr) $(shlibdeps_opts)
        dh_installdeb -p$(pkghdr)
        $(lockme) dh_gencontrol -p$(pkghdr)
        dh_md5sums -p$(pkghdr)
@@ -387,7 +504,7 @@ ifneq ($(skipsub),true)
                dh_installdocs -p$$pkg;                 \
                dh_compress -p$$pkg;                    \
                dh_fixperms -p$$pkg -X/boot/;           \
-               dh_shlibdeps -p$$pkg;                   \
+               dh_shlibdeps -p$$pkg $(shlibdeps_opts); \
                dh_installdeb -p$$pkg;                  \
                $(lockme) dh_gencontrol -p$$pkg;                        \
                dh_md5sums -p$$pkg;                     \
@@ -426,6 +543,30 @@ ifneq ($(skipdbg),true)
        # Now, the package wont get into the archive, but it will get put
        # into the debug system.
 endif
+
+ifeq ($(do_linux_tools),true)
+       dh_installchangelogs -p$(pkgtools)
+       dh_installdocs -p$(pkgtools)
+       dh_compress -p$(pkgtools)
+       dh_fixperms -p$(pkgtools)
+       dh_shlibdeps -p$(pkgtools) $(shlibdeps_opts)
+       dh_installdeb -p$(pkgtools)
+       $(lockme) dh_gencontrol -p$(pkgtools)
+       dh_md5sums -p$(pkgtools)
+       dh_builddeb -p$(pkgtools)
+endif
+ifeq ($(do_cloud_tools),true)
+       dh_installchangelogs -p$(pkgcloud)
+       dh_installdocs -p$(pkgcloud)
+       dh_compress -p$(pkgcloud)
+       dh_fixperms -p$(pkgcloud)
+       dh_shlibdeps -p$(pkgcloud) $(shlibdeps_opts)
+       dh_installdeb -p$(pkgcloud)
+       $(lockme) dh_gencontrol -p$(pkgcloud)
+       dh_md5sums -p$(pkgcloud)
+       dh_builddeb -p$(pkgcloud)
+endif
+
 ifneq ($(full_build),false)
        # Clean out this flavours build directory.
        rm -rf $(builddir)/build-$*
@@ -440,83 +581,142 @@ builddirpa = $(builddir)/tools-perarch
 
 $(stampdir)/stamp-prepare-perarch:
        @echo Debug: $@
-ifeq ($(do_tools),true)
+ifeq ($(do_any_tools),true)
        rm -rf $(builddirpa)
        install -d $(builddirpa)
-       for i in *; do ln -s $(CURDIR)/$$i $(builddirpa); done
-       rm $(builddirpa)/tools
-       rsync -a tools/ $(builddirpa)/tools/
+       rsync -a --exclude debian --exclude debian.master --exclude $(DEBIAN) --exclude .git -a ./ $(builddirpa)/
 endif
        touch $@
 
-$(stampdir)/stamp-build-perarch: $(stampdir)/stamp-prepare-perarch
+$(stampdir)/stamp-build-perarch: $(stampdir)/stamp-prepare-perarch install-arch-headers
        @echo Debug: $@
-ifeq ($(do_tools),true)
+ifeq ($(do_linux_tools),true)
+ifeq ($(do_tools_usbip),true)
+       chmod 755 $(builddirpa)/tools/usb/usbip/autogen.sh
+       cd $(builddirpa)/tools/usb/usbip && ./autogen.sh
+       chmod 755 $(builddirpa)/tools/usb/usbip/configure
+       cd $(builddirpa)/tools/usb/usbip && ./configure --prefix=$(builddirpa)/tools/usb/usbip/bin
+       cd $(builddirpa)/tools/usb/usbip && make install CFLAGS="-g -O2 -static" CROSS_COMPILE=$(CROSS_COMPILE)
+endif
+ifeq ($(do_tools_cpupower),true)
+       # Allow for multiple installed versions of cpupower and libcpupower.so:
+       # Override LIB_MIN in order to to generate a versioned .so named
+       # libcpupower.so.$(abi_release) and link cpupower with that.
+       make -C $(builddirpa)/tools/power/cpupower \
+               CROSS_COMPILE=$(CROSS_COMPILE) \
+               CROSS=$(CROSS_COMPILE) \
+               LIB_MIN=$(abi_release) CPUFREQ_BENCH=false
+endif
 ifeq ($(do_tools_perf),true)
+       cd $(builddirpa) && $(kmake) $(defconfig)
+       mv $(builddirpa)/.config $(builddirpa)/.config.old
+       sed -e 's/^# \(CONFIG_MODVERSIONS\) is not set$$/\1=y/' \
+         -e 's/.*CONFIG_LOCALVERSION_AUTO.*/# CONFIG_LOCALVERSION_AUTO is not set/' \
+         $(builddirpa)/.config.old > $(builddirpa)/.config
+       cd $(builddirpa) && $(kmake) silentoldconfig
+       cd $(builddirpa) && $(kmake) prepare
        cd $(builddirpa)/tools/perf && \
-               make HAVE_CPLUS_DEMANGLE=1 CROSS_COMPILE=$(CROSS_COMPILE) NO_LIBPYTHON=1 NO_LIBPERL=1 PYTHON=python2.7
+               $(kmake) prefix=/usr HAVE_CPLUS_DEMANGLE=1 CROSS_COMPILE=$(CROSS_COMPILE) NO_LIBPYTHON=1 NO_LIBPERL=1 PYTHON=python2.7
+endif
+ifeq ($(do_tools_x86),true)
+       cd $(builddirpa)/tools/power/x86/x86_energy_perf_policy && make CROSS_COMPILE=$(CROSS_COMPILE)
+       cd $(builddirpa)/tools/power/x86/turbostat && make CROSS_COMPILE=$(CROSS_COMPILE)
+endif
+endif
+ifeq ($(do_cloud_tools),true)
+ifeq ($(do_tools_hyperv),true)
+       cd $(builddirpa)/tools/hv && make CFLAGS="-I$(headers_dir)/usr/include -I$(headers_dir)/usr/include/$(DEB_HOST_MULTIARCH)" CROSS_COMPILE=$(CROSS_COMPILE) hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon
 endif
-       if [ "$(arch)" = "amd64" ] || [ "$(arch)" = "i386" ]; then \
-               cd $(builddirpa)/tools/power/x86/x86_energy_perf_policy && make CROSS_COMPILE=$(CROSS_COMPILE); \
-               cd $(builddirpa)/tools/power/x86/turbostat && make CROSS_COMPILE=$(CROSS_COMPILE); \
-               if [ "$(do_hyperv)" = "true" ]; then \
-                       cd $(builddirpa)/tools/hv && make CROSS_COMPILE=$(CROSS_COMPILE); \
-               fi; \
-       fi
 endif
        @touch $@
 
 install-perarch: toolspkgdir = $(CURDIR)/debian/$(tools_pkg_name)
+install-perarch: cloudpkgdir = $(CURDIR)/debian/$(cloud_pkg_name)
 install-perarch: $(stampdir)/stamp-build-perarch
        @echo Debug: $@
        # Add the tools.
-ifeq ($(do_tools),true)
-       install -d $(toolspkgdir)/usr/bin
+ifeq ($(do_linux_tools),true)
+       install -d $(toolspkgdir)/usr/lib
+       install -d $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+ifeq ($(do_tools_usbip),true)
+       install -m755 $(builddirpa)/tools/usb/usbip/bin/sbin/usbip \
+               $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/usb/usbip/bin/sbin/usbipd \
+               $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+endif
+ifeq ($(do_tools_cpupower),true)
+       install -m755 $(builddirpa)/tools/power/cpupower/cpupower \
+               $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       # Install only the full versioned libcpupower.so.$(abi_release), not
+       # the usual symlinks to it.
+       install -m644 $(builddirpa)/tools/power/cpupower/libcpupower.so.$(abi_release) \
+               $(toolspkgdir)/usr/lib/
+endif
 ifeq ($(do_tools_perf),true)
-       install -s -m755 $(builddirpa)/tools/perf/perf \
-               $(toolspkgdir)/usr/bin/perf_$(abi_release)
-endif
-       if [ "$(arch)" = "amd64" ] || [ "$(arch)" = "i386" ]; then \
-               install -s -m755 $(builddirpa)/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy \
-                       $(toolspkgdir)/usr/bin/x86_energy_perf_policy_$(abi_release); \
-               install -s -m755 $(builddirpa)/tools/power/x86/turbostat/turbostat \
-                       $(toolspkgdir)/usr/bin/turbostat_$(abi_release); \
-               if [ "$(do_hyperv)" = "true" ]; then \
-                       install -d $(toolspkgdir)/usr/sbin; \
-                       install -s -m755 $(builddirpa)/tools/hv/hv_kvp_daemon \
-                               $(toolspkgdir)/usr/sbin/hv_kvp_daemon_$(abi_release); \
-               fi; \
-       fi
+       install -m755 $(builddirpa)/tools/perf/perf $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+endif
+ifeq ($(do_tools_x86),true)
+       install -m755 $(builddirpa)/tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy \
+               $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/power/x86/turbostat/turbostat \
+               $(toolspkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+endif
+endif
+ifeq ($(do_cloud_tools),true)
+ifeq ($(do_tools_hyperv),true)
+       install -d $(cloudpkgdir)/usr/lib
+       install -d $(cloudpkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/hv/hv_kvp_daemon \
+               $(cloudpkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/hv/hv_vss_daemon \
+               $(cloudpkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/hv/hv_fcopy_daemon \
+               $(cloudpkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+       install -m755 $(builddirpa)/tools/hv/lsvmbus \
+               $(cloudpkgdir)/usr/lib/$(src_pkg_name)-tools-$(abi_release)
+endif
 endif
 
 binary-perarch: toolspkg = $(tools_pkg_name)
+binary-perarch: cloudpkg = $(cloud_pkg_name)
 binary-perarch: install-perarch
        @echo Debug: $@
-ifeq ($(do_tools),true)
+ifeq ($(do_linux_tools),true)
+       dh_strip -p$(toolspkg)
        dh_installchangelogs -p$(toolspkg)
        dh_installdocs -p$(toolspkg)
        dh_compress -p$(toolspkg)
        dh_fixperms -p$(toolspkg)
-       dh_shlibdeps -p$(toolspkg)
+       dh_shlibdeps -p$(toolspkg) $(shlibdeps_opts)
        dh_installdeb -p$(toolspkg)
        $(lockme) dh_gencontrol -p$(toolspkg)
        dh_md5sums -p$(toolspkg)
        dh_builddeb -p$(toolspkg)
 endif
+ifeq ($(do_cloud_tools),true)
+       dh_strip -p$(cloudpkg)
+       dh_installchangelogs -p$(cloudpkg)
+       dh_installdocs -p$(cloudpkg)
+       dh_compress -p$(cloudpkg)
+       dh_fixperms -p$(cloudpkg)
+       dh_shlibdeps -p$(cloudpkg) $(shlibdeps_opts)
+       dh_installdeb -p$(cloudpkg)
+       $(lockme) dh_gencontrol -p$(cloudpkg)
+       dh_md5sums -p$(cloudpkg)
+       dh_builddeb -p$(cloudpkg)
+endif
 
 binary-debs: signed = $(CURDIR)/debian/$(bin_pkg_name)-signed
 binary-debs: signedv = $(CURDIR)/debian/$(bin_pkg_name)-signed/$(release)-$(revision)
 binary-debs: signed_tar = $(src_pkg_name)_$(release)-$(revision)_$(arch).tar.gz
 binary-debs: binary-perarch $(addprefix binary-,$(flavours))
        @echo Debug: $@
-ifeq ($(arch),amd64)
 ifeq ($(uefi_signed),true)
        echo $(release)-$(revision) > $(signedv)/version
        cd $(signedv) && ls *.efi >flavours
        cd $(signed) && tar czvf ../../../$(signed_tar) .
        dpkg-distaddfile $(signed_tar) raw-uefi -
 endif
-endif
 
 build-arch-deps-$(do_flavour_image_package) += $(addprefix $(stampdir)/stamp-build-,$(flavours))
 build-arch: $(build-arch-deps-true)