blob: 85995f90e5c80e7c37775d03a21667b874e59b72 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Sam Ravnborg18c32da2007-12-09 08:55:13 +010010# Only overwrite automatically generated Makefiles
11# (so we do not overwrite kernel Makefile)
Masahiro Yamada4fd61272018-09-18 17:45:53 +090012if test -e Makefile && ! grep -q Automatically Makefile
Sam Ravnborg18c32da2007-12-09 08:55:13 +010013then
14 exit 0
15fi
Sam Ravnborgd2301242008-11-21 23:00:12 +010016if [ "${quiet}" != "silent_" ]; then
Masahiro Yamada4fd61272018-09-18 17:45:53 +090017 echo " GEN Makefile"
Sam Ravnborgd2301242008-11-21 23:00:12 +010018fi
Jan Beulichfd5f0cd2006-05-02 12:33:20 +020019
Masahiro Yamada4fd61272018-09-18 17:45:53 +090020cat << EOF > Makefile
Linus Torvalds1da177e2005-04-16 15:20:36 -070021# Automatically generated by $0: don't edit
22
Jan Beulich1d3b3bf2008-01-11 09:09:00 +000023lastword = \$(word \$(words \$(1)),\$(1))
24makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
25
Peter Foley0ff35772011-07-04 18:55:23 -040026ifeq ("\$(origin V)", "command line")
27VERBOSE := \$(V)
28endif
29ifneq (\$(VERBOSE),1)
30Q := @
31endif
32
Jan Beulich1d3b3bf2008-01-11 09:09:00 +000033MAKEARGS := -C $1
34MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36MAKEFLAGS += --no-print-directory
37
Masahiro Yamada9319f452014-04-09 15:51:35 +090038.PHONY: __sub-make \$(MAKECMDGOALS)
Jan Beulich96678282006-01-30 10:05:09 +010039
Masahiro Yamada9319f452014-04-09 15:51:35 +090040__sub-make:
41 \$(Q)\$(MAKE) \$(MAKEARGS) \$(MAKECMDGOALS)
Milton Miller0b357862007-09-21 18:09:02 -050042
Masahiro Yamada9319f452014-04-09 15:51:35 +090043\$(filter-out __sub-make, \$(MAKECMDGOALS)): __sub-make
Jan Beulich3c955b42010-08-16 11:58:58 +010044 @:
Linus Torvalds1da177e2005-04-16 15:20:36 -070045EOF