3 * Copyright 2003-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
.arm
;
19 import java
.util
.Vector
;
21 import net
.sf
.antcontrib
.cpptasks
.CUtil
;
22 import net
.sf
.antcontrib
.cpptasks
.OptimizationEnum
;
23 import net
.sf
.antcontrib
.cpptasks
.compiler
.CommandLineCCompiler
;
24 import net
.sf
.antcontrib
.cpptasks
.compiler
.LinkType
;
25 import net
.sf
.antcontrib
.cpptasks
.compiler
.Linker
;
27 import org
.apache
.tools
.ant
.types
.Environment
;
29 * Adapter for the ARM C Compilers
31 * See Doc No: ARM DUI 0151A, Issued: Nov 2001 at
32 * http://www.arm.com/arm/User_Guides?OpenDocument
37 public class ADSCCompiler
extends CommandLineCCompiler
{
39 * Header file extensions
41 private static final String
[] headerExtensions
= new String
[]{".h", ".hpp",
44 * Source file extensions
46 private static final String
[] sourceExtensions
= new String
[]{".c", ".cc",
47 ".cpp", ".cxx", ".c++"};
49 * Singleton for ARM 32-bit C compiler
51 private static final ADSCCompiler armcc
= new ADSCCompiler("armcc", false,
54 * Singleton for ARM 32-bit C++ compiler
56 private static final ADSCCompiler armcpp
= new ADSCCompiler("armcpp",
59 * Singleton for ARM 16-bit C compiler
61 private static final ADSCCompiler tcc
= new ADSCCompiler("tcc", false, null);
63 * Singleton for ARM 16-bit C++ compiler
65 private static final ADSCCompiler tcpp
= new ADSCCompiler("tcpp", false,
68 * Singleton for ARM 32-bit C compiler
70 public static ADSCCompiler
getArmCC() {
74 * Singleton for ARM 32-bit C++ compiler
76 public static ADSCCompiler
getArmCpp() {
80 * Singleton for ARM 16-bit C compiler
82 public static ADSCCompiler
getThumbCC() {
86 * Singleton for ARM 16-bit C++ compiler
88 public static ADSCCompiler
getThumbCpp() {
91 private static void quoteFile(StringBuffer buf
, String outPath
) {
92 if (outPath
.indexOf(' ') >= 0) {
101 * Private constructor
105 * @param newEnvironment
110 private ADSCCompiler(String command
, boolean newEnvironment
, Environment env
) {
111 super(command
, "-vsn", sourceExtensions
, headerExtensions
, ".o", false,
112 null, newEnvironment
, env
);
115 * Adds command switches for generic configuration options
117 * @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#addImpliedArgs(java.util.Vector,
118 * boolean, boolean, boolean,
119 * net.sf.antcontrib.cpptasks.compiler.LinkType)
121 protected void addImpliedArgs(Vector args
,
123 final boolean multithreaded
,
124 final boolean exceptions
,
125 final LinkType linkType
,
127 final OptimizationEnum optimization
,
128 final Boolean defaultflag
) {
130 args
.addElement("-g");
133 // didn't see anything about producing
134 // anything other than executables in the docs
135 if (linkType
.isExecutable()) {
136 } else if (linkType
.isSharedLibrary()) {
140 * Adds flags that customize the warnings reported
142 * Compiler does not appear to have warning levels but ability to turn off
143 * specific errors by explicit switches, could fabricate levels by
144 * prioritizing errors.
146 * @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#addWarningSwitch(java.util.Vector,
149 protected void addWarningSwitch(Vector args
, int warnings
) {
152 * Add command line options for preprocessor macro
154 * @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#getDefineSwitch(java.lang.StringBuffer,
155 * java.lang.String, java.lang.String)
157 protected void getDefineSwitch(StringBuffer buffer
, String define
,
160 buffer
.append(define
);
163 buffer
.append(value
);
167 * ARMINC environment variable contains the default include path
169 * @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#getEnvironmentIncludePath()
171 protected File
[] getEnvironmentIncludePath() {
172 return CUtil
.getPathFromEnvironment("ARMINC", ";");
175 * Returns command line option to specify include directory
178 protected String
getIncludeDirSwitch(String source
) {
179 StringBuffer buf
= new StringBuffer("-I");
180 quoteFile(buf
, source
);
181 return buf
.toString();
186 * @see net.sf.antcontrib.cpptasks.compiler.Processor#getLinker(net.sf.antcontrib.cpptasks.compiler.LinkType)
188 public Linker
getLinker(LinkType type
) {
189 if (type
.isStaticLibrary()) {
190 return ADSLibrarian
.getInstance();
192 if (type
.isSharedLibrary()) {
193 return ADSLinker
.getDllInstance();
195 return ADSLinker
.getInstance();
198 * Maximum command line length
200 * @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#getMaximumCommandLength()
202 public int getMaximumCommandLength() {
206 * Adds command to undefine preprocessor macro
208 * @see net.sf.antcontrib.cpptasks.compiler.CommandLineCompiler#getUndefineSwitch(java.lang.StringBuffer,
211 protected void getUndefineSwitch(StringBuffer buffer
, String define
) {
213 buffer
.append(define
);