Makefile.package 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. # Makefile for the different targets used to generate full packages of a kernel
  3. include $(srctree)/scripts/Kbuild.include
  4. include $(srctree)/scripts/Makefile.lib
  5. # Git
  6. # ---------------------------------------------------------------------------
  7. filechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null
  8. .tmp_HEAD: check-git FORCE
  9. $(call filechk,HEAD)
  10. PHONY += check-git
  11. check-git:
  12. @if ! $(srctree)/scripts/check-git; then \
  13. echo >&2 "error: creating source package requires git repository"; \
  14. false; \
  15. fi
  16. git-config-tar.gz = -c tar.tar.gz.command="$(KGZIP)"
  17. git-config-tar.bz2 = -c tar.tar.bz2.command="$(KBZIP2)"
  18. git-config-tar.lzma = -c tar.tar.lzma.command="$(LZMA)"
  19. git-config-tar.xz = -c tar.tar.xz.command="$(XZ)"
  20. git-config-tar.zst = -c tar.tar.zst.command="$(ZSTD)"
  21. quiet_cmd_archive = ARCHIVE $@
  22. cmd_archive = git -C $(srctree) $(git-config-tar$(suffix $@)) archive \
  23. --output=$$(realpath $@) $(archive-args)
  24. suffix-gzip := .gz
  25. suffix-bzip2 := .bz2
  26. suffix-lzma := .lzma
  27. suffix-xz := .xz
  28. # Linux source tarball
  29. # ---------------------------------------------------------------------------
  30. linux-tarballs := $(addprefix linux, .tar.gz .tar.bz2 .tar.lzma .tar.xz)
  31. targets += $(linux-tarballs)
  32. $(linux-tarballs): archive-args = --prefix=linux/ $$(cat $<)
  33. $(linux-tarballs): .tmp_HEAD FORCE
  34. $(call if_changed,archive)
  35. # rpm-pkg srcrpm-pkg binrpm-pkg
  36. # ---------------------------------------------------------------------------
  37. quiet_cmd_mkspec = GEN $@
  38. cmd_mkspec = $(srctree)/scripts/package/mkspec $@
  39. rpmbuild/SPECS/kernel.spec: FORCE
  40. $(call cmd,mkspec)
  41. PHONY += rpm-sources
  42. rpm-sources: linux.tar.gz
  43. $(Q)mkdir -p rpmbuild/SOURCES
  44. $(Q)ln -f linux.tar.gz rpmbuild/SOURCES/linux.tar.gz
  45. $(Q)cp $(KCONFIG_CONFIG) rpmbuild/SOURCES/config
  46. $(Q)$(srctree)/scripts/package/gen-diff-patch rpmbuild/SOURCES/diff.patch
  47. PHONY += rpm-pkg srcrpm-pkg binrpm-pkg
  48. ifneq ($(CC),$(HOSTCC))
  49. rpm-no-devel = --without=devel
  50. endif
  51. rpm-pkg: private build-type := a
  52. srcrpm-pkg: private build-type := s
  53. binrpm-pkg: private build-type := b
  54. rpm-pkg srcrpm-pkg: rpm-sources
  55. rpm-pkg srcrpm-pkg binrpm-pkg: rpmbuild/SPECS/kernel.spec
  56. +$(strip rpmbuild -b$(build-type) rpmbuild/SPECS/kernel.spec \
  57. --define='_topdir $(abspath rpmbuild)' \
  58. $(if $(filter a b, $(build-type)), \
  59. --target $(UTS_MACHINE)-linux --build-in-place --noprep --define='_smp_mflags %{nil}' \
  60. $$(rpm -q rpm >/dev/null 2>&1 || echo --nodeps) \
  61. $(rpm-no-devel)) \
  62. $(RPMOPTS))
  63. # deb-pkg srcdeb-pkg bindeb-pkg
  64. # ---------------------------------------------------------------------------
  65. KDEB_SOURCE_COMPRESS ?= gzip
  66. supported-deb-source-compress := gzip bzip2 lzma xz
  67. PHONY += linux.tar.unsupported-deb-src-compress
  68. linux.tar.unsupported-deb-src-compress:
  69. @echo "error: KDEB_SOURCE_COMPRESS=$(KDEB_SOURCE_COMPRESS) is not supported. The supported values are: $(supported-deb-source-compress)" >&2
  70. @false
  71. debian-orig-suffix := \
  72. $(strip $(if $(filter $(supported-deb-source-compress), $(KDEB_SOURCE_COMPRESS)), \
  73. $(suffix-$(KDEB_SOURCE_COMPRESS)),.unsupported-deb-src-compress))
  74. quiet_cmd_debianize = GEN $@
  75. cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)
  76. debian: FORCE
  77. $(call cmd,debianize)
  78. PHONY += debian-orig
  79. debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
  80. debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
  81. debian-orig: private orig-name = $(source)_$(version).orig.tar$(debian-orig-suffix)
  82. debian-orig: mkdebian-opts = --need-source
  83. debian-orig: linux.tar$(debian-orig-suffix) debian
  84. $(Q)if [ "$$(df --output=target .. 2>/dev/null)" = "$$(df --output=target $< 2>/dev/null)" ]; then \
  85. ln -f $< ../$(orig-name); \
  86. else \
  87. cp $< ../$(orig-name); \
  88. fi
  89. PHONY += deb-pkg srcdeb-pkg bindeb-pkg
  90. deb-pkg: private build-type := source,binary
  91. srcdeb-pkg: private build-type := source
  92. bindeb-pkg: private build-type := binary
  93. deb-pkg srcdeb-pkg: debian-orig
  94. bindeb-pkg: debian
  95. deb-pkg srcdeb-pkg bindeb-pkg:
  96. +$(strip dpkg-buildpackage \
  97. --build=$(build-type) --no-pre-clean --unsigned-changes \
  98. $(if $(findstring source, $(build-type)), \
  99. --unsigned-source --compression=$(KDEB_SOURCE_COMPRESS)) \
  100. $(if $(findstring binary, $(build-type)), \
  101. -R'$(MAKE) -f debian/rules' -j1 -a$$(cat debian/arch), \
  102. --no-check-builddeps) \
  103. $(DPKG_FLAGS))
  104. # snap-pkg
  105. # ---------------------------------------------------------------------------
  106. PHONY += snap-pkg
  107. snap-pkg:
  108. rm -rf $(objtree)/snap
  109. mkdir $(objtree)/snap
  110. $(MAKE) clean
  111. sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
  112. s@SRCTREE@$(realpath $(srctree))@" \
  113. $(srctree)/scripts/package/snapcraft.template > \
  114. $(objtree)/snap/snapcraft.yaml
  115. cd $(objtree)/snap && \
  116. snapcraft --target-arch=$(UTS_MACHINE)
  117. # pacman-pkg
  118. # ---------------------------------------------------------------------------
  119. PHONY += pacman-pkg
  120. pacman-pkg:
  121. @ln -srf $(srctree)/scripts/package/PKGBUILD $(objtree)/PKGBUILD
  122. +BUILDDIR="$(realpath $(objtree))/pacman" \
  123. CARCH="$(UTS_MACHINE)" \
  124. KBUILD_MAKEFLAGS="$(MAKEFLAGS)" \
  125. KBUILD_REVISION="$(shell $(srctree)/scripts/build-version)" \
  126. makepkg $(MAKEPKGOPTS)
  127. # dir-pkg tar*-pkg - tarball targets
  128. # ---------------------------------------------------------------------------
  129. tar-install: FORCE
  130. $(Q)$(MAKE) -f $(srctree)/Makefile
  131. +$(Q)$(srctree)/scripts/package/buildtar $@
  132. compress-tar.gz = -I "$(KGZIP)"
  133. compress-tar.bz2 = -I "$(KBZIP2)"
  134. compress-tar.xz = -I "$(XZ)"
  135. compress-tar.zst = -I "$(ZSTD)"
  136. quiet_cmd_tar = TAR $@
  137. cmd_tar = cd $<; tar cf ../$@ $(compress-tar$(suffix $@)) --owner=root --group=root --sort=name *
  138. dir-tarballs := $(addprefix linux-$(KERNELRELEASE)-$(ARCH), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
  139. $(dir-tarballs): tar-install
  140. $(call cmd,tar)
  141. PHONY += dir-pkg
  142. dir-pkg: tar-install
  143. @echo "Kernel tree successfully created in $<"
  144. PHONY += tar-pkg
  145. tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar
  146. @:
  147. tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE
  148. @:
  149. # modules-cpio-pkg - generate an initramfs with the modules
  150. # ---------------------------------------------------------------------------
  151. .tmp_modules_cpio: FORCE
  152. $(Q)$(MAKE) -f $(srctree)/Makefile
  153. $(Q)rm -rf $@
  154. $(Q)$(MAKE) -f $(srctree)/Makefile INSTALL_MOD_PATH=$@/$(INSTALL_MOD_PATH) modules_install
  155. quiet_cmd_cpio = CPIO $@
  156. cmd_cpio = $(CONFIG_SHELL) $(srctree)/usr/gen_initramfs.sh -o $@ $<
  157. modules-$(KERNELRELEASE)-$(ARCH).cpio: .tmp_modules_cpio
  158. $(call cmd,cpio)
  159. PHONY += modules-cpio-pkg
  160. modules-cpio-pkg: modules-$(KERNELRELEASE)-$(ARCH).cpio
  161. @:
  162. # perf-tar*-src-pkg - generate a source tarball with perf source
  163. # ---------------------------------------------------------------------------
  164. .tmp_perf:
  165. $(Q)mkdir .tmp_perf
  166. .tmp_perf/HEAD: .tmp_HEAD | .tmp_perf
  167. $(call cmd,copy)
  168. quiet_cmd_perf_version_file = GEN $@
  169. cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))
  170. # PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the
  171. # timestamp of PERF-VERSION-FILE.
  172. # The best is to fix tools/perf/util/PERF-VERSION-GEN.
  173. .tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf
  174. $(call cmd,perf_version_file)
  175. perf-archive-args = --add-file=$$(realpath $(word 2, $^)) \
  176. --add-file=$$(realpath $(word 3, $^)) \
  177. $$(cat $(word 2, $^))^{tree} $$(cat $<)
  178. perf-tarballs := $(addprefix perf-$(KERNELVERSION), .tar .tar.gz .tar.bz2 .tar.xz .tar.zst)
  179. targets += $(perf-tarballs)
  180. $(perf-tarballs): archive-args = --prefix=perf-$(KERNELVERSION)/ $(perf-archive-args)
  181. $(perf-tarballs): tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE
  182. $(call if_changed,archive)
  183. PHONY += perf-tar-src-pkg
  184. perf-tar-src-pkg: perf-$(KERNELVERSION).tar
  185. @:
  186. perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE
  187. @:
  188. # Help text displayed when executing 'make help'
  189. # ---------------------------------------------------------------------------
  190. PHONY += help
  191. help:
  192. @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
  193. @echo ' srcrpm-pkg - Build only the source kernel RPM package'
  194. @echo ' binrpm-pkg - Build only the binary kernel RPM package'
  195. @echo ' deb-pkg - Build both source and binary deb kernel packages'
  196. @echo ' srcdeb-pkg - Build only the source kernel deb package'
  197. @echo ' bindeb-pkg - Build only the binary kernel deb package'
  198. @echo ' snap-pkg - Build only the binary kernel snap package'
  199. @echo ' (will connect to external hosts)'
  200. @echo ' pacman-pkg - Build only the binary kernel pacman package'
  201. @echo ' dir-pkg - Build the kernel as a plain directory structure'
  202. @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
  203. @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
  204. @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
  205. @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
  206. @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball'
  207. @echo ' modules-cpio-pkg - Build the kernel modules as cpio archive'
  208. @echo ' (uses INSTALL_MOD_PATH inside the archive)'
  209. @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression'
  210. @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression'
  211. @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
  212. @echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression'
  213. @echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression'
  214. PHONY += FORCE
  215. FORCE:
  216. # Read all saved command lines and dependencies for the $(targets) we
  217. # may be building above, using $(if_changed{,_dep}). As an
  218. # optimization, we don't need to read them if the target does not
  219. # exist, we will rebuild anyway in that case.
  220. existing-targets := $(wildcard $(sort $(targets)))
  221. -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
  222. .PHONY: $(PHONY)