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.sun;
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 Sun C89 C++ Compiler
37   *
38   * @author Hiram Chirino (cojonudo14@hotmail.com)
39   */
40  public class C89CCompiler extends CommandLineCCompiler {
41    private static final AbstractCompiler instance = new C89CCompiler(false, null);
42  
43    public static AbstractCompiler getInstance() {
44      return instance;
45    }
46  
47    private C89CCompiler(final boolean newEnvironment, final Environment env) {
48      super("c89", null, new String[] {
49          ".c", ".cc", ".cpp", ".cxx", ".c++"
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      args.addElement("-c");
60      /*
61       * if (exceptions) { args.addElement("/GX"); }
62       */
63      if (debug) {
64        args.addElement("-g");
65        args.addElement("-D_DEBUG");
66        /*
67         * if (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
68         * args.addElement("/MTd"); } else { args.addElement("/MDd");
69         * args.addElement("/D_DLL"); } } else { args.addElement("/MLd"); }
70         */
71      } else {
72        args.addElement("-DNDEBUG");
73        /*
74         * if (multithreaded) { args.addElement("/D_MT"); if (staticLink) {
75         * args.addElement("/MT"); } else { args.addElement("/MD");
76         * args.addElement("/D_DLL"); } } else { args.addElement("/ML"); }
77         */
78      }
79    }
80  
81    @Override
82    protected void addWarningSwitch(final Vector<String> args, final int level) {
83      C89Processor.addWarningSwitch(args, level);
84    }
85  
86    @Override
87    public Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
88      if (newEnvironment || env != null) {
89        return new C89CCompiler(newEnvironment, env);
90      }
91      return this;
92    }
93  
94    @Override
95    protected void getDefineSwitch(final StringBuffer buf, final String define, final String value) {
96      C89Processor.getDefineSwitch(buf, define, value);
97    }
98  
99    @Override
100   protected File[] getEnvironmentIncludePath() {
101     return CUtil.getPathFromEnvironment("INCLUDE", ":");
102   }
103 
104   @Override
105   protected String getIncludeDirSwitch(final String includeDir) {
106     return C89Processor.getIncludeDirSwitch(includeDir);
107   }
108 
109   @Override
110   public Linker getLinker(final LinkType type) {
111     return C89Linker.getInstance().getLinker(type);
112   }
113 
114   @Override
115   public int getMaximumCommandLength() {
116     return Integer.MAX_VALUE;
117   }
118 
119   /* Only compile one file at time for now */
120   @Override
121   protected int getMaximumInputFilesPerCommand() {
122     return 1;
123   }
124 
125   @Override
126   protected void getUndefineSwitch(final StringBuffer buf, final String define) {
127     C89Processor.getUndefineSwitch(buf, define);
128   }
129 }