]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/borland/BorlandProcessor.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / borland / BorlandProcessor.java
CommitLineData
878ddf1f 1/*\r
2 * \r
3 * Copyright 2002-2004 The Ant-Contrib project\r
4 *\r
5 * Licensed under the Apache License, Version 2.0 (the "License");\r
6 * you may not use this file except in compliance with the License.\r
7 * You may obtain a copy of the License at\r
8 *\r
9 * http://www.apache.org/licenses/LICENSE-2.0\r
10 *\r
11 * Unless required by applicable law or agreed to in writing, software\r
12 * distributed under the License is distributed on an "AS IS" BASIS,\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 * See the License for the specific language governing permissions and\r
15 * limitations under the License.\r
16 */\r
17package net.sf.antcontrib.cpptasks.borland;\r
18import java.io.BufferedReader;\r
19import java.io.File;\r
20import java.io.FileReader;\r
21import java.io.IOException;\r
22import java.io.Reader;\r
23import java.util.Vector;\r
24import java.io.FileWriter;\r
25\r
26import net.sf.antcontrib.cpptasks.CUtil;\r
27import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;\r
28/**\r
29 * A add-in class for Borland(r) processor adapters\r
30 * \r
31 * \r
32 */\r
33public final class BorlandProcessor {\r
34 public static void addWarningSwitch(Vector args, int level) {\r
35 switch (level) {\r
36 case 0 :\r
37 args.addElement("-w-");\r
38 break;\r
39 case 5 :\r
40 args.addElement("-w!");\r
41 break;\r
42 default :\r
43 args.addElement("-w");\r
44 break;\r
45 }\r
46 }\r
47 public static String getCommandFileSwitch(String cmdFile) {\r
48 StringBuffer buf = new StringBuffer("@");\r
49 quoteFile(buf, cmdFile);\r
50 return buf.toString();\r
51 }\r
52 public static void getDefineSwitch(StringBuffer buffer, String define,\r
53 String value) {\r
54 buffer.append("-D");\r
55 buffer.append(define);\r
56 if (value != null && value.length() > 0) {\r
57 buffer.append('=');\r
58 buffer.append(value);\r
59 }\r
60 }\r
61 /**\r
62 * This method extracts path information from the appropriate .cfg file in\r
63 * the install directory.\r
64 * \r
65 * @param toolName\r
66 * Tool name, for example, "bcc32", "brc32", "ilink32"\r
67 * @param switchChar\r
68 * Command line switch character, for example "L" for libraries\r
69 * @param defaultRelativePaths\r
70 * default paths relative to executable directory\r
71 * @return path\r
72 */\r
73 public static File[] getEnvironmentPath(String toolName, char switchChar,\r
74 String[] defaultRelativePath) {\r
75 if (toolName == null) {\r
76 throw new NullPointerException("toolName");\r
77 }\r
78 if (defaultRelativePath == null) {\r
79 throw new NullPointerException("defaultRelativePath");\r
80 }\r
81 String[] path = defaultRelativePath;\r
82 File exeDir = CUtil.getExecutableLocation(toolName + ".exe");\r
83 if (exeDir != null) {\r
84 File cfgFile = new File(exeDir, toolName + ".cfg");\r
85 if (cfgFile.exists()) {\r
86 try {\r
87 Reader reader = new BufferedReader(new FileReader(cfgFile));\r
88 BorlandCfgParser cfgParser = new BorlandCfgParser(\r
89 switchChar);\r
90 path = cfgParser.parsePath(reader);\r
91 reader.close();\r
92 } catch (IOException ex) {\r
93 //\r
94 // could be logged\r
95 //\r
96 }\r
97 }\r
98 } else {\r
99 //\r
100 // if can't find the executable,\r
101 // assume current directory to resolve relative paths\r
102 //\r
103 exeDir = new File(System.getProperty("user.dir"));\r
104 }\r
105 int nonExistant = 0;\r
106 File[] resourcePath = new File[path.length];\r
107 for (int i = 0; i < path.length; i++) {\r
108 resourcePath[i] = new File(path[i]);\r
109 if (!resourcePath[i].isAbsolute()) {\r
110 resourcePath[i] = new File(exeDir, path[i]);\r
111 }\r
112 //\r
113 // if any of the entries do not exist or are\r
114 // not directories, null them out\r
115 if (!(resourcePath[i].exists() && resourcePath[i].isDirectory())) {\r
116 resourcePath[i] = null;\r
117 nonExistant++;\r
118 }\r
119 }\r
120 //\r
121 // if there were some non-existant or non-directory\r
122 // entries in the configuration file then\r
123 // create a shorter array\r
124 if (nonExistant > 0) {\r
125 File[] culled = new File[resourcePath.length - nonExistant];\r
126 int index = 0;\r
127 for (int i = 0; i < resourcePath.length; i++) {\r
128 if (resourcePath[i] != null) {\r
129 culled[index++] = resourcePath[i];\r
130 }\r
131 }\r
132 resourcePath = culled;\r
133 }\r
134 return resourcePath;\r
135 }\r
136 public static String getIncludeDirSwitch(String includeOption,\r
137 String includeDir) {\r
138 StringBuffer buf = new StringBuffer(includeOption);\r
139 quoteFile(buf, includeDir);\r
140 return buf.toString();\r
141 }\r
142 public static String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {\r
143 StringBuffer buf = new StringBuffer();\r
144 String[] patterns = new String[libnames.length];\r
145 for (int i = 0; i < libnames.length; i++) {\r
146 buf.setLength(0);\r
147 buf.append(libnames[i]);\r
148 buf.append(".lib");\r
149 patterns[i] = buf.toString();\r
150 }\r
151 return patterns;\r
152 }\r
153 public static String[] getOutputFileSwitch(String outFile) {\r
154 return new String[0];\r
155 }\r
156 public static void getUndefineSwitch(StringBuffer buffer, String define) {\r
157 buffer.append("-U");\r
158 buffer.append(define);\r
159 }\r
160 public static boolean isCaseSensitive() {\r
161 return false;\r
162 }\r
163 private static void quoteFile(StringBuffer buf, String outPath) {\r
164 if (outPath.indexOf(' ') >= 0) {\r
165 buf.append('\"');\r
166 buf.append(outPath);\r
167 buf.append('\"');\r
168 } else {\r
169 buf.append(outPath);\r
170 }\r
171 }\r
172 \r
173 /**\r
174 * Prepares argument list to execute the linker using a response file.\r
175 * \r
176 * @param outputFile\r
177 * linker output file\r
178 * @param args\r
179 * output of prepareArguments\r
180 * @return arguments for runTask\r
181 */\r
182 public static String[] prepareResponseFile(File outputFile, \r
183 String[] args,\r
184 String continuation)\r
185 throws IOException {\r
186 String baseName = outputFile.getName();\r
187 File commandFile = new File(outputFile.getParent(), baseName + ".lnk");\r
188 FileWriter writer = new FileWriter(commandFile);\r
189 for (int i = 1; i < args.length - 1; i++) {\r
190 writer.write(args[i]);\r
191 //\r
192 // if either the current argument ends with\r
193 // or next argument starts with a comma then\r
194 // don't split the line\r
195 if (args[i].endsWith(",") || args[i + 1].startsWith(",")) {\r
196 writer.write(' ');\r
197 } else {\r
198 //\r
199 // split the line to make it more readable\r
200 //\r
201 writer.write(continuation);\r
202 }\r
203 }\r
204 //\r
205 // write the last argument\r
206 //\r
207 if (args.length > 1) {\r
208 writer.write(args[args.length - 1]);\r
209 }\r
210 writer.close();\r
211 String[] execArgs = new String[2];\r
212 execArgs[0] = args[0];\r
213 execArgs[1] = getCommandFileSwitch(commandFile.toString());\r
214 return execArgs;\r
215 }\r
216 \r
217 private BorlandProcessor() {\r
218 }\r
219}\r