blob: e19d6565f24570363e0bd464e64f1abc01e25ccb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#!/bin/sh
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01002# SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07003# Generates a small Makefile used in the root of the output
4# directory, to allow make to be started from there.
5# The Makefile also allow for more convinient build of external modules
6
7# Usage
8# $1 - Kernel src directory
9# $2 - Output directory
10# $3 - version
11# $4 - patchlevel
12
13
Jan Beulichfd5f0cd2006-05-02 12:33:20 +020014test ! -r $2/Makefile -o -O $2/Makefile || exit 0
Sam Ravnborg18c32da2007-12-09 08:55:13 +010015# Only overwrite automatically generated Makefiles
16# (so we do not overwrite kernel Makefile)
Guillaume Chazarain971edcf2007-12-11 13:22:08 +010017if test -e $2/Makefile && ! grep -q Automatically $2/Makefile
Sam Ravnborg18c32da2007-12-09 08:55:13 +010018then
19 exit 0
20fi
Sam Ravnborgd2301242008-11-21 23:00:12 +010021if [ "${quiet}" != "silent_" ]; then
22 echo " GEN $2/Makefile"
23fi
Jan Beulichfd5f0cd2006-05-02 12:33:20 +020024
25cat << EOF > $2/Makefile
Linus Torvalds1da177e2005-04-16 15:20:36 -070026# Automatically generated by $0: don't edit
27
28VERSION = $3
29PATCHLEVEL = $4
30
Jan Beulich1d3b3bf2008-01-11 09:09:00 +000031lastword = \$(word \$(words \$(1)),\$(1))
32makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
33
Peter Foley0ff35772011-07-04 18:55:23 -040034ifeq ("\$(origin V)", "command line")
35VERBOSE := \$(V)
36endif
37ifneq (\$(VERBOSE),1)
38Q := @
39endif
40
Jan Beulich1d3b3bf2008-01-11 09:09:00 +000041MAKEARGS := -C $1
42MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44MAKEFLAGS += --no-print-directory
45
Masahiro Yamada9319f452014-04-09 15:51:35 +090046.PHONY: __sub-make \$(MAKECMDGOALS)
Jan Beulich96678282006-01-30 10:05:09 +010047
Masahiro Yamada9319f452014-04-09 15:51:35 +090048__sub-make:
49 \$(Q)\$(MAKE) \$(MAKEARGS) \$(MAKECMDGOALS)
Milton Miller0b357862007-09-21 18:09:02 -050050
Masahiro Yamada9319f452014-04-09 15:51:35 +090051\$(filter-out __sub-make, \$(MAKECMDGOALS)): __sub-make
Jan Beulich3c955b42010-08-16 11:58:58 +010052 @:
Linus Torvalds1da177e2005-04-16 15:20:36 -070053EOF