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.gcc;
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.OptimizationEnum;
28  import com.github.maven_nar.cpptasks.compiler.CommandLineCompiler;
29  import com.github.maven_nar.cpptasks.compiler.LinkType;
30  import com.github.maven_nar.cpptasks.compiler.Linker;
31  import com.github.maven_nar.cpptasks.compiler.Processor;
32  import com.github.maven_nar.cpptasks.parser.CParser;
33  import com.github.maven_nar.cpptasks.parser.Parser;
34  
35  /**
36   * Adapter for the GNU windres resource compiler.
37   *
38   * @author Curt Arnold
39   */
40  public final class WindresResourceCompiler extends CommandLineCompiler {
41    private static final WindresResourceCompiler instance = new WindresResourceCompiler(false, null);
42  
43    public static WindresResourceCompiler getInstance() {
44      return instance;
45    }
46  
47    private WindresResourceCompiler(final boolean newEnvironment, final Environment env) {
48      super("windres", null, new String[] {
49        ".rc"
50      }, new String[] {
51          ".h", ".hpp", ".inl"
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      if (debug) {
59        args.addElement("-D_DEBUG");
60      } else {
61        args.addElement("-DNDEBUG");
62      }
63    }
64  
65    @Override
66    protected void addWarningSwitch(final Vector args, final int level) {
67    }
68  
69    @Override
70    public Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
71      if (newEnvironment || env != null) {
72        return new WindresResourceCompiler(newEnvironment, env);
73      }
74      return this;
75    }
76  
77    /**
78     * The include parser for C will work just fine, but we didn't want to
79     * inherit from CommandLineCCompiler
80     */
81    @Override
82    protected Parser createParser(final File source) {
83      return new CParser();
84    }
85  
86    @Override
87    protected int getArgumentCountPerInputFile() {
88      return 2;
89    }
90  
91    @Override
92    protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
93      buffer.append("-D");
94      buffer.append(define);
95      if (value != null && value.length() > 0) {
96        buffer.append('=');
97        buffer.append(value);
98      }
99    }
100 
101   @Override
102   protected File[] getEnvironmentIncludePath() {
103     return new File[0];
104   }
105 
106   @Override
107   public String getIdentifier() {
108     return "GNU windres";
109   }
110 
111   @Override
112   protected String getIncludeDirSwitch(final String includeDir) {
113     return "-I" + includeDir;
114   }
115 
116   @Override
117   protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
118     if (index == 0) {
119       final String outputFileName = getOutputFileNames(filename, null)[0];
120       return "-o" + outputFileName;
121     }
122     return filename;
123   }
124 
125   @Override
126   public Linker getLinker(final LinkType type) {
127     return GccLinker.getInstance().getLinker(type);
128   }
129 
130   @Override
131   public int getMaximumCommandLength() {
132     return 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     buffer.append("-U");
143     buffer.append(define);
144   }
145 }