18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci# Makefile for the different targets used to generate full packages of a kernel
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciinclude $(srctree)/scripts/Kbuild.include
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci# RPM target
78c2ecf20Sopenharmony_ci# ---------------------------------------------------------------------------
88c2ecf20Sopenharmony_ci# The rpm target generates two rpm files:
98c2ecf20Sopenharmony_ci# /usr/src/packages/SRPMS/kernel-2.6.7rc2-1.src.rpm
108c2ecf20Sopenharmony_ci# /usr/src/packages/RPMS/i386/kernel-2.6.7rc2-1.<arch>.rpm
118c2ecf20Sopenharmony_ci# The src.rpm files includes all source for the kernel being built
128c2ecf20Sopenharmony_ci# The <arch>.rpm includes kernel configuration, modules etc.
138c2ecf20Sopenharmony_ci#
148c2ecf20Sopenharmony_ci# Process to create the rpm files
158c2ecf20Sopenharmony_ci# a) clean the kernel
168c2ecf20Sopenharmony_ci# b) Generate .spec file
178c2ecf20Sopenharmony_ci# c) Build a tar ball, using symlink to make kernel version
188c2ecf20Sopenharmony_ci#    first entry in the path
198c2ecf20Sopenharmony_ci# d) and pack the result to a tar.gz file
208c2ecf20Sopenharmony_ci# e) generate the rpm files, based on kernel.spec
218c2ecf20Sopenharmony_ci# - Use /. to avoid tar packing just the symlink
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci# Note that the rpm-pkg target cannot be used with KBUILD_OUTPUT,
248c2ecf20Sopenharmony_ci# but the binrpm-pkg target can; for some reason O= gets ignored.
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci# Remove hyphens since they have special meaning in RPM filenames
278c2ecf20Sopenharmony_ciKERNELPATH := kernel-$(subst -,_,$(KERNELRELEASE))
288c2ecf20Sopenharmony_ciKDEB_SOURCENAME ?= linux-$(KERNELRELEASE)
298c2ecf20Sopenharmony_ciKBUILD_PKG_ROOTCMD ?="fakeroot -u"
308c2ecf20Sopenharmony_ciexport KDEB_SOURCENAME
318c2ecf20Sopenharmony_ci# Include only those top-level files that are needed by make, plus the GPL copy
328c2ecf20Sopenharmony_ciTAR_CONTENT := $(KBUILD_ALLDIRS) .config .scmversion Makefile \
338c2ecf20Sopenharmony_ci               Kbuild Kconfig COPYING $(wildcard localversion*)
348c2ecf20Sopenharmony_ciMKSPEC     := $(srctree)/scripts/package/mkspec
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciquiet_cmd_src_tar = TAR     $(2).tar.gz
378c2ecf20Sopenharmony_ci      cmd_src_tar = \
388c2ecf20Sopenharmony_ciif test "$(objtree)" != "$(srctree)"; then \
398c2ecf20Sopenharmony_ci	echo >&2; \
408c2ecf20Sopenharmony_ci	echo >&2 "  ERROR:"; \
418c2ecf20Sopenharmony_ci	echo >&2 "  Building source tarball is not possible outside the"; \
428c2ecf20Sopenharmony_ci	echo >&2 "  kernel source tree. Don't set KBUILD_OUTPUT, or use the"; \
438c2ecf20Sopenharmony_ci	echo >&2 "  binrpm-pkg or bindeb-pkg target instead."; \
448c2ecf20Sopenharmony_ci	echo >&2; \
458c2ecf20Sopenharmony_ci	false; \
468c2ecf20Sopenharmony_cifi ; \
478c2ecf20Sopenharmony_ci$(srctree)/scripts/setlocalversion --save-scmversion; \
488c2ecf20Sopenharmony_citar -I $(KGZIP) -c $(RCS_TAR_IGNORE) -f $(2).tar.gz \
498c2ecf20Sopenharmony_ci	--transform 's:^:$(2)/:S' $(TAR_CONTENT) $(3); \
508c2ecf20Sopenharmony_cirm -f $(objtree)/.scmversion
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci# rpm-pkg
538c2ecf20Sopenharmony_ci# ---------------------------------------------------------------------------
548c2ecf20Sopenharmony_ciPHONY += rpm-pkg
558c2ecf20Sopenharmony_cirpm-pkg:
568c2ecf20Sopenharmony_ci	$(MAKE) clean
578c2ecf20Sopenharmony_ci	$(CONFIG_SHELL) $(MKSPEC) >$(objtree)/kernel.spec
588c2ecf20Sopenharmony_ci	$(call cmd,src_tar,$(KERNELPATH),kernel.spec)
598c2ecf20Sopenharmony_ci	+rpmbuild $(RPMOPTS) --target $(UTS_MACHINE) -ta $(KERNELPATH).tar.gz \
608c2ecf20Sopenharmony_ci	--define='_smp_mflags %{nil}'
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci# binrpm-pkg
638c2ecf20Sopenharmony_ci# ---------------------------------------------------------------------------
648c2ecf20Sopenharmony_ciPHONY += binrpm-pkg
658c2ecf20Sopenharmony_cibinrpm-pkg:
668c2ecf20Sopenharmony_ci	$(MAKE) -f $(srctree)/Makefile
678c2ecf20Sopenharmony_ci	$(CONFIG_SHELL) $(MKSPEC) prebuilt > $(objtree)/binkernel.spec
688c2ecf20Sopenharmony_ci	+rpmbuild $(RPMOPTS) --define "_builddir $(objtree)" --target \
698c2ecf20Sopenharmony_ci		$(UTS_MACHINE) -bb $(objtree)/binkernel.spec
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ciPHONY += deb-pkg
728c2ecf20Sopenharmony_cideb-pkg:
738c2ecf20Sopenharmony_ci	$(MAKE) clean
748c2ecf20Sopenharmony_ci	$(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
758c2ecf20Sopenharmony_ci	$(call cmd,src_tar,$(KDEB_SOURCENAME))
768c2ecf20Sopenharmony_ci	origversion=$$(dpkg-parsechangelog -SVersion |sed 's/-[^-]*$$//');\
778c2ecf20Sopenharmony_ci		mv $(KDEB_SOURCENAME).tar.gz ../$(KDEB_SOURCENAME)_$${origversion}.orig.tar.gz
788c2ecf20Sopenharmony_ci	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -i.git -us -uc
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ciPHONY += bindeb-pkg
818c2ecf20Sopenharmony_cibindeb-pkg:
828c2ecf20Sopenharmony_ci	$(CONFIG_SHELL) $(srctree)/scripts/package/mkdebian
838c2ecf20Sopenharmony_ci	+dpkg-buildpackage -r$(KBUILD_PKG_ROOTCMD) -a$$(cat debian/arch) $(DPKG_FLAGS) -b -nc -uc
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciPHONY += intdeb-pkg
868c2ecf20Sopenharmony_ciintdeb-pkg:
878c2ecf20Sopenharmony_ci	+$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci# snap-pkg
908c2ecf20Sopenharmony_ci# ---------------------------------------------------------------------------
918c2ecf20Sopenharmony_ciPHONY += snap-pkg
928c2ecf20Sopenharmony_cisnap-pkg:
938c2ecf20Sopenharmony_ci	rm -rf $(objtree)/snap
948c2ecf20Sopenharmony_ci	mkdir $(objtree)/snap
958c2ecf20Sopenharmony_ci	$(MAKE) clean
968c2ecf20Sopenharmony_ci	$(call cmd,src_tar,$(KERNELPATH))
978c2ecf20Sopenharmony_ci	sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \
988c2ecf20Sopenharmony_ci		s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \
998c2ecf20Sopenharmony_ci		$(srctree)/scripts/package/snapcraft.template > \
1008c2ecf20Sopenharmony_ci		$(objtree)/snap/snapcraft.yaml
1018c2ecf20Sopenharmony_ci	cd $(objtree)/snap && \
1028c2ecf20Sopenharmony_ci	snapcraft --target-arch=$(UTS_MACHINE)
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci# tarball targets
1058c2ecf20Sopenharmony_ci# ---------------------------------------------------------------------------
1068c2ecf20Sopenharmony_citar-pkgs := dir-pkg tar-pkg targz-pkg tarbz2-pkg tarxz-pkg
1078c2ecf20Sopenharmony_ciPHONY += $(tar-pkgs)
1088c2ecf20Sopenharmony_ci$(tar-pkgs):
1098c2ecf20Sopenharmony_ci	$(MAKE) -f $(srctree)/Makefile
1108c2ecf20Sopenharmony_ci	+$(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci# perf-pkg - generate a source tarball with perf source
1138c2ecf20Sopenharmony_ci# ---------------------------------------------------------------------------
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ciperf-tar=perf-$(KERNELVERSION)
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ciquiet_cmd_perf_tar = TAR
1188c2ecf20Sopenharmony_ci      cmd_perf_tar = \
1198c2ecf20Sopenharmony_cigit --git-dir=$(srctree)/.git archive --prefix=$(perf-tar)/         \
1208c2ecf20Sopenharmony_ci	HEAD^{tree} $$(cd $(srctree);                               \
1218c2ecf20Sopenharmony_ci		       echo $$(cat tools/perf/MANIFEST)) \
1228c2ecf20Sopenharmony_ci	-o $(perf-tar).tar;                                         \
1238c2ecf20Sopenharmony_cimkdir -p $(perf-tar);                                               \
1248c2ecf20Sopenharmony_cigit --git-dir=$(srctree)/.git rev-parse HEAD > $(perf-tar)/HEAD;    \
1258c2ecf20Sopenharmony_ci(cd $(srctree)/tools/perf;                                          \
1268c2ecf20Sopenharmony_ciutil/PERF-VERSION-GEN $(CURDIR)/$(perf-tar)/);              \
1278c2ecf20Sopenharmony_citar rf $(perf-tar).tar $(perf-tar)/HEAD $(perf-tar)/PERF-VERSION-FILE; \
1288c2ecf20Sopenharmony_cirm -r $(perf-tar);                                                  \
1298c2ecf20Sopenharmony_ci$(if $(findstring tar-src,$@),,                                     \
1308c2ecf20Sopenharmony_ci$(if $(findstring bz2,$@),$(KBZIP2),                                 \
1318c2ecf20Sopenharmony_ci$(if $(findstring gz,$@),$(KGZIP),                                  \
1328c2ecf20Sopenharmony_ci$(if $(findstring xz,$@),$(XZ),                                     \
1338c2ecf20Sopenharmony_ci$(error unknown target $@))))                                       \
1348c2ecf20Sopenharmony_ci	-f -9 $(perf-tar).tar)
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ciperf-tar-pkgs := perf-tar-src-pkg perf-targz-src-pkg perf-tarbz2-src-pkg perf-tarxz-src-pkg
1378c2ecf20Sopenharmony_ciPHONY += $(perf-tar-pkgs)
1388c2ecf20Sopenharmony_ci$(perf-tar-pkgs):
1398c2ecf20Sopenharmony_ci	$(call cmd,perf_tar)
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci# Help text displayed when executing 'make help'
1428c2ecf20Sopenharmony_ci# ---------------------------------------------------------------------------
1438c2ecf20Sopenharmony_ciPHONY += help
1448c2ecf20Sopenharmony_cihelp:
1458c2ecf20Sopenharmony_ci	@echo '  rpm-pkg             - Build both source and binary RPM kernel packages'
1468c2ecf20Sopenharmony_ci	@echo '  binrpm-pkg          - Build only the binary kernel RPM package'
1478c2ecf20Sopenharmony_ci	@echo '  deb-pkg             - Build both source and binary deb kernel packages'
1488c2ecf20Sopenharmony_ci	@echo '  bindeb-pkg          - Build only the binary kernel deb package'
1498c2ecf20Sopenharmony_ci	@echo '  snap-pkg            - Build only the binary kernel snap package'
1508c2ecf20Sopenharmony_ci	@echo '                        (will connect to external hosts)'
1518c2ecf20Sopenharmony_ci	@echo '  dir-pkg             - Build the kernel as a plain directory structure'
1528c2ecf20Sopenharmony_ci	@echo '  tar-pkg             - Build the kernel as an uncompressed tarball'
1538c2ecf20Sopenharmony_ci	@echo '  targz-pkg           - Build the kernel as a gzip compressed tarball'
1548c2ecf20Sopenharmony_ci	@echo '  tarbz2-pkg          - Build the kernel as a bzip2 compressed tarball'
1558c2ecf20Sopenharmony_ci	@echo '  tarxz-pkg           - Build the kernel as a xz compressed tarball'
1568c2ecf20Sopenharmony_ci	@echo '  perf-tar-src-pkg    - Build $(perf-tar).tar source tarball'
1578c2ecf20Sopenharmony_ci	@echo '  perf-targz-src-pkg  - Build $(perf-tar).tar.gz source tarball'
1588c2ecf20Sopenharmony_ci	@echo '  perf-tarbz2-src-pkg - Build $(perf-tar).tar.bz2 source tarball'
1598c2ecf20Sopenharmony_ci	@echo '  perf-tarxz-src-pkg  - Build $(perf-tar).tar.xz source tarball'
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci.PHONY: $(PHONY)
162