perf tools: Fix build error on read only source.
[sfrench/cifs-2.6.git] / scripts / mkmakefile
index e0f54b9d8feca95bf693ec7cc9ad294bd70ab1df..67d59c7a18dc57b1580a833ed37e832eff227c85 100644 (file)
@@ -17,7 +17,9 @@ if test -e $2/Makefile && ! grep -q Automatically $2/Makefile
 then
        exit 0
 fi
-echo "  GEN     $2/Makefile"
+if [ "${quiet}" != "silent_" ]; then
+       echo "  GEN     $2/Makefile"
+fi
 
 cat << EOF > $2/Makefile
 # Automatically generated by $0: don't edit
@@ -25,8 +27,11 @@ 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
 
@@ -35,10 +40,11 @@ MAKEFLAGS += --no-print-directory
 all    := \$(filter-out all Makefile,\$(MAKECMDGOALS))
 
 all:
-       \$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT) \$(all)
+       \$(MAKE) \$(MAKEARGS) \$(all)
 
 Makefile:;
 
 \$(all) %/: all
        @:
+
 EOF