Add scripts/Makefile.container to wrap the make command in a container
using the CONTAINER= variable to specify the image name.  For example:

    make -f scripts/Makefile.container CONTAINER=korg-gcc defconfig

The container image name is entirely arbitrary and the container tool
may be Docker, Podman or any other compatible alternative specified by
the CONTAINER_COMMAND variable.  The default is set to docker for now.

Cc: Nathan Chancellor <[email protected]>
Cc: Miguel Ojeda <[email protected]>
Link: 
https://lore.kernel.org/all/[email protected]/
Signed-off-by: Guillaume Tucker <[email protected]>
---
 scripts/Makefile.container | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 scripts/Makefile.container

diff --git a/scripts/Makefile.container b/scripts/Makefile.container
new file mode 100644
index 000000000000..711cf9188016
--- /dev/null
+++ b/scripts/Makefile.container
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0
+
+ifeq ($(CONTAINER),)
+$(error "Usage: make CONTAINER=<container-image-name> [...]")
+endif
+CONTAINER_COMMAND ?= docker
+PHONY := __all
+
+__all:
+%:
+       @echo Running in $(CONTAINER_COMMAND) $(CONTAINER)
+       @$(CONTAINER_COMMAND) run -it -v $(PWD):/src -w /src \
+       $(CONTAINER) $(MAKE) \
+       $(subst CONTAINER=$(CONTAINER),,$(MAKEFLAGS)) \
+       $(GNUMAKEFLAGS) $(MAKECMDGOALS)
-- 
2.47.3


Reply via email to