Makefile: support relative paths for out of tree builds

And complain if the output directory cannot be created.
diff --git a/project/Makefile.in b/project/Makefile.in
index 034b1fa..6aa1d43 100644
--- a/project/Makefile.in
+++ b/project/Makefile.in
@@ -30,7 +30,8 @@
 BASE_DIR:=$(shell pwd)
 ifdef O
 ifeq ("$(origin O)", "command line")
-BASE_DIR := $(O)
+BASE_DIR := $(shell mkdir -p $(O) && cd $(O) && pwd)
+$(if $(BASE_DIR),, $(error output directory "$(O)" does not exist))
 endif
 endif