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.msvc;
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.Linker;
32  import com.github.maven_nar.cpptasks.compiler.Processor;
33  import com.github.maven_nar.cpptasks.parser.CParser;
34  import com.github.maven_nar.cpptasks.parser.Parser;
35  
36  /**
37   * Adapter for the Microsoft (r) Windows 32 Resource Compiler
38   *
39   * @author Curt Arnold
40   */
41  public final class MsvcResourceCompiler extends CommandLineCompiler {
42    private static final MsvcResourceCompiler instance = new MsvcResourceCompiler(false, null);
43  
44    public static MsvcResourceCompiler getInstance() {
45      return instance;
46    }
47  
48    private String identifier;
49  
50    private MsvcResourceCompiler(final boolean newEnvironment, final Environment env) {
51      super("rc", null, new String[] {
52        ".rc"
53      }, new String[] {
54          ".h", ".hpp", ".inl"
55      }, ".res", false, null, newEnvironment, env);
56    }
57  
58    @Override
59    protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
60        final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
61      if (debug) {
62        args.addElement("/D_DEBUG");
63      } else {
64        args.addElement("/DNDEBUG");
65      }
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 MsvcResourceCompiler(newEnvironment, env);
76      }
77      return this;
78    }
79  
80    /**
81     * The include parser for C will work just fine, but we didn't want to
82     * inherit from CommandLineCCompiler
83     */
84    @Override
85    protected Parser createParser(final File source) {
86      return new CParser();
87    }
88  
89    @Override
90    protected int getArgumentCountPerInputFile() {
91      return 2;
92    }
93  
94    @Override
95    protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
96      MsvcProcessor.getDefineSwitch(buffer, define, value);
97    }
98  
99    @Override
100   protected File[] getEnvironmentIncludePath() {
101     return CUtil.getPathFromEnvironment("INCLUDE", ";");
102   }
103 
104   @Override
105   public String getIdentifier() {
106     return "Microsoft (R) Windows (R) Resource Compiler";
107   }
108 
109   @Override
110   protected String getIncludeDirSwitch(final String includeDir) {
111     return MsvcProcessor.getIncludeDirSwitch(includeDir);
112   }
113 
114   @Override
115   protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
116     if (index == 0) {
117       final String outputFileName = getOutputFileNames(filename, null)[0];
118       final String fullOutputName = new File(outputDir, outputFileName).toString();
119       return "/fo" + fullOutputName;
120     }
121     return filename;
122   }
123 
124   @Override
125   public Linker getLinker(final LinkType type) {
126     return MsvcLinker.getInstance().getLinker(type);
127   }
128 
129   @Override
130   public int getMaximumCommandLength() {
131     // FREEHEP stay on the safe side
132     return 32000; // 32767;
133   }
134 
135   @Override
136   protected int getMaximumInputFilesPerCommand() {
137     return 1;
138   }
139 
140   @Override
141   protected void getUndefineSwitch(final StringBuffer buffer, final String define) {
142     MsvcProcessor.getUndefineSwitch(buffer, define);
143   }
144 }