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 convenient build of external modules 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun# Usage 7*4882a593Smuzhiyun# $1 - Kernel src directory 8*4882a593Smuzhiyun# $2 - Output directory 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun 11*4882a593Smuzhiyuntest ! -r $2/Makefile -o -O $2/Makefile || exit 0 12*4882a593Smuzhiyun# Only overwrite automatically generated Makefiles 13*4882a593Smuzhiyun# (so we do not overwrite buildroot Makefile) 14*4882a593Smuzhiyunif test -e $2/Makefile && ! grep -q Automatically $2/Makefile 15*4882a593Smuzhiyunthen 16*4882a593Smuzhiyun exit 0 17*4882a593Smuzhiyunfi 18*4882a593Smuzhiyunecho " GEN $2/Makefile" 19*4882a593Smuzhiyun 20*4882a593Smuzhiyuncat << EOF > $2/Makefile 21*4882a593Smuzhiyun# Automatically generated by $0: don't edit 22*4882a593Smuzhiyun 23*4882a593Smuzhiyunifeq ("\$(origin V)", "command line") 24*4882a593SmuzhiyunVERBOSE := \$(V) 25*4882a593Smuzhiyunendif 26*4882a593Smuzhiyunifneq (\$(VERBOSE),1) 27*4882a593SmuzhiyunQ := @ 28*4882a593Smuzhiyunendif 29*4882a593Smuzhiyun 30*4882a593Smuzhiyunlastword = \$(word \$(words \$(1)),\$(1)) 31*4882a593Smuzhiyunmakedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST))) 32*4882a593Smuzhiyun 33*4882a593SmuzhiyunMAKEARGS := -C $1 34*4882a593SmuzhiyunMAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir)) 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunMAKEFLAGS += --no-print-directory 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun.PHONY: _all \$(MAKECMDGOALS) 39*4882a593Smuzhiyun 40*4882a593Smuzhiyunall := \$(filter-out Makefile,\$(MAKECMDGOALS)) 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun_all: 43*4882a593Smuzhiyun \$(Q)umask 0022 && \$(MAKE) \$(MAKEARGS) \$(all) 44*4882a593Smuzhiyun 45*4882a593SmuzhiyunMakefile:; 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun\$(all): _all 48*4882a593Smuzhiyun @: 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun%/: _all 51*4882a593Smuzhiyun @: 52*4882a593SmuzhiyunEOF 53