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 6KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE)) 7KBUILD_PKG_ROOTCMD ?="fakeroot -u" 8# Include only those top-level files that are needed by make, plus the GPL copy 9TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \ 10 include init io_uring ipc kernel lib mm net rust \ 11 samples scripts security sound tools usr virt \ 12 .config Makefile \ 13 Kbuild Kconfig COPYING $(wildcard localversion*) 14MKSPEC := $(srctree)/scripts/package/mkspec 15 16quiet_cmd_src_tar = TAR $(2).tar.gz 17 cmd_src_tar = \ 18if test "$(objtree)" != "$(srctree)"; then \ 19 echo >&2; \ 20 echo >&2 " ERROR:"; \ 21 echo >&2 " Building source tarball is not possible outside the"; \ 22 echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT"; \ 23 echo >&2; \ 24 false; \ 25fi ; \ 26tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \ 27 --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3) 28 29# .tmp_filelist .tmp_filelist_exclude 30# --------------------------------------------------------------------------- 31 32scripts/list-gitignored: FORCE 33 $(Q)$(MAKE) -f $(srctree)/Makefile scripts_package 34 35# 1f5d3a6b6532e25a5cdf1f311956b2b03d343a48 removed '*.rej' from .gitignore, 36# but it is definitely a generated file. 37filechk_filelist = \ 38 $< --exclude='*.rej' --output=$@_exclude --prefix=./ --rootdir=$(srctree) --stat=- 39 40.tmp_filelist: scripts/list-gitignored FORCE 41 $(call filechk,filelist) 42 43# tarball 44# --------------------------------------------------------------------------- 45 46quiet_cmd_tar = TAR $@ 47 cmd_tar = tar -c -f $@ $(tar-compress-opt) $(tar-exclude-opt) \ 48 --owner=0 --group=0 --sort=name \ 49 --transform 's:^\.:$*:S' -C $(tar-rootdir) . 50 51tar-rootdir := $(srctree) 52 53%.tar.gz: private tar-compress-opt := -I $(KGZIP) 54%.tar.gz: 55 $(call cmd,tar) 56 57# Linux source tarball 58# --------------------------------------------------------------------------- 59 60linux.tar.gz: tar-exclude-opt = --exclude=./$@ --exclude-from=$<_exclude 61linux.tar.gz: .tmp_filelist 62 63# rpm-pkg 64# --------------------------------------------------------------------------- 65PHONY += rpm-pkg 66rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec) 67rpm-pkg: srcrpm-pkg 68 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \ 69 --define='_smp_mflags %{nil}' 70 71# srcrpm-pkg 72# --------------------------------------------------------------------------- 73PHONY += srcrpm-pkg 74srcrpm-pkg: linux.tar.gz 75 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec 76 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \ 77 --define='_smp_mflags %{nil}' --define='_sourcedir .' --define='_srcrpmdir .' 78 79# binrpm-pkg 80# --------------------------------------------------------------------------- 81PHONY += binrpm-pkg 82binrpm-pkg: 83 $(MAKE) -f $(srctree)/Makefile 84 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec 85 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ 86 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec 87 88quiet_cmd_debianize = GEN $@ 89 cmd_debianize = $(srctree)/scripts/package/mkdebian 90 91debian: FORCE 92 $(call cmd,debianize) 93 94PHONY += debian-orig 95debian-orig: private source = $(shell dpkg-parsechangelog -S Source) 96debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//') 97debian-orig: private orig-name = $(source)_$(version).orig.tar.gz 98debian-orig: linux.tar.gz debian 99 $(Q)cp $< ../$(orig-name) 100 101PHONY += deb-pkg 102deb-pkg: debian-orig 103 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \ 104 --build=source,binary --source-option=-sP -nc -us -uc 105 106PHONY += bindeb-pkg 107bindeb-pkg: debian 108 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc 109 110PHONY += intdeb-pkg 111intdeb-pkg: 112 +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb 113 114# snap-pkg 115# --------------------------------------------------------------------------- 116PHONY += snap-pkg 117snap-pkg: 118 rm -rf $(objtree)/snap 119 mkdir $(objtree)/snap 120 $(MAKE) clean 121 $(call cmd,src_tar,$(KERNELPATH)) 122 sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \ 123 s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \ 124 $(srctree)/scripts/package/snapcraft.template > \ 125 $(objtree)/snap/snapcraft.yaml 126 cd $(objtree)/snap && \ 127 snapcraft --target-arch=$(UTS_MACHINE) 128 129# tarball targets 130# --------------------------------------------------------------------------- 131tar-pkgs := dir-pkg tar-pkg targz-pkg tarbz2-pkg tarxz-pkg tarzst-pkg 132PHONY += $(tar-pkgs) 133$(tar-pkgs): 134 $(MAKE) -f $(srctree)/Makefile 135 +$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@ 136 137# perf-pkg - generate a source tarball with perf source 138# --------------------------------------------------------------------------- 139 140perf-tar=perf-$(KERNELVERSION) 141 142quiet_cmd_perf_tar = TAR 143 cmd_perf_tar = \ 144git --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/ \ 145 HEAD^{tree} $$(cd $(srctree); \ 146 echo $$(cat tools/perf/MANIFEST)) \ 147 -o $(perf-tar).tar; \ 148mkdir -p $(perf-tar); \ 149git --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD; \ 150(cd $(srctree)/tools/perf; \ 151util/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/); \ 152tar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \ 153rm -r $(perf-tar); \ 154$(if $(findstring tar-src,$@),, \ 155$(if $(findstring bz2,$@),$(KBZIP2), \ 156$(if $(findstring gz,$@),$(KGZIP), \ 157$(if $(findstring xz,$@),$(XZ), \ 158$(if $(findstring zst,$@),$(ZSTD), \ 159$(error unknown target $@))))) \ 160 -f -9 $(perf-tar).tar) 161 162perf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg \ 163 perf-tarxz-src-pkg perf-tarzst-src-pkg 164PHONY += $(perf-tar-pkgs) 165$(perf-tar-pkgs): 166 $(call cmd,perf_tar) 167 168# Help text displayed when executing 'make help' 169# --------------------------------------------------------------------------- 170PHONY += help 171help: 172 @echo ' rpm-pkg - Build both source and binary RPM kernel packages' 173 @echo ' srcrpm-pkg - Build only the source kernel RPM package' 174 @echo ' binrpm-pkg - Build only the binary kernel RPM package' 175 @echo ' deb-pkg - Build both source and binary deb kernel packages' 176 @echo ' bindeb-pkg - Build only the binary kernel deb package' 177 @echo ' snap-pkg - Build only the binary kernel snap package' 178 @echo ' (will connect to external hosts)' 179 @echo ' dir-pkg - Build the kernel as a plain directory structure' 180 @echo ' tar-pkg - Build the kernel as an uncompressed tarball' 181 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' 182 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' 183 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' 184 @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball' 185 @echo ' perf-tar-src-pkg - Build $(perf-tar).tar source tarball' 186 @echo ' perf-targz-src-pkg - Build $(perf-tar).tar.gz source tarball' 187 @echo ' perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball' 188 @echo ' perf-tarxz-src-pkg - Build $(perf-tar).tar.xz source tarball' 189 @echo ' perf-tarzst-src-pkg - Build $(perf-tar).tar.zst source tarball' 190 191PHONY += FORCE 192FORCE: 193 194.PHONY: $(PHONY) 195