summaryrefslogblamecommitdiffstats
path: root/scripts/mkmakefile
blob: 85995f90e5c80e7c37775d03a21667b874e59b72 (plain) (tree)
1
2
3
4
5
6
7
8
9
         
                                  





                                                                       
 

                                                  
                                                       


              
                                    
                                 
  
 
                     

                                           


                                                      






                                     

                                                                                          


                                 
                                   
 

                                                   
 
                                                       
          
   
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Generates a small Makefile used in the root of the output
# directory, to allow make to be started from there.
# The Makefile also allow for more convinient build of external modules

# Usage
# $1 - Kernel src directory

# Only overwrite automatically generated Makefiles
# (so we do not overwrite kernel Makefile)
if test -e Makefile && ! grep -q Automatically Makefile
then
	exit 0
fi
if [ "${quiet}" != "silent_" ]; then
	echo "  GEN     Makefile"
fi

cat << EOF > Makefile
# Automatically generated by $0: don't edit

lastword = \$(word \$(words \$(1)),\$(1))
makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))

ifeq ("\$(origin V)", "command line")
VERBOSE := \$(V)
endif
ifneq (\$(VERBOSE),1)
Q := @
endif

MAKEARGS := -C $1
MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))

MAKEFLAGS += --no-print-directory

.PHONY: __sub-make \$(MAKECMDGOALS)

__sub-make:
	\$(Q)\$(MAKE) \$(MAKEARGS) \$(MAKECMDGOALS)

\$(filter-out __sub-make, \$(MAKECMDGOALS)): __sub-make
	@:
EOF