Makefile.package 8.18 KB
Newer Older
1
# SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds's avatar
Linus Torvalds committed
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
Linus Torvalds's avatar
Linus Torvalds committed
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 12
               include init io_uring ipc kernel lib mm net rust \
               samples scripts security sound tools usr virt \
13
               .config Makefile \
14
               Kbuild Kconfig COPYING $(wildcard localversion*)
Linus Torvalds's avatar
Linus Torvalds committed
15 16
MKSPEC     := $(srctree)/scripts/package/mkspec

17 18 19
quiet_cmd_src_tar = TAR     $(2).tar.gz
      cmd_src_tar = \
if test "$(objtree)" != "$(srctree)"; then \
20 21 22
	echo >&2; \
	echo >&2 "  ERROR:"; \
	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 26
	false; \
fi ; \
27
tar -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 34
%.tar.gz: %.tar
	$(call cmd,gzip)
35

36 37
%.tar.bz2: %.tar
	$(call cmd,bzip2)
38

39 40
%.tar.xz: %.tar
	$(call cmd,xzmisc)
41

42 43
%.tar.zst: %.tar
	$(call cmd,zstd)
44

45 46
# Git
# ---------------------------------------------------------------------------
47

48
filechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null
49

50 51
.tmp_HEAD: check-git FORCE
	$(call filechk,HEAD)
52

53 54 55 56 57 58
PHONY += check-git
check-git:
	@if ! $(srctree)/scripts/check-git; then \
		echo >&2 "error: creating source package requires git repository"; \
		false; \
	fi
59

60 61 62 63
quiet_cmd_archive = ARCHIVE $@
      cmd_archive = git -C $(srctree) archive \
                    --output=$$(realpath $@) --prefix=$(basename $@)/ $(archive-args)

64 65 66
# Linux source tarball
# ---------------------------------------------------------------------------

67
targets += linux.tar
68
linux.tar: archive-args = $$(cat $<)
69
linux.tar: .tmp_HEAD FORCE
70
	$(call if_changed,archive)
71

Linus Torvalds's avatar
Linus Torvalds committed
72
# rpm-pkg
73
# ---------------------------------------------------------------------------
74
PHONY += rpm-pkg
75 76 77
rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec)
rpm-pkg: srcrpm-pkg
	+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \
78
	--define='_smp_mflags %{nil}'
Linus Torvalds's avatar
Linus Torvalds committed
79

80 81 82
# srcrpm-pkg
# ---------------------------------------------------------------------------
PHONY += srcrpm-pkg
83
srcrpm-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

Linus Torvalds's avatar
Linus Torvalds committed
88
# binrpm-pkg
89
# ---------------------------------------------------------------------------
90 91
PHONY += binrpm-pkg
binrpm-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

97
quiet_cmd_debianize = GEN     $@
98
      cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts)
99 100 101 102 103 104 105 106

debian: FORCE
	$(call cmd,debianize)

PHONY += debian-orig
debian-orig: private source = $(shell dpkg-parsechangelog -S Source)
debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//')
debian-orig: private orig-name = $(source)_$(version).orig.tar.gz
107
debian-orig: mkdebian-opts = --need-source
108
debian-orig: linux.tar.gz debian
109 110 111 112 113
	$(Q)if [ "$(df  --output=target .. 2>/dev/null)" = "$(df --output=target $< 2>/dev/null)" ]; then \
		ln -f $< ../$(orig-name); \
	else \
		cp $< ../$(orig-name); \
	fi
114

115
PHONY += deb-pkg
116
deb-pkg: debian-orig
117
	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \
118
		--build=source,binary -nc -us -uc
Riku Voipio's avatar
Riku Voipio committed
119

120
PHONY += bindeb-pkg
121
bindeb-pkg: debian
122
	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
123

124 125
PHONY += intdeb-pkg
intdeb-pkg:
126
	+$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
Linus Torvalds's avatar
Linus Torvalds committed
127

128 129
# snap-pkg
# ---------------------------------------------------------------------------
130 131
PHONY += snap-pkg
snap-pkg:
132 133 134 135 136 137 138 139 140 141 142
	rm -rf $(objtree)/snap
	mkdir $(objtree)/snap
	$(MAKE) clean
	$(call cmd,src_tar,$(KERNELPATH))
	sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
		s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
		$(srctree)/scripts/package/snapcraft.template > \
		$(objtree)/snap/snapcraft.yaml
	cd $(objtree)/snap && \
	snapcraft --target-arch=$(UTS_MACHINE)

143
# dir-pkg tar*-pkg - tarball targets
144
# ---------------------------------------------------------------------------
145 146 147 148 149

tar-install: FORCE
	$(Q)$(MAKE) -f $(srctree)/Makefile
	+$(Q)$(srctree)/scripts/package/buildtar $@

150 151 152 153 154 155
quiet_cmd_tar = TAR     $@
      cmd_tar = cd $<; tar cf ../$@ --owner=root --group=root --sort=name *

linux-$(KERNELRELEASE)-$(ARCH).tar: tar-install
	$(call cmd,tar)

156 157 158 159
PHONY += dir-pkg
dir-pkg: tar-install
	@echo "Kernel tree successfully created in $<"

160 161
PHONY += tar-pkg
tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar
162 163
	@:

164 165
tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE
	@:
166

167
# perf-tar*-src-pkg - generate a source tarball with perf source
168 169
# ---------------------------------------------------------------------------

170 171
.tmp_perf:
	$(Q)mkdir .tmp_perf
172

173 174
.tmp_perf/HEAD: .tmp_HEAD | .tmp_perf
	$(call cmd,copy)
175 176 177 178

quiet_cmd_perf_version_file = GEN     $@
      cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@))

179
# PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the
180 181
# timestamp of PERF-VERSION-FILE.
# 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 184
	$(call cmd,perf_version_file)

185
perf-archive-args = --add-file=$$(realpath $(word 2, $^)) \
186 187
	--add-file=$$(realpath $(word 3, $^)) \
	$$(cat $(word 2, $^))^{tree} $$(cat $<)
188

189
targets += perf-$(KERNELVERSION).tar
190
perf-$(KERNELVERSION).tar: archive-args = $(perf-archive-args)
191
perf-$(KERNELVERSION).tar: tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE
192
	$(call if_changed,archive)
193 194 195 196

PHONY += perf-tar-src-pkg
perf-tar-src-pkg: perf-$(KERNELVERSION).tar
	@:
197

198 199
perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE
	@:
200

Linus Torvalds's avatar
Linus Torvalds committed
201 202
# Help text displayed when executing 'make help'
# ---------------------------------------------------------------------------
203 204
PHONY += help
help:
205
	@echo '  rpm-pkg             - Build both source and binary RPM kernel packages'
206
	@echo '  srcrpm-pkg          - Build only the source kernel RPM package'
Riku Voipio's avatar
Riku Voipio committed
207 208 209
	@echo '  binrpm-pkg          - Build only the binary kernel RPM package'
	@echo '  deb-pkg             - Build both source and binary deb kernel packages'
	@echo '  bindeb-pkg          - Build only the binary kernel deb package'
210 211
	@echo '  snap-pkg            - Build only the binary kernel snap package'
	@echo '                        (will connect to external hosts)'
212
	@echo '  dir-pkg             - Build the kernel as a plain directory structure'
213 214 215
	@echo '  tar-pkg             - Build the kernel as an uncompressed tarball'
	@echo '  targz-pkg           - Build the kernel as a gzip compressed tarball'
	@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 219 220 221 222
	@echo '  perf-tar-src-pkg    - Build the perf source tarball with no compression'
	@echo '  perf-targz-src-pkg  - Build the perf source tarball with gzip compression'
	@echo '  perf-tarbz2-src-pkg - Build the perf source tarball with bz2 compression'
	@echo '  perf-tarxz-src-pkg  - Build the perf source tarball with xz compression'
	@echo '  perf-tarzst-src-pkg - Build the perf source tarball with zst compression'
223

224 225 226
PHONY += FORCE
FORCE:

227 228 229 230 231 232 233 234 235
# Read all saved command lines and dependencies for the $(targets) we
# may be building above, using $(if_changed{,_dep}). As an
# optimization, we don't need to read them if the target does not
# exist, we will rebuild anyway in that case.

existing-targets := $(wildcard $(sort $(targets)))

-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)

236
.PHONY: $(PHONY)