applypatch changes for patching recovery image

Make some changes needed to applypatch in order to store the recovery
image in the system partition as a binary patch relative to the boot
image:

  - make applypatch use shared libraries, so it's smaller.  It will
    need to be on the main system so it can install the recovery
    image.  Make an applypatch_static binary for use in recovery
    packages (still needed for updating cupcake devices to donut).

  - output the results of patching to an in-memory buffer and write
    that to the partition; there's no convenient /tmp for us to us.
    (This should be basically a no-op in recovery, since /tmp is a
    ramdisk anyway.)
diff --git a/tools/applypatch/applypatch.h b/tools/applypatch/applypatch.h
index ccd8424..3701087 100644
--- a/tools/applypatch/applypatch.h
+++ b/tools/applypatch/applypatch.h
@@ -39,10 +39,7 @@
 // and use it as the source instead.
 #define CACHE_TEMP_SOURCE "/cache/saved.file"
 
-// When writing to an MTD partition, we first put the output in this
-// temp file, then copy it to the partition once the patching is
-// finished (and the target sha1 verified).
-#define MTD_TARGET_TEMP_FILE "/tmp/mtd-temp"
+typedef size_t (*SinkFn)(unsigned char*, size_t, void*);
 
 // applypatch.c
 size_t FreeSpaceForFile(const char* filename);
@@ -52,15 +49,15 @@
 void ShowBSDiffLicense();
 int ApplyBSDiffPatch(const unsigned char* old_data, ssize_t old_size,
                      const char* patch_filename, ssize_t offset,
-                     FILE* output, SHA_CTX* ctx);
+                     SinkFn sink, void* token, SHA_CTX* ctx);
 int ApplyBSDiffPatchMem(const unsigned char* old_data, ssize_t old_size,
                         const char* patch_filename, ssize_t patch_offset,
                         unsigned char** new_data, ssize_t* new_size);
 
 // imgpatch.c
 int ApplyImagePatch(const unsigned char* old_data, ssize_t old_size,
-                     const char* patch_filename,
-                     FILE* output, SHA_CTX* ctx);
+                    const char* patch_filename,
+                    SinkFn sink, void* token, SHA_CTX* ctx);
 
 // freecache.c
 int MakeFreeSpaceOnCache(size_t bytes_needed);