]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/gcc/GccCompatibleCCompiler.java
Initial import.
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / gcc / GccCompatibleCCompiler.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.gcc;\r
18import java.io.File;\r
19import java.util.Vector;\r
20import net.sf.antcontrib.cpptasks.CUtil;\r
21import net.sf.antcontrib.cpptasks.compiler.CommandLineCCompiler;\r
22import net.sf.antcontrib.cpptasks.compiler.LinkType;\r
23import org.apache.tools.ant.types.Environment;\r
24import net.sf.antcontrib.cpptasks.OptimizationEnum;\r
25\r
26/**\r
27 * Abstract base class for compilers that attempt to be command line compatible\r
28 * with GCC\r
29 *\r
30 * @author Adam Murdoch\r
31 * @author Curt Arnold\r
32 */\r
33public abstract class GccCompatibleCCompiler extends CommandLineCCompiler {\r
34 private final static String[] headerExtensions = new String[]{".h", ".hpp",\r
35 ".inl"};\r
36 private final static String[] sourceExtensions = new String[]{".c", ".cc",\r
37 ".cpp", ".cxx", ".c++", ".i", ".f", ".for"};\r
38 private final static String[] defaultflags = new String[]{"-c"};\r
39 /**\r
40 * Private constructor. Use GccCCompiler.getInstance() to get singleton\r
41 * instance of this class.\r
42 */\r
43 protected GccCompatibleCCompiler(String command, String identifierArg,\r
44 boolean libtool, GccCompatibleCCompiler libtoolCompiler,\r
45 boolean newEnvironment, Environment env) {\r
46 super(command, identifierArg, sourceExtensions, headerExtensions,\r
47 libtool ? ".fo" : ".o", libtool, libtoolCompiler,\r
48 newEnvironment, env);\r
49 }\r
50 /**\r
51 * Private constructor. Use GccCCompiler.getInstance() to get singleton\r
52 * instance of this class.\r
53 */\r
54 protected GccCompatibleCCompiler(String command, String identifierArg,\r
55 String[] sourceExtensions, String[] headerExtensions,\r
56 boolean libtool, GccCompatibleCCompiler libtoolCompiler,\r
57 boolean newEnvironment, Environment env) {\r
58 super(command, identifierArg, sourceExtensions, headerExtensions,\r
59 libtool ? ".fo" : ".o", libtool, libtoolCompiler,\r
60 newEnvironment, env);\r
61 }\r
62 public void addImpliedArgs(final Vector args,\r
63 final boolean debug,\r
64 final boolean multithreaded,\r
65 final boolean exceptions,\r
66 final LinkType linkType,\r
67 final Boolean rtti,\r
68 final OptimizationEnum optimization,\r
69 final Boolean defaultflag) {\r
70 //\r
71 // -fPIC is too much trouble\r
72 // users have to manually add it for\r
73 // operating systems that make sense\r
74 //\r
75 if (defaultflag != null && defaultflag.booleanValue()) {\r
76 for (int i = 0; i < defaultflags.length; i++) {\r
77 args.addElement(defaultflags[i]);\r
78 }\r
79 }\r
80 if (debug) {\r
81 args.addElement("-g");\r
82 } else {\r
83 if (optimization != null) {\r
84 if (optimization.isSize()) {\r
85 args.addElement("-Os");\r
86 } else if (optimization.isSpeed()) {\r
87 if ("full".equals(optimization.getValue())) {\r
88 args.addElement("-O2");\r
89 } else {\r
90 if ("speed".equals(optimization.getValue())) {\r
91 args.addElement("-O1");\r
92 } else {\r
93 args.addElement("-O3");\r
94 }\r
95 }\r
96 }\r
97 }\r
98 }\r
99 if (getIdentifier().indexOf("mingw") >= 0) {\r
100 if (linkType.isSubsystemConsole()) {\r
101 args.addElement("-mconsole");\r
102 }\r
103 if (linkType.isSubsystemGUI()) {\r
104 args.addElement("-mwindows");\r
105 }\r
106 }\r
107 if (rtti != null && !rtti.booleanValue()) {\r
108 args.addElement("-fno-rtti");\r
109 }\r
110\r
111 }\r
112 /**\r
113 * Adds an include path to the command.\r
114 */\r
115 public void addIncludePath(String path, Vector cmd) {\r
116 cmd.addElement("-I" + path);\r
117 }\r
118 public void addWarningSwitch(Vector args, int level) {\r
119 switch (level) {\r
120 case 0 :\r
121 args.addElement("-w");\r
122 break;\r
123 case 5 :\r
124 args.addElement("-Werror");\r
125 /* nobreak */\r
126 case 4 :\r
127 args.addElement("-W");\r
128 /* nobreak */\r
129 case 3 :\r
130 args.addElement("-Wall");\r
131 break;\r
132 }\r
133 }\r
134 public void getDefineSwitch(StringBuffer buffer, String define, String value) {\r
135 buffer.append("-D");\r
136 buffer.append(define);\r
137 if (value != null && value.length() > 0) {\r
138 buffer.append('=');\r
139 buffer.append(value);\r
140 }\r
141 }\r
142 protected File[] getEnvironmentIncludePath() {\r
143 return CUtil.getPathFromEnvironment("INCLUDE", ":");\r
144 }\r
145 public String getIncludeDirSwitch(String includeDir) {\r
146 return "-I" + includeDir;\r
147 }\r
148 public void getUndefineSwitch(StringBuffer buffer, String define) {\r
149 buffer.append("-U");\r
150 buffer.append(define);\r
151 }\r
152}\r