Index: source-builder/config/gdb-common-1.cfg
===================================================================
--- source-builder/config/gdb-common-1.cfg	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/config/gdb-common-1.cfg	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -4,4 +4,101 @@
 # This configuration file configure's, make's and install's gdb.
 #
+
+#
+# Python
+#
+# GDB uses python internally so we need to link to a suitable python
+# dev kit. The dev kit for python is the header and a library. These
+# files are versioned where the header file is located in a directory
+# based on:
+#
+#  pythonM.m/Python.h
+#
+# where 'M' is the major version number and 'm' is the minor verison
+# number. The library is:
+#
+#  libpythonM.m.a
+#
+# The python command is 'pythonM' which means we need to query it for
+# the minor number.
+#
+# The python running the RSB may not be suitable, for example a MSC,
+# MSYS or Cygwin version on Windows when we want the MinGW python dev
+# file. A specific version cannot be forced because older versions of
+# GDB can only link to 'python2'.
+#
+# Host support can perform a complex query of the system, for example
+# Windows and set '%{gdb_python2}' and '%{gdb_python3}' with the full
+# path to that version's executable.
+#
+# A configuration of GDB can set the version required by setting
+# '%{gdb-python-version}' to the versions command, eg python2.
+#
+# The procedure is:
+#
+# 1. If the macros '%{gdb_python2}' or '%{gdb_python3}' are present
+#    use that path they contain. Assume the path is valid.
+#
+# 2. Does the version of gdb specify a version of python that must be
+#    used. Override with '%define gdb-python-version python2'.
+#
+# 3. Search for 'python2' and if not found search for 'python3'.
+#
+%if %{defined gdb-python2}
+  %define gdb-enable-python %{gdb_python2}
+%else
+  %if %{defined gdb-python3}
+    %define gdb-enable-python %{gdb_python3}
+  %else
+    %if %{defined gdb-python-version}
+      %define gdb-enable-python %(command -v %{gdb-python-version || true})
+    %else
+      %define gdb-enable-python %(command -v python2 || true)
+      %if %{gdb-enable-python} == %{nil}
+        %define gdb-enable-python %(command -v python3 || true)
+      %endif
+      %if %{gdb-enable-python} == %{nil}
+          %define gdb-enable-python %(command -v python || true})
+      %endif
+    %endif
+    %if %{gdb-enable-python} == %{nil}
+      %error "gdb: python: no valid version of python found"
+    %endif
+  %endif
+%endif
+
+#
+# Get the Python's major and minor version from the python
+# command. The headers and libraries are installed under a major/minor
+# (mm) version path and name.
+#
+# The library file name can vary across the hosts so wildcard the search.
+#
+%define gdb-python-ver-mm %(%{gdb-enable-python} --version 2>&1 | sed -e 's/.* //g' | rev | cut -d'.' -f2- | rev)
+%define gdb-python-ver-header python%{gdb-python-ver-mm}/Python.h
+%define gdb-python-ver-lib libpython%{gdb-python-ver-mm}.*
+%if %{host_includes} == %{nil}
+  %define gdb-host-incs %{nil}
+%else
+  %define gdb-host-incs -I '%{host_includes}'
+%endif
+%define gdb-python-header-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-incs} -H %{gdb-python-ver-header})
+%if %{gdb-python-header-check} == not-found
+  %error "gdb: python: header file not found: %{gdb-python-ver-header}, please install"
+%endif
+#
+# Too hard to find on MacOS (darwin), the header is good enough.
+#
+%ifnos darwin
+  %if %{host_ldflags} == %{nil}
+    %define gdb-host-libs %{nil}
+  %else
+    %define gdb-host-libs -L '%{host_ldflags}'
+  %endif
+  %define gdb-python-lib-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-libs} -l %{gdb-python-ver-lib})
+  %if %{gdb-python-lib-check} == not-found
+    %error "gdb: python: library file not found: %{gdb-python-ver-lib}, please install"
+  %endif
+%endif
 
 #
@@ -42,5 +139,5 @@
 Version:   %{gdb_version}
 Release:   %{release}
-URL: 	   http://www.gnu.org/software/gdb/
+URL:       http://www.gnu.org/software/gdb/
 BuildRoot: %{_tmppath}/%{name}-root-%(%{__id_u} -n)
 
@@ -71,5 +168,9 @@
   %define with_python_option --with-python=%{with_python_path}
 %else
-  %define with_python_option --with-python
+  %if %{defined gdb-enable-python}
+    %define with_python_option --with-python=%{gdb-enable-python}
+  %else
+    %define with_python_option --with-python
+  %endif
 %endif
 
Index: source-builder/defaults.mc
===================================================================
--- source-builder/defaults.mc	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/defaults.mc	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -66,7 +66,9 @@
 host_cflags:         none,    convert,  '-O2 -pipe'
 host_cxxflags:       none,    convert,  '-O2 -pipe'
+host_ldflags:        none,    convert,  ''
 host_includes:       none,    convert,  ''
 build_cflags:        none,    convert,  '-O2 -pipe'
 build_cxxflags:      none,    convert,  '-O2 -pipe'
+build_ldflags:       none,    convert,  ''
 build_includes:      none,    convert,  ''
 
@@ -203,8 +205,8 @@
 SB_HOST_CFLAGS="%{host_cflags} %{host_includes}"
 SB_HOST_CXXFLAGS="%{host_cxxflags} %{host_includes}"
-SB_HOST_LDFLAGS="%{?host_ldflags:%{host_ldflags}} %{?_tmproot:-L%{_tmproot}/${SB_PREFIX_CLEAN}/lib}"
+SB_HOST_LDFLAGS="%{host_ldflags} %{?_tmproot:-L%{_tmproot}/${SB_PREFIX_CLEAN}/lib}"
 SB_BUILD_CFLAGS="%{build_cflags} %{?_tmproot:-I%{_tmproot}/${SB_PREFIX_CLEAN}/include}"
 SB_BUILD_CXXFLAGS="%{build_cxxflags} %{?_tmproot:-I%{_tmproot}/${SB_PREFIX_CLEAN}/include}"
-SB_BUILD_LDFLAGS="%{?build_ldflags:%{build_ldflags}} %{?_tmproot:-L%{_tmproot}/${SB_PREFIX_CLEAN}/lib}"
+SB_BUILD_LDFLAGS="%{build_ldflags} %{?_tmproot:-L%{_tmproot}/${SB_PREFIX_CLEAN}/lib}"
 SB_CFLAGS="${SB_BUILD_CFLAGS} %{build_includes}"
 SB_CXXFLAGS="${SB_BUILD_CXXFLAGS} %{build_includes}"
Index: source-builder/pkg-config
===================================================================
--- source-builder/pkg-config	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/pkg-config	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -1,226 +1,27 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2014-2016 Chris Johns (chrisj@rtems.org)
+# Copyright 2018 Chris Johns (chrisj@rtems.org)
 # All rights reserved.
 #
 # This file is part of the RTEMS Tools package in 'rtems-tools'.
 #
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
 #
-# 1. Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-
-from __future__ import print_function
-
-import os
-import sys
-
-base = os.path.dirname(sys.argv[0])
-sys.path.insert(0, base + '/sb')
-
-try:
-    import argparse
-except:
-    sys.path.insert(0, base + '/sb/imports')
-    try:
-        import argparse
-    except:
-        print("Incorrect Source Builder installation", file = sys.stderr)
-        sys.exit(1)
-
-try:
-    import pkgconfig
-except ImportError:
-    print("Incorrect Source Builder installation", file = sys.stderr)
-    sys.exit(1)
-
-#
-# Make trace true to get a file of what happens and what is being asked.
-#
-trace = True
-trace_stdout = False
-logfile = 'pkg-config.log'
-out = None
-srcfd = None
-
-#
-# Write all the package source parsed to a single file.
-#
-trace_src = True
-if trace_src:
-    srcfd = open('pkg-src.txt', 'w')
-
-def src(text):
-    if srcfd:
-        srcfd.writelines(text)
-
-def log(s, lf = True):
-    global trace, logfile, out
-    if trace:
-        if out is None:
-            if logfile:
-                out = open(logfile, 'a')
-            else:
-                out = sys.stdout
-        if lf:
-            if out != sys.stdout and trace_stdout:
-                print(s)
-            print(s, file = out)
-        else:
-            if out != sys.stdout and trace_stdout:
-                print(s, end = '')
-                sys.stdout.flush()
-            print(s, end = '', file = out)
-
-def run(argv):
-
-    class version_action(argparse.Action):
-        def __call__(self, parser, namespace, values, option_string = None):
-            parts = values[0].strip().split('.')
-            for p in parts:
-                if not p.isdigit():
-                    raise error('invalid version value: %s' % (values))
-            setattr(namespace, self.dest, '.'.join(parts))
-
-    ec = 0
-
-    opts = argparse.ArgumentParser(prog = 'pkg-config', description = 'Package Configuration.')
-    opts.add_argument('libraries', metavar='lib', type = str,  help = 'a library', nargs = '*')
-    opts.add_argument('--modversion', dest = 'modversion', action = 'store', default = None,
-                      help = 'Requests that the version information of the libraries.')
-    opts.add_argument('--print-errors', dest = 'print_errors', action = 'store_true',
-                      default = False,
-                      help = 'Print any errors.')
-    opts.add_argument('--short-errors', dest = 'short_errors', action = 'store_true',
-                      default = False,
-                      help = 'Make error messages short.')
-    opts.add_argument('--silence-errors', dest = 'silence_errors', action = 'store_true',
-                      default = False,
-                      help = 'Do not print any errors.')
-    opts.add_argument('--errors-to-stdout', dest = 'errors_to_stdout', action = 'store_true',
-                      default = False,
-                      help = 'Print errors to stdout rather than stderr.')
-    opts.add_argument('--cflags', dest = 'cflags', action = 'store_true',
-                      default = False,
-                      help = 'This prints pre-processor and compile flags required to' \
-                             ' compile the package(s)')
-    opts.add_argument('--libs', dest = 'libs', action = 'store_true',
-                      default = False,
-                      help = 'This option is identical to "--cflags", only it prints the' \
-                             ' link flags.')
-    opts.add_argument('--libs-only-L', dest = 'libs_only_L', action = 'store_true',
-                      default = False,
-                      help = 'This prints the -L/-R part of "--libs".')
-    opts.add_argument('--libs-only-l', dest = 'libs_only_l', action = 'store_true',
-                      default = False,
-                      help = 'This prints the -l part of "--libs".')
-    opts.add_argument('--variable', dest = 'variable', action = 'store',
-                      nargs = 1, default = None,
-                      help = 'This returns the value of a variable.')
-    opts.add_argument('--define-variable', dest = 'define_variable', action = 'store',
-                      nargs = 1, default = None,
-                      help = 'This sets a global value for a variable')
-    opts.add_argument('--uninstalled', dest = 'uninstalled', action = 'store_true',
-                      default = False,
-                      help = 'Ignored')
-    opts.add_argument('--atleast-pkgconfig-version', dest = 'atleast_pkgconfig_version',
-                      action = 'store', nargs = 1, default = None,
-                      help = 'Check the version of package config. Always ok.')
-    opts.add_argument('--exists', dest = 'exists', action = 'store_true',
-                      default = False,
-                      help = 'Test if a library is present')
-    opts.add_argument('--atleast-version', dest = 'atleast_version',
-                      action = version_action, nargs = 1, default = None,
-                      help = 'The package is at least this version.')
-    opts.add_argument('--exact-version', dest = 'exact_version', action = version_action,
-                       nargs = 1, default = None,
-                        help = 'The package is the exact version.')
-    opts.add_argument('--max-version', dest = 'max_version', action = version_action,
-                      nargs = 1, default = None,
-                      help = 'The package is no later than this version.')
-    opts.add_argument('--msvc-syntax', dest = 'msvc_syntax', action = 'store_true',
-                      default = False,
-                      help = 'Ignored')
-    opts.add_argument('--dont-define-prefix', dest = 'dont_define_prefix', action = 'store_true',
-                      default = False,
-                      help = 'Ignored')
-    opts.add_argument('--prefix-variable', dest = 'prefix', action = 'store',
-                      nargs = 1, default = pkgconfig.default_prefix(),
-                      help = 'Define the prefix.')
-    opts.add_argument('--static', dest = 'static', action = 'store_true',
-                      default = False,
-                      help = 'Output libraries suitable for static linking')
-    opts.add_argument('--dump', dest = 'dump', action = 'store_true',
-                      default = False,
-                      help = 'Dump the package if one is found.')
-
-    args = opts.parse_args(argv[1:])
-
-    if (args.exists and (args.exact_version or args.max_version)) or \
-            (args.exact_version and (args.exists or args.max_version)) or \
-            (args.max_version and (args.exists or args.exact_version)):
-        raise error('only one of --exists, --exact-version, or --max-version')
-
-    if args.dont_define_prefix:
-        args.prefix = pkgconfig.default_prefix(False)
-
-    exists = False
-
-    ec = 1
-
-    if args.atleast_pkgconfig_version:
-        ec = 0
-    else:
-        ec, pkg, flags = pkgconfig.check_package(args.libraries, args, log, src)
-        if ec == 0:
-            if args.cflags:
-                if len(flags['cflags']):
-                    print(flags['cflags'])
-                    log('cflags: %s' % (flags['cflags']))
-                else:
-                    log('cflags: empty')
-            if args.libs:
-                if len(flags['libs']):
-                    print(flags['libs'])
-                    log('libs: %s' % (flags['libs']))
-                else:
-                    log('libs: empty')
-
-    #pkgconfig.package.dump_loaded()
-
-    return ec
-
-try:
-    log('-' * 40)
-    log('pkg-config', lf = False)
-    for a in sys.argv[1:]:
-        log(' "%s"' % (a), lf = False)
-    log('')
-    ec = run(sys.argv)
-    log('ec = %d' % (ec))
-except ImportError:
-    print("incorrect package config installation", file = sys.stderr)
-    sys.exit(1)
-except pkgconfig.error as e:
-    print('error: %s' % (e), file = sys.stderr)
-    sys.exit(1)
-sys.exit(ec)
+set -e
+base=$(dirname $0)
+PYTHON_CMD=${base}/sb/cmd-pkg-config.py
+if test -f ${base}/sb/python-wrapper.sh; then
+  . ${base}/sb/python-wrapper.sh
+fi
+echo "error: python wrapper not found"
Index: source-builder/sb-bootstrap
===================================================================
--- source-builder/sb-bootstrap	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb-bootstrap	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -1,6 +1,6 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2013 Chris Johns (chrisj@rtems.org)
+# Copyright 2018 Chris Johns (chrisj@rtems.org)
 # All rights reserved.
 #
@@ -18,14 +18,10 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-from __future__ import print_function
-
-import sys, os
-base = os.path.dirname(sys.argv[0])
-sys.path.insert(0, base + '/sb')
-try:
-    import bootstrap
-    bootstrap.run(sys.argv)
-except ImportError:
-    print("Incorrect Source Builder installation", file = sys.stderr)
-    sys.exit(1)
+#
+set -e
+base=$(dirname $0)
+PYTHON_CMD=${base}/sb/cmd-bootstrap.py
+if test -f ${base}/sb/python-wrapper.sh; then
+  . ${base}/sb/python-wrapper.sh
+fi
+echo "error: python wrapper not found"
Index: source-builder/sb-builder
===================================================================
--- source-builder/sb-builder	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb-builder	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -1,6 +1,6 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
+# Copyright 2018 Chris Johns (chrisj@rtems.org)
 # All rights reserved.
 #
@@ -18,14 +18,10 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-from __future__ import print_function
-
-import sys, os
-base = os.path.dirname(sys.argv[0])
-sys.path.insert(0, base + '/sb')
-try:
-    import build
-    build.run(sys.argv)
-except ImportError:
-    print("Incorrect Source Builder installation", file = sys.stderr)
-    sys.exit(1)
+#
+set -e
+base=$(dirname $0)
+PYTHON_CMD=${base}/sb/cmd-builder.py
+if test -f ${base}/sb/python-wrapper.sh; then
+  . ${base}/sb/python-wrapper.sh
+fi
+echo "error: python wrapper not found"
Index: source-builder/sb-check
===================================================================
--- source-builder/sb-check	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb-check	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -1,6 +1,6 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
+# Copyright 2018 Chris Johns (chrisj@rtems.org)
 # All rights reserved.
 #
@@ -18,14 +18,10 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-from __future__ import print_function
-
-import sys, os
-base = os.path.dirname(sys.argv[0])
-sys.path.insert(0, base + '/sb')
-try:
-    import check
-    check.run()
-except ImportError:
-    print("Incorrect Source Builder installation", file = sys.stderr)
-    sys.exit(1)
+#
+set -e
+base=$(dirname $0)
+PYTHON_CMD=${base}/sb/cmd-check.py
+if test -f ${base}/sb/python-wrapper.sh; then
+  . ${base}/sb/python-wrapper.sh
+fi
+echo "error: python wrapper not found"
Index: source-builder/sb-defaults
===================================================================
--- source-builder/sb-defaults	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb-defaults	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -1,6 +1,6 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2010-2013 Chris Johns (chrisj@rtems.org)
+# Copyright 2018 Chris Johns (chrisj@rtems.org)
 # All rights reserved.
 #
@@ -18,14 +18,10 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-from __future__ import print_function
-
-import sys, os
-base = os.path.dirname(sys.argv[0])
-sys.path.insert(0, base + '/sb')
-try:
-    import options
-    options.run(sys.argv)
-except ImportError:
-    print("Incorrect Source Builder installation", file = sys.stderr)
-    sys.exit(1)
+#
+set -e
+base=$(dirname $0)
+PYTHON_CMD=${base}/sb/cmd-defaults.py
+if test -f ${base}/sb/python-wrapper.sh; then
+  . ${base}/sb/python-wrapper.sh
+fi
+echo "error: python wrapper not found"
Index: source-builder/sb-reports
===================================================================
--- source-builder/sb-reports	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb-reports	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -1,6 +1,6 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2010-2013 Chris Johns (chrisj@rtems.org)
+# Copyright 2018 Chris Johns (chrisj@rtems.org)
 # All rights reserved.
 #
@@ -18,14 +18,10 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-from __future__ import print_function
-
-import sys, os
-base = os.path.dirname(sys.argv[0])
-sys.path.insert(0, base + '/sb')
-try:
-    import reports
-    reports.run(sys.argv)
-except ImportError:
-    print("Incorrect Source Builder installation", file = sys.stderr)
-    sys.exit(1)
+#
+set -e
+base=$(dirname $0)
+PYTHON_CMD=${base}/sb/cmd-reports.py
+if test -f ${base}/sb/python-wrapper.sh; then
+  . ${base}/sb/python-wrapper.sh
+fi
+echo "error: python wrapper not found"
Index: source-builder/sb-rtems-config
===================================================================
--- source-builder/sb-rtems-config	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb-rtems-config	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -1,6 +1,6 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
+# Copyright 2018 Chris Johns (chrisj@rtems.org)
 # All rights reserved.
 #
@@ -18,14 +18,10 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-from __future__ import print_function
-
-import sys, os
-base = os.path.dirname(sys.argv[0])
-sys.path.insert(0, base + '/sb')
-try:
-    import rtemsconfig
-    rtemsconfig.run(sys.argv)
-except ImportError:
-    print("Incorrect Source Builder installation", file = sys.stderr)
-    sys.exit(1)
+#
+set -e
+base=$(dirname $0)
+PYTHON_CMD=${base}/sb/cmd-rtems-config.py
+if test -f ${base}/sb/python-wrapper.sh; then
+  . ${base}/sb/python-wrapper.sh
+fi
+echo "error: python wrapper not found"
Index: source-builder/sb-set-builder
===================================================================
--- source-builder/sb-set-builder	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb-set-builder	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -1,6 +1,6 @@
-#! /usr/bin/env python
+#! /bin/sh
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
+# Copyright 2018 Chris Johns (chrisj@rtems.org)
 # All rights reserved.
 #
@@ -18,15 +18,10 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-from __future__ import print_function
-
-import sys, os
-base = os.path.dirname(sys.argv[0])
-sys.path.insert(0, base + '/sb')
-
-try:
-    import setbuilder
-    setbuilder.run()
-except ImportError:
-    print("Incorrect Source Builder installation", file = sys.stderr)
-    sys.exit(1)
+#
+set -e
+base=$(dirname $0)
+PYTHON_CMD=${base}/sb/cmd-set-builder.py
+if test -f ${base}/sb/python-wrapper.sh; then
+  . ${base}/sb/python-wrapper.sh
+fi
+echo "error: python wrapper not found"
Index: source-builder/sb/build.py
===================================================================
--- source-builder/sb/build.py	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb/build.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -70,5 +70,13 @@
 
     def append(self, text):
+        is_str = False
         if type(text) is str:
+            is_str = True
+        try:
+            if type(text) is unicode:
+                is_str = True
+        except:
+            pass
+        if is_str:
             text = text.splitlines()
         if not log.quiet:
Index: source-builder/sb/cmd-bootstrap.py
===================================================================
--- source-builder/sb/cmd-bootstrap.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
+++ source-builder/sb/cmd-bootstrap.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -0,0 +1,29 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2013 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+from __future__ import print_function
+
+import sys, os
+
+try:
+    import bootstrap
+    bootstrap.run(sys.argv)
+except ImportError:
+    print("Incorrect Source Builder installation", file = sys.stderr)
+    sys.exit(1)
Index: source-builder/sb/cmd-builder.py
===================================================================
--- source-builder/sb/cmd-builder.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
+++ source-builder/sb/cmd-builder.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -0,0 +1,29 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+from __future__ import print_function
+
+import sys, os
+
+try:
+    import build
+    build.run(sys.argv)
+except ImportError:
+    print("Incorrect Source Builder installation", file = sys.stderr)
+    sys.exit(1)
Index: source-builder/sb/cmd-check.py
===================================================================
--- source-builder/sb/cmd-check.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
+++ source-builder/sb/cmd-check.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -0,0 +1,29 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+from __future__ import print_function
+
+import sys, os
+
+try:
+    import check
+    check.run()
+except ImportError:
+    print("Incorrect Source Builder installation", file = sys.stderr)
+    sys.exit(1)
Index: source-builder/sb/cmd-defaults.py
===================================================================
--- source-builder/sb/cmd-defaults.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
+++ source-builder/sb/cmd-defaults.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -0,0 +1,29 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2010-2013 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+from __future__ import print_function
+
+import sys, os
+
+try:
+    import options
+    options.run(sys.argv)
+except ImportError:
+    print("Incorrect Source Builder installation", file = sys.stderr)
+    sys.exit(1)
Index: source-builder/sb/cmd-pkg-config.py
===================================================================
--- source-builder/sb/cmd-pkg-config.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
+++ source-builder/sb/cmd-pkg-config.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -0,0 +1,220 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2014-2016 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+from __future__ import print_function
+
+import os
+import sys
+
+base = os.path.dirname(sys.argv[0])
+
+try:
+    import argparse
+except:
+    sys.path.insert(0, base + '/sb/imports')
+    try:
+        import argparse
+    except:
+        print("Incorrect Source Builder installation", file = sys.stderr)
+        sys.exit(1)
+
+import pkgconfig
+
+#
+# Make trace true to get a file of what happens and what is being asked.
+#
+trace = True
+trace_stdout = False
+logfile = 'pkg-config.log'
+out = None
+srcfd = None
+
+#
+# Write all the package source parsed to a single file.
+#
+trace_src = True
+if trace_src:
+    srcfd = open('pkg-src.txt', 'w')
+
+def src(text):
+    if srcfd:
+        srcfd.writelines(text)
+
+def log(s, lf = True):
+    global trace, logfile, out
+    if trace:
+        if out is None:
+            if logfile:
+                out = open(logfile, 'a')
+            else:
+                out = sys.stdout
+        if lf:
+            if out != sys.stdout and trace_stdout:
+                print(s)
+            print(s, file = out)
+        else:
+            if out != sys.stdout and trace_stdout:
+                print(s, end = '')
+                sys.stdout.flush()
+            print(s, end = '', file = out)
+
+def run(argv):
+
+    class version_action(argparse.Action):
+        def __call__(self, parser, namespace, values, option_string = None):
+            parts = values[0].strip().split('.')
+            for p in parts:
+                if not p.isdigit():
+                    raise error('invalid version value: %s' % (values))
+            setattr(namespace, self.dest, '.'.join(parts))
+
+    ec = 0
+
+    opts = argparse.ArgumentParser(prog = 'pkg-config', description = 'Package Configuration.')
+    opts.add_argument('libraries', metavar='lib', type = str,  help = 'a library', nargs = '*')
+    opts.add_argument('--modversion', dest = 'modversion', action = 'store', default = None,
+                      help = 'Requests that the version information of the libraries.')
+    opts.add_argument('--print-errors', dest = 'print_errors', action = 'store_true',
+                      default = False,
+                      help = 'Print any errors.')
+    opts.add_argument('--short-errors', dest = 'short_errors', action = 'store_true',
+                      default = False,
+                      help = 'Make error messages short.')
+    opts.add_argument('--silence-errors', dest = 'silence_errors', action = 'store_true',
+                      default = False,
+                      help = 'Do not print any errors.')
+    opts.add_argument('--errors-to-stdout', dest = 'errors_to_stdout', action = 'store_true',
+                      default = False,
+                      help = 'Print errors to stdout rather than stderr.')
+    opts.add_argument('--cflags', dest = 'cflags', action = 'store_true',
+                      default = False,
+                      help = 'This prints pre-processor and compile flags required to' \
+                             ' compile the package(s)')
+    opts.add_argument('--libs', dest = 'libs', action = 'store_true',
+                      default = False,
+                      help = 'This option is identical to "--cflags", only it prints the' \
+                             ' link flags.')
+    opts.add_argument('--libs-only-L', dest = 'libs_only_L', action = 'store_true',
+                      default = False,
+                      help = 'This prints the -L/-R part of "--libs".')
+    opts.add_argument('--libs-only-l', dest = 'libs_only_l', action = 'store_true',
+                      default = False,
+                      help = 'This prints the -l part of "--libs".')
+    opts.add_argument('--variable', dest = 'variable', action = 'store',
+                      nargs = 1, default = None,
+                      help = 'This returns the value of a variable.')
+    opts.add_argument('--define-variable', dest = 'define_variable', action = 'store',
+                      nargs = 1, default = None,
+                      help = 'This sets a global value for a variable')
+    opts.add_argument('--uninstalled', dest = 'uninstalled', action = 'store_true',
+                      default = False,
+                      help = 'Ignored')
+    opts.add_argument('--atleast-pkgconfig-version', dest = 'atleast_pkgconfig_version',
+                      action = 'store', nargs = 1, default = None,
+                      help = 'Check the version of package config. Always ok.')
+    opts.add_argument('--exists', dest = 'exists', action = 'store_true',
+                      default = False,
+                      help = 'Test if a library is present')
+    opts.add_argument('--atleast-version', dest = 'atleast_version',
+                      action = version_action, nargs = 1, default = None,
+                      help = 'The package is at least this version.')
+    opts.add_argument('--exact-version', dest = 'exact_version', action = version_action,
+                       nargs = 1, default = None,
+                        help = 'The package is the exact version.')
+    opts.add_argument('--max-version', dest = 'max_version', action = version_action,
+                      nargs = 1, default = None,
+                      help = 'The package is no later than this version.')
+    opts.add_argument('--msvc-syntax', dest = 'msvc_syntax', action = 'store_true',
+                      default = False,
+                      help = 'Ignored')
+    opts.add_argument('--dont-define-prefix', dest = 'dont_define_prefix', action = 'store_true',
+                      default = False,
+                      help = 'Ignored')
+    opts.add_argument('--prefix-variable', dest = 'prefix', action = 'store',
+                      nargs = 1, default = pkgconfig.default_prefix(),
+                      help = 'Define the prefix.')
+    opts.add_argument('--static', dest = 'static', action = 'store_true',
+                      default = False,
+                      help = 'Output libraries suitable for static linking')
+    opts.add_argument('--dump', dest = 'dump', action = 'store_true',
+                      default = False,
+                      help = 'Dump the package if one is found.')
+
+    args = opts.parse_args(argv[1:])
+
+    if (args.exists and (args.exact_version or args.max_version)) or \
+            (args.exact_version and (args.exists or args.max_version)) or \
+            (args.max_version and (args.exists or args.exact_version)):
+        raise error('only one of --exists, --exact-version, or --max-version')
+
+    if args.dont_define_prefix:
+        args.prefix = pkgconfig.default_prefix(False)
+
+    exists = False
+
+    ec = 1
+
+    if args.atleast_pkgconfig_version:
+        ec = 0
+    else:
+        ec, pkg, flags = pkgconfig.check_package(args.libraries, args, log, src)
+        if ec == 0:
+            if args.cflags:
+                if len(flags['cflags']):
+                    print(flags['cflags'])
+                    log('cflags: %s' % (flags['cflags']))
+                else:
+                    log('cflags: empty')
+            if args.libs:
+                if len(flags['libs']):
+                    print(flags['libs'])
+                    log('libs: %s' % (flags['libs']))
+                else:
+                    log('libs: empty')
+
+    #pkgconfig.package.dump_loaded()
+
+    return ec
+
+try:
+    log('-' * 40)
+    log('pkg-config', lf = False)
+    for a in sys.argv[1:]:
+        log(' "%s"' % (a), lf = False)
+    log('')
+    ec = run(sys.argv)
+    log('ec = %d' % (ec))
+except ImportError:
+    print("incorrect package config installation", file = sys.stderr)
+    sys.exit(1)
+except pkgconfig.error as e:
+    print('error: %s' % (e), file = sys.stderr)
+    sys.exit(1)
+sys.exit(ec)
Index: source-builder/sb/cmd-reports.py
===================================================================
--- source-builder/sb/cmd-reports.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
+++ source-builder/sb/cmd-reports.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -0,0 +1,29 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2010-2013 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+from __future__ import print_function
+
+import sys, os
+
+try:
+    import reports
+    reports.run(sys.argv)
+except ImportError:
+    print("Incorrect Source Builder installation", file = sys.stderr)
+    sys.exit(1)
Index: source-builder/sb/cmd-rtems-config.py
===================================================================
--- source-builder/sb/cmd-rtems-config.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
+++ source-builder/sb/cmd-rtems-config.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -0,0 +1,29 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+from __future__ import print_function
+
+import sys, os
+
+try:
+    import rtemsconfig
+    rtemsconfig.run(sys.argv)
+except ImportError:
+    print("Incorrect Source Builder installation", file = sys.stderr)
+    sys.exit(1)
Index: source-builder/sb/cmd-set-builder.py
===================================================================
--- source-builder/sb/cmd-set-builder.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
+++ source-builder/sb/cmd-set-builder.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -0,0 +1,29 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2010-2012 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+from __future__ import print_function
+
+import sys, os
+
+try:
+    import setbuilder
+    setbuilder.run()
+except ImportError:
+    print("Incorrect Source Builder installation", file = sys.stderr)
+    sys.exit(1)
Index: source-builder/sb/config.py
===================================================================
--- source-builder/sb/config.py	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb/config.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -558,5 +558,5 @@
                     colon = m.find(':')
                     if colon < 8:
-                        log.warning('malformed expand macro, no colon found')
+                        log.warning(self._name_line_msg('malformed expand macro, no colon found'))
                     else:
                         e = self._expand(m[colon + 1:-1].strip())
@@ -577,5 +577,5 @@
                 elif m.startswith('%{echo'):
                     if not m.endswith('}'):
-                        log.warning("malformed conditional macro '%s'" % (m))
+                        log.warning(self._name_line_msg("malformed conditional macro '%s'" % (m)))
                         mn = None
                     else:
@@ -649,5 +649,5 @@
                     if colon < 0:
                         if not m.endswith('}'):
-                            log.warning("malformed conditional macro '%s'" % (m))
+                            log.warning(self._name_line_msg("malformed conditional macro '%s'" % (m)))
                             mn = None
                         else:
@@ -691,5 +691,5 @@
     def _disable(self, config, ls):
         if len(ls) != 2:
-            log.warning('invalid disable statement')
+            log.warning(self._name_line_msg('invalid disable statement'))
         else:
             if ls[1] == 'select':
@@ -698,9 +698,9 @@
                                                                      ls[1]))
             else:
-                log.warning('invalid disable statement: %s' % (ls[1]))
+                log.warning(self._name_line_msg('invalid disable statement: %s' % (ls[1])))
 
     def _select(self, config, ls):
         if len(ls) != 2:
-            log.warning('invalid select statement')
+            log.warning(self._name_line_msg('invalid select statement'))
         else:
             r = self.macros.set_read_map(ls[1])
@@ -717,5 +717,5 @@
     def _define(self, config, ls):
         if len(ls) <= 1:
-            log.warning('invalid macro definition')
+            log.warning(self._name_line_msg('invalid macro definition'))
         else:
             d = self._label(ls[1])
@@ -728,5 +728,5 @@
                         self.macros[d] = ' '.join([f.strip() for f in ls[2:]])
                 else:
-                    log.warning("macro '%s' already defined" % (d))
+                    log.warning(self._name_line_msg("macro '%s' already defined" % (d)))
             else:
                 if len(ls) == 2:
@@ -737,5 +737,5 @@
     def _undefine(self, config, ls):
         if len(ls) <= 1:
-            log.warning('invalid macro definition')
+            log.warning(self._name_line_msg('invalid macro definition'))
         else:
             mn = self._label(ls[1])
@@ -842,5 +842,5 @@
                 log.trace('config: %s: %3d: _if[%i]: next OP found at %i' % (self.name, self.lc,
                                                                              self.if_depth,
-                i))
+                                                                             i))
             ls = cls[:i]
             if len(ls) == 0:
@@ -965,4 +965,14 @@
                     break
         return self._ifs(config, ls, '%ifos', isos, isvalid, dir, info)
+
+    def _ifnos(self, config, ls, isvalid, dir, info):
+        isnos = True
+        if isvalid:
+            os = self.define('_os')
+            for l in ls:
+                if l in os:
+                    isnos = False
+                    break
+        return self._ifs(config, ls, '%ifnos', isnos, isvalid, dir, info)
 
     def _ifarch(self, config, positive, ls, isvalid, dir, info):
@@ -1064,4 +1074,8 @@
                     if len(d):
                         return ('data', d)
+                elif ls[0] == '%ifnos':
+                    d = self._ifnos(config, ls, isvalid, dir, info)
+                    if len(d):
+                        return ('data', d)
                 elif ls[0] == '%ifarch':
                     d = self._ifarch(config, True, ls, isvalid, dir, info)
@@ -1075,9 +1089,9 @@
                     if roc:
                         return ('control', '%endif', '%endif')
-                    log.warning("unexpected '" + ls[0] + "'")
+                    log.warning(self._name_line_msg("unexpected '" + ls[0] + "'"))
                 elif ls[0] == '%else':
                     if roc:
                         return ('control', '%else', '%else')
-                    log.warning("unexpected '" + ls[0] + "'")
+                    log.warning(self._name_line_msg("unexpected '" + ls[0] + "'"))
                 elif ls[0].startswith('%defattr'):
                     return ('data', [l])
@@ -1104,5 +1118,5 @@
                                           (self.name, self.lc, ls[0].strip()))
                                 return ('directive', ls[0].strip(), ls[1:])
-                        log.warning("unknown directive: '" + ls[0] + "'")
+                        log.warning(self._name_line_msg("unknown directive: '" + ls[0] + "'"))
                         return ('data', [lo])
             else:
@@ -1125,5 +1139,5 @@
             else:
                 if results[2][0].strip() != '-n':
-                    log.warning("unknown directive option: '%s'" % (' '.join(results[2])))
+                    log.warning(self._name_line_msg("unknown directive option: '%s'" % (' '.join(results[2]))))
                 _package = results[2][1].strip()
             self._set_package(_package)
@@ -1147,5 +1161,5 @@
             elif l.startswith('%warning'):
                 l = self._expand(l)
-                log.warning(l[9:])
+                log.warning(self._name_line_msg(l[9:]))
             if not directive:
                 l = self._expand(l)
@@ -1162,5 +1176,5 @@
                     self._info_append(info, info_data)
                 else:
-                    log.warning("invalid format: '%s'" % (info_data[:-1]))
+                    log.warning(self._name_line_msg("invalid format: '%s'" % (info_data[:-1])))
             else:
                 l = self._expand(l)
@@ -1276,5 +1290,5 @@
                     if r[1] == '%end':
                         break
-                    log.warning("unexpected '%s'" % (r[1]))
+                    log.warning(self._name_line_msg("unexpected '%s'" % (r[1])))
                 elif r[0] == 'directive':
                     if r[1] == '%include':
Index: source-builder/sb/freebsd.py
===================================================================
--- source-builder/sb/freebsd.py	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb/freebsd.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -58,4 +58,6 @@
         '_host_alias':      ('none',    'none',     '%{nil}'),
         '_host_arch':       ('none',    'none',     cpu),
+        'host_includes':    ('none',    'convert',  '-I%{_usr}/include'),
+        'host_ldflags':     ('none',    'convert',  '-L%{_usr}/lib'),
         '_usr':             ('dir',     'required', '/usr/local'),
         '_var':             ('dir',     'optional', '/usr/local/var'),
@@ -68,5 +70,5 @@
         '__make':           ('exe',     'required', 'gmake'),
         '__patch_opts':     ('none',     'none',    '-E')
-        }
+    }
 
     defines['_build']        = defines['_host']
@@ -111,5 +113,5 @@
         # Fix the mess iconv is on FreeBSD 10.0.
         #
-        defines['iconv_includes'] = ('none', 'none', '-I/usr/local/include -L/usr/local/lib')
+        defines['iconv_includes'] = ('none', 'none', '%{_host_includes} %{_host_ldflags}')
 
         #
Index: source-builder/sb/macros.py
===================================================================
--- source-builder/sb/macros.py	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb/macros.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -54,5 +54,6 @@
             return self.keys
 
-    def _unicode_to_str(self, us):
+    @staticmethod
+    def _unicode_to_str(us):
         try:
             if type(us) == unicode:
@@ -175,5 +176,5 @@
             raise TypeError('bad value tuple (attrib field): %s' % (value[1]))
         if value[1] == 'convert':
-            value = self.expand(value)
+            value = (value[0], value[1], self.expand(value[2]))
         self.macros[self.write_map][self.key_filter(key)] = value
 
@@ -182,5 +183,5 @@
 
     def __contains__(self, key):
-        return self.has_key(key)
+        return self.has_key(self._unicode_to_str(key))
 
     def __len__(self):
@@ -202,4 +203,5 @@
 
     def has_key(self, key):
+        key = self._unicode_to_str(key)
         if type(key) is not str:
             raise TypeError('bad key type (want str): %s' % (type(key)))
@@ -453,4 +455,5 @@
     def expand(self, _str):
         """Simple basic expander of config file macros."""
+        _str = self._unicode_to_str(_str)
         expanded = True
         while expanded:
Index: source-builder/sb/options.py
===================================================================
--- source-builder/sb/options.py	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb/options.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -603,7 +603,12 @@
 
     #
+    # Adjust the args to remove the wrapper.
+    #
+    args = args[1:]
+
+    #
     # The path to this command.
     #
-    command_path = path.dirname(args[0])
+    command_path = path.dirname(path.abspath(args[0]))
     if len(command_path) == 0:
         command_path = '.'
Index: source-builder/sb/path.py
===================================================================
--- source-builder/sb/path.py	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb/path.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -31,8 +31,11 @@
 import stat
 import string
+import sys
 
 import error
 
+windows_posix = sys.platform == 'msys'
 windows = os.name == 'nt'
+
 win_maxpath = 254
 
@@ -55,11 +58,13 @@
 
 def shell(path):
+    if isinstance(path, bytes):
+        path = path.decode('ascii')
     if path is not None:
-        if windows:
-            path = path.encode('ascii', 'ignore')
+        if windows or windows_posix:
+            path = path.encode('ascii', 'ignore').decode('ascii')
             if path.startswith('\\\\?\\'):
                 path = path[4:]
             if len(path) > 1 and path[1] == ':':
-                path = '/%s%s' % (path[0], path[2:])
+                path = '/%s%s' % (path[0].lower(), path[2:])
             path = path.replace('\\', '/')
         while '//' in path:
Index: source-builder/sb/python-wrapper.sh
===================================================================
--- source-builder/sb/python-wrapper.sh	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
+++ source-builder/sb/python-wrapper.sh	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -0,0 +1,39 @@
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2018 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+set -e
+if test ! -f $PYTHON_CMD; then
+  echo "error: python command not found: $PYTHON_CMD"
+  exit 5
+fi
+for py in python2 python3 python
+do
+  set +e
+  py_cmd=$(command -v $py)
+  set -e
+  if test -n "$RTEMS_PYTHON_OVERRIDE"; then
+    if test "$RTEMS_PYTHON_OVERRIDE" != "$py"; then
+      py_cmd=""
+    fi
+  fi
+  if test -n "$py_cmd"; then
+    exec $py_cmd $PYTHON_CMD $0 $*
+  fi
+done
+echo "error: no valid python found"
+exit 5
Index: source-builder/sb/rtems-build-dep
===================================================================
--- source-builder/sb/rtems-build-dep	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
+++ source-builder/sb/rtems-build-dep	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -0,0 +1,169 @@
+#! /bin/sh
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2018 Chris Johns (chrisj@rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+#
+# Host Build Dependence
+#
+# This script finds a file that is part of the compiler's default
+# build environment. The file can be header or a library.
+#
+# Header files:
+#  - Get the list of include directories from the compiler.
+#  - Search the include paths for the header file.
+#
+# Library:
+#  - Ask the compiler to print the library paths, add on any user
+#    paths and search with a wilecard.
+#
+
+set -e
+
+op=
+name=
+includes=
+libraries=
+compile=
+verbose=no
+debug=no
+
+if [ $# -eq 0 ]; then
+    echo 'Usage: rtems-build-dep [-c compiler] [-H header] [-I header-paths]
+                       [-l library] [-L library-paths] [-v] [-d]'
+    exit 2
+fi
+while [ $# > 0 ]
+do
+    case "$1"
+    in
+	-c)
+	    if [ $# -eq 1 ]; then
+		echo 'error: no compiler (-c) provided'
+		exit 2
+	    fi
+	    compiler="$2"; shift;
+            shift;;
+	-H)
+	    if [ $# -eq 1 ]; then
+		echo 'error: no header (-H) provided'
+		exit 2
+	    fi
+	    op="header"
+            name="$2"; shift;
+            shift;;
+	-I)
+	    if [ $# -eq 1 ]; then
+		echo 'error: no header path (-I) provided'
+		exit 2
+	    fi
+            includes="$2"; shift;
+            shift;;
+	-l)
+	    if [ $# -eq 1 ]; then
+		echo 'error: no library (-l) provided'
+		exit 2
+	    fi
+	    op="library"
+            name="$2"; shift;
+            shift;;
+	-L)
+	    if [ $# -eq 1 ]; then
+		echo 'error: no library path (-L) provided'
+		exit 2
+	    fi
+            libraries="$2"; shift;
+            shift;;
+	-v)
+	    verbose=yes
+            shift;;
+	-d)
+	    debug=yes
+            shift;;
+	*)
+	    break;
+    esac
+done
+
+if [ ${debug} = yes ]; then
+    set -x
+fi
+
+if [ -z "${op}" ]; then
+    echo "error: no header or library file to find found."
+    exit 2
+fi
+if [ -z "${compiler}" ]; then
+    echo "error: no compiler provided."
+    exit 2
+fi
+if [ -z "${name}" ]; then
+    echo "error: no name found."
+    exit 2
+fi
+
+#
+# Header file.
+#
+if [ ${op} = "header" ]; then
+    inc_paths=$(echo | ${compiler} ${includes} -xc -E -v - 2>&1 | \
+	       awk 'BEGIN {flag=0;} /starts here/{flag=1;next}/End/{flag=0}flag')
+    for p in ${inc_paths}
+    do
+	if [ ${verbose} = yes ]; then
+	    echo "Include: ${p}"
+	fi
+	if [ -f "${p}/${name}" ]; then
+	    echo "found"
+	    exit 0
+	fi
+    done
+    echo "not-found"
+    exit 0
+fi
+
+#
+# Library file
+#
+if [ ${op} = "library" ]; then
+    if [ "${OS}" = "Windows_NT" ]; then
+	sep=';'
+    else
+	sep=':'
+    fi
+    lib_paths_1=$(${compiler} -print-search-dirs 2>&1 | \
+		      grep libraries | \
+		      sed -e 's/libraries:.*=//' | \
+		      awk 'BEGIN {FS="'${sep}'"} {for (i=0;++i<=NF;) print $i;}')
+    lib_paths_2=$(echo ${libraries} | \
+		      awk 'BEGIN {FS="-L"} {for (i=0;++i<=NF;) if (length($i) > 0) print $i;}')
+    for p in ${lib_paths_1} ${lib_paths_2}
+    do
+	if [ ${verbose} = yes ]; then
+	    echo "Library: ${p}/${name}"
+	fi
+	if ls ${p}/${name} 1> /dev/null 2>&1; then
+	    echo "found"
+	    exit 0
+	fi
+    done
+    echo "not-found"
+    exit 0
+fi
+
+exit 1
Index: source-builder/sb/windows.py
===================================================================
--- source-builder/sb/windows.py	(revision 8992d20b8c28af7c95c8b95da054aa9d94521426)
+++ source-builder/sb/windows.py	(revision 13f4c379997b53b204d8534d198da2fa35dd5630)
@@ -1,5 +1,5 @@
 #
 # RTEMS Tools Project (http://www.rtems.org/)
-# Copyright 2010-2013 Chris Johns (chrisj@rtems.org)
+# Copyright 2010-2018 Chris Johns (chrisj@rtems.org)
 # All rights reserved.
 #
@@ -22,10 +22,10 @@
 #
 
-import error
-import pprint
 import os
 import sys
 
+import error
 import execute
+import path
 
 def load():
@@ -147,11 +147,17 @@
     #  7. W64/Python3 - gdb-7.9 needs python2.
     #
-    if sys.platform == 'win32' and 'MSC' in sys.version:
-        raise error.general('python.org Pythons are built with MSC and cannot be linked with GDB')
-
+    # Find a suitable python2 and python3.
+    #
+    for p in os.environ['PATH'].split(os.pathsep):
+        sh = os.path.join(p, 'sh.exe')
+        if os.path.exists(sh) and os.path.isfile(sh):
+            break
+        sh = None
+    if sh is None:
+        raise error.general('cannot find a shell (sh.exe) in the PATH')
     #
     # Search the MSYS2 install tree for a suitable python.
     #
-    if sys.platform == 'msys':
+    if sys.platform == 'msys' or True:
         e = execute.capture_execution()
         exit_code, proc, output = e.shell("sh -c mount")
@@ -167,22 +173,18 @@
         if install_point[1] != ':':
             raise error.general('invalid MSYS root mount point: %s' % install_point)
-        install_point = '/%s%s' % (install_point[0], install_point[2:])
-        bin = '/mingw%s/bin' % (machsize)
-        bin_list = os.listdir(bin)
-        exe = None
-        for python in ['python2.exe']:
-            for f in bin_list:
-                if f == python:
-                    exe = install_point + os.path.join(bin, f)
-                    break;
-            if exe is not None:
-                break
-        if exe is None:
-            raise error.general('no valid python found; you need a mingw%s python2 installed' % (machsize))
-        defines['with_python_path'] = exe
-
+        install_point = path.shell(install_point)
+        mingw = path.join(install_point, 'mingw%s' % (machsize))
+        if not path.exists(mingw) or not path.isdir(mingw):
+            raise error.general('cannot find MinGW install: %s' % (path.host(mingw)))
+        for version in ['2', '3']:
+            python = 'python%s' % (version)
+            exe = path.join(mingw, 'bin', '%s.exe' % (python))
+            if not path.exists(exe) or not path.isdir(exe):
+                defines['gdb_python%s' % (version)] = exe
+                header = path.join(mingw, python)
 
     return defines
 
 if __name__ == '__main__':
+    import pprint
     pprint.pprint(load())
