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.openwatcom;
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.CommandLineCompiler;
30  import com.github.maven_nar.cpptasks.compiler.LinkType;
31  import com.github.maven_nar.cpptasks.compiler.Processor;
32  
33  /**
34   * An abstract base class for the OpenWatcom C and Fortran compilers.
35   *
36   * @author Curt Arnold
37   */
38  public abstract class OpenWatcomCompiler extends CommandLineCompiler {
39    /**
40     * Constructor.
41     * 
42     * @param command
43     *          String command
44     * @param identifierArg
45     *          String identifier
46     * @param sourceExtensions
47     *          String[] source extension
48     * @param headerExtensions
49     *          String[] header extension
50     * @param newEnvironment
51     *          boolean use new enviroment
52     * @param env
53     *          Environment environment
54     */
55    protected OpenWatcomCompiler(final String command, final String identifierArg, final String[] sourceExtensions,
56        final String[] headerExtensions, final boolean newEnvironment, final Environment env) {
57      super(command, identifierArg, sourceExtensions, headerExtensions, ".obj", false, null, newEnvironment, env);
58    }
59  
60    /**
61     * Add implied arguments.
62     * 
63     * @param args
64     *          Vector command line arguments
65     * @param debug
66     *          boolean is debug
67     * @param multithreaded
68     *          boolean multithreaderd
69     * @param exceptions
70     *          boolean support exceptions
71     * @param linkType
72     *          LinkType link type
73     * @param rtti
74     *          Boolean run time type information
75     * @param optimization
76     *          OptimizationEnum
77     */
78    @Override
79    protected final void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
80        final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
81      args.addElement("/c");
82      if (exceptions) {
83        args.addElement("/xs");
84      }
85      if (multithreaded) {
86        args.addElement("/bm");
87      }
88      if (debug) {
89        args.addElement("/d2");
90        args.addElement("/od");
91        args.addElement("/d_DEBUG");
92      } else {
93        if (optimization != null) {
94          if (optimization.isSize()) {
95            args.addElement("/os");
96          }
97          if (optimization.isSpeed()) {
98            args.addElement("/ot");
99          }
100       }
101       args.addElement("/dNDEBUG");
102     }
103     if (rtti != null && rtti.booleanValue()) {
104       args.addElement("/xr");
105     }
106   }
107 
108   /**
109    * Add warning switch.
110    * 
111    * @param args
112    *          Vector command line arguments
113    * @param level
114    *          int warning level
115    */
116   @Override
117   protected final void addWarningSwitch(final Vector<String> args, final int level) {
118     OpenWatcomProcessor.addWarningSwitch(args, level);
119   }
120 
121   /**
122    * Change enviroment.
123    * 
124    * @param newEnvironment
125    *          boolean use new enviroment
126    * @param env
127    *          Environment environment
128    * @return Processor modified processor
129    */
130   @Override
131   public final Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
132     return this;
133   }
134 
135   /**
136    * Get define switch.
137    * 
138    * @param buffer
139    *          StringBuffer buffer
140    * @param define
141    *          String preprocessor macro
142    * @param value
143    *          String value, may be null.
144    */
145   @Override
146   protected final void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
147     OpenWatcomProcessor.getDefineSwitch(buffer, define, value);
148   }
149 
150   /**
151    * Get include path from environment.
152    * 
153    * @return File[]
154    */
155   @Override
156   protected final File[] getEnvironmentIncludePath() {
157     return CUtil.getPathFromEnvironment("INCLUDE", ";");
158   }
159 
160   /**
161    * Get include directory switch.
162    * 
163    * @param includeDir
164    *          String include directory
165    * @return String command line argument
166    */
167   @Override
168   protected final String getIncludeDirSwitch(final String includeDir) {
169     return OpenWatcomProcessor.getIncludeDirSwitch(includeDir);
170   }
171 
172   /**
173    * Get maximum command line length.
174    * 
175    * @return int maximum command line length
176    */
177   @Override
178   public final int getMaximumCommandLength() {
179     return 4096;
180   }
181 
182   /**
183    * Get undefine switch.
184    * 
185    * @param buffer
186    *          StringBuffer argument destination
187    * @param define
188    *          String preprocessor macro
189    */
190   @Override
191   protected final void getUndefineSwitch(final StringBuffer buffer, final String define) {
192     OpenWatcomProcessor.getUndefineSwitch(buffer, define);
193   }
194 
195 }