support out-of-tree builds

This will allow us to avoid doing a git clone.

BUG=None
TEST=`emerge-x86-alex rootdev` still works

Change-Id: I2515981c5aa426eebecc6333d8ae7b50276ae577
Reviewed-on: https://chromium-review.googlesource.com/175520
Reviewed-by: Liam McLoughlin <lmcloughlin@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/Makefile b/Makefile
index 75d0702..f50a96e 100644
--- a/Makefile
+++ b/Makefile
@@ -2,18 +2,21 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-all: rootdev librootdev.so.1.0
+OUT = $(CURDIR)
+$(shell mkdir -p $(OUT))
 
-rootdev: rootdev.c main.c
+all: $(OUT)/rootdev $(OUT)/librootdev.so.1.0
+
+$(OUT)/rootdev: rootdev.c main.c
 	$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ -O2 -Wall
 
-librootdev.so.1.0: rootdev.c
+$(OUT)/librootdev.so.1.0: rootdev.c
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -fPIC \
-          -Wl,-soname,librootdev.so.1 $< -o $@
-	ln -s $@ librootdev.so.1
-	ln -s $@ librootdev.so
+		-Wl,-soname,librootdev.so.1 $< -o $@
+	ln -s $(@F) $(OUT)/librootdev.so.1
+	ln -s $(@F) $(OUT)/librootdev.so
 
 clean:
-	rm -f rootdev librootdev.so*
+	rm -f $(OUT)/rootdev $(OUT)/librootdev.so*
 
 .PHONY: clean