From: Matthias Schiffer <mschiffer@universe-factory.net>
Date: Sun, 24 Apr 2016 08:45:44 +0200
Subject: rules.mk: make the locked template available even if flock has not been built yet (fall back to unlocked shell command)

Signed-off-by: Felix Fietkau <nbd@openwrt.org>

Backport of r48414

diff --git a/rules.mk b/rules.mk
index 9d0134d..ece5026 100644
--- a/rules.mk
+++ b/rules.mk
@@ -310,12 +310,16 @@ endef
 # Execute commands under flock
 # $(1) => The shell expression.
 # $(2) => The lock name. If not given, the global lock will be used.
-define locked
+ifneq ($(wildcard $(STAGING_DIR_HOST)/bin/flock),)
+  define locked
 	SHELL= \
-	$(STAGING_DIR_HOST)/bin/flock \
+	flock \
 		$(TMP_DIR)/.$(if $(2),$(strip $(2)),global).flock \
 		-c '$(subst ','\'',$(1))'
-endef
+  endef
+else
+  locked=$(1)
+endif
 
 # Recursively copy paths into another directory, purge dangling
 # symlinks before.