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