xref: /OK3568_Linux_fs/u-boot/scripts/mkmakefile (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh
2*4882a593Smuzhiyun# Generates a small Makefile used in the root of the output
3*4882a593Smuzhiyun# directory, to allow make to be started from there.
4*4882a593Smuzhiyun# The Makefile also allow for more convinient build of external modules
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun# Usage
7*4882a593Smuzhiyun# $1 - Kernel src directory
8*4882a593Smuzhiyun# $2 - Output directory
9*4882a593Smuzhiyun# $3 - version
10*4882a593Smuzhiyun# $4 - patchlevel
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun
13*4882a593Smuzhiyuntest ! -r $2/Makefile -o -O $2/Makefile || exit 0
14*4882a593Smuzhiyun# Only overwrite automatically generated Makefiles
15*4882a593Smuzhiyun# (so we do not overwrite kernel Makefile)
16*4882a593Smuzhiyunif test -e $2/Makefile && ! grep -q Automatically $2/Makefile
17*4882a593Smuzhiyunthen
18*4882a593Smuzhiyun	exit 0
19*4882a593Smuzhiyunfi
20*4882a593Smuzhiyunif [ "${quiet}" != "silent_" ]; then
21*4882a593Smuzhiyun	echo "  GEN     $2/Makefile"
22*4882a593Smuzhiyunfi
23*4882a593Smuzhiyun
24*4882a593Smuzhiyuncat << EOF > $2/Makefile
25*4882a593Smuzhiyun# Automatically generated by $0: don't edit
26*4882a593Smuzhiyun
27*4882a593SmuzhiyunVERSION = $3
28*4882a593SmuzhiyunPATCHLEVEL = $4
29*4882a593Smuzhiyun
30*4882a593Smuzhiyunlastword = \$(word \$(words \$(1)),\$(1))
31*4882a593Smuzhiyunmakedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
32*4882a593Smuzhiyun
33*4882a593Smuzhiyunifeq ("\$(origin V)", "command line")
34*4882a593SmuzhiyunVERBOSE := \$(V)
35*4882a593Smuzhiyunendif
36*4882a593Smuzhiyunifneq (\$(VERBOSE),1)
37*4882a593SmuzhiyunQ := @
38*4882a593Smuzhiyunendif
39*4882a593Smuzhiyun
40*4882a593SmuzhiyunMAKEARGS := -C $1
41*4882a593SmuzhiyunMAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
42*4882a593Smuzhiyun
43*4882a593SmuzhiyunMAKEFLAGS += --no-print-directory
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun.PHONY: __sub-make \$(MAKECMDGOALS)
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun__sub-make:
48*4882a593Smuzhiyun	\$(Q)\$(MAKE) \$(MAKEARGS) \$(MAKECMDGOALS)
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun\$(filter-out __sub-make, \$(MAKECMDGOALS)): __sub-make
51*4882a593Smuzhiyun	@:
52*4882a593SmuzhiyunEOF
53