verity-static: bring back static compilation for verity

This common.mk is old, but the basics of this are good. This shows how to get
all your static libraries dynamically and link them.  The trick is picking PIC
over PIE since toolchains rarely ship with PIE components.  If we havepie
archives, we should use them :)

TEST=builds and runs
BUG=none

Change-Id: I070d4eff8fb3bdc604ea67ee3f67dac50d03740e
Reviewed-on: https://gerrit.chromium.org/gerrit/14631
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Tested-by: Will Drewry <wad@chromium.org>
Commit-Ready: Will Drewry <wad@chromium.org>
diff --git a/Makefile b/Makefile
index f6ee0b9..14cc809 100644
--- a/Makefile
+++ b/Makefile
@@ -35,12 +35,19 @@
 #RM_ON_CLEAN += $(OUT)verity-l
 
 # Current toolchain doesn't support -pie statically linked binaries
-#$(OUT)verity-static: $(C_OBJECTS) $(OUT)kernel/libkernel-pie.a \
-#                       /usr/lib/libcrypto.a
-#	@# Build the target as a binary with extra flags
-#	$(call cc_binary,-static)
-#all: $(OUT)verity-static
-#RM_ON_CLEAN += $(wildcard $(OUT)verity-static)
+$(OUT)verity-static: \
+                     $(filter-out %_testrunner.o %_unittest.o,$(CXX_OBJECTS)) \
+                     $(C_OBJECTS) $(OUT)kernel/libkernel-pic.a \
+                     $(OUT)simple_file/libsimple_file-pic.a \
+                     $(shell $(CXX) -print-file-name=libcrypto.a) \
+                     $(shell $(CXX) -print-file-name=libz.a) \
+                     $(shell $(CXX) -print-file-name=libdl.a) \
+                     $(shell $(CXX) -print-file-name=libstdc++.a) \
+                     $(shell $(CXX) -print-file-name=libc.a)
+	@# Build the target as a binary with extra flags
+	$(call cc_binary,-static)
+all: $(OUT)verity-static
+RM_ON_CLEAN += $(wildcard $(OUT)verity-static)
 
 $(OUT)verity: $(filter-out %_testrunner.o %_unittest.o,$(CXX_OBJECTS)) \
               $(C_OBJECTS) \
diff --git a/simple_file/module.mk b/simple_file/module.mk
index 5037073..b154e90 100644
--- a/simple_file/module.mk
+++ b/simple_file/module.mk
@@ -7,7 +7,13 @@
 $(OUT)simple_file/libsimple_file-pie.a: $(simple_file_CXX_OBJECTS)
 	$(call update_archive,pie)
 
+$(OUT)simple_file/libsimple_file-pic.a: $(simple_file_CXX_OBJECTS)
+	$(call update_archive,pic)
+
+
 # Add our target
 all: $(OUT)simple_file/libsimple_file-pie.a
+all: $(OUT)simple_file/libsimple_file-pic.a
 # Ditto
 RM_ON_CLEAN += $(OUT)simple_file/libsimple_file-pie.a
+RM_ON_CLEAN += $(OUT)simple_file/libsimple_file-pic.a