rules 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. define binary
  37. $(Q)dh_testdir $(DH_OPTIONS)
  38. $(Q)dh_testroot $(DH_OPTIONS)
  39. $(Q)dh_prep $(DH_OPTIONS)
  40. $(Q)+$(MAKE) $(make-opts) run-command KBUILD_RUN_COMMAND='+$$(srctree)/scripts/package/builddeb $(package)'
  41. $(Q)dh_installdocs $(DH_OPTIONS)
  42. $(Q)dh_installchangelogs $(DH_OPTIONS)
  43. $(Q)dh_compress $(DH_OPTIONS)
  44. $(Q)dh_fixperms $(DH_OPTIONS)
  45. $(Q)dh_gencontrol $(DH_OPTIONS) -- -f$(call mk-files,$@)
  46. $(Q)dh_md5sums $(DH_OPTIONS)
  47. $(Q)dh_builddeb $(DH_OPTIONS) -- $(addprefix -Z,$(KDEB_COMPRESS))
  48. endef
  49. .PHONY: $(binary-targets)
  50. $(binary-targets): build-arch
  51. $(Q)truncate -s0 $(call mk-files,$@)
  52. $(if $(package),$(binary))
  53. .PHONY: binary binary-indep binary-arch
  54. binary: binary-arch binary-indep
  55. binary-indep: build-indep
  56. binary-arch: $(binary-targets)
  57. $(Q)cat $(call mk-files,$^) > debian/files
  58. .PHONY: build build-indep build-arch
  59. build: build-arch build-indep
  60. build-indep:
  61. build-arch:
  62. $(Q)$(MAKE) $(make-opts) olddefconfig
  63. $(Q)$(MAKE) $(make-opts) $(if $(filter um,$(ARCH)),,headers) all
  64. .PHONY: clean
  65. clean:
  66. $(Q)dh_clean
  67. $(Q)rm -rf debian/deb-env.vars* debian/*.files
  68. $(Q)$(MAKE) ARCH=$(ARCH) clean
  69. # If DEB_HOST_ARCH is empty, it is likely that debian/rules was executed
  70. # directly. Run 'dpkg-architecture --print-set --print-format=make' to
  71. # generate a makefile construct that exports all DEB_* variables.
  72. ifndef DEB_HOST_ARCH
  73. include debian/deb-env.vars
  74. debian/deb-env.vars:
  75. $(Q)dpkg-architecture -a$$(cat debian/arch) --print-set --print-format=make > $@.tmp
  76. $(Q)mv $@.tmp $@
  77. endif