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.CCTask;
28  import com.github.maven_nar.cpptasks.CUtil;
29  import com.github.maven_nar.cpptasks.CompilerDef;
30  import com.github.maven_nar.cpptasks.OptimizationEnum;
31  import com.github.maven_nar.cpptasks.ProcessorDef;
32  import com.github.maven_nar.cpptasks.TargetDef;
33  import com.github.maven_nar.cpptasks.VersionInfo;
34  import com.github.maven_nar.cpptasks.compiler.CommandLineCompiler;
35  import com.github.maven_nar.cpptasks.compiler.CommandLineCompilerConfiguration;
36  import com.github.maven_nar.cpptasks.compiler.CompilerConfiguration;
37  import com.github.maven_nar.cpptasks.compiler.LinkType;
38  import com.github.maven_nar.cpptasks.compiler.Linker;
39  import com.github.maven_nar.cpptasks.compiler.Processor;
40  import com.github.maven_nar.cpptasks.parser.Parser;
41  
42  /**
43   * Adapter for the Microsoft (r) Windows 32 Message Compiler
44   *
45   * @author Greg Domjan
46   *
47   *         MC [-?aAbcdnouUv] [-co] [-cs namespace] [-css namespace] [-e
48   *         extension]
49   *         [-h path] [-km] [-m length] [-mof] [-p prefix] [-P prefix] [-r path]
50   *         [-s path] [-t path] [-w path] [-W path] [-x path] [-z name]
51   *         filename [filename]
52   */
53  public final class MsvcMessageCompiler extends CommandLineCompiler {
54    private static final MsvcMessageCompiler instance = new MsvcMessageCompiler(false, null);
55  
56    public static MsvcMessageCompiler getInstance() {
57      return instance;
58    }
59  
60    private MsvcMessageCompiler(final boolean newEnvironment, final Environment env) {
61      super("mc", null, new String[] {
62          ".mc", ".man"
63      }, new String[] {}, ".rc", false, null, newEnvironment, env);
64    }
65  
66    @Override
67    protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
68        final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
69      // no identified configuration compiler arguments implied from these
70      // options.
71    }
72  
73    @Override
74    protected void addIncludes(final String baseDirPath, final File[] includeDirs, final Vector<String> args,
75        final Vector<String> relativeArgs, final StringBuffer includePathId, final boolean isSystem) {
76      // no include switch
77      // for some reason we are still getting args in the output??
78    }
79  
80    @Override
81    protected void addWarningSwitch(final Vector<String> args, final int level) {
82    }
83  
84    @Override
85    protected boolean canParse(final File sourceFile) {
86      return false;
87    }
88  
89    @Override
90    public Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
91      if (newEnvironment || env != null) {
92        return new MsvcMessageCompiler(newEnvironment, env);
93      }
94      return this;
95    }
96  
97    @Override
98    protected Parser createParser(final File source) {
99      // neither file type has references to other elements that need to be found
100     // through parsing.
101     return null;
102   }
103   
104   @Override
105   protected CompilerConfiguration createConfiguration(final CCTask task, final LinkType linkType,
106       final ProcessorDef[] baseDefs, final CompilerDef specificDef, final TargetDef targetPlatform,
107       final VersionInfo versionInfo) {
108     return new CommandLineCompilerConfiguration((CommandLineCompilerConfiguration)super.createConfiguration(task, linkType, baseDefs, specificDef, targetPlatform, versionInfo), null, null, true);
109   }
110 
111   @Override
112   protected int getArgumentCountPerInputFile() {
113     return 5;
114   }
115 
116   @Override
117   protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
118     // no define switch
119   }
120 
121   @Override
122   protected File[] getEnvironmentIncludePath() {
123     return CUtil.getPathFromEnvironment("INCLUDE", ";");
124   }
125 
126   @Override
127   public String getIdentifier() {
128     return "Microsoft (R) Windows (R) Message Compiler";
129   }
130 
131   @Override
132   protected String getIncludeDirSwitch(final String includeDir) {
133     return null; // no include switch
134   }
135 
136   @Override
137   protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
138     switch (index) {
139       case 0:
140         return "-r";
141       case 1:
142         return outputDir.getAbsolutePath();
143       case 2:
144         return "-h";
145       case 3:
146         return outputDir.getAbsolutePath();
147     }
148     return filename;
149   }
150 
151   @Override
152   public Linker getLinker(final LinkType type) {
153     return MsvcLinker.getInstance().getLinker(type);
154   }
155 
156   @Override
157   public int getMaximumCommandLength() {
158     return 32000;
159   }
160 
161   @Override
162   protected int getMaximumInputFilesPerCommand() {
163     return 1;
164   }
165 
166   @Override
167   protected void getUndefineSwitch(final StringBuffer buffer, final String define) {
168     MsvcProcessor.getUndefineSwitch(buffer, define);
169   }
170 }