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.os390;
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.CompilerDef;
29  import com.github.maven_nar.cpptasks.OptimizationEnum;
30  import com.github.maven_nar.cpptasks.compiler.AbstractCompiler;
31  import com.github.maven_nar.cpptasks.compiler.CommandLineCCompiler;
32  import com.github.maven_nar.cpptasks.compiler.LinkType;
33  import com.github.maven_nar.cpptasks.compiler.Linker;
34  import com.github.maven_nar.cpptasks.compiler.Processor;
35  import com.github.maven_nar.cpptasks.types.UndefineArgument;
36  
37  /**
38   * Adapter for the IBM (R) OS/390 (tm) C++ Compiler
39   *
40   * @author Hiram Chirino (cojonudo14@hotmail.com)
41   */
42  public class OS390CCompiler extends CommandLineCCompiler {
43    private static final AbstractCompiler instance = new OS390CCompiler(false, null);
44  
45    public static AbstractCompiler getInstance() {
46      return instance;
47    }
48  
49    private OS390CCompiler(final boolean newEnvironment, final Environment env) {
50      super("cxx", null, new String[] {
51          ".c", ".cc", ".cpp", ".cxx", ".c++", ".s"
52      }, new String[] {
53          ".h", ".hpp"
54      }, ".o", false, null, newEnvironment, env);
55    }
56  
57    @Override
58    protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
59        final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
60      // Specifies that only compilations and assemblies be done.
61      // Link-edit is not done
62      args.addElement("-c");
63      args.addElement("-W");
64      args.addElement("c,NOEXPMAC,NOSHOWINC");
65      /*
66       * if (exceptions) { args.addElement("/GX"); }
67       */
68      if (debug) {
69        args.addElement("-g");
70        args.addElement("-D");
71        args.addElement("_DEBUG");
72        /*
73         * if (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
74         * args.addElement("/MTd"); } else { args.addElement("/MDd");
75         * args.addElement("/D_DLL"); } } else { args.addElement("/MLd"); }
76         */
77      } else {
78        args.addElement("-D");
79        args.addElement("NEBUG");
80        /*
81         * if (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
82         * args.addElement("/MT"); } else { args.addElement("/MD");
83         * args.addElement("/D_DLL"); } } else { args.addElement("/ML"); }
84         */
85      }
86    }
87  
88    @Override
89    protected void addWarningSwitch(final Vector<String> args, final int level) {
90      OS390Processor.addWarningSwitch(args, level);
91    }
92  
93    /**
94     * The buildDefineArguments implementation CommandLineCCompiler is not good
95     * for us because os390 defines are give by -D definex instead of
96     * /Ddefinex, 2 args not 1! since we implement this ourslefs, we do not
97     * have to implement the getDefineSwitch() and the getUndefineSwitch().
98     */
99    @Override
100   protected void buildDefineArguments(final CompilerDef[] defs, final Vector<String> args) {
101     //
102     // assume that we aren't inheriting defines from containing <cc>
103     //
104     UndefineArgument[] merged = defs[0].getActiveDefines();
105     for (int i = 1; i < defs.length; i++) {
106       //
107       // if we are inheriting, merge the specific defines with the
108       // containing defines
109       merged = UndefineArgument.merge(defs[i].getActiveDefines(), merged);
110     }
111     final StringBuffer buf = new StringBuffer(30);
112     for (final UndefineArgument current : merged) {
113       buf.setLength(0);
114       if (current.isDefine()) {
115         args.addElement("-D");
116         buf.append(current.getName());
117         if (current.getValue() != null && current.getValue().length() > 0) {
118           buf.append('=');
119           buf.append(current.getValue());
120         }
121         args.addElement(buf.toString());
122       } else {
123         args.addElement("-U");
124         args.addElement(current.getName());
125       }
126     }
127   }
128 
129   @Override
130   public Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
131     if (newEnvironment || env != null) {
132       return new OS390CCompiler(newEnvironment, env);
133     }
134     return this;
135   }
136 
137   @Override
138   protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
139   }
140 
141   @Override
142   protected File[] getEnvironmentIncludePath() {
143     return CUtil.getPathFromEnvironment("INCLUDE", ":");
144   }
145 
146   @Override
147   protected String getIncludeDirSwitch(final String includeDir) {
148     return OS390Processor.getIncludeDirSwitch(includeDir);
149   }
150 
151   @Override
152   public Linker getLinker(final LinkType type) {
153     return OS390Linker.getInstance().getLinker(type);
154   }
155 
156   @Override
157   public int getMaximumCommandLength() {
158     return Integer.MAX_VALUE;
159   }
160 
161   /* Only compile one file at time for now */
162   @Override
163   protected int getMaximumInputFilesPerCommand() {
164     return Integer.MAX_VALUE;
165   }
166 
167   @Override
168   protected void getUndefineSwitch(final StringBuffer buffer, final String define) {
169   }
170 }