]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/global/OutputManager.java
- Fixed EDKT146; The override warning message has been reduced to almost none.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / OutputManager.java
CommitLineData
878ddf1f 1/** @file\r
2 OutputManager class.\r
3 \r
4 OutputManager class set output directories for every module by BUILD_MODE.\r
5 \r
6Copyright (c) 2006, Intel Corporation\r
7All rights reserved. This program and the accompanying materials\r
8are licensed and made available under the terms and conditions of the BSD License\r
9which accompanies this distribution. The full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14**/\r
15package org.tianocore.build.global;\r
16\r
17import org.apache.tools.ant.Project;\r
18import java.io.File;\r
1fa1cb75 19import org.tianocore.build.global.PropertyManager;\r
878ddf1f 20\r
21/**\r
22 OutputManager class is used to setup output directories (BIN_DIR, DEST_DIR_OUTPUT, \r
a29c47e0 23 DEST_DIR_DEBUG). \r
878ddf1f 24 \r
25 @since GenBuild 1.0\r
26**/\r
27public class OutputManager {\r
878ddf1f 28\r
29 ///\r
a29c47e0 30 /// means intermediate files will put under Module's dir\r
878ddf1f 31 ///\r
a29c47e0 32 private String MODULE = "MODULE";\r
878ddf1f 33 \r
34 ///\r
a29c47e0 35 /// mean intermediate files will put under a unify dir\r
878ddf1f 36 ///\r
a29c47e0 37 private String UNIFIED = "UNIFIED";\r
878ddf1f 38 \r
878ddf1f 39 \r
a29c47e0 40 private String userdir;\r
878ddf1f 41 \r
a29c47e0 42 private String type;\r
878ddf1f 43 ///\r
a29c47e0 44 /// Singleton Design Pattern\r
878ddf1f 45 ///\r
a29c47e0 46 private static OutputManager object;\r
878ddf1f 47 \r
a29c47e0 48 public synchronized static OutputManager getInstance() {\r
49 if ( object == null ) {\r
50 object = new OutputManager();\r
51 }\r
52 return object;\r
53 }\r
54 \r
55 public void setup(String userdir, String type) {\r
56 this.userdir = userdir;\r
57 this.type = type;\r
58 }\r
878ddf1f 59 \r
60 /**\r
a29c47e0 61 Setup BIN_DIR, DEST_DIR_OUTPUT and DEST_DIR_OUTPUT, following are the rules:\r
62 \r
63 <p>Divide all output files into two types: one is final files, such as FFS \r
64 file for driver module while LIB file for library module; another is \r
65 intermediate files, such AutoGen.c, OBJ files, Section files and so on. \r
66 \r
67 <p>In FPD, OutputDirectory element is used to specify where to put the output \r
68 files to. There are two mode (MODULE | UNIFIED). MODULE mode means that all \r
69 output files will put to the module directory while UNIFIED mode means that \r
70 all output files will put together. Default is UNIFIED mode. \r
71 \r
72 <p>BUILD_DIR is the base directory for current module build. By default, \r
73 BUILD_DIR is PLATFORM_DIR/Build in UNIFIED mode while is MODULE_DIR/Build \r
74 in MODULE mode. Of course, user can customize BUILD_DIR. If user-defined \r
75 BUILD_DIR is relative path, then look as related to WORKSPACE_DIR. \r
878ddf1f 76 \r
a29c47e0 77 <p>Then, BIN_DIR is BUILD_DIR/TARGET/TOOLCHAIN/ARCH;\r
78 \r
79 <p>FV_DIR is BUILD_DIR/TARGET/TOOLCHAIN/FV;\r
80 \r
81 <p>DEST_DIR_DEBUG | DEST_DIR_OUTPUT is: \r
82 BIN_DIR/PACKAGE_RELATIVE_DIR/MODULE_RELATIVE_DIR/DEBUG | OUTPUT\r
83\r
878ddf1f 84 \r
85 @param project current ANT build Project\r
a29c47e0 86 @param userdir user-defined directory\r
87 @param type the module build type (MODULE or UNIFIED)\r
878ddf1f 88 **/\r
a29c47e0 89 public void update(Project project) {\r
a29c47e0 90 //\r
91 // Default mode is UNIFIED. \r
92 //\r
93 if (type != null && type.equalsIgnoreCase(MODULE)) {\r
94 type = MODULE;\r
95 }\r
96 else {\r
97 type = UNIFIED;\r
98 }\r
99 \r
100 //\r
101 // default BUILD_DIR value\r
102 //\r
103 String buildDir;\r
104 if(type.equals(MODULE)){\r
105 buildDir = project.getProperty("MODULE_DIR") + File.separatorChar + "Build";\r
106 }\r
107 else {\r
108 buildDir = project.getProperty("PLATFORM_DIR") + File.separatorChar + "Build";\r
109 }\r
110 \r
111 //\r
112 // If user define BUILD_DIR\r
113 //\r
114 if (userdir != null && ! userdir.equals("")) {\r
115 File buildFile = new File(userdir);\r
116 if (buildFile.isAbsolute()){\r
117 buildDir = userdir;\r
118 }\r
119 //\r
120 // If path is not absolute, then look as related to WORKSPACE_DIR\r
121 //\r
122 else {\r
123 buildDir = GlobalData.getWorkspacePath() + File.separatorChar + userdir;\r
878ddf1f 124 }\r
125 }\r
878ddf1f 126 \r
a29c47e0 127 //\r
128 // Define BIN_DIR and FV_DIR\r
129 //\r
130 String binDir = buildDir + File.separatorChar + project.getProperty("TARGET")\r
131 + File.separatorChar + project.getProperty("TOOLCHAIN") \r
132 + File.separatorChar + project.getProperty("ARCH") ;\r
878ddf1f 133 \r
a29c47e0 134 String fvDir = buildDir + File.separatorChar + project.getProperty("TARGET")\r
135 + File.separatorChar + project.getProperty("TOOLCHAIN") \r
136 + File.separatorChar + "FV";\r
878ddf1f 137 \r
a29c47e0 138 //\r
139 // Define DEST_DIR_OUTPUT and DEST_DIR_DEBUG\r
140 //\r
141 String destDir = binDir + File.separatorChar + project.getProperty("PACKAGE_RELATIVE_DIR")\r
142 + File.separatorChar + project.getProperty("MODULE_RELATIVE_DIR");\r
878ddf1f 143 \r
a29c47e0 144 //\r
145 // Set properties\r
146 //\r
1fa1cb75 147 PropertyManager.setProperty(project, "BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));\r
148 PropertyManager.setProperty(project, "FV_DIR", fvDir.replaceAll("(\\\\)", "/"));\r
149 PropertyManager.setProperty(project, "BIN_DIR", binDir.replaceAll("(\\\\)", "/"));\r
150 PropertyManager.setProperty(project, "DEST_DIR_DEBUG", (destDir + File.separatorChar + "DEBUG").replaceAll("(\\\\)", "/"));\r
151 PropertyManager.setProperty(project, "DEST_DIR_OUTPUT", (destDir + File.separatorChar + "OUTPUT").replaceAll("(\\\\)", "/"));\r
878ddf1f 152 \r
a29c47e0 153 //\r
154 // Create all directory if necessary\r
155 //\r
156 (new File(buildDir)).mkdirs();\r
157 (new File(fvDir)).mkdirs();\r
158 (new File(binDir)).mkdirs();\r
159 (new File(destDir + File.separatorChar + "DEBUG")).mkdirs();\r
160 (new File(destDir + File.separatorChar + "OUTPUT")).mkdirs();\r
878ddf1f 161 }\r
a29c47e0 162 \r
163 public boolean prepareBuildDir(Project project){\r
164 boolean isUnified = true;\r
165 \r
166 if (type.equalsIgnoreCase("MODULE")) {\r
167 isUnified = false;\r
168 }\r
169 \r
170 String buildDir = project.getProperty("PLATFORM_DIR") + File.separatorChar + "Build";\r
171 //\r
172 // If user define BUILD_DIR\r
173 //\r
174 if (userdir != null && ! userdir.equals("")) {\r
175 File buildFile = new File(userdir);\r
176 if (buildFile.isAbsolute()){\r
177 buildDir = userdir;\r
178 }\r
179 //\r
180 // If path is not absolute, then look as related to WORKSPACE_DIR\r
181 //\r
182 else {\r
183 buildDir = GlobalData.getWorkspacePath() + File.separatorChar + userdir;\r
184 }\r
185 }\r
82516887 186 \r
a29c47e0 187 //\r
188 // Set to property\r
189 //\r
1fa1cb75 190 PropertyManager.setProperty(project, "BUILD_DIR", buildDir.replaceAll("(\\\\)", "/"));\r
a29c47e0 191 \r
192 //\r
193 // Create all directory if necessary\r
194 //\r
195 (new File(buildDir)).mkdirs();\r
196 return isUnified;\r
197 }\r
198\r
199}