netns xfrm: fix "ip xfrm state|policy count" misreport
[safe/jmp/linux-2.6] / scripts / mkmakefile
index 7f9d544..67d59c7 100644 (file)
 
 
 test ! -r $2/Makefile -o -O $2/Makefile || exit 0
-echo "  GEN     $2/Makefile"
+# 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
+if [ "${quiet}" != "silent_" ]; then
+       echo "  GEN     $2/Makefile"
+fi
 
 cat << EOF > $2/Makefile
 # Automatically generated by $0: don't edit
@@ -19,18 +27,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