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/openssl.py b/.waf-tools/openssl.py
index eb85462..e2ba7d0 100644
--- a/.waf-tools/openssl.py
+++ b/.waf-tools/openssl.py
@@ -9,8 +9,7 @@
         opt.tool_options('openssl')
 
     def configure(conf):
-        conf.load('compiler_c openssl')
-
+        conf.load('compiler_cxx openssl')
         conf.check_openssl()
 
     def build(bld):
@@ -23,21 +22,10 @@
 
 @conf
 def check_openssl(self,*k,**kw):
-    root = k and k[0] or kw.get('path',None) or Options.options.with_openssl
+    root = k and k[0] or kw.get('path', None) or Options.options.with_openssl
     mandatory = kw.get('mandatory', True)
-    var = kw.get('var', 'OPENSSL')
+    var = kw.get('uselib_store', 'OPENSSL')
 
-    CODE = """
-#include <openssl/crypto.h>
-#include <stdio.h>
-
-int main(int argc, char **argv) {
-    (void)argc;
-    printf("%s", argv[0]);
-
-    return 0;
-}
-"""
     if root:
         libcrypto = self.check_cxx(lib=['ssl', 'crypto'],
                        msg='Checking for OpenSSL library',
@@ -45,16 +33,14 @@
                        uselib_store=var,
                        mandatory=mandatory,
                        cxxflags="-I%s/include" % root,
-                       linkflags="-L%s/lib" % root,
-                       fragment=CODE)
+                       linkflags="-L%s/lib" % root)
     else:
         libcrypto = self.check_cxx(lib=['ssl', 'crypto'],
                        msg='Checking for OpenSSL library',
                        define_name='HAVE_%s' % var,
                        uselib_store=var,
-                       mandatory=mandatory,
-                       fragment=CODE)
+                       mandatory=mandatory)
 
 def options(opt):
-    opt.add_option('--with-openssl', type='string', default='',
+    opt.add_option('--with-openssl', type='string', default=None,
                    dest='with_openssl', help='''Path to OpenSSL''')