Index: trunk/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/AutoGen/GenMake.py
===================================================================
--- trunk/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/AutoGen/GenMake.py	(revision 107043)
+++ trunk/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/AutoGen/GenMake.py	(revision 107053)
@@ -56,6 +56,8 @@
 NMAKE_FILETYPE = "nmake"
 GMAKE_FILETYPE = "gmake"
+KMK_FILETYPE   = "kmk";             # vbox
 WIN32_PLATFORM = "win32"
 POSIX_PLATFORM = "posix"
+KBUILD_PLATFORM = "kbuild";         # vbox
 
 ## BuildFile class
@@ -73,4 +75,5 @@
     _FILE_NAME_ = {
         NMAKE_FILETYPE :   "Makefile",
+        KMK_FILETYPE :     "Makefile.kmk", # vbox
         GMAKE_FILETYPE :   "GNUmakefile"
     }
@@ -101,4 +104,5 @@
     _FILE_HEADER_ = {
         NMAKE_FILETYPE :   _MAKEFILE_HEADER % _FILE_NAME_[NMAKE_FILETYPE],
+        KMK_FILETYPE :     _MAKEFILE_HEADER % _FILE_NAME_[KMK_FILETYPE],    # vbox
         GMAKE_FILETYPE :   _MAKEFILE_HEADER % _FILE_NAME_[GMAKE_FILETYPE]
     }
@@ -113,10 +117,18 @@
     _SHELL_CMD_ = {
         WIN32_PLATFORM : {
-            "CP"    :   "copy /y",
-            "MV"    :   "move /y",
-            "RM"    :   "del /f /q",
-            "MD"    :   "mkdir",
-            "RD"    :   "rmdir /s /q",
+            "CP"    :  "copy /y",
+            "MV"    :  "move /y",
+            "RM"    :  "del /f /q",
+            "MD"    :  "mkdir",
+            "RD"    :  "rmdir /s /q",
         },
+
+        KBUILD_PLATFORM : {                     # vbox
+            "CP"    :  "kmk_builtin_cp -f",     # vbox
+            "MV"    :  "kmk_builtin_mv -f",     # vbox
+            "MD"    :  "kmk_builtin_mkdir -p",  # vbox
+            "RM"    :  "kmk_builtin_rm -f",     # vbox
+            "RD"    :  "kmk_builtin_rm -Rf",    # vbox
+        },                                      # vbox
 
         POSIX_PLATFORM : {
@@ -132,4 +144,5 @@
     _SEP_ = {
         WIN32_PLATFORM :   "\\",
+        KBUILD_PLATFORM :  "\\" if sys.platform == "win32" else '/',                        # vbox
         POSIX_PLATFORM :   "/"
     }
@@ -138,4 +151,5 @@
     _MD_TEMPLATE_ = {
         WIN32_PLATFORM :   'if not exist %(dir)s $(MD) %(dir)s',
+        KBUILD_PLATFORM :  "$(MD) -- %(dir)s",                                              # vbox
         POSIX_PLATFORM :   "$(MD) %(dir)s"
     }
@@ -144,4 +158,5 @@
     _RD_TEMPLATE_ = {
         WIN32_PLATFORM :   'if exist %(dir)s $(RD) %(dir)s',
+        KBUILD_PLATFORM :  "$(RD) -- %(dir)s",                                              # vbox
         POSIX_PLATFORM :   "$(RD) %(dir)s"
     }
@@ -149,4 +164,5 @@
     _CP_TEMPLATE_ = {
         WIN32_PLATFORM :   'if exist %(Src)s $(CP) %(Src)s %(Dst)s',
+        KBUILD_PLATFORM :  "kmk_builtin_test -f %(Src)s -- $(CP) -- %(Src)s %(Dst)s",       # vbox
         POSIX_PLATFORM :   "test -f %(Src)s && $(CP) %(Src)s %(Dst)s"
     }
@@ -154,4 +170,5 @@
     _CD_TEMPLATE_ = {
         WIN32_PLATFORM :   'if exist %(dir)s cd %(dir)s',
+        KBUILD_PLATFORM :  "test -e %(dir)s && cd %(dir)s",                                 # vbox
         POSIX_PLATFORM :   "test -e %(dir)s && cd %(dir)s"
     }
@@ -159,4 +176,5 @@
     _MAKE_TEMPLATE_ = {
         WIN32_PLATFORM :   'if exist %(file)s "$(MAKE)" $(MAKE_FLAGS) -f %(file)s',
+        KBUILD_PLATFORM :  '+kmk_test -e %(file)s -- "$(MAKE)" $(MAKE_FLAGS) -f %(file)s',  # vbox
         POSIX_PLATFORM :   'test -e %(file)s && "$(MAKE)" $(MAKE_FLAGS) -f %(file)s'
     }
@@ -164,4 +182,5 @@
     _INCLUDE_CMD_ = {
         NMAKE_FILETYPE :   '!INCLUDE',
+        KMK_FILETYPE :     "include",                                                       # vbox
         GMAKE_FILETYPE :   "include"
     }
@@ -181,4 +200,6 @@
         if "nmake" in MakePath:
             self._FileType = NMAKE_FILETYPE
+        elif "kmk" in MakePath:                     # vbox
+            self._FileType = KMK_FILETYPE           # vbox
         else:
             self._FileType = GMAKE_FILETYPE
@@ -188,4 +209,8 @@
         else:
             self._Platform = POSIX_PLATFORM
+        # vbox start
+        if self._FileType == KMK_FILETYPE:
+            self._Platform = KBUILD_PLATFORM
+        # vbox end
 
     ## Create build file.
@@ -244,4 +269,25 @@
                     break
             return Path
+
+    # VBox begin
+    def FixQuietAndRedirForCommandList(self, asCommands):
+        asRet = [];
+        for sCmd in asCommands:
+            sCmd = sCmd.strip();
+            if sCmd:
+                if sCmd.startswith('if exist ') and self._FileType == KMK_FILETYPE:
+                    raise Exception('sCmd=%s' % (sCmd,));
+
+                if self._FileType == KMK_FILETYPE and sCmd.count('>') == 1 and '&' not in sCmd:
+                    sCmd, sOutput = sCmd.split('>');
+                    sCmd = 'kmk_builtin_redirect -wto %s -- %s' % (sOutput.strip(), sCmd.strip());
+
+                if sCmd[0] == '-' and self._FileType == NMAKE_FILETYPE:
+                    sCmd = '-$(EFI_QUIET)' + sCmd[1:];
+                else:
+                    sCmd = '$(EFI_QUIET)' + sCmd;
+            asRet.append(sCmd);
+        return asRet;
+    # VBox end
 
 ## ModuleMakefile class
@@ -1050,19 +1096,4 @@
                         Deps.append("$(%s)" % T.ListFileMacro)
 
-                # VBox - begin: Add $(QUIET)
-                sAllCmds = None;
-                for sCmd in T.Commands:
-                    sCmd = sCmd.strip();
-                    if len(sCmd) > 0:
-                        if sCmd[0] == '-' and self._FileType == 'nmake':
-                            sCmd = '-$(EFI_QUIET)' + sCmd[1:];
-                        else:
-                            sCmd = '$(EFI_QUIET)' + sCmd;
-                        if sAllCmds is None:
-                            sAllCmds = sCmd;
-                        else:
-                            sAllCmds += '\n\t' + sCmd;
-                # VBox - end.
-
                 if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and Type == TAB_C_CODE_FILE:
                     T, CmdTarget, CmdTargetDict, CmdCppDict = self.ParserCCodeFile(T, Type, CmdSumDict, CmdTargetDict,
@@ -1070,7 +1101,6 @@
                                                                                    ToolsDef, resp_file_number)
                     resp_file_number += 1
-                    TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": CCodeDeps}
-                    # VBox: Original: TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": sAllCmds,"deps": CCodeDeps}
-                    CmdLine = self._BUILD_TARGET_TEMPLATE.Replace(TargetDict).rstrip().replace('\t$(OBJLIST', '$(OBJLIST')
+                    TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(self.FixQuietAndRedirForCommandList(T.Commands)),"deps": CCodeDeps}
+                    CmdLine = self._BUILD_TARGET_TEMPLATE.Replace(TargetDict).rstrip().replace('\t$(OBJLIST', '$(OBJLIST').replace('\t$(EFI_QUIET)$(OBJLIST', '$(OBJLIST')
                     if T.Commands:
                         CmdLine = '%s%s' %(CmdLine, TAB_LINE_BREAK)
@@ -1078,13 +1108,19 @@
                         self.BuildTargetList.append(CmdLine)
                 else:
-                    TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": Deps}
-                    # VBox: Original: TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": sAllCmds,"deps": Deps}
+                    TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(self.FixQuietAndRedirForCommandList(T.Commands)),"deps": Deps}
+                    if self._FileType == KMK_FILETYPE and len(T.Outputs) > 1:                               # vbox
+                        # kmk has syntax for multiple output files.                                         # vbox
+                        asTargets = [TargetDict["target"],];                                                # vbox
+                        for oOutput in T.Outputs[1:]:                                                       # vbox
+                            asTargets.append(self.PlaceMacro(oOutput.Path, self.Macros));                   # vbox
+                        TargetDict["target"] = ' +| '.join(asTargets)                                       # vbox
                     self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict))
 
-                    # Add a Makefile rule for targets generating multiple files.
-                    # The main output is a prerequisite for the other output files.
-                    for i in T.Outputs[1:]:
-                        AnnexeTargetDict = {"target": self.PlaceMacro(i.Path, self.Macros), "cmd": "", "deps": self.PlaceMacro(T.Target.Path, self.Macros)}
-                        self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(AnnexeTargetDict))
+                    if self._FileType != KMK_FILETYPE:                                                      # vbox
+                        # Add a Makefile rule for targets generating multiple files.
+                        # The main output is a prerequisite for the other output files.
+                        for i in T.Outputs[1:]:
+                            AnnexeTargetDict = {"target": self.PlaceMacro(i.Path, self.Macros), "cmd": "", "deps": self.PlaceMacro(T.Target.Path, self.Macros)}
+                            self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(AnnexeTargetDict))
 
     def ParserCCodeFile(self, T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict, RespFile, ToolsDef,
Index: trunk/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
===================================================================
--- trunk/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py	(revision 107043)
+++ trunk/src/VBox/Devices/EFI/Firmware/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py	(revision 107053)
@@ -509,5 +509,7 @@
             SaveFileOnChange(CommandFile, ' '.join(Cmd), False)
             if IsMakefile:
-                if sys.platform == "win32":
+                if True:                                                # vbox: badly abstracted.
+                    Cmd = ['kmk_test', '-e', Input[0], '--'] + Cmd      # vbox: badly abstracted.
+                elif sys.platform == "win32":
                     Cmd = ['if', 'exist', Input[0]] + Cmd
                 else:
