mkmakefile 1.19 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
#!/bin/sh
2
# SPDX-License-Identifier: GPL-2.0
Linus Torvalds's avatar
Linus Torvalds committed
3 4 5 6 7 8 9 10 11 12 13
# Generates a small Makefile used in the root of the output
# directory, to allow make to be started from there.
# The Makefile also allow for more convinient build of external modules

# Usage
# $1 - Kernel src directory
# $2 - Output directory
# $3 - version
# $4 - patchlevel


14
test ! -r $2/Makefile -o -O $2/Makefile || exit 0
15 16
# Only overwrite automatically generated Makefiles
# (so we do not overwrite kernel Makefile)
17
if test -e $2/Makefile && ! grep -q Automatically $2/Makefile
18 19 20
then
	exit 0
fi
21 22 23
if [ "${quiet}" != "silent_" ]; then
	echo "  GEN     $2/Makefile"
fi
24 25

cat << EOF > $2/Makefile
Linus Torvalds's avatar
Linus Torvalds committed
26 27 28 29 30
# Automatically generated by $0: don't edit

VERSION = $3
PATCHLEVEL = $4

31 32 33
lastword = \$(word \$(words \$(1)),\$(1))
makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))

34 35 36 37 38 39 40
ifeq ("\$(origin V)", "command line")
VERBOSE := \$(V)
endif
ifneq (\$(VERBOSE),1)
Q := @
endif

41 42
MAKEARGS := -C $1
MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
Linus Torvalds's avatar
Linus Torvalds committed
43 44 45

MAKEFLAGS += --no-print-directory

46
.PHONY: __sub-make \$(MAKECMDGOALS)
Jan Beulich's avatar
Jan Beulich committed
47

48 49
__sub-make:
	\$(Q)\$(MAKE) \$(MAKEARGS) \$(MAKECMDGOALS)
50

51
\$(filter-out __sub-make, \$(MAKECMDGOALS)): __sub-make
Jan Beulich's avatar
Jan Beulich committed
52
	@:
Linus Torvalds's avatar
Linus Torvalds committed
53
EOF