Commit | Line | Data |
---|---|---|
ec8f24b7 | 1 | # SPDX-License-Identifier: GPL-2.0-only |
1da177e4 | 2 | # Makefile for the different targets used to generate full packages of a kernel |
000ec95f MY |
3 | |
4 | include $(srctree)/scripts/Kbuild.include | |
05e96e96 | 5 | include $(srctree)/scripts/Makefile.lib |
1da177e4 | 6 | |
e1287eb8 | 7 | KERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE)) |
b41d920a | 8 | KBUILD_PKG_ROOTCMD ?="fakeroot -u" |
6615d6c3 | 9 | # Include only those top-level files that are needed by make, plus the GPL copy |
a3c4d4ab | 10 | TAR_CONTENT := Documentation LICENSES arch block certs crypto drivers fs \ |
df1f1ea9 PL |
11 | include init io_uring ipc kernel lib mm net rust \ |
12 | samples scripts security sound tools usr virt \ | |
f6e09b07 | 13 | .config Makefile \ |
6615d6c3 | 14 | Kbuild Kconfig COPYING $(wildcard localversion*) |
1da177e4 | 15 | MKSPEC := $(srctree)/scripts/package/mkspec |
1da177e4 | 16 | |
26803821 RV |
17 | quiet_cmd_src_tar = TAR $(2).tar.gz |
18 | cmd_src_tar = \ | |
19 | if test "$(objtree)" != "$(srctree)"; then \ | |
262dad68 MY |
20 | echo >&2; \ |
21 | echo >&2 " ERROR:"; \ | |
22 | echo >&2 " Building source tarball is not possible outside the"; \ | |
6fc91752 | 23 | echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT"; \ |
262dad68 | 24 | echo >&2; \ |
26803821 RV |
25 | false; \ |
26 | fi ; \ | |
e4a42c82 | 27 | tar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \ |
f6e09b07 | 28 | --transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3) |
26803821 | 29 | |
05e96e96 | 30 | # tarball compression |
7bf4582d MY |
31 | # --------------------------------------------------------------------------- |
32 | ||
05e96e96 MY |
33 | %.tar.gz: %.tar |
34 | $(call cmd,gzip) | |
7bf4582d | 35 | |
05e96e96 MY |
36 | %.tar.bz2: %.tar |
37 | $(call cmd,bzip2) | |
7bf4582d | 38 | |
05e96e96 MY |
39 | %.tar.xz: %.tar |
40 | $(call cmd,xzmisc) | |
7bf4582d | 41 | |
05e96e96 MY |
42 | %.tar.zst: %.tar |
43 | $(call cmd,zstd) | |
7bf4582d | 44 | |
05e96e96 MY |
45 | # Git |
46 | # --------------------------------------------------------------------------- | |
7bf4582d | 47 | |
05e96e96 | 48 | filechk_HEAD = git -C $(srctree) rev-parse --verify HEAD 2>/dev/null |
e0ca1674 | 49 | |
05e96e96 MY |
50 | .tmp_HEAD: check-git FORCE |
51 | $(call filechk,HEAD) | |
e0ca1674 | 52 | |
05e96e96 MY |
53 | PHONY += check-git |
54 | check-git: | |
55 | @if ! $(srctree)/scripts/check-git; then \ | |
56 | echo >&2 "error: creating source package requires git repository"; \ | |
57 | false; \ | |
58 | fi | |
e0ca1674 | 59 | |
7bf4582d MY |
60 | # Linux source tarball |
61 | # --------------------------------------------------------------------------- | |
62 | ||
05e96e96 MY |
63 | quiet_cmd_archive_linux = ARCHIVE $@ |
64 | cmd_archive_linux = \ | |
65 | git -C $(srctree) archive --output=$$(realpath $@) --prefix=$(basename $@)/ $$(cat $<) | |
66 | ||
67 | targets += linux.tar | |
68 | linux.tar: .tmp_HEAD FORCE | |
69 | $(call if_changed,archive_linux) | |
7bf4582d | 70 | |
1da177e4 | 71 | # rpm-pkg |
0131705d | 72 | # --------------------------------------------------------------------------- |
6a4f6a26 | 73 | PHONY += rpm-pkg |
1ec9bb70 MY |
74 | rpm-pkg: srpm = $(shell rpmspec --srpm --query --queryformat='%{name}-%{VERSION}-%{RELEASE}.src.rpm' kernel.spec) |
75 | rpm-pkg: srcrpm-pkg | |
76 | +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -rb $(srpm) \ | |
8a16a070 | 77 | --define='_smp_mflags %{nil}' |
1da177e4 | 78 | |
8818039f IV |
79 | # srcrpm-pkg |
80 | # --------------------------------------------------------------------------- | |
81 | PHONY += srcrpm-pkg | |
6fc91752 | 82 | srcrpm-pkg: linux.tar.gz |
8818039f | 83 | $(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec |
6fc91752 | 84 | +rpmbuild $(RPMOPTS) --target $(UTS_MACHINE)-linux -bs kernel.spec \ |
81f59a26 | 85 | --define='_smp_mflags %{nil}' --define='_sourcedir rpmbuild/SOURCES' --define='_srcrpmdir .' |
8818039f | 86 | |
1da177e4 | 87 | # binrpm-pkg |
0131705d | 88 | # --------------------------------------------------------------------------- |
6a4f6a26 MY |
89 | PHONY += binrpm-pkg |
90 | binrpm-pkg: | |
175209cc | 91 | $(MAKE) -f $(srctree)/Makefile |
65013203 | 92 | $(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec |
606625be | 93 | +rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \ |
6105e4f6 | 94 | $(UTS_MACHINE)-linux -bb $(objtree)/binkernel.spec |
af60e207 | 95 | |
6eabebb1 | 96 | quiet_cmd_debianize = GEN $@ |
aa7d233f | 97 | cmd_debianize = $(srctree)/scripts/package/mkdebian $(mkdebian-opts) |
6eabebb1 MY |
98 | |
99 | debian: FORCE | |
100 | $(call cmd,debianize) | |
101 | ||
102 | PHONY += debian-orig | |
103 | debian-orig: private source = $(shell dpkg-parsechangelog -S Source) | |
104 | debian-orig: private version = $(shell dpkg-parsechangelog -S Version | sed 's/-[^-]*$$//') | |
105 | debian-orig: private orig-name = $(source)_$(version).orig.tar.gz | |
aa7d233f | 106 | debian-orig: mkdebian-opts = --need-source |
6eabebb1 | 107 | debian-orig: linux.tar.gz debian |
b44aa8c9 MY |
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 | |
6eabebb1 | 113 | |
6a4f6a26 | 114 | PHONY += deb-pkg |
6eabebb1 | 115 | deb-pkg: debian-orig |
7bf4582d | 116 | +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) \ |
e7853995 | 117 | --build=source,binary -nc -us -uc |
3716001b | 118 | |
6a4f6a26 | 119 | PHONY += bindeb-pkg |
6eabebb1 | 120 | bindeb-pkg: debian |
117948ac | 121 | +dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc |
b41d920a | 122 | |
6a4f6a26 MY |
123 | PHONY += intdeb-pkg |
124 | intdeb-pkg: | |
b41d920a | 125 | +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb |
1da177e4 | 126 | |
5704d455 PP |
127 | # snap-pkg |
128 | # --------------------------------------------------------------------------- | |
6a4f6a26 MY |
129 | PHONY += snap-pkg |
130 | snap-pkg: | |
5704d455 PP |
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 | ||
1fc90958 | 142 | # dir-pkg tar*-pkg - tarball targets |
6d983fea | 143 | # --------------------------------------------------------------------------- |
1fc90958 | 144 | |
1fc90958 MY |
145 | tar-install: FORCE |
146 | $(Q)$(MAKE) -f $(srctree)/Makefile | |
147 | +$(Q)$(srctree)/scripts/package/buildtar $@ | |
148 | ||
05e96e96 MY |
149 | quiet_cmd_tar = TAR $@ |
150 | cmd_tar = cd $<; tar cf ../$@ --owner=root --group=root --sort=name * | |
151 | ||
152 | linux-$(KERNELRELEASE)-$(ARCH).tar: tar-install | |
153 | $(call cmd,tar) | |
154 | ||
1fc90958 MY |
155 | PHONY += dir-pkg |
156 | dir-pkg: tar-install | |
157 | @echo "Kernel tree successfully created in $<" | |
158 | ||
05e96e96 MY |
159 | PHONY += tar-pkg |
160 | tar-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar | |
1fc90958 MY |
161 | @: |
162 | ||
05e96e96 MY |
163 | tar%-pkg: linux-$(KERNELRELEASE)-$(ARCH).tar.% FORCE |
164 | @: | |
6d983fea | 165 | |
e0ca1674 | 166 | # perf-tar*-src-pkg - generate a source tarball with perf source |
8e5564e6 ACM |
167 | # --------------------------------------------------------------------------- |
168 | ||
05e96e96 MY |
169 | .tmp_perf: |
170 | $(Q)mkdir .tmp_perf | |
e0ca1674 | 171 | |
05e96e96 MY |
172 | .tmp_perf/HEAD: .tmp_HEAD | .tmp_perf |
173 | $(call cmd,copy) | |
e0ca1674 MY |
174 | |
175 | quiet_cmd_perf_version_file = GEN $@ | |
176 | cmd_perf_version_file = cd $(srctree)/tools/perf; util/PERF-VERSION-GEN $(dir $(abspath $@)) | |
177 | ||
05e96e96 | 178 | # PERF-VERSION-FILE and .tmp_HEAD are independent, but this avoids updating the |
e0ca1674 MY |
179 | # timestamp of PERF-VERSION-FILE. |
180 | # The best is to fix tools/perf/util/PERF-VERSION-GEN. | |
05e96e96 | 181 | .tmp_perf/PERF-VERSION-FILE: .tmp_HEAD $(srctree)/tools/perf/util/PERF-VERSION-GEN | .tmp_perf |
e0ca1674 MY |
182 | $(call cmd,perf_version_file) |
183 | ||
05e96e96 MY |
184 | quiet_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 $<) | |
e0ca1674 | 190 | |
05e96e96 MY |
191 | targets += perf-$(KERNELVERSION).tar |
192 | perf-$(KERNELVERSION).tar: tools/perf/MANIFEST .tmp_perf/HEAD .tmp_perf/PERF-VERSION-FILE FORCE | |
193 | $(call if_changed,archive_perf) | |
194 | ||
195 | PHONY += perf-tar-src-pkg | |
196 | perf-tar-src-pkg: perf-$(KERNELVERSION).tar | |
197 | @: | |
e0ca1674 | 198 | |
05e96e96 MY |
199 | perf-tar%-src-pkg: perf-$(KERNELVERSION).tar.% FORCE |
200 | @: | |
8e5564e6 | 201 | |
1da177e4 LT |
202 | # Help text displayed when executing 'make help' |
203 | # --------------------------------------------------------------------------- | |
6a4f6a26 MY |
204 | PHONY += help |
205 | help: | |
8e5564e6 | 206 | @echo ' rpm-pkg - Build both source and binary RPM kernel packages' |
9c9b55a5 | 207 | @echo ' srcrpm-pkg - Build only the source kernel RPM package' |
3716001b RV |
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' | |
a64c0440 GU |
211 | @echo ' snap-pkg - Build only the binary kernel snap package' |
212 | @echo ' (will connect to external hosts)' | |
af7db99a | 213 | @echo ' dir-pkg - Build the kernel as a plain directory structure' |
8e5564e6 ACM |
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' | |
9a17f400 | 217 | @echo ' tarxz-pkg - Build the kernel as a xz compressed tarball' |
88f5e1e6 | 218 | @echo ' tarzst-pkg - Build the kernel as a zstd compressed tarball' |
e0ca1674 MY |
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' | |
000ec95f | 224 | |
7bf4582d MY |
225 | PHONY += FORCE |
226 | FORCE: | |
227 | ||
05e96e96 MY |
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 | ||
233 | existing-targets := $(wildcard $(sort $(targets))) | |
234 | ||
235 | -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) | |
236 | ||
000ec95f | 237 | .PHONY: $(PHONY) |