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