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