kbuild: add a phony target to run a command with Kbuild env vars
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 22 Jul 2023 04:47:55 +0000 (13:47 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Mon, 24 Jul 2023 15:59:32 +0000 (00:59 +0900)
There are some cases where we want to run a command with the same
environment variables as Kbuild uses. For example, 'make coccicheck'
invokes scripts/coccicheck from the top Makefile so that the script can
reference to ${LINUXINCLUDE}, ${KBUILD_EXTMOD}, etc. The top Makefile
defines several phony targets that run a script.

We do it also for an internally used script, which results in a somewhat
complex call graph.

One example:

 debian/rules binary-arch
   -> make intdeb-pkg
      -> scripts/package/builddeb

It is also tedious to add a dedicated target like 'intdeb-pkg' for each
use case.

Add a generic target 'run-command' to run an arbitrary command in an
environment with all Kbuild variables set.

The usage is:

  $ make run-command KBUILD_RUN_COMMAND=<command>

The concept is similar to:

  $ dpkg-architecture -c <command>

This executes <command> in an environment which has all DEB_* variables
defined.

Convert the existing 'make intdeb-pkg'.

Another possible usage is to interrogate a Make variable.

  $ make run-command KBUILD_RUN_COMMAND='echo $(KBUILD_CFLAGS)'

might be useful to see KBUILD_CFLAGS set by the top Makefile.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Makefile
scripts/Makefile.package
scripts/package/mkdebian

index d36e5361810faf0c8fb042a1a79b5bf0c3d207d6..8533ba64713c1ce4f9378f84a437338ab3d4d952 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2148,6 +2148,10 @@ kernelversion:
 image_name:
        @echo $(KBUILD_IMAGE)
 
+PHONY += run-command
+run-command:
+       $(Q)$(KBUILD_RUN_COMMAND)
+
 quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files)))
       cmd_rmfiles = rm -rf $(rm-files)
 
index e9217e997c683c7428e6fca61a9ef7f845c22b72..7cd61a374dae70689524592e809359fce206b9cb 100644 (file)
@@ -146,10 +146,6 @@ deb-pkg srcdeb-pkg bindeb-pkg:
                --no-check-builddeps) \
        $(DPKG_FLAGS))
 
-PHONY += intdeb-pkg
-intdeb-pkg:
-       +$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb
-
 # snap-pkg
 # ---------------------------------------------------------------------------
 PHONY += snap-pkg
index ba2453e08d408d1ebf8946c64b583b1fb9f336b3..9105abab9728caf4d9bf05203074906e8c8844c5 100755 (executable)
@@ -283,7 +283,8 @@ build: build-arch
 binary-indep:
 binary-arch: build-arch
        \$(MAKE) -f \$(srctree)/Makefile ARCH=${ARCH} \
-       KERNELRELEASE=\$(KERNELRELEASE) intdeb-pkg
+       KERNELRELEASE=\$(KERNELRELEASE) \
+       run-command KBUILD_RUN_COMMAND=+\$(srctree)/scripts/package/builddeb
 
 clean:
        rm -rf debian/files debian/linux-*