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 5include $(srctree)/scripts/Makefile.lib 6 7KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE)) 8KBUILD_PKG_ROOTCMD ?="fakeroot -u" 9# Include only those top-level files that are needed by make, plus the GPL copy 10TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \ 11 include init io_uring ipc kernel lib mm net rust \ 12 samples scripts security sound tools usr virt \ 13 .config Makefile \ 14 Kbuild Kconfig COPYING $(wildcard localversion*) 15MKSPEC := $(srctree)/scripts/package/mkspec 16 17quiet_cmd_src_tar = TAR $(2).tar.gz 18 cmd_src_tar = \ 19if test "$(objtree)" != "$(srctree)"; then \ 20 echo >&2; \ 21 echo >&2 " ERROR:"; \ 22 echo >&2 " Building source tarball is not possible outside the"; \ 23 echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT"; \ 24 echo >&2; \ 25 false; \ 26fi ; \ 27tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \ 28 --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3) 29 30# tarball compression 31# --------------------------------------------------------------------------- 32 33%.tar.gz: %.tar 34 $(call cmd,gzip) 35 36%.tar.bz2: %.tar 37 $(call cmd,bzip2) 38 39%.tar.xz: %.tar 40 $(call cmd,xzmisc) 41 42%.tar.zst: %.tar 43 $(call cmd,zstd) 44 45# Git 46# --------------------------------------------------------------------------- 47 48filechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null 49 50.tmp_HEAD: check-git FORCE 51 $(call filechk,HEAD) 52 53PHONY += check-git 54check-git: 55 @if ! $(srctree)/scripts/check-git; then \ 56 echo >&2 "error: creating source package requires git repository"; \ 57 false; \ 58 fi 59 60quiet_cmd_archive = ARCHIVE $@ 61 cmd_archive = git -C $(srctree) archive \ 62 --output=$$(realpath $@) --prefix=$(basename $@)/ $(archive-args) 63 64# Linux source tarball 65# --------------------------------------------------------------------------- 66 67targets += linux.tar 68linux.tar: archive-args = $$(cat $<) 69linux.tar: .tmp_HEAD FORCE 70 $(call if_changed,archive) 71 72# rpm-pkg 73# --------------------------------------------------------------------------- 74PHONY += rpm-pkg 75rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec) 76rpm-pkg: srcrpm-pkg 77 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \ 78 --define='_smp_mflags %{nil}' 79 80# srcrpm-pkg 81# --------------------------------------------------------------------------- 82PHONY += srcrpm-pkg 83srcrpm-pkg: linux.tar.gz 84 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec 85 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \ 86 --define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .' 87 88# binrpm-pkg 89# --------------------------------------------------------------------------- 90PHONY += binrpm-pkg 91binrpm-pkg: 92 $(MAKE) -f $(srctree)/Makefile 93 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec 94 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ 95 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec 96 97quiet_cmd_debianize = GEN $@ 98 cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts) 99 100debian: FORCE 101 $(call cmd,debianize) 102 103PHONY += debian-orig 104debian-orig: private source = $(shell dpkg-parsechangelog -S Source) 105debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//') 106debian-orig: private orig-name = $(source)_$(version).orig.tar.gz 107debian-orig: mkdebian-opts = --need-source 108debian-orig: linux.tar.gz debian 109 $(Q)if [ "$(df --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \ 110 ln -f $< ../$(orig-name); \ 111 else \ 112 cp $< ../$(orig-name); \ 113 fi 114 115PHONY += deb-pkg 116deb-pkg: debian-orig 117 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \ 118 --build=source,binary -nc -us -uc 119 120PHONY += bindeb-pkg 121bindeb-pkg: debian 122 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc 123 124PHONY += intdeb-pkg 125intdeb-pkg: 126 +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb 127 128# snap-pkg 129# --------------------------------------------------------------------------- 130PHONY += snap-pkg 131snap-pkg: 132 rm -rf $(objtree)/snap 133 mkdir $(objtree)/snap 134 $(MAKE) clean 135 $(call cmd,src_tar,$(KERNELPATH)) 136 sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \ 137 s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \ 138 $(srctree)/scripts/package/snapcraft.template > \ 139 $(objtree)/snap/snapcraft.yaml 140 cd $(objtree)/snap && \ 141 snapcraft --target-arch=$(UTS_MACHINE) 142 143# dir-pkg tar*-pkg - tarball targets 144# --------------------------------------------------------------------------- 145 146tar-install: FORCE 147 $(Q)$(MAKE) -f $(srctree)/Makefile 148 +$(Q)$(srctree)/scripts/package/buildtar $@ 149 150quiet_cmd_tar = TAR $@ 151 cmd_tar = cd $<; tar cf ../$@ --owner=root --group=root --sort=name * 152 153linux-$(KERNELRELEASE)-$(ARCH).tar: tar-install 154 $(call cmd,tar) 155 156PHONY += dir-pkg 157dir-pkg: tar-install 158 @echo "Kernel tree successfully created in $<" 159 160PHONY += tar-pkg 161tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar 162 @: 163 164tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE 165 @: 166 167# perf-tar*-src-pkg - generate a source tarball with perf source 168# --------------------------------------------------------------------------- 169 170.tmp_perf: 171 $(Q)mkdir .tmp_perf 172 173.tmp_perf/HEAD: .tmp_HEAD | .tmp_perf 174 $(call cmd,copy) 175 176quiet_cmd_perf_version_file = GEN $@ 177 cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@)) 178 179# PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the 180# timestamp of PERF-VERSION-FILE. 181# The best is to fix tools/perf/util/PERF-VERSION-GEN. 182.tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf 183 $(call cmd,perf_version_file) 184 185perf-archive-args = --add-file=$$(realpath $(word 2, $^)) \ 186 --add-file=$$(realpath $(word 3, $^)) \ 187 $$(cat $(word 2, $^))^{tree} $$(cat $<) 188 189targets += perf-$(KERNELVERSION).tar 190perf-$(KERNELVERSION).tar: archive-args = $(perf-archive-args) 191perf-$(KERNELVERSION).tar: tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE 192 $(call if_changed,archive) 193 194PHONY += perf-tar-src-pkg 195perf-tar-src-pkg: perf-$(KERNELVERSION).tar 196 @: 197 198perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE 199 @: 200 201# Help text displayed when executing 'make help' 202# --------------------------------------------------------------------------- 203PHONY += help 204help: 205 @echo ' rpm-pkg - Build both source and binary RPM kernel packages' 206 @echo ' srcrpm-pkg - Build only the source kernel RPM package' 207 @echo ' binrpm-pkg - Build only the binary kernel RPM package' 208 @echo ' deb-pkg - Build both source and binary deb kernel packages' 209 @echo ' bindeb-pkg - Build only the binary kernel deb package' 210 @echo ' snap-pkg - Build only the binary kernel snap package' 211 @echo ' (will connect to external hosts)' 212 @echo ' dir-pkg - Build the kernel as a plain directory structure' 213 @echo ' tar-pkg - Build the kernel as an uncompressed tarball' 214 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' 215 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' 216 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' 217 @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball' 218 @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression' 219 @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression' 220 @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression' 221 @echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression' 222 @echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression' 223 224PHONY += FORCE 225FORCE: 226 227# Read all saved command lines and dependencies for the $(targets) we 228# may be building above, using $(if_changed{,_dep}). As an 229# optimization, we don't need to read them if the target does not 230# exist, we will rebuild anyway in that case. 231 232existing-targets := $(wildcard $(sort $(targets))) 233 234-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 235 236.PHONY: $(PHONY) 237