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 60# Linux source tarball 61# --------------------------------------------------------------------------- 62 63quiet_cmd_archive_linux = ARCHIVE $@ 64 cmd_archive_linux = \ 65 git -C $(srctree) archive --output=$$(realpath $@) --prefix=$(basename $@)/ $$(cat $<) 66 67targets += linux.tar 68linux.tar: .tmp_HEAD FORCE 69 $(call if_changed,archive_linux) 70 71# rpm-pkg 72# --------------------------------------------------------------------------- 73PHONY += rpm-pkg 74rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec) 75rpm-pkg: srcrpm-pkg 76 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \ 77 --define='_smp_mflags %{nil}' 78 79# srcrpm-pkg 80# --------------------------------------------------------------------------- 81PHONY += srcrpm-pkg 82srcrpm-pkg: linux.tar.gz 83 $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec 84 +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \ 85 --define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .' 86 87# binrpm-pkg 88# --------------------------------------------------------------------------- 89PHONY += binrpm-pkg 90binrpm-pkg: 91 $(MAKE) -f $(srctree)/Makefile 92 $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec 93 +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ 94 $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec 95 96quiet_cmd_debianize = GEN $@ 97 cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts) 98 99debian: FORCE 100 $(call cmd,debianize) 101 102PHONY += debian-orig 103debian-orig: private source = $(shell dpkg-parsechangelog -S Source) 104debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//') 105debian-orig: private orig-name = $(source)_$(version).orig.tar.gz 106debian-orig: mkdebian-opts = --need-source 107debian-orig: linux.tar.gz debian 108 $(Q)if [ "$(df --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \ 109 ln -f $< ../$(orig-name); \ 110 else \ 111 cp $< ../$(orig-name); \ 112 fi 113 114PHONY += deb-pkg 115deb-pkg: debian-orig 116 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \ 117 --build=source,binary -nc -us -uc 118 119PHONY += bindeb-pkg 120bindeb-pkg: debian 121 +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc 122 123PHONY += intdeb-pkg 124intdeb-pkg: 125 +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb 126 127# snap-pkg 128# --------------------------------------------------------------------------- 129PHONY += snap-pkg 130snap-pkg: 131 rm -rf $(objtree)/snap 132 mkdir $(objtree)/snap 133 $(MAKE) clean 134 $(call cmd,src_tar,$(KERNELPATH)) 135 sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \ 136 s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \ 137 $(srctree)/scripts/package/snapcraft.template > \ 138 $(objtree)/snap/snapcraft.yaml 139 cd $(objtree)/snap && \ 140 snapcraft --target-arch=$(UTS_MACHINE) 141 142# dir-pkg tar*-pkg - tarball targets 143# --------------------------------------------------------------------------- 144 145tar-install: FORCE 146 $(Q)$(MAKE) -f $(srctree)/Makefile 147 +$(Q)$(srctree)/scripts/package/buildtar $@ 148 149quiet_cmd_tar = TAR $@ 150 cmd_tar = cd $<; tar cf ../$@ --owner=root --group=root --sort=name * 151 152linux-$(KERNELRELEASE)-$(ARCH).tar: tar-install 153 $(call cmd,tar) 154 155PHONY += dir-pkg 156dir-pkg: tar-install 157 @echo "Kernel tree successfully created in $<" 158 159PHONY += tar-pkg 160tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar 161 @: 162 163tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE 164 @: 165 166# perf-tar*-src-pkg - generate a source tarball with perf source 167# --------------------------------------------------------------------------- 168 169.tmp_perf: 170 $(Q)mkdir .tmp_perf 171 172.tmp_perf/HEAD: .tmp_HEAD | .tmp_perf 173 $(call cmd,copy) 174 175quiet_cmd_perf_version_file = GEN $@ 176 cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@)) 177 178# PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the 179# timestamp of PERF-VERSION-FILE. 180# The best is to fix tools/perf/util/PERF-VERSION-GEN. 181.tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf 182 $(call cmd,perf_version_file) 183 184quiet_cmd_archive_perf = ARCHIVE $@ 185 cmd_archive_perf = \ 186 git -C $(srctree) archive --output=$$(realpath $@) --prefix=$(basename $@)/ \ 187 --add-file=$$(realpath $(word 2, $^)) \ 188 --add-file=$$(realpath $(word 3, $^)) \ 189 $$(cat $(word 2, $^))^{tree} $$(cat $<) 190 191targets += perf-$(KERNELVERSION).tar 192perf-$(KERNELVERSION).tar: tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE 193 $(call if_changed,archive_perf) 194 195PHONY += perf-tar-src-pkg 196perf-tar-src-pkg: perf-$(KERNELVERSION).tar 197 @: 198 199perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE 200 @: 201 202# Help text displayed when executing 'make help' 203# --------------------------------------------------------------------------- 204PHONY += help 205help: 206 @echo ' rpm-pkg - Build both source and binary RPM kernel packages' 207 @echo ' srcrpm-pkg - Build only the source kernel RPM package' 208 @echo ' binrpm-pkg - Build only the binary kernel RPM package' 209 @echo ' deb-pkg - Build both source and binary deb kernel packages' 210 @echo ' bindeb-pkg - Build only the binary kernel deb package' 211 @echo ' snap-pkg - Build only the binary kernel snap package' 212 @echo ' (will connect to external hosts)' 213 @echo ' dir-pkg - Build the kernel as a plain directory structure' 214 @echo ' tar-pkg - Build the kernel as an uncompressed tarball' 215 @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' 216 @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' 217 @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' 218 @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball' 219 @echo ' perf-tar-src-pkg - Build the perf source tarball with no compression' 220 @echo ' perf-targz-src-pkg - Build the perf source tarball with gzip compression' 221 @echo ' perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression' 222 @echo ' perf-tarxz-src-pkg - Build the perf source tarball with xz compression' 223 @echo ' perf-tarzst-src-pkg - Build the perf source tarball with zst compression' 224 225PHONY += FORCE 226FORCE: 227 228# Read all saved command lines and dependencies for the $(targets) we 229# may be building above, using $(if_changed{,_dep}). As an 230# optimization, we don't need to read them if the target does not 231# exist, we will rebuild anyway in that case. 232 233existing-targets := $(wildcard $(sort $(targets))) 234 235-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 236 237.PHONY: $(PHONY) 238