View Javadoc

1   /*
2    * #%L
3    * Native ARchive plugin for Maven
4    * %%
5    * Copyright (C) 2002 - 2014 NAR Maven Plugin developers.
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   * http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package com.github.maven_nar.cpptasks.arm;
21  
22  import java.io.File;
23  import java.util.Vector;
24  
25  import org.apache.tools.ant.types.Environment;
26  
27  import com.github.maven_nar.cpptasks.CUtil;
28  import com.github.maven_nar.cpptasks.OptimizationEnum;
29  import com.github.maven_nar.cpptasks.compiler.CommandLineCCompiler;
30  import com.github.maven_nar.cpptasks.compiler.LinkType;
31  import com.github.maven_nar.cpptasks.compiler.Linker;
32  
33  /**
34   * Adapter for the ARM C Compilers
35   *
36   * See Doc No: ARM DUI 0151A, Issued: Nov 2001 at
37   * http://www.arm.com/arm/User_Guides?OpenDocument
38   *
39   * @author Curt Arnold
40   *
41   */
42  public class ADSCCompiler extends CommandLineCCompiler {
43    /**
44     * Header file extensions
45     */
46    private static final String[] headerExtensions = new String[] {
47        ".h", ".hpp", ".inl"
48    };
49    /**
50     * Source file extensions
51     */
52    private static final String[] sourceExtensions = new String[] {
53        ".c", ".cc", ".cpp", ".cxx", ".c++"
54    };
55    /**
56     * Singleton for ARM 32-bit C compiler
57     */
58    private static final ADSCCompiler armcc = new ADSCCompiler("armcc", false, null);
59    /**
60     * Singleton for ARM 32-bit C++ compiler
61     */
62    private static final ADSCCompiler armcpp = new ADSCCompiler("armcpp", false, null);
63    /**
64     * Singleton for ARM 16-bit C compiler
65     */
66    private static final ADSCCompiler tcc = new ADSCCompiler("tcc", false, null);
67    /**
68     * Singleton for ARM 16-bit C++ compiler
69     */
70    private static final ADSCCompiler tcpp = new ADSCCompiler("tcpp", false, null);
71  
72    /**
73     * Singleton for ARM 32-bit C compiler
74     */
75    public static ADSCCompiler getArmCC() {
76      return armcc;
77    }
78  
79    /**
80     * Singleton for ARM 32-bit C++ compiler
81     */
82    public static ADSCCompiler getArmCpp() {
83      return armcpp;
84    }
85  
86    /**
87     * Singleton for ARM 16-bit C compiler
88     */
89    public static ADSCCompiler getThumbCC() {
90      return tcc;
91    }
92  
93    /**
94     * Singleton for ARM 16-bit C++ compiler
95     */
96    public static ADSCCompiler getThumbCpp() {
97      return tcpp;
98    }
99  
100   private static void quoteFile(final StringBuffer buf, final String outPath) {
101     if (outPath.indexOf(' ') >= 0) {
102       buf.append('\"');
103       buf.append(outPath);
104       buf.append('\"');
105     } else {
106       buf.append(outPath);
107     }
108   }
109 
110   /**
111    * Private constructor
112    * 
113    * @param command
114    *          executable name
115    * @param newEnvironment
116    *          Change environment
117    * @param env
118    *          New environment
119    */
120   private ADSCCompiler(final String command, final boolean newEnvironment, final Environment env) {
121     super(command, "-vsn", sourceExtensions, headerExtensions, ".o", false, null, newEnvironment, env);
122   }
123 
124   /**
125    * {@inheritDoc}
126    */
127   @Override
128   protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
129       final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
130     if (debug) {
131       args.addElement("-g");
132     }
133     //
134     // didn't see anything about producing
135     // anything other than executables in the docs
136     if (linkType.isExecutable()) {
137     } else if (linkType.isSharedLibrary()) {
138     }
139   }
140 
141   /**
142    * Adds flags that customize the warnings reported
143    * 
144    * Compiler does not appear to have warning levels but ability to turn off
145    * specific errors by explicit switches, could fabricate levels by
146    * prioritizing errors.
147    * 
148    * @see com.github.maven_nar.cpptasks.compiler.CommandLineCompiler#addWarningSwitch(java.util.Vector,
149    *      int)
150    */
151   @Override
152   protected void addWarningSwitch(final Vector<String> args, final int warnings) {
153   }
154 
155   /**
156    * Add command line options for preprocessor macro
157    * 
158    * @see com.github.maven_nar.cpptasks.compiler.CommandLineCompiler#getDefineSwitch(java.lang.StringBuffer,
159    *      java.lang.String, java.lang.String)
160    */
161   @Override
162   protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
163     buffer.append("-D");
164     buffer.append(define);
165     if (value != null) {
166       buffer.append('=');
167       buffer.append(value);
168     }
169   }
170 
171   /**
172    * ARMINC environment variable contains the default include path
173    * 
174    * @see com.github.maven_nar.cpptasks.compiler.CommandLineCompiler#getEnvironmentIncludePath()
175    */
176   @Override
177   protected File[] getEnvironmentIncludePath() {
178     return CUtil.getPathFromEnvironment("ARMINC", ";");
179   }
180 
181   /**
182    * Returns command line option to specify include directory
183    * 
184    */
185   @Override
186   protected String getIncludeDirSwitch(final String source) {
187     final StringBuffer buf = new StringBuffer("-I");
188     quoteFile(buf, source);
189     return buf.toString();
190   }
191 
192   @Override
193   public Linker getLinker(final LinkType type) {
194     if (type.isStaticLibrary()) {
195       return ADSLibrarian.getInstance();
196     }
197     if (type.isSharedLibrary()) {
198       return ADSLinker.getDllInstance();
199     }
200     return ADSLinker.getInstance();
201   }
202 
203   /**
204    * Maximum command line length
205    * 
206    * @see com.github.maven_nar.cpptasks.compiler.CommandLineCompiler#getMaximumCommandLength()
207    */
208   @Override
209   public int getMaximumCommandLength() {
210     return 1000;
211   }
212 
213   /** Adds command to undefine preprocessor macro. */
214   @Override
215   protected void getUndefineSwitch(final StringBuffer buffer, final String define) {
216     buffer.append("-U");
217     buffer.append(define);
218   }
219 }