rules 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/make -f
  2. # SPDX-License-Identifier: GPL-2.0-only
  3. # in case debian/rules is executed directly
  4. export DEB_RULES_REQUIRES_ROOT := no
  5. include debian/rules.vars
  6. ifneq (,$(filter-out parallel=1,$(filter parallel=%,$(DEB_BUILD_OPTIONS))))
  7. NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
  8. MAKEFLAGS += -j$(NUMJOBS)
  9. endif
  10. # When KBUILD_VERBOSE is undefined (presumably you are directly working with
  11. # the debianized tree), show verbose logs unless DEB_BUILD_OPTION=terse is set.
  12. ifeq ($(origin KBUILD_VERBOSE),undefined)
  13. ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
  14. export KBUILD_VERBOSE := 1
  15. else
  16. Q := @
  17. endif
  18. endif
  19. revision = $(shell dpkg-parsechangelog -S Version | sed -n 's/.*-//p')
  20. CROSS_COMPILE ?= $(filter-out $(DEB_BUILD_GNU_TYPE)-, $(DEB_HOST_GNU_TYPE)-)
  21. make-opts = ARCH=$(ARCH) KERNELRELEASE=$(KERNELRELEASE) \
  22. $(addprefix KBUILD_BUILD_VERSION=,$(revision)) \
  23. $(addprefix CROSS_COMPILE=,$(CROSS_COMPILE))
  24. binary-targets := $(addprefix binary-, image image-dbg headers libc-dev)
  25. all-packages = $(shell dh_listpackages)
  26. image-package = $(filter linux-image-% user-%, $(filter-out %-dbg, $(all-packages)))
  27. image-dbg-package = $(filter %-dbg, $(all-packages))
  28. libc-dev-package = $(filter linux-libc-dev, $(all-packages))
  29. headers-package = $(filter linux-headers-%, $(all-packages))
  30. mk-files = $(patsubst binary-%,debian/%.files,$1)
  31. package = $($(@:binary-%=%-package))
  32. # DH_OPTION is an environment variable common for all debhelper commands.
  33. # We could 'export' it, but here it is passed from the command line to clarify
  34. # which package is being processed in the build log.
  35. DH_OPTIONS = -p$(package)
  36. # Note: future removal of KDEB_COMPRESS
  37. # dpkg-deb >= 1.21.10 supports the DPKG_DEB_COMPRESSOR_TYPE environment
  38. # variable, which provides the same functionality as KDEB_COMPRESS. The
  39. # KDEB_COMPRESS variable will be removed in the future.
  40. define binary
  41. $(Q)dh_testdir $(DH_OPTIONS)
  42. $(Q)dh_testroot $(DH_OPTIONS)
  43. $(Q)dh_prep $(DH_OPTIONS)
  44. $(Q)+$(MAKE) $(make-opts) run-command KBUILD_RUN_COMMAND='+$$(srctree)/scripts/package/builddeb $(package)'
  45. $(Q)dh_installdocs $(DH_OPTIONS)
  46. $(Q)dh_installchangelogs $(DH_OPTIONS)
  47. $(Q)dh_compress $(DH_OPTIONS)
  48. $(Q)dh_fixperms $(DH_OPTIONS)
  49. $(Q)dh_gencontrol $(DH_OPTIONS) -- -f$(call mk-files,$@)
  50. $(Q)dh_md5sums $(DH_OPTIONS)
  51. $(Q)dh_builddeb $(DH_OPTIONS) -- $(addprefix -Z,$(KDEB_COMPRESS))
  52. endef
  53. .PHONY: $(binary-targets)
  54. $(binary-targets): build-arch
  55. $(Q)truncate -s0 $(call mk-files,$@)
  56. $(if $(package),$(binary))
  57. .PHONY: binary binary-indep binary-arch
  58. binary: binary-arch binary-indep
  59. binary-indep: build-indep
  60. binary-arch: $(binary-targets)
  61. $(Q)cat $(call mk-files,$^) > debian/files
  62. .PHONY: build build-indep build-arch
  63. build: build-arch build-indep
  64. build-indep:
  65. build-arch:
  66. $(Q)$(MAKE) $(make-opts) olddefconfig
  67. $(Q)$(MAKE) $(make-opts) $(if $(filter um,$(ARCH)),,headers) all
  68. .PHONY: clean
  69. clean:
  70. $(Q)dh_clean
  71. $(Q)rm -rf debian/deb-env.vars* debian/*.files
  72. $(Q)$(MAKE) ARCH=$(ARCH) clean
  73. # If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed
  74. # directly. Run 'dpkg-architecture --print-set --print-format=make' to
  75. # generate a makefile construct that exports all DEB_* variables.
  76. ifndef DEB_HOST_ARCH
  77. include debian/deb-env.vars
  78. debian/deb-env.vars:
  79. $(Q)dpkg-architecture -a$$(cat debian/arch) --print-set --print-format=make > $@.tmp
  80. $(Q)mv $@.tmp $@
  81. endif