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.os400;
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.AbstractCompiler;
30  import com.github.maven_nar.cpptasks.compiler.CommandLineCCompiler;
31  import com.github.maven_nar.cpptasks.compiler.LinkType;
32  import com.github.maven_nar.cpptasks.compiler.Linker;
33  import com.github.maven_nar.cpptasks.compiler.Processor;
34  
35  /**
36   * Adapter for the IBM (R) OS/390 (tm) C++ Compiler
37   *
38   * @author Hiram Chirino (cojonudo14@hotmail.com)
39   */
40  public class IccCompiler extends CommandLineCCompiler {
41    private static final AbstractCompiler instance = new IccCompiler(false, null);
42  
43    public static AbstractCompiler getInstance() {
44      return instance;
45    }
46  
47    private IccCompiler(final boolean newEnvironment, final Environment env) {
48      super("icc", null, new String[] {
49          ".c", ".cc", ".cpp", ".cxx", ".c++", ".s"
50      }, new String[] {
51          ".h", ".hpp"
52      }, ".o", false, null, newEnvironment, env);
53    }
54  
55    @Override
56    protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
57        final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
58      // Specifies that only compilations and assemblies be done.
59      // Link-edit is not done
60      args.addElement("-c");
61      /*
62       * if (exceptions) { args.addElement("/GX"); }
63       */
64      if (debug) {
65        args.addElement("-g");
66        /*
67         * args.addElement("-D"); args.addElement("_DEBUG"); if
68         * (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
69         * args.addElement("/MTd"); } else { args.addElement("/MDd");
70         * args.addElement("/D_DLL"); } } else { args.addElement("/MLd"); }
71         */
72      } else {
73        /*
74         * args.addElement("-D"); args.addElement("NEBUG"); if
75         * (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
76         * args.addElement("/MT"); } else { args.addElement("/MD");
77         * args.addElement("/D_DLL"); } } else { args.addElement("/ML"); }
78         */
79      }
80    }
81  
82    @Override
83    protected void addWarningSwitch(final Vector<String> args, final int level) {
84      IccProcessor.addWarningSwitch(args, level);
85    }
86  
87    @Override
88    public Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
89      if (newEnvironment || env != null) {
90        return new IccCompiler(newEnvironment, env);
91      }
92      return this;
93    }
94  
95    @Override
96    protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
97      buffer.append("-q");
98      buffer.append(define);
99      if (value != null && value.length() > 0) {
100       buffer.append('=');
101       buffer.append(value);
102     }
103   }
104 
105   @Override
106   protected File[] getEnvironmentIncludePath() {
107     return CUtil.getPathFromEnvironment("INCLUDE", ":");
108   }
109 
110   @Override
111   protected String getIncludeDirSwitch(final String includeDir) {
112     return IccProcessor.getIncludeDirSwitch(includeDir);
113   }
114 
115   @Override
116   public Linker getLinker(final LinkType type) {
117     return IccLinker.getInstance().getLinker(type);
118   }
119 
120   @Override
121   public int getMaximumCommandLength() {
122     return Integer.MAX_VALUE;
123   }
124 
125   /* Only compile one file at time for now */
126   @Override
127   protected int getMaximumInputFilesPerCommand() {
128     return 1;
129     // return Integer.MAX_VALUE;
130   }
131 
132   @Override
133   protected void getUndefineSwitch(final StringBuffer buffer, final String define) {
134     /*
135      * buffer.addElement("-q"); buf.append(define);
136      */
137   }
138 }