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.hp;
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.LinkType;
30  import com.github.maven_nar.cpptasks.compiler.Linker;
31  import com.github.maven_nar.cpptasks.gcc.GccCompatibleCCompiler;
32  
33  /**
34   * Adapter for the HP aC++ C++ compiler
35   *
36   * @author Curt Arnold
37   */
38  public final class aCCCompiler extends GccCompatibleCCompiler {
39    private final static String[] headerExtensions = new String[] {
40        ".h", ".hpp", ".inl"
41    };
42    private final static String[] sourceExtensions = new String[] {
43        ".c", ".cc", ".cxx", ".cpp", ".c++", ".i", ".s"
44    };
45  
46    private static final aCCCompiler instance = new aCCCompiler("aCC", sourceExtensions, headerExtensions, false, null);
47  
48    /**
49     * Gets singleton instance of this class
50     */
51    public static aCCCompiler getInstance() {
52      return instance;
53    }
54  
55    private String identifier;
56    private File[] includePath;
57  
58    /**
59     * Private constructor. Use GccCCompiler.getInstance() to get singleton
60     * instance of this class.
61     */
62    private aCCCompiler(final String command, final String[] sourceExtensions, final String[] headerExtensions,
63        final boolean newEnvironment, final Environment env) {
64      super(command, "-help", sourceExtensions, headerExtensions, false, null, newEnvironment, env);
65    }
66  
67    @Override
68    public void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
69        final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
70      args.addElement("-c");
71      if (debug) {
72        args.addElement("-g");
73      }
74      /*
75       * if (multithreaded) { args.addElement("-mt"); }
76       */
77  
78      //
79      // per patch 1193690
80      //
81      if (linkType.isSharedLibrary() && !args.contains("+Z")) {
82        args.addElement("+z");
83      }
84    }
85  
86    @Override
87    public void addWarningSwitch(final Vector<String> args, final int level) {
88      switch (level) {
89        case 0:
90          args.addElement("-w");
91          break;
92        case 1:
93        case 2:
94          args.addElement("+w");
95          break;
96      /*
97       * case 3: case 4: case 5: args.addElement("+w2"); break;
98       */
99      }
100   }
101 
102   @Override
103   public File[] getEnvironmentIncludePath() {
104     if (this.includePath == null) {
105       final File ccLoc = CUtil.getExecutableLocation("aCC");
106       if (ccLoc != null) {
107         final File compilerIncludeDir = new File(new File(ccLoc, "../include").getAbsolutePath());
108         if (compilerIncludeDir.exists()) {
109           this.includePath = new File[2];
110           this.includePath[0] = compilerIncludeDir;
111         }
112       }
113       if (this.includePath == null) {
114         this.includePath = new File[1];
115       }
116       this.includePath[this.includePath.length - 1] = new File("/usr/include");
117     }
118     return this.includePath;
119   }
120 
121   @Override
122   public Linker getLinker(final LinkType linkType) {
123     return aCCLinker.getInstance().getLinker(linkType);
124   }
125 
126   @Override
127   public int getMaximumCommandLength() {
128     return Integer.MAX_VALUE;
129   }
130 }