Index: /trunk/configure.vbs
===================================================================
--- /trunk/configure.vbs	(revision 85783)
+++ /trunk/configure.vbs	(revision 85784)
@@ -36,10 +36,9 @@
 Set g_objFileSys = WScript.CreateObject("Scripting.FileSystemObject")
 
-dim g_strPathkBuild, g_strPathkBuildBin, g_strPathDev, g_strPathVCC, g_strPathPSDK, g_strVerPSDK, g_strPathDDK, g_strSubOutput
+' kBuild stuff.
+dim g_strPathkBuild, g_strPathkBuildBin, g_strPathDev
 g_strPathkBuild = ""
+g_strPathkBuildBin = ""
 g_strPathDev = ""
-g_strPathVCC = ""
-g_strPathPSDK = ""
-g_strPathDDK = ""
 
 dim g_strTargetArch
@@ -49,7 +48,27 @@
 g_strHostArch = ""
 
+' Visual C++ info.
+dim g_strPathVCC, g_strVCCVersion
+g_strPathVCC = ""
+g_strVCCVersion = ""
+
+' SDK and DDK.
+dim g_strPathPSDK, g_strVerPSDK, g_strPathDDK
+g_strPathPSDK = ""
+g_strVerPSDK = ""
+g_strPathDDK = ""
+
+' COM disabling.
 dim g_blnDisableCOM, g_strDisableCOM
 g_blnDisableCOM = False
 g_strDisableCOM = ""
+
+' Whether to ignore (continue) on errors.
+dim g_blnContinueOnError, g_rcExit
+g_blnContinueOnError = False
+
+' The script's exit code (for ignored errors).
+dim g_rcScript
+g_rcScript = 0
 
 ' Whether to try the internal stuff first or last.
@@ -499,5 +518,5 @@
       set obj = g_objFileSys.GetFolder(strFolder)
       for each objSub in obj.SubFolders
-         if StrComp(Left(objSub.Name, Len(strStartingWith)), strStartingWith) = 0 Then
+         if StrComp(Left(objSub.Name, Len(strStartingWith)), strStartingWith) = 0 then
             HasSubdirsStartingWith = True
             LogPrint "# HasSubdirsStartingWith(" & strFolder & "," & strStartingWith & ") found " & objSub.Name
@@ -532,5 +551,5 @@
       i = 0
       for each objSub in obj.SubFolders
-         if StrComp(Left(objSub.Name, Len(strStartingWith)), strStartingWith) = 0 Then
+         if StrComp(Left(objSub.Name, Len(strStartingWith)), strStartingWith) = 0 then
             i = i + 1
          end if
@@ -540,5 +559,5 @@
          i = 0
          for each objSub in obj.SubFolders
-            if StrComp(Left(objSub.Name, Len(strStartingWith)), strStartingWith) = 0 Then
+            if StrComp(Left(objSub.Name, Len(strStartingWith)), strStartingWith) = 0 then
                arrResult(i) = objSub.Name
                i = i + 1
@@ -682,5 +701,5 @@
 sub MsgFatal(strMsg)
    Print "fatal error: " & strMsg
-   Wscript.Quit
+   Wscript.Quit(1)
 end sub
 
@@ -690,5 +709,8 @@
 sub MsgError(strMsg)
    Print "error: " & strMsg
-   Wscript.Quit
+   if g_blnContinueOnError = False then
+      Wscript.Quit(1)
+   end if
+   g_rcScript = 1
 end sub
 
@@ -1114,5 +1136,5 @@
    end if
 
-   if (Shell(DosSlashes(g_strPathkBuildBin & "/kmk.exe") & " --version", True) <> 0) Then
+   if (Shell(DosSlashes(g_strPathkBuildBin & "/kmk.exe") & " --version", True) <> 0) then
       MsgFatal "Can't execute '" & g_strPathkBuildBin & "/kmk.exe --version'. check configure.log for the out."
       exit sub
@@ -1180,5 +1202,5 @@
 
       strSavedPath = EnvGet("PATH")
-      if (m_strPathVCCommon <> "") Then
+      if (m_strPathVCCommon <> "") then
          EnvAppend "PATH", ";" & m_strPathVCCommon & "/IDE"
       end if
@@ -1263,5 +1285,5 @@
             ' 15.0+ layout?  This is fun because of the multiple CL versions (/tools/msvc/xx.yy.bbbbb/).
             ' OTOH, the user may have pointed us directly to one of them.
-            if LogDirExists(m_strPathVC & "/Tools/MSVC") Then
+            if LogDirExists(m_strPathVC & "/Tools/MSVC") then
                m_blnNewLayout = True
                LogPrint " => seems okay. new layout."
@@ -1277,5 +1299,5 @@
                checkInner(m_strPathVC)
             ' 14.0 and older layout?
-            elseif LogFileExists(m_strPathVC, "/bin/cl.exe") Then
+            elseif LogFileExists(m_strPathVC, "/bin/cl.exe") then
                m_blnNewLayout = False
                if   LogFileExists(m_strPathVC, "bin/link.exe") _
@@ -1325,5 +1347,5 @@
 
    public function checkProgFiles(strSubdir)
-      if m_blnFound = False Then
+      if m_blnFound = False then
          dim strProgFiles
          for each strProgFiles in g_arrProgramFiles
@@ -1394,4 +1416,5 @@
    end if
    g_strPathVCC = objState.m_strPathVC
+   g_strVCCVersion = objState.m_strVersion
 
    '
@@ -1680,5 +1703,5 @@
 
    ' The tools location (first).
-   if (strPathlibSDL = "") And (g_blnInternalFirst = True) Then
+   if (strPathlibSDL = "") And (g_blnInternalFirst = True) then
       str = g_strPathDev & "/win." & g_strTargetArch & "/libsdl"
       if HasSubdirsStartingWith(str, "v") then
@@ -1689,9 +1712,9 @@
 
    ' Poke about in the path.
-   if strPathlibSDL = "" Then
+   if strPathlibSDL = "" then
       str = WhichEx("LIB", "SDLmain.lib")
-      if str = "" Then str = Which("..\lib\SDLmain.lib")
-      if str = "" Then str = Which("SDLmain.lib")
-      if str <> "" Then
+      if str = "" then str = Which("..\lib\SDLmain.lib")
+      if str = "" then str = Which("SDLmain.lib")
+      if str <> "" then
          str = PathParent(PathStripFilename(str))
          if CheckForlibSDLSub(str) then strPathlibSDL = str
@@ -1699,7 +1722,7 @@
    end if
 
-   if strPathlibSDL = "" Then
+   if strPathlibSDL = "" then
       str = Which("SDL.dll")
-      if str <> "" Then
+      if str <> "" then
          str = PathParent(PathStripFilename(str))
          if CheckForlibSDLSub(str) then strPathlibSDL = str
@@ -1708,5 +1731,5 @@
 
    ' The tools location (post).
-   if (strPathlibSDL = "") And (g_blnInternalFirst = False) Then
+   if (strPathlibSDL = "") And (g_blnInternalFirst = False) then
       str = g_strPathDev & "/win." & g_strTargetArch & "/libsdl"
       if HasSubdirsStartingWith(str, "v") then
@@ -1778,7 +1801,7 @@
    end if
 
-   if strPathXml2 = "" Then
+   if strPathXml2 = "" then
       str = Which("libxml2.lib")
-      if str <> "" Then
+      if str <> "" then
          str = PathParent(PathStripFilename(str))
          if CheckForXml2Sub(str) then strPathXml2 = str
@@ -1852,7 +1875,7 @@
    end if
 
-   if strPathSsl = "" Then
+   if strPathSsl = "" then
       str = Which("libssl.lib")
-      if str <> "" Then
+      if str <> "" then
          str = PathParent(PathStripFilename(str))
          if CheckForSslSub(str) then strPathSsl = str
@@ -1928,7 +1951,7 @@
    end if
 
-   if strPathCurl = "" Then
+   if strPathCurl = "" then
       str = Which("libcurl.lib")
-      if str <> "" Then
+      if str <> "" then
          str = PathParent(PathStripFilename(str))
          if CheckForCurlSub(str) then strPathCurl = str
@@ -1980,4 +2003,5 @@
 ' Checks for any Qt5 binaries.
 sub CheckForQt(strOptQt5)
+   dim strPathQt5, arrFolders, arrInfixes, strInfix
    PrintHdr "Qt5"
 
@@ -1985,17 +2009,27 @@
    ' Try to find the Qt5 installation (user specified path with --with-qt5)
    '
+   LogPrint "Checking for user specified path of Qt5 ... "
    strPathQt5 = ""
-
-   LogPrint "Checking for user specified path of Qt5 ... "
-   if (strPathQt5 = "") And (strOptQt5 <> "") then
-      strOptQt5 = UnixSlashes(strOptQt5)
-      if CheckForQt5Sub(strOptQt5) then strPathQt5 = strOptQt5
-   end if
-
-   ' Check the dev tools
-   if (strPathQt5 = "") Then
-      strPathQt5 = g_strPathDev & "/win." & g_strTargetArch & "/qt/v5.5.1-r138"
-      if CheckForQt5Sub(strPathQt5) = False then strPathQt5 = ""
-   end if
+   if strOptQt5 <> "" then
+      strPathQt5 = CheckForQt5Sub(UnixSlashes(strOptQt5))
+   end if
+
+   ' Check the dev tools - prefer ones matching the compiler.
+   if strPathQt5 = "" then
+      arrFolders = GetSubdirsStartingWithSorted(g_strPathDev & "/win." & g_strTargetArch & "/qt", "v5")
+      arrInfixes = Array(LCase(g_strVCCVersion), Left(LCase(g_strVCCVersion), Len(g_strVCCVersion) - 1), "")
+      for each strInfix in arrInfixes
+         for i = UBound(arrFolders) to LBound(arrFolders) step -1
+            if strInfix = "" or InStr(1, LCase(arrFolders(i)), strInfix) > 0 then
+               strPathQt5 = CheckForQt5Sub(g_strPathDev & "/win." & g_strTargetArch & "/qt/" & arrFolders(i))
+               if strPathQt5 <> "" then exit for
+            end if
+         next
+         if strPathQt5 <> "" then exit for
+      next
+   end if
+
+   ' Note! We could scan Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\UFH\SHC looking for entries
+   '       executing stuff like C:\qt\5.x.y\msvc2017_64\bin\qtenv2.bat
 
    ' Display the result.
@@ -2020,6 +2054,5 @@
 ' Checks if the specified path points to an usable Qt5 library.
 function CheckForQt5Sub(strPathQt5)
-
-   CheckForQt5Sub = False
+   CheckForQt5Sub = ""
    LogPrint "trying: strPathQt5=" & strPathQt5
 
@@ -2035,7 +2068,6 @@
          Or LogFileExists(strPathQt5, "lib/Qt5NetworkVBox.lib")) _
       then
-         CheckForQt5Sub = True
-   end if
-
+         CheckForQt5Sub = strPathQt5
+   end if
 end function
 
@@ -2067,4 +2099,5 @@
    Print "  -h, --help              Display this."
    Print "  --target-arch=x86|amd64 The target architecture."
+   Print "  --continue-on-error     Do not stop on errors."
    Print "  --internal-last         Check internal tools (tools/win.*) last."
    Print "  --internal-first        Check internal tools (tools/win.*) first (default)."
@@ -2085,5 +2118,5 @@
    Print "                          (Expecting bin, include and lib subdirs.)"
    Print "  --with-VC-Common=PATH   Maybe needed for 2015 and older to"
-   Print "                          locate the Common7 directory.
+   Print "                          locate the Common7 directory."
    Print "  --with-python=PATH      The python to use."
    Print "  --with-libxml2=PATH     To use a libxml2 other than the VBox one."
@@ -2098,13 +2131,14 @@
 ' The main() like function.
 '
-Sub Main
+function Main
    '
    ' Write the log header and check that we're not using wscript.
    '
    LogInit
-   If UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" Then
+   if UCase(Right(Wscript.FullName, 11)) = "WSCRIPT.EXE" then
       Wscript.Echo "This script must be run under CScript."
-      Wscript.Quit(1)
-   End If
+      Main = 1
+      exit function
+   end if
 
    '
@@ -2188,4 +2222,6 @@
          case "--disable-sdl"
             blnOptDisableSDL = True
+         case "--continue-on-error"
+            g_blnContinueOnError = True
          case "--internal-first"
             g_blnInternalFirst = True
@@ -2196,9 +2232,11 @@
          case "-h", "--help", "-?"
             usage
-            Wscript.Quit(0)
+            Main = 0
+            exit function
          case else
             Wscript.echo "syntax error: Unknown option '" & str &"'."
             usage
-            Wscript.Quit(1)
+            Main = 2
+            exit function
       end select
    next
@@ -2276,8 +2314,14 @@
    Print "  kmk"
    Print ""
-
-End Sub
-
-
-Main
-
+   if g_rcScript <> 0 then
+      Print "Warning: ignored errors. See above or in configure.log."
+   end if
+
+   Main = g_rcScript
+end function
+
+'
+' What crt0.o typically does:
+'
+WScript.Quit(Main())
+
