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