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/sqlite3.py b/.waf-tools/sqlite3.py
new file mode 100644
index 0000000..4eabeaa
--- /dev/null
+++ b/.waf-tools/sqlite3.py
@@ -0,0 +1,36 @@
+#! /usr/bin/env python
+# encoding: utf-8
+
+from waflib import Options
+from waflib.Configure import conf
+
+def options(opt):
+    opt.add_option('--with-sqlite3', type='string', default=None,
+                   dest='with_sqlite3', help='''Path to SQLite3, e.g., /usr/local''')
+
+@conf
+def check_sqlite3(self, *k, **kw):
+    root = k and k[0] or kw.get('path', None) or Options.options.with_sqlite3
+    mandatory = kw.get('mandatory', True)
+    var = kw.get('uselib_store', 'SQLITE3')
+
+    if root:
+        self.check_cxx(lib='sqlite3',
+                       msg='Checking for SQLite3 library',
+                       define_name='HAVE_%s' % var,
+                       uselib_store=var,
+                       mandatory=mandatory,
+                       cxxflags="-I%s/include" % root,
+                       linkflags="-L%s/lib" % root)
+    else:
+        try:
+            self.check_cfg(package='sqlite3',
+                           args=['--cflags', '--libs'],
+                           uselib_store='SQLITE3',
+                           mandatory=True)
+        except:
+            self.check_cxx(lib='sqlite3',
+                           msg='Checking for SQLite3 library',
+                           define_name='HAVE_%s' % var,
+                           uselib_store=var,
+                           mandatory=mandatory)