Makefile 6.5 KB

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