]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/GenMake.py
BaseTools:Enable the /MP option of MSVC compiler
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / GenMake.py
index 10913661907e9466460763d51baedbe204d87e00..7562dc68b36c31e5f0d0c4029607b17a4e8e3114 100644 (file)
@@ -429,7 +429,7 @@ cleanlib:
         self.CommonFileDependency = []\r
         self.FileListMacros = {}\r
         self.ListFileMacros = {}\r
-\r
+        self.ObjTargetDict = {}\r
         self.FileCache = {}\r
         self.LibraryBuildCommandList = []\r
         self.LibraryFileList = []\r
@@ -512,6 +512,9 @@ cleanlib:
                     # Remove duplicated include path, if any\r
                     if Attr == "FLAGS":\r
                         Value = RemoveDupOption(Value, IncPrefix, MyAgo.IncludePathList)\r
+                        if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and Tool == 'CC' and '/GM' in Value:\r
+                            Value = Value.replace(' /MP', '')\r
+                            MyAgo.BuildOption[Tool][Attr] = Value\r
                         if Tool == "OPTROM" and PCI_COMPRESS_Flag:\r
                             ValueList = Value.split()\r
                             if ValueList:\r
@@ -612,6 +615,11 @@ cleanlib:
                 False\r
                 )\r
 \r
+        # Generate objlist used to create .obj file\r
+        for Type in self.ObjTargetDict:\r
+            NewLine = ' '.join(list(self.ObjTargetDict[Type]))\r
+            FileMacroList.append("OBJLIST_%s = %s" % (list(self.ObjTargetDict.keys()).index(Type), NewLine))\r
+\r
         BcTargetList = []\r
 \r
         MakefileName = self._FILE_NAME_[self._FileType]\r
@@ -921,6 +929,10 @@ cleanlib:
         for File in DepSet:\r
             self.CommonFileDependency.append(self.PlaceMacro(File.Path, self.Macros))\r
 \r
+        CmdSumDict = {}\r
+        CmdTargetDict = {}\r
+        CmdCppDict = {}\r
+        DependencyDict = FileDependencyDict.copy()\r
         for File in FileDependencyDict:\r
             # skip non-C files\r
             if File.Ext not in [".c", ".C"] or File.Name == "AutoGen.c":\r
@@ -928,6 +940,7 @@ cleanlib:
             NewDepSet = set(FileDependencyDict[File])\r
             NewDepSet -= DepSet\r
             FileDependencyDict[File] = ["$(COMMON_DEPS)"] + list(NewDepSet)\r
+            DependencyDict[File] = list(NewDepSet)\r
 \r
         # Convert target description object to target string in makefile\r
         for Type in self._AutoGenObject.Targets:\r
@@ -939,11 +952,21 @@ cleanlib:
                     self.ListFileMacros[T.ListFileMacro] = []\r
                 if T.GenIncListFile and T.IncListFileMacro not in self.ListFileMacros:\r
                     self.ListFileMacros[T.IncListFileMacro] = []\r
+                if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and Type == TAB_C_CODE_FILE:\r
+                    NewFile = self.PlaceMacro(str(T), self.Macros)\r
+                    if self.ObjTargetDict.get(T.Target.SubDir):\r
+                        self.ObjTargetDict[T.Target.SubDir].add(NewFile)\r
+                    else:\r
+                        self.ObjTargetDict[T.Target.SubDir] = set()\r
+                        self.ObjTargetDict[T.Target.SubDir].add(NewFile)\r
 \r
                 Deps = []\r
+                CCodeDeps = []\r
                 # Add force-dependencies\r
                 for Dep in T.Dependencies:\r
                     Deps.append(self.PlaceMacro(str(Dep), self.Macros))\r
+                    if Dep != '$(MAKE_FILE)':\r
+                        CCodeDeps.append(self.PlaceMacro(str(Dep), self.Macros))\r
                 # Add inclusion-dependencies\r
                 if len(T.Inputs) == 1 and T.Inputs[0] in FileDependencyDict:\r
                     for F in FileDependencyDict[T.Inputs[0]]:\r
@@ -967,12 +990,59 @@ cleanlib:
                     if Type in [TAB_OBJECT_FILE, TAB_STATIC_LIBRARY]:\r
                         Deps.append("$(%s)" % T.ListFileMacro)\r
 \r
-                TargetDict = {\r
-                    "target"    :   self.PlaceMacro(T.Target.Path, self.Macros),\r
-                    "cmd"       :   "\n\t".join(T.Commands),\r
-                    "deps"      :   Deps\r
-                }\r
-                self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict))\r
+                if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and Type == TAB_C_CODE_FILE:\r
+                    T, CmdTarget, CmdTargetDict, CmdCppDict = self.ParserCCodeFile(T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict)\r
+                    TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": CCodeDeps}\r
+                    CmdLine = self._BUILD_TARGET_TEMPLATE.Replace(TargetDict).rstrip().replace('\t$(OBJLIST', '$(OBJLIST')\r
+                    if T.Commands:\r
+                        CmdLine = '%s%s' %(CmdLine, TAB_LINE_BREAK)\r
+                    if CCodeDeps or CmdLine:\r
+                        self.BuildTargetList.append(CmdLine)\r
+                else:\r
+                    TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": Deps}\r
+                    self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(TargetDict))\r
+\r
+    def ParserCCodeFile(self, T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict):\r
+        if not CmdSumDict:\r
+            for item in self._AutoGenObject.Targets[Type]:\r
+                CmdSumDict[item.Target.SubDir] = item.Target.BaseName\r
+                for CppPath in item.Inputs:\r
+                    Path = self.PlaceMacro(CppPath.Path, self.Macros)\r
+                    if CmdCppDict.get(item.Target.SubDir):\r
+                        CmdCppDict[item.Target.SubDir].append(Path)\r
+                    else:\r
+                        CmdCppDict[item.Target.SubDir] = ['$(MAKE_FILE)', Path]\r
+                    if CppPath.Path in DependencyDict:\r
+                        for Temp in DependencyDict[CppPath.Path]:\r
+                            try:\r
+                                Path = self.PlaceMacro(Temp.Path, self.Macros)\r
+                            except:\r
+                                continue\r
+                            if Path not in (self.CommonFileDependency + CmdCppDict[item.Target.SubDir]):\r
+                                CmdCppDict[item.Target.SubDir].append(Path)\r
+        if T.Commands:\r
+            CommandList = T.Commands[:]\r
+            for Item in CommandList[:]:\r
+                SingleCommandList = Item.split()\r
+                if len(SingleCommandList) > 0 and '$(CC)' in SingleCommandList[0]:\r
+                    for Temp in SingleCommandList:\r
+                        if Temp.startswith('/Fo'):\r
+                            CmdSign = '%s%s' % (Temp.rsplit(TAB_SLASH, 1)[0], TAB_SLASH)\r
+                            break\r
+                    else: continue\r
+                    if CmdSign not in list(CmdTargetDict.keys()):\r
+                        CmdTargetDict[CmdSign] = Item.replace(Temp, CmdSign)\r
+                    else:\r
+                        CmdTargetDict[CmdSign] = "%s %s" % (CmdTargetDict[CmdSign], SingleCommandList[-1])\r
+                    Index = CommandList.index(Item)\r
+                    CommandList.pop(Index)\r
+                    if SingleCommandList[-1].endswith("%s%s.c" % (TAB_SLASH, CmdSumDict[CmdSign.lstrip('/Fo').rsplit(TAB_SLASH, 1)[0]])):\r
+                        Cpplist = CmdCppDict[T.Target.SubDir]\r
+                        Cpplist.insert(0, '$(OBJLIST_%d): $(COMMON_DEPS)' % list(self.ObjTargetDict.keys()).index(T.Target.SubDir))\r
+                        T.Commands[Index] = '%s\n\t%s' % (' \\\n\t'.join(Cpplist), CmdTargetDict[CmdSign])\r
+                    else:\r
+                        T.Commands.pop(Index)\r
+        return T, CmdSumDict, CmdTargetDict, CmdCppDict\r
 \r
     ## For creating makefile targets for dependent libraries\r
     def ProcessDependentLibrary(self):\r