Skip to content

Commit 1d3b3bf

Browse files
Jan Beulichsravnborg
authored andcommitted
kbuild: scripts/mkmakefile: dynamic determination of output directory
Rather than fixing the output directory in the generated Makefile, determine it from the placement of Makefile. This allows moving the build tree around or accessing it through different mount paths. (The lastword definition is a compatibility one for make prior to 3.81; newer make will simply ignore it and use the [faster] built-in.) Signed-off-by: Jan Beulich <jbeulich@novell.com> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
1 parent df578e7 commit 1d3b3bf

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎scripts/mkmakefile‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ cat << EOF > $2/Makefile
2525
VERSION = $3
2626
PATCHLEVEL = $4
2727
28-
KERNELSRC := $1
29-
KERNELOUTPUT := $2
28+
lastword = \$(word \$(words \$(1)),\$(1))
29+
makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
30+
31+
MAKEARGS := -C $1
32+
MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
3033
3134
MAKEFLAGS += --no-print-directory
3235
@@ -35,10 +38,11 @@ MAKEFLAGS += --no-print-directory
3538
all := \$(filter-out all Makefile,\$(MAKECMDGOALS))
3639
3740
all:
38-
\$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT) \$(all)
41+
\$(MAKE) \$(MAKEARGS) \$(all)
3942
4043
Makefile:;
4144
4245
\$(all) %/: all
4346
@:
47+
4448
EOF

0 commit comments

Comments
 (0)