]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccProcessor.java
3 * Copyright 2002-2004 The Ant-Contrib project
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package net
.sf
.antcontrib
.cpptasks
.gcc
.cross
.sparc_sun_solaris2
;
18 import java
.io
.BufferedReader
;
20 import java
.io
.FileReader
;
21 import java
.io
.IOException
;
22 import java
.util
.Vector
;
24 import net
.sf
.antcontrib
.cpptasks
.CUtil
;
25 import net
.sf
.antcontrib
.cpptasks
.compiler
.CaptureStreamHandler
;
26 import net
.sf
.antcontrib
.cpptasks
.types
.LibraryTypeEnum
;
29 * A add-in class for Gcc processors
33 public class GccProcessor
{
34 // the results from gcc -dumpmachine
35 private static String machine
;
36 private static String
[] specs
;
37 // the results from gcc -dumpversion
38 private static String version
;
39 private static int addLibraryPatterns(String
[] libnames
, StringBuffer buf
,
40 String prefix
, String extension
, String
[] patterns
, int offset
) {
41 for (int i
= 0; i
< libnames
.length
; i
++) {
44 buf
.append(libnames
[i
]);
45 buf
.append(extension
);
46 patterns
[offset
+ i
] = buf
.toString();
48 return offset
+ libnames
.length
;
51 * Converts absolute Cygwin file or directory names to the corresponding
55 * array of names, some elements may be null, will be changed in
58 public static void convertCygwinFilenames(String
[] names
) {
60 throw new NullPointerException("names");
62 File gccDir
= CUtil
.getExecutableLocation(GccCCompiler
.CMD_PREFIX
65 String prefix
= gccDir
.getAbsolutePath() + "/..";
66 StringBuffer buf
= new StringBuffer();
67 for (int i
= 0; i
< names
.length
; i
++) {
68 String name
= names
[i
];
69 if (name
!= null && name
.length() > 1 && name
.charAt(0) == '/') {
73 names
[i
] = buf
.toString();
78 public static String
[] getLibraryPatterns(String
[] libnames
, LibraryTypeEnum libType
) {
79 StringBuffer buf
= new StringBuffer();
80 String
[] patterns
= new String
[libnames
.length
* 2];
81 int offset
= addLibraryPatterns(libnames
, buf
, "lib", ".a", patterns
, 0);
83 offset
= addLibraryPatterns(libnames
, buf
, "lib", ".sl", patterns
,
86 offset
= addLibraryPatterns(libnames
, buf
, "lib", ".so", patterns
,
91 public static String
getMachine() {
92 if (machine
== null) {
93 String
[] args
= new String
[]{GccCCompiler
.CMD_PREFIX
+ "gcc",
95 String
[] cmdout
= CaptureStreamHandler
.run(args
);
96 if (cmdout
.length
== 0) {
97 machine
= "nomachine";
104 public static String
[] getOutputFileSwitch(String letter
, String outputFile
) {
105 StringBuffer buf
= new StringBuffer();
106 if (outputFile
.indexOf(' ') >= 0) {
108 buf
.append(outputFile
.replace('\\', '/'));
111 buf
.append(outputFile
.replace('\\', '/'));
113 String
[] retval
= new String
[]{letter
, buf
.toString()};
117 * Returns the contents of the gcc specs file.
119 * The implementation locates gcc.exe in the executable path and then
120 * builds a relative path name from the results of -dumpmachine and
121 * -dumpversion. Attempts to use gcc -dumpspecs to provide this information
122 * resulted in stalling on the Execute.run
124 * @returns contents of the specs file
126 public static String
[] getSpecs() {
128 File gccParent
= CUtil
129 .getExecutableLocation(GccCCompiler
.CMD_PREFIX
+ "gcc.exe");
130 if (gccParent
!= null) {
132 // build a relative path like
133 // ../lib/gcc-lib/i686-pc-cygwin/2.95.3-5/specs
135 StringBuffer buf
= new StringBuffer("../lib/gcc-lib/");
136 buf
.append(getMachine());
138 buf
.append(getVersion());
139 buf
.append("/specs");
141 // resolve it relative to the location of gcc.exe
143 String relativePath
= buf
.toString();
144 File specsFile
= new File(gccParent
, relativePath
);
146 // found the specs file
150 // read the lines in the file
152 BufferedReader reader
= new BufferedReader(new FileReader(
154 Vector lines
= new Vector(100);
155 String line
= reader
.readLine();
156 while (line
!= null) {
157 lines
.addElement(line
);
158 line
= reader
.readLine();
160 specs
= new String
[lines
.size()];
161 lines
.copyInto(specs
);
162 } catch (IOException ex
) {
167 specs
= new String
[0];
171 public static String
getVersion() {
172 if (version
== null) {
173 String
[] args
= new String
[]{GccCCompiler
.CMD_PREFIX
+ "gcc",
175 String
[] cmdout
= CaptureStreamHandler
.run(args
);
176 if (cmdout
.length
== 0) {
177 version
= "noversion";
184 public static boolean isCaseSensitive() {
188 * Determines if task is running with cygwin
190 * @return true if cygwin was detected
192 public static boolean isCygwin() {
193 return getMachine().indexOf("cygwin") > 0;
195 private static boolean isHPUX() {
196 String osname
= System
.getProperty("os.name").toLowerCase();
197 if (osname
.indexOf("hp") >= 0 && osname
.indexOf("ux") >= 0) {
204 * Parses the results of the specs file for a specific processor and
207 * @param specsContent
208 * Contents of specs file as returned from getSpecs
209 * @param specSectionStart
210 * start of spec section, for example "*cpp:"
212 * command line switches such as "-istart"
214 public static String
[][] parseSpecs(String
[] specsContent
,
215 String specSectionStart
, String
[] options
) {
216 if (specsContent
== null) {
217 throw new NullPointerException("specsContent");
219 if (specSectionStart
== null) {
220 throw new NullPointerException("specSectionStart");
222 if (options
== null) {
223 throw new NullPointerException("option");
225 String
[][] optionValues
= new String
[options
.length
][];
226 StringBuffer optionValue
= new StringBuffer(40);
227 for (int i
= 0; i
< specsContent
.length
; i
++) {
228 String specLine
= specsContent
[i
];
230 // if start of section then start paying attention
232 if (specLine
.startsWith(specSectionStart
)) {
233 Vector
[] optionVectors
= new Vector
[options
.length
];
234 for (int j
= 0; j
< options
.length
; j
++) {
235 optionVectors
[j
] = new Vector(10);
238 // go to next line and examine contents
239 // and repeat until end of file
241 for (i
++; i
< specsContent
.length
; i
++) {
242 specLine
= specsContent
[i
];
243 for (int j
= 0; j
< options
.length
; j
++) {
244 int optionStart
= specLine
.indexOf(options
[j
]);
245 while (optionStart
>= 0) {
246 optionValue
.setLength(0);
248 // walk rest of line looking for first non
250 // and then next space
251 boolean hasNonBlank
= false;
252 int k
= optionStart
+ options
[j
].length();
253 for (; k
< specLine
.length(); k
++) {
255 // either a blank or a "}" (close of
257 // section will end the path
259 if (specLine
.charAt(k
) == ' '
260 || specLine
.charAt(k
) == '}') {
266 optionValue
.append(specLine
.charAt(k
));
270 // transition back to whitespace
271 // value is over, add it to vector
273 optionVectors
[j
].addElement(optionValue
277 // find next occurance on line
279 optionStart
= specLine
.indexOf(options
[j
], k
);
284 // copy vectors over to option arrays
286 for (int j
= 0; j
< options
.length
; j
++) {
287 optionValues
[j
] = new String
[optionVectors
[j
].size()];
288 optionVectors
[j
].copyInto(optionValues
[j
]);
293 // fill in any missing option values with
294 // a zero-length string array
295 for (int i
= 0; i
< optionValues
.length
; i
++) {
296 String
[] zeroLenArray
= new String
[0];
297 if (optionValues
[i
] == null) {
298 optionValues
[i
] = zeroLenArray
;
303 private GccProcessor() {