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.borland;
21  
22  import java.io.File;
23  import java.util.Vector;
24  
25  import org.apache.tools.ant.BuildException;
26  import org.apache.tools.ant.types.Environment;
27  
28  import com.github.maven_nar.cpptasks.CCTask;
29  import com.github.maven_nar.cpptasks.OptimizationEnum;
30  import com.github.maven_nar.cpptasks.compiler.CommandLineCompiler;
31  import com.github.maven_nar.cpptasks.compiler.CommandLineCompilerConfiguration;
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.compiler.ProgressMonitor;
36  import com.github.maven_nar.cpptasks.parser.CParser;
37  import com.github.maven_nar.cpptasks.parser.Parser;
38  
39  /**
40   * Adapter for the Borland(r) brc32 Resource compiler.
41   *
42   * @author Curt Arnold
43   */
44  public class BorlandResourceCompiler extends CommandLineCompiler {
45    private static final BorlandResourceCompiler instance = new BorlandResourceCompiler(false, null);
46  
47    public static BorlandResourceCompiler getInstance() {
48      return instance;
49    }
50  
51    private BorlandResourceCompiler(final boolean newEnvironment, final Environment env) {
52      super("brc32", "c:\\__bogus\\__bogus.rc", new String[] {
53        ".rc"
54      }, new String[] {
55          ".h", ".hpp", ".inl"
56      }, ".res", false, null, newEnvironment, env);
57    }
58  
59    @Override
60    protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
61        final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
62      //
63      // compile only
64      //
65      args.addElement("-r");
66    }
67  
68    @Override
69    protected void addWarningSwitch(final Vector<String> args, final int level) {
70    }
71  
72    @Override
73    public Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
74      if (newEnvironment || env != null) {
75        return new BorlandResourceCompiler(newEnvironment, env);
76      }
77      return this;
78    }
79  
80    @Override
81    public void compile(final CCTask task, final File outputDir, final String[] sourceFiles, final String[] args,
82        final String[] endArgs, final boolean relentless, final CommandLineCompilerConfiguration config,
83        final ProgressMonitor monitor) throws BuildException {
84      super.compile(task, outputDir, sourceFiles, args, endArgs, relentless, config, monitor);
85    }
86  
87    /**
88     * The include parser for C will work just fine, but we didn't want to
89     * inherit from CommandLineCCompiler
90     */
91    @Override
92    protected Parser createParser(final File source) {
93      return new CParser();
94    }
95  
96    @Override
97    protected int getArgumentCountPerInputFile() {
98      return 2;
99    }
100 
101   @Override
102   protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
103     buffer.append("-d");
104     buffer.append(define);
105     if (value != null && value.length() > 0) {
106       buffer.append('=');
107       buffer.append(value);
108     }
109   }
110 
111   @Override
112   protected File[] getEnvironmentIncludePath() {
113     return BorlandProcessor.getEnvironmentPath("brc32", 'i', new String[] {
114       "..\\include"
115     });
116   }
117 
118   @Override
119   protected String getIncludeDirSwitch(final String includeDir) {
120     return BorlandProcessor.getIncludeDirSwitch("-i", includeDir);
121   }
122 
123   @Override
124   protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
125     if (index == 0) {
126       final String[] outputFileNames = getOutputFileNames(filename, null);
127       final String fullOutputName = new File(outputDir, outputFileNames[0]).toString();
128       return "-fo" + fullOutputName;
129     }
130     return filename;
131   }
132 
133   @Override
134   public Linker getLinker(final LinkType type) {
135     return BorlandLinker.getInstance().getLinker(type);
136   }
137 
138   @Override
139   public int getMaximumCommandLength() {
140     return 1024;
141   }
142 
143   @Override
144   protected int getMaximumInputFilesPerCommand() {
145     return 1;
146   }
147 
148   @Override
149   protected void getUndefineSwitch(final StringBuffer buffer, final String define) {
150   }
151 }