Makefile.package 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. # RPM target
  5. # ---------------------------------------------------------------------------
  6. # The rpm target generates two rpm files:
  7. # /usr/src/packages/SRPMS/kernel-2.6.7rc2-1.src.rpm
  8. # /usr/src/packages/RPMS/i386/kernel-2.6.7rc2-1.<arch>.rpm
  9. # The src.rpm files includes all source for the kernel being built
  10. # The <arch>.rpm includes kernel configuration, modules etc.
  11. #
  12. # Process to create the rpm files
  13. # a) clean the kernel
  14. # b) Generate .spec file
  15. # c) Build a tar ball, using symlink to make kernel version
  16. # first entry in the path
  17. # d) and pack the result to a tar.gz file
  18. # e) generate the rpm files, based on kernel.spec
  19. # - Use /. to avoid tar packing just the symlink
  20. # Note that the rpm-pkg target cannot be used with KBUILD_OUTPUT,
  21. # but the binrpm-pkg target can; for some reason O= gets ignored.
  22. # Remove hyphens since they have special meaning in RPM filenames
  23. KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
  24. KDEB_SOURCENAME ?= linux-$(KERNELRELEASE)
  25. KBUILD_PKG_ROOTCMD ?="fakeroot -u"
  26. export KDEB_SOURCENAME
  27. # Include only those top-level files that are needed by make, plus the GPL copy
  28. TAR_CONTENT := $(KBUILD_ALLDIRS) .config .scmversion Makefile \
  29. Kbuild Kconfig COPYING $(wildcard localversion*)
  30. MKSPEC := $(srctree)/scripts/package/mkspec
  31. quiet_cmd_src_tar = TAR $(2).tar.gz
  32. cmd_src_tar = \
  33. if test "$(objtree)" != "$(srctree)"; then \
  34. echo >&2; \
  35. echo >&2 " ERROR:"; \
  36. echo >&2 " Building source tarball is not possible outside the"; \
  37. echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT, or use the"; \
  38. echo >&2 " binrpm-pkg or bindeb-pkg target instead."; \
  39. echo >&2; \
  40. false; \
  41. fi ; \
  42. $(srctree)/scripts/setlocalversion --save-scmversion; \
  43. tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
  44. --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3); \
  45. rm -f $(objtree)/.scmversion
  46. # rpm-pkg
  47. # ---------------------------------------------------------------------------
  48. PHONY += rpm-pkg
  49. rpm-pkg:
  50. $(MAKE) clean
  51. $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
  52. $(call cmd,src_tar,$(KERNELPATH),kernel.spec)
  53. +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE) -ta $(KERNELPATH).tar.gz \
  54. --define='_smp_mflags %{nil}'
  55. # binrpm-pkg
  56. # ---------------------------------------------------------------------------
  57. PHONY += binrpm-pkg
  58. binrpm-pkg:
  59. $(MAKE) -f $(srctree)/Makefile
  60. $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
  61. +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
  62. $(UTS_MACHINE) -bb $(objtree)/binkernel.spec
  63. PHONY += deb-pkg
  64. deb-pkg:
  65. $(MAKE) clean
  66. $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
  67. $(call cmd,src_tar,$(KDEB_SOURCENAME))
  68. origversion=$$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$$//');\
  69. mv $(KDEB_SOURCENAME).tar.gz ../$(KDEB_SOURCENAME)_$${origversion}.orig.tar.gz
  70. +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -i.git -us -uc
  71. PHONY += bindeb-pkg
  72. bindeb-pkg:
  73. $(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
  74. +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
  75. PHONY += intdeb-pkg
  76. intdeb-pkg:
  77. +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
  78. # snap-pkg
  79. # ---------------------------------------------------------------------------
  80. PHONY += snap-pkg
  81. snap-pkg:
  82. rm -rf $(objtree)/snap
  83. mkdir $(objtree)/snap
  84. $(MAKE) clean
  85. $(call cmd,src_tar,$(KERNELPATH))
  86. sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
  87. s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
  88. $(srctree)/scripts/package/snapcraft.template > \
  89. $(objtree)/snap/snapcraft.yaml
  90. cd $(objtree)/snap && \
  91. snapcraft --target-arch=$(UTS_MACHINE)
  92. # tarball targets
  93. # ---------------------------------------------------------------------------
  94. tar-pkgs := dir-pkg tar-pkg targz-pkg tarbz2-pkg tarxz-pkg
  95. PHONY += $(tar-pkgs)
  96. $(tar-pkgs):
  97. $(MAKE) -f $(srctree)/Makefile
  98. +$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@
  99. # perf-pkg - generate a source tarball with perf source
  100. # ---------------------------------------------------------------------------
  101. perf-tar=perf-$(KERNELVERSION)
  102. quiet_cmd_perf_tar = TAR
  103. cmd_perf_tar = \
  104. git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/ \
  105. HEAD^{tree} $$(cd $(srctree); \
  106. echo $$(cat tools/perf/MANIFEST)) \
  107. -o $(perf-tar).tar; \
  108. mkdir -p $(perf-tar); \
  109. git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD; \
  110. (cd $(srctree)/tools/perf; \
  111. util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/); \
  112. tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \
  113. rm -r $(perf-tar); \
  114. $(if $(findstring tar-src,$@),, \
  115. $(if $(findstring bz2,$@),$(KBZIP2), \
  116. $(if $(findstring gz,$@),$(KGZIP), \
  117. $(if $(findstring xz,$@),$(XZ), \
  118. $(error unknown target $@)))) \
  119. -f -9 $(perf-tar).tar)
  120. perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg perf-tarxz-src-pkg
  121. PHONY += $(perf-tar-pkgs)
  122. $(perf-tar-pkgs):
  123. $(call cmd,perf_tar)
  124. # Help text displayed when executing 'make help'
  125. # ---------------------------------------------------------------------------
  126. PHONY += help
  127. help:
  128. @echo ' rpm-pkg - Build both source and binary RPM kernel packages'
  129. @echo ' binrpm-pkg - Build only the binary kernel RPM package'
  130. @echo ' deb-pkg - Build both source and binary deb kernel packages'
  131. @echo ' bindeb-pkg - Build only the binary kernel deb package'
  132. @echo ' snap-pkg - Build only the binary kernel snap package'
  133. @echo ' (will connect to external hosts)'
  134. @echo ' dir-pkg - Build the kernel as a plain directory structure'
  135. @echo ' tar-pkg - Build the kernel as an uncompressed tarball'
  136. @echo ' targz-pkg - Build the kernel as a gzip compressed tarball'
  137. @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball'
  138. @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball'
  139. @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball'
  140. @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball'
  141. @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball'
  142. @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball'
  143. .PHONY: $(PHONY)