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.ti;
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 TI DSP compilers with cl** commands
35   *
36   * @author CurtA
37   */
38  public class ClxxCCompiler extends CommandLineCCompiler {
39    /**
40     * Header file extensions
41     */
42    private static final String[] headerExtensions = new String[] {
43        ".h", ".hpp", ".inl"
44    };
45    /**
46     * Source file extensions
47     */
48    private static final String[] sourceExtensions = new String[] {
49        ".c", ".cc", ".cpp", ".cxx", ".c++"
50    };
51    /**
52     * Singleton for TMS320C55x
53     */
54    private static final ClxxCCompiler cl55 = new ClxxCCompiler("cl55", false, null);
55    /**
56     * Singleton for TMS320C6000
57     */
58    private static final ClxxCCompiler cl6x = new ClxxCCompiler("cl6x", false, null);
59  
60    public static ClxxCCompiler getCl55Instance() {
61      return cl55;
62    }
63  
64    public static ClxxCCompiler getCl6xInstance() {
65      return cl6x;
66    }
67  
68    /**
69     * Private constructor
70     * 
71     * @param command
72     *          executable name
73     * @param newEnvironment
74     *          Change environment
75     * @param env
76     *          New environment
77     */
78    private ClxxCCompiler(final String command, final boolean newEnvironment, final Environment env) {
79      super(command, "-h", sourceExtensions, headerExtensions, ".o", false, null, newEnvironment, env);
80    }
81  
82    @Override
83    protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
84        final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
85      if (debug) {
86        args.addElement("-gw");
87      }
88    }
89  
90    @Override
91    protected void addWarningSwitch(final Vector<String> args, final int warnings) {
92      // TODO Auto-generated method stub
93    }
94  
95    @Override
96    protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
97      buffer.append("-d");
98      buffer.append(define);
99      if (value != null) {
100       buffer.append('=');
101       buffer.append(value);
102     }
103   }
104 
105   @Override
106   protected File[] getEnvironmentIncludePath() {
107     final File[] c_dir = CUtil.getPathFromEnvironment("C_DIR", ";");
108     final File[] cx_dir = CUtil.getPathFromEnvironment("C6X_C_DIR", ";");
109     if (c_dir.length == 0) {
110       return cx_dir;
111     }
112     if (cx_dir.length == 0) {
113       return c_dir;
114     }
115     final File[] combo = new File[c_dir.length + cx_dir.length];
116     System.arraycopy(cx_dir, 0, combo, 0, cx_dir.length);
117     System.arraycopy(c_dir, 0, combo, 0 + cx_dir.length, c_dir.length);
118     return combo;
119   }
120 
121   @Override
122   protected String getIncludeDirSwitch(final String source) {
123     return "-I" + source;
124   }
125 
126   @Override
127   public Linker getLinker(final LinkType type) {
128     if (type.isStaticLibrary()) {
129       if (this == cl6x) {
130         return ClxxLibrarian.getCl6xInstance();
131       }
132       return ClxxLibrarian.getCl55Instance();
133     }
134     if (type.isSharedLibrary()) {
135       if (this == cl6x) {
136         return ClxxLinker.getCl6xDllInstance();
137       }
138       return ClxxLinker.getCl55DllInstance();
139     }
140     if (this == cl6x) {
141       return ClxxLinker.getCl6xInstance();
142     }
143     return ClxxLinker.getCl55Instance();
144   }
145 
146   @Override
147   public int getMaximumCommandLength() {
148     return 1024;
149   }
150 
151   @Override
152   protected void getUndefineSwitch(final StringBuffer buffer, final String define) {
153     buffer.append("-u");
154     buffer.append(define);
155   }
156 }