-BUILD:= $(foreach i,$(BUILD_POSSIBLE),$(wildcard $(i)/environment.mak))
-BUILD:= $(patsubst %/,%,$(firstword $(dir $(BUILD))))
+BUILDX:= $(foreach i,$(BUILD_POSSIBLE),$(wildcard $(i)/environment.mak*))
+
+ifeq ($(words $(BUILDX)),0)
+
+# Check for a busted wildcard function. We use this function in several
+# places, it must work.
+ifeq ($(words $(wildcard *)),0)
+error-all/environment.mak:
+ echo You have a broken version of GNU Make - upgrade.
+ error-out-and-die
+else
+error-all/environment.mak:
+ echo Can not find the build directory in $(BUILD_POSSIBLE) -- use BUILD=
+ error-out-and-die
+endif