rootdev: fix -d, add -c and -r. ifdefs for so use

Multiple changes:
- Ensure the -d flag trims off all of the partition info and only if there is a partition
- Add -c, device node creation for platform-agnostic /dev/ROOT, /dev/ROOT0 and /dev/ROOT1
- Add -r, resolve the first slave if the device is a device-mapper device
- Add -s, create a symlink from the found device to /dev/ACTIVE_ROOT
- Adds short-circuiting if /dev/ACTIVE_ROOT exists to both dm resolution and
  normal lookups
- Add support for building a library with a reusable header and interfaces

I'll follow this up with a change to install <rootdev/rootdev.h> and the .so in
the ebuild if the interface is at all interesting.  If prefered, I can just add:
rootdev -s -r to chromeos_startup, then AU can just rely on readlink(/dev/ACTIVE_ROOT).

BUG=chromium-os:5988
TEST=built for x86-generic testing with vroot: -r, -s, -c, -d and combos
     switching to non-vroot to test now
     can someone test arm for me?

Change-Id: Ibab8072afb012ea77d457517f1849e0917d02892

Review URL: http://codereview.chromium.org/3141038
diff --git a/Makefile b/Makefile
index 873a392..75d0702 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,19 @@
+# Copyright (C) 2010 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
 
-rootdev : rootdev.c
+all: rootdev librootdev.so.1.0
 
-.PHONY: clean clobber
-clean clobber:
-	rm -f rootdev
+rootdev: rootdev.c main.c
+	$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ -O2 -Wall
+
+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
+
+clean:
+	rm -f rootdev librootdev.so*
+
+.PHONY: clean