blob: 0cc04426074403458583b73339754c2a588bfa13 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#!/bin/sh
2# Generates a small Makefile used in the root of the output
3# directory, to allow make to be started from there.
4# The Makefile also allow for more convinient build of external modules
5
6# Usage
7# $1 - Kernel src directory
8# $2 - Output directory
9# $3 - version
10# $4 - patchlevel
11
12
Jan Beulichfd5f0cd2006-05-02 12:33:20 +020013test ! -r $2/Makefile -o -O $2/Makefile || exit 0
Sam Ravnborg18c32da2007-12-09 08:55:13 +010014# Only overwrite automatically generated Makefiles
15# (so we do not overwrite kernel Makefile)
Guillaume Chazarain971edcf2007-12-11 13:22:08 +010016if test -e $2/Makefile && ! grep -q Automatically $2/Makefile
Sam Ravnborg18c32da2007-12-09 08:55:13 +010017then
18 exit 0
19fi
Sam Ravnborgd2301242008-11-21 23:00:12 +010020if [ "${quiet}" != "silent_" ]; then
21 echo " GEN $2/Makefile"
22fi
Jan Beulichfd5f0cd2006-05-02 12:33:20 +020023
24cat << EOF > $2/Makefile
Linus Torvalds1da177e2005-04-16 15:20:36 -070025# Automatically generated by $0: don't edit
26
27VERSION = $3
28PATCHLEVEL = $4
29
Jan Beulich1d3b3bf2008-01-11 09:09:00 +000030lastword = \$(word \$(words \$(1)),\$(1))
31makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
32
Peter Foley0ff35772011-07-04 18:55:23 -040033ifeq ("\$(origin V)", "command line")
34VERBOSE := \$(V)
35endif
36ifneq (\$(VERBOSE),1)
37Q := @
38endif
39
Jan Beulich1d3b3bf2008-01-11 09:09:00 +000040MAKEARGS := -C $1
41MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43MAKEFLAGS += --no-print-directory
44
Jan Beulich96678282006-01-30 10:05:09 +010045.PHONY: all \$(MAKECMDGOALS)
46
Milton Miller0b357862007-09-21 18:09:02 -050047all := \$(filter-out all Makefile,\$(MAKECMDGOALS))
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049all:
Peter Foley0ff35772011-07-04 18:55:23 -040050 \$(Q)\$(MAKE) \$(MAKEARGS) \$(all)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Jan Beulich96678282006-01-30 10:05:09 +010052Makefile:;
53
Jan Beulich3c955b42010-08-16 11:58:58 +010054\$(all): all
Milton Miller0b357862007-09-21 18:09:02 -050055 @:
Jan Beulich1d3b3bf2008-01-11 09:09:00 +000056
Jan Beulich3c955b42010-08-16 11:58:58 +010057%/: all
58 @:
Linus Torvalds1da177e2005-04-16 15:20:36 -070059EOF