Revamp build process

Change-Id: Ic685b3fc658d0489d16952ee0760fa6363fd58ef
Reviewed-on: http://review.couchbase.org/26929
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
Fix build problems with mingw

Change-Id: I00ca199f51c43c85557b08b0e3a0b22cc8158307