x86: include/asm-x86/pgalloc.h/bitops.h: checkpatch cleanups - formatting only
[sfrench/cifs-2.6.git] / scripts / mkmakefile
index 7f9d544f9b6c07339021bdb80762feeb7b95f9bf..e65d8b33faa4cae649044fb48d8fc87fa012d574 100644 (file)
 
 
 test ! -r $2/Makefile -o -O $2/Makefile || exit 0
+# Only overwrite automatically generated Makefiles
+# (so we do not overwrite kernel Makefile)
+if test -e $2/Makefile && ! grep -q Automatically $2/Makefile
+then
+       exit 0
+fi
 echo "  GEN     $2/Makefile"
 
 cat << EOF > $2/Makefile
@@ -19,18 +25,24 @@ cat << EOF > $2/Makefile
 VERSION = $3
 PATCHLEVEL = $4
 
-KERNELSRC    := $1
-KERNELOUTPUT := $2
+lastword = \$(word \$(words \$(1)),\$(1))
+makedir := \$(dir \$(call lastword,\$(MAKEFILE_LIST)))
+
+MAKEARGS := -C $1
+MAKEARGS += O=\$(if \$(patsubst /%,,\$(makedir)),\$(CURDIR)/)\$(patsubst %/,%,\$(makedir))
 
 MAKEFLAGS += --no-print-directory
 
 .PHONY: all \$(MAKECMDGOALS)
 
+all    := \$(filter-out all Makefile,\$(MAKECMDGOALS))
+
 all:
-       \$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT)
+       \$(MAKE) \$(MAKEARGS) \$(all)
 
 Makefile:;
 
-\$(filter-out all Makefile,\$(MAKECMDGOALS)) %/:
-       \$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT) \$@
+\$(all) %/: all
+       @:
+
 EOF