build: Reorganizing wscript into a set smaller function-specific scripts

This commit also fixes #1401 (path to sqlite3 can be explicitly
specified and the script will try to detect sqlite3 without the use of
pkg-config)

Change-Id: Ic91ec968410705b19d2df443523026c4e0e95c6b
diff --git a/.waf-tools/osx-security.py b/.waf-tools/osx-security.py
new file mode 100644
index 0000000..9bcb3a8
--- /dev/null
+++ b/.waf-tools/osx-security.py
@@ -0,0 +1,36 @@
+#! /usr/bin/env python
+# encoding: utf-8
+
+from waflib import Logs, Utils
+from waflib.Configure import conf
+
+OSX_SECURITY_CODE='''
+#include <CoreFoundation/CoreFoundation.h>
+#include <Security/Security.h>
+#include <Security/SecRandom.h>
+#include <CoreServices/CoreServices.h>
+#include <Security/SecDigestTransform.h>
+
+int main(int argc, char **argv) {
+    (void)argc; (void)argv;
+    return 0;
+}
+'''
+
+@conf
+def check_osx_security(conf, *k, **kw):
+    if Utils.unversioned_sys_platform() == "darwin":
+        try:
+            conf.check_cxx(framework_name='CoreFoundation', uselib_store='OSX_COREFOUNDATION',
+                           mandatory=True)
+            conf.check_cxx(framework_name='CoreServices', uselib_store='OSX_CORESERVICES',
+                           mandatory=True)
+            conf.check_cxx(framework_name='Security', uselib_store='OSX_SECURITY',
+                           define_name='HAVE_SECURITY', use="OSX_COREFOUNDATION",
+                           fragment=OSX_SECURITY_CODE, mandatory=True)
+
+            conf.define('HAVE_OSX_SECURITY', 1)
+            conf.env['HAVE_OSX_SECURITY'] = True
+        except:
+            Logs.warn("Compiling on OSX, but CoreFoundation, CoreServices, or Security framework is not functional.")
+            Logs.warn("The frameworks are known to work only with Apple-specific compilers: llvm-gcc-4.2 or clang")