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.ibm;
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.OptimizationEnum;
28  import com.github.maven_nar.cpptasks.compiler.LinkType;
29  import com.github.maven_nar.cpptasks.compiler.Linker;
30  import com.github.maven_nar.cpptasks.gcc.GccCompatibleCCompiler;
31  
32  /**
33   * Adapter for the IBM(r) Visual Age(tm) C++ compiler for AIX(tm)
34   *
35   * @author Curt Arnold
36   */
37  public final class VisualAgeCCompiler extends GccCompatibleCCompiler {
38    private final static String[] headerExtensions = new String[] {
39        ".h", ".hpp", ".inl"
40    };
41    private final static String[] sourceExtensions = new String[] {
42        ".c", ".cc", ".cxx", ".cpp", ".i", ".s"
43    };
44  
45    private static final VisualAgeCCompiler instance = new VisualAgeCCompiler("xlC", sourceExtensions, headerExtensions,
46        false, null);
47  
48    /**
49     * Gets singleton instance of this class
50     */
51    public static VisualAgeCCompiler getInstance() {
52      return instance;
53    }
54  
55    private String identifier;
56    private File[] includePath;
57  
58    /**
59     * Private constructor. Use getInstance() to get singleton instance of this
60     * class.
61     */
62    private VisualAgeCCompiler(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      if (linkType.isSharedLibrary()) {
75        args.addElement("-fpic");
76      }
77      if (rtti != null) {
78        if (rtti.booleanValue()) {
79          args.addElement("-qrtti=all");
80        } else {
81          args.addElement("-qnortti");
82        }
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          args.addElement("-qflag=s:s");
94          break;
95        case 2:
96          args.addElement("-qflag=e:e");
97          break;
98        case 3:
99          args.addElement("-qflag=w:w");
100         break;
101       case 4:
102         args.addElement("-qflag=i:i");
103         break;
104       case 5:
105         args.addElement("-qhalt=w:w");
106         break;
107     }
108   }
109 
110   /**
111    * Gets identifier for the compiler.
112    * 
113    * Initial attempt at extracting version information
114    * would lock up. Using a stock response.
115    */
116   @Override
117   public String getIdentifier() {
118     return "VisualAge compiler - unidentified version";
119   }
120 
121   @Override
122   public Linker getLinker(final LinkType linkType) {
123     return VisualAgeLinker.getInstance().getLinker(linkType);
124   }
125 
126   @Override
127   public int getMaximumCommandLength() {
128     return Integer.MAX_VALUE;
129   }
130 
131 }