Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kbuild: support building external modules in a separate build directory

There has been a long-standing request to support building external
modules in a separate build directory.

This commit introduces a new environment variable, KBUILD_EXTMOD_OUTPUT,
and its shorthand Make variable, MO.

A simple usage:

$ make -C <kernel-dir> M=<module-src-dir> MO=<module-build-dir>

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>

+35 -11
+7 -1
Documentation/kbuild/kbuild.rst
··· 137 137 This variable can also be used to point to the kernel output directory when 138 138 building external modules against a pre-built kernel in a separate build 139 139 directory. Please note that this does NOT specify the output directory for the 140 - external modules themselves. 140 + external modules themselves. (Use KBUILD_EXTMOD_OUTPUT for that purpose.) 141 141 142 142 The output directory can also be specified using "O=...". 143 143 144 144 Setting "O=..." takes precedence over KBUILD_OUTPUT. 145 + 146 + KBUILD_EXTMOD_OUTPUT 147 + -------------------- 148 + Specify the output directory for external modules. 149 + 150 + Setting "MO=..." takes precedence over KBUILD_EXTMOD_OUTPUT. 145 151 146 152 KBUILD_EXTRA_WARN 147 153 -----------------
+7 -1
Documentation/kbuild/modules.rst
··· 66 66 of the kernel output directory if the kernel was built in a separate 67 67 build directory.) 68 68 69 - make -C $KDIR M=$PWD 69 + You can optionally pass MO= option if you want to build the modules in 70 + a separate directory. 71 + 72 + make -C $KDIR M=$PWD [MO=$BUILD_DIR] 70 73 71 74 -C $KDIR 72 75 The directory that contains the kernel and relevant build ··· 82 79 The value given to "M" is the absolute path of the 83 80 directory where the external module (kbuild file) is 84 81 located. 82 + 83 + MO=$BUILD_DIR 84 + Specifies a separate output directory for the external module. 85 85 86 86 Targets 87 87 -------
+18 -2
Makefile
··· 134 134 KBUILD_EXTMOD := $(M) 135 135 endif 136 136 137 + ifeq ("$(origin MO)", "command line") 138 + KBUILD_EXTMOD_OUTPUT := $(MO) 139 + endif 140 + 137 141 $(if $(word 2, $(KBUILD_EXTMOD)), \ 138 142 $(error building multiple external modules is not supported)) 139 143 ··· 191 187 else 192 188 objtree := $(CURDIR) 193 189 endif 194 - output := $(KBUILD_EXTMOD) 190 + output := $(or $(KBUILD_EXTMOD_OUTPUT),$(KBUILD_EXTMOD)) 195 191 # KBUILD_EXTMOD might be a relative path. Remember its absolute path before 196 192 # Make changes the working directory. 197 193 srcroot := $(realpath $(KBUILD_EXTMOD)) ··· 649 645 } > Makefile 650 646 651 647 outputmakefile: 648 + ifeq ($(KBUILD_EXTMOD),) 652 649 @if [ -f $(srctree)/.config -o \ 653 650 -d $(srctree)/include/config -o \ 654 651 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \ ··· 659 654 echo >&2 "***"; \ 660 655 false; \ 661 656 fi 662 - $(Q)ln -fsn $(srctree) source 657 + else 658 + @if [ -f $(srcroot)/modules.order ]; then \ 659 + echo >&2 "***"; \ 660 + echo >&2 "*** The external module source tree is not clean."; \ 661 + echo >&2 "*** Please run 'make -C $(abs_srctree) M=$(realpath $(srcroot)) clean'"; \ 662 + echo >&2 "***"; \ 663 + false; \ 664 + fi 665 + endif 666 + $(Q)ln -fsn $(srcroot) source 663 667 $(call cmd,makefile) 664 668 $(Q)test -e .gitignore || \ 665 669 { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore ··· 1953 1939 KBUILD_MODULES := 1 1954 1940 1955 1941 endif 1942 + 1943 + prepare: outputmakefile 1956 1944 1957 1945 # Preset locale variables to speed up the build process. Limit locale 1958 1946 # tweaks to this spot to avoid wrong language settings when running
+3 -5
scripts/Makefile.host
··· 96 96 $(KBUILD_HOSTRUSTFLAGS) $(HOST_EXTRARUSTFLAGS) \ 97 97 $(HOSTRUSTFLAGS_$(target-stem)) 98 98 99 - # $(objtree)/$(obj) for including generated headers from checkin source files 100 - ifeq ($(KBUILD_EXTMOD),) 99 + # $(obj) for including generated headers from checkin source files 101 100 ifdef building_out_of_srctree 102 - hostc_flags += -I $(objtree)/$(obj) 103 - hostcxx_flags += -I $(objtree)/$(obj) 104 - endif 101 + hostc_flags += -I $(obj) 102 + hostcxx_flags += -I $(obj) 105 103 endif 106 104 107 105 #####
-2
scripts/Makefile.lib
··· 213 213 214 214 # $(src) for including checkin headers from generated source files 215 215 # $(obj) for including generated headers from checkin source files 216 - ifeq ($(KBUILD_EXTMOD),) 217 216 ifdef building_out_of_srctree 218 217 _c_flags += $(addprefix -I, $(src) $(obj)) 219 218 _a_flags += $(addprefix -I, $(src) $(obj)) 220 219 _cpp_flags += $(addprefix -I, $(src) $(obj)) 221 - endif 222 220 endif 223 221 224 222 # If $(is-kernel-object) is 'y', this object will be linked to vmlinux or modules