To fix EDKT284.
[mirror_edk2.git] / Tools / Source / ContextTool / org / tianocore / context / TargetFile.java
index 2b10d7c..3143b8c 100644 (file)
@@ -117,51 +117,177 @@ public class TargetFile {
         //\r
         try {\r
             while ((textLine = br.readLine()) != null) {\r
+                //\r
+                // the line is composed of Space\r
+                //\r
                 if (textLine.trim().compareToIgnoreCase("") == 0) {\r
                     bw.write(textLine);\r
                     bw.newLine();\r
-                } else if ((textLine.trim().charAt(0) == '#') && (textLine.indexOf("=") == -1)){\r
+                } \r
+                //\r
+                // the line starts with "#", and no "="\r
+                //\r
+                else if ((textLine.trim().charAt(0) == '#') && (textLine.indexOf("=") == -1)){\r
                     bw.write(textLine);\r
                     bw.newLine();\r
                 } else {\r
+                    //\r
+                    //modify at the first time, and there should be *ACTIVE_PLATFORM*=* in the line\r
+                    //\r
                     if (textLine.indexOf("ACTIVE_PLATFORM") != -1) {\r
-                        if(ParseParameter.pstr.length() > ParseParameter.length) {\r
-                            bw.write(ParseParameter.pstr);\r
-                        } else {\r
-                            bw.write(textLine);\r
+                        if(pflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.pstr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.pstr);\r
+                                    bw.newLine();\r
+                                    pflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.pstr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.pstr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            pflag = false;\r
                         }\r
-                        bw.newLine();\r
                     } else if (textLine.indexOf("TARGET_ARCH") != -1) {\r
-                        if(ParseParameter.astr.length() > ParseParameter.length) {\r
-                            bw.write(ParseParameter.astr);\r
-                        } else {\r
-                            bw.write(textLine);\r
+                        if(aflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.astr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.astr);\r
+                                    bw.newLine();\r
+                                    aflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.astr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.astr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            aflag = false;\r
                         }\r
-                        bw.newLine();\r
                     } else if (textLine.indexOf("TARGET") != -1) {\r
-                        if(ParseParameter.tstr.length() > ParseParameter.length) {\r
-                            bw.write(ParseParameter.tstr);\r
-                        } else {\r
-                            bw.write(textLine);\r
+                        if(tflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.tstr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.tstr);\r
+                                    bw.newLine();\r
+                                    tflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.tstr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.tstr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            tflag = false;\r
                         }\r
-                        bw.newLine();\r
                     } else if (textLine.indexOf("TOOL_CHAIN_CONF") != -1) {\r
-                        if(ParseParameter.cstr.length() > ParseParameter.length) {\r
-                            bw.write(ParseParameter.cstr);\r
-                        } else {\r
-                            bw.write(textLine);\r
+                        if(cflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.cstr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.cstr);\r
+                                    bw.newLine();\r
+                                    cflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.cstr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.cstr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            cflag = false;\r
                         }\r
-                        bw.newLine();\r
                     } else if (textLine.indexOf("TOOL_CHAIN_TAG") != -1) {\r
-                        if(ParseParameter.nstr.length() > ParseParameter.length) {\r
-                            bw.write(ParseParameter.nstr);\r
-                        } else {\r
-                            bw.write(textLine);\r
+                        if(nflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.nstr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.nstr);\r
+                                    bw.newLine();\r
+                                    nflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.nstr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.nstr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            nflag = false;\r
+                        }\r
+                    } else if (textLine.indexOf("MAX_CONCURRENT_THREAD_NUMBER") != -1) {\r
+                        if(mflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.mstr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.mstr);\r
+                                    bw.newLine();\r
+                                    mflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.mstr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.mstr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            mflag = false;\r
+                        }\r
+                    }else if (textLine.indexOf("MULTIPLE_THREAD") != -1) {\r
+                        if(meflag == true){\r
+                            if(textLine.trim().charAt(0) == '#'){\r
+                                if(ParseParameter.mestr.length() > ParseParameter.length) {\r
+                                    bw.write(ParseParameter.mestr);\r
+                                    bw.newLine();\r
+                                    meflag = false;\r
+                                }\r
+                                continue;\r
+                            }\r
+                            if(ParseParameter.mestr.length() > ParseParameter.length) {\r
+                                bw.write(ParseParameter.mestr);\r
+                            } else {\r
+                                bw.write(textLine);\r
+                            }\r
+                            bw.newLine();\r
+                            meflag = false;\r
                         }\r
-                        bw.newLine();\r
                     }\r
                 }\r
             }\r
+            //\r
+            //user maybe delete the line *ACTIVE_PLATFORM*=*\r
+            //\r
+            if( (pflag == true) && (ParseParameter.pstr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.pstr);\r
+                bw.newLine();\r
+            } else if ( (tflag == true) && (ParseParameter.tstr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.tstr);\r
+                bw.newLine();\r
+            } else if ( (aflag == true) && (ParseParameter.astr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.astr);\r
+                bw.newLine();\r
+            } else if ( (cflag == true) && (ParseParameter.cstr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.cstr);\r
+                bw.newLine();\r
+            } else if ( (nflag == true) && (ParseParameter.nstr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.nstr);\r
+                bw.newLine();\r
+            } else if ( (meflag == true) && (ParseParameter.mestr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.mestr);\r
+                bw.newLine();\r
+            } else if ( (mflag == true) && (ParseParameter.mstr.length() > ParseParameter.length) ){\r
+                bw.write(ParseParameter.mstr);\r
+                bw.newLine();\r
+            }\r
         } catch (IOException e) {\r
             System.out.println("\n#  read or write file error!");\r
             return false;\r
@@ -208,18 +334,22 @@ public class TargetFile {
         }\r
         FileChannel outputChannel = outputFile.getChannel();\r
 \r
-        ByteBuffer[] buffers = new ByteBuffer[5];\r
+        ByteBuffer[] buffers = new ByteBuffer[7];\r
         buffers[0] = ByteBuffer.allocate(ParseParameter.pstr.toString().length());\r
         buffers[1] = ByteBuffer.allocate(ParseParameter.tstr.toString().length());\r
         buffers[2] = ByteBuffer.allocate(ParseParameter.astr.toString().length());\r
         buffers[3] = ByteBuffer.allocate(ParseParameter.cstr.toString().length());\r
         buffers[4] = ByteBuffer.allocate(ParseParameter.nstr.toString().length());\r
+        buffers[5] = ByteBuffer.allocate(ParseParameter.mestr.toString().length());\r
+        buffers[6] = ByteBuffer.allocate(ParseParameter.mstr.toString().length());\r
 \r
         buffers[0].put(ParseParameter.pstr.toString().getBytes()).flip();\r
         buffers[1].put(ParseParameter.tstr.toString().getBytes()).flip();\r
         buffers[2].put(ParseParameter.astr.toString().getBytes()).flip();\r
         buffers[3].put(ParseParameter.cstr.toString().getBytes()).flip();\r
         buffers[4].put(ParseParameter.nstr.toString().getBytes()).flip();\r
+        buffers[5].put(ParseParameter.mestr.toString().getBytes()).flip();\r
+        buffers[6].put(ParseParameter.mstr.toString().getBytes()).flip();\r
 \r
         try {\r
             ByteBuffer bufofCP = ByteBuffer.allocate(Copyright.length());\r
@@ -255,6 +385,16 @@ public class TargetFile {
             outputChannel.write(buffer4);\r
             outputChannel.write(buffers[4]);\r
             \r
+            ByteBuffer buffer5 = ByteBuffer.allocate(meusage.length());\r
+            buffer4.put(meusage.getBytes()).flip();\r
+            outputChannel.write(buffer5);\r
+            outputChannel.write(buffers[5]);\r
+            \r
+            ByteBuffer buffer6 = ByteBuffer.allocate(musage.length());\r
+            buffer4.put(musage.getBytes()).flip();\r
+            outputChannel.write(buffer6);\r
+            outputChannel.write(buffers[6]);\r
+            \r
             outputFile.close();\r
         } catch (IOException e) {\r
             System.out.println("\n# The operations of file failed !");\r
@@ -272,6 +412,17 @@ public class TargetFile {
     /// point to target.txt.\r
     ///\r
     private static File Fd;\r
+    \r
+    ///\r
+    /// when the flag is true, the corresponding str should be add at the end of file.\r
+    ///\r
+    private static boolean pflag = true;\r
+    private static boolean tflag = true;\r
+    private static boolean aflag = true;\r
+    private static boolean cflag = true;\r
+    private static boolean nflag = true;\r
+    private static boolean mflag = true;\r
+    private static boolean meflag = true;\r
 \r
     private static final String Copyright = "#\n"\r
             + "#  Copyright (c) 2006, Intel Corporation\n"\r
@@ -331,4 +482,16 @@ public class TargetFile {
             + "#  TAGNAME               List      Optional   Specify the name(s) of the tools_def.txt TagName to use.\n"\r
             + "#                                             If not specified, all applicable TagName tools will be \n"\r
             + "#                                             used for the build.  The list uses space character separation.\n";\r
+    \r
+    private static final String musage = "\n\n"\r
+            + "#  MULTIPLE_THREAD       FLAG      Optional   Flag to enable multi-thread build. If not specified, default\n"\r
+            + "#                                             is \"Disable\". If your computer is multi-core or multiple CPUs,\n" \r
+            + "#                                             enabling this feature will bring much benefit. For multi-thread\n" \r
+            + "#                                             built, the log will write to ${BUILD_DIR}/build.log.\n" \r
+            + "#                                             This feature is only for PLATFORM build, and clean, cleanall or\n"\r
+            + "#                                             stand-alone module build is still using the normal way.\n";\r
+    private static final String meusage = "\n\n"\r
+            + "# MAX_CONCURRENT_THREAD_NUMBER  NUMBER  Optional  The number of concurrent threads. Default is 2. Recommend to\n" \r
+            + "#                                                 set this value to one more than the number of your compurter\n"\r
+            + "#                                                 cores or CPUs.\n";\r
 }\r