]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/gcc/cross/sparc_sun_solaris2/GccCCompiler.java
Initial import.
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / gcc / cross / sparc_sun_solaris2 / GccCCompiler.java
CommitLineData
878ddf1f 1/*\r
2 * \r
3 * Copyright 2001-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.gcc.cross.sparc_sun_solaris2;\r
18import java.io.File;\r
19import java.util.Vector;\r
20\r
21import net.sf.antcontrib.cpptasks.CUtil;\r
22import net.sf.antcontrib.cpptasks.compiler.LinkType;\r
23import net.sf.antcontrib.cpptasks.compiler.Linker;\r
24import net.sf.antcontrib.cpptasks.compiler.Processor;\r
25import net.sf.antcontrib.cpptasks.gcc.GccCompatibleCCompiler;\r
26import net.sf.antcontrib.cpptasks.parser.CParser;\r
27import net.sf.antcontrib.cpptasks.parser.FortranParser;\r
28import net.sf.antcontrib.cpptasks.parser.Parser;\r
29\r
30import org.apache.tools.ant.BuildException;\r
31import org.apache.tools.ant.types.Environment;\r
32import net.sf.antcontrib.cpptasks.OptimizationEnum;\r
33\r
34/**\r
35 * Adapter for the GCC C/C++ compiler\r
36 * \r
37 * @author Adam Murdoch\r
38 */\r
39public final class GccCCompiler extends GccCompatibleCCompiler {\r
40 private final static String[] sourceExtensions = new String[]{".c", /* C */\r
41 ".cc", /* C++ */\r
42 ".cpp", /* C++ */\r
43 ".cxx", /* C++ */\r
44 ".c++", /* C++ */\r
45 ".i", /* preprocessed C */\r
46 ".ii", /* preprocessed C++ */\r
47 ".f", /* FORTRAN */\r
48 ".for", /* FORTRAN */\r
49 ".m", /* Objective-C */\r
50 ".mm", /* Objected-C++ */\r
51 ".s" /* Assembly */\r
52 };\r
53 private final static String[] headerExtensions = new String[]{".h", ".hpp",\r
54 ".inl"};\r
55 public static final String CMD_PREFIX = "sparc-sun-solaris2-";\r
56 private static final GccCCompiler cppInstance = new GccCCompiler(CMD_PREFIX\r
57 + "c++", sourceExtensions, headerExtensions, false,\r
58 new GccCCompiler(CMD_PREFIX + "c++", sourceExtensions,\r
59 headerExtensions, true, null, false, null), false, null);\r
60 private static final GccCCompiler g77Instance = new GccCCompiler(CMD_PREFIX\r
61 + "g77", sourceExtensions, headerExtensions, false,\r
62 new GccCCompiler(CMD_PREFIX + "g77", sourceExtensions,\r
63 headerExtensions, true, null, false, null), false, null);\r
64 private static final GccCCompiler gppInstance = new GccCCompiler(CMD_PREFIX\r
65 + "g++", sourceExtensions, headerExtensions, false,\r
66 new GccCCompiler(CMD_PREFIX + "g++", sourceExtensions,\r
67 headerExtensions, true, null, false, null), false, null);\r
68 private static final GccCCompiler instance = new GccCCompiler(CMD_PREFIX\r
69 + "gcc", sourceExtensions, headerExtensions, false,\r
70 new GccCCompiler(CMD_PREFIX + "gcc", sourceExtensions,\r
71 headerExtensions, true, null, false, null), false, null);\r
72 /**\r
73 * Gets c++ adapter\r
74 */\r
75 public static GccCCompiler getCppInstance() {\r
76 return cppInstance;\r
77 }\r
78 /**\r
79 * Gets g77 adapter\r
80 */\r
81 public static GccCCompiler getG77Instance() {\r
82 return g77Instance;\r
83 }\r
84 /**\r
85 * Gets gpp adapter\r
86 */\r
87 public static GccCCompiler getGppInstance() {\r
88 return gppInstance;\r
89 }\r
90 /**\r
91 * Gets gcc adapter\r
92 */\r
93 public static GccCCompiler getInstance() {\r
94 return instance;\r
95 }\r
96 private String identifier;\r
97 private File[] includePath;\r
98 private boolean isPICMeaningful = true;\r
99 /**\r
100 * Private constructor. Use GccCCompiler.getInstance() to get singleton\r
101 * instance of this class.\r
102 */\r
103 private GccCCompiler(String command, String[] sourceExtensions,\r
104 String[] headerExtensions, boolean isLibtool,\r
105 GccCCompiler libtoolCompiler, boolean newEnvironment,\r
106 Environment env) {\r
107 super(command, null, sourceExtensions, headerExtensions, isLibtool,\r
108 libtoolCompiler, newEnvironment, env);\r
109 isPICMeaningful = System.getProperty("os.name").indexOf("Windows") < 0;\r
110 }\r
111 public void addImpliedArgs(final Vector args, \r
112 final boolean debug,\r
113 final boolean multithreaded, \r
114 final boolean exceptions, \r
115 final LinkType linkType,\r
116 final Boolean rtti,\r
117 final OptimizationEnum optimization,\r
118 final Boolean defaultflag) {\r
119 super.addImpliedArgs(args, debug, multithreaded, \r
120 exceptions, linkType, rtti, optimization, defaultflag);\r
121 if (isPICMeaningful && linkType.isSharedLibrary()) {\r
122 args.addElement("-fPIC");\r
123 }\r
124 }\r
125 public Processor changeEnvironment(boolean newEnvironment, Environment env) {\r
126 if (newEnvironment || env != null) {\r
127 return new GccCCompiler(getCommand(), this.getSourceExtensions(),\r
128 this.getHeaderExtensions(), this.getLibtool(),\r
129 (GccCCompiler) this.getLibtoolCompiler(), newEnvironment,\r
130 env);\r
131 }\r
132 return this;\r
133 }\r
134 /**\r
135 * Create parser to determine dependencies.\r
136 * \r
137 * Will create appropriate parser (C++, FORTRAN) based on file extension.\r
138 * \r
139 */\r
140 protected Parser createParser(File source) {\r
141 if (source != null) {\r
142 String sourceName = source.getName();\r
143 int lastDot = sourceName.lastIndexOf('.');\r
144 if (lastDot >= 0 && lastDot + 1 < sourceName.length()) {\r
145 char afterDot = sourceName.charAt(lastDot + 1);\r
146 if (afterDot == 'f' || afterDot == 'F') {\r
147 return new FortranParser();\r
148 }\r
149 }\r
150 }\r
151 return new CParser();\r
152 }\r
153 public File[] getEnvironmentIncludePath() {\r
154 if (includePath == null) {\r
155 //\r
156 // construct default include path from machine id and version id\r
157 //\r
158 String[] defaultInclude = new String[1];\r
159 StringBuffer buf = new StringBuffer("/lib/");\r
160 buf.append(GccProcessor.getMachine());\r
161 buf.append('/');\r
162 buf.append(GccProcessor.getVersion());\r
163 buf.append("/include");\r
164 defaultInclude[0] = buf.toString();\r
165 //\r
166 // read specs file and look for -istart and -idirafter\r
167 //\r
168 String[] specs = GccProcessor.getSpecs();\r
169 String[][] optionValues = GccProcessor.parseSpecs(specs, "*cpp:",\r
170 new String[]{"-isystem ", "-idirafter "});\r
171 //\r
172 // if no entries were found, then use a default path\r
173 //\r
174 if (optionValues[0].length == 0 && optionValues[1].length == 0) {\r
175 optionValues[0] = new String[]{"/usr/local/include",\r
176 "/usr/include", "/usr/include/win32api"};\r
177 }\r
178 //\r
179 // remove mingw entries.\r
180 // For MinGW compiles this will mean the\r
181 // location of the sys includes will be\r
182 // wrong in dependencies.xml\r
183 // but that should have no significant effect\r
184 for (int i = 0; i < optionValues.length; i++) {\r
185 for (int j = 0; j < optionValues[i].length; j++) {\r
186 if (optionValues[i][j].indexOf("mingw") > 0) {\r
187 optionValues[i][j] = null;\r
188 }\r
189 }\r
190 }\r
191 //\r
192 // if cygwin then\r
193 // we have to prepend location of gcc32\r
194 // and .. to start of absolute filenames to\r
195 // have something that will exist in the\r
196 // windows filesystem\r
197 if (GccProcessor.isCygwin()) {\r
198 GccProcessor.convertCygwinFilenames(optionValues[0]);\r
199 GccProcessor.convertCygwinFilenames(optionValues[1]);\r
200 GccProcessor.convertCygwinFilenames(defaultInclude);\r
201 }\r
202 int count = CUtil.checkDirectoryArray(optionValues[0]);\r
203 count += CUtil.checkDirectoryArray(optionValues[1]);\r
204 count += CUtil.checkDirectoryArray(defaultInclude);\r
205 includePath = new File[count];\r
206 int index = 0;\r
207 for (int i = 0; i < optionValues.length; i++) {\r
208 for (int j = 0; j < optionValues[i].length; j++) {\r
209 if (optionValues[i][j] != null) {\r
210 includePath[index++] = new File(optionValues[i][j]);\r
211 }\r
212 }\r
213 }\r
214 for (int i = 0; i < defaultInclude.length; i++) {\r
215 if (defaultInclude[i] != null) {\r
216 includePath[index++] = new File(defaultInclude[i]);\r
217 }\r
218 }\r
219 }\r
220 return (File[]) includePath.clone();\r
221 }\r
222 public String getIdentifier() throws BuildException {\r
223 if (identifier == null) {\r
224 StringBuffer buf;\r
225 if (getLibtool()) {\r
226 buf = new StringBuffer("libtool ");\r
227 } else {\r
228 buf = new StringBuffer(' ');\r
229 }\r
230 buf.append(getCommand());\r
231 buf.append(' ');\r
232 buf.append(GccProcessor.getVersion());\r
233 buf.append(' ');\r
234 buf.append(GccProcessor.getMachine());\r
235 identifier = buf.toString();\r
236 }\r
237 return identifier;\r
238 }\r
239 public Linker getLinker(LinkType linkType) {\r
240 return GccLinker.getInstance().getLinker(linkType);\r
241 }\r
242 public int getMaximumCommandLength() {\r
243 return Integer.MAX_VALUE;\r
244 }\r
245}\r