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.CParser;
41  import com.github.maven_nar.cpptasks.parser.Parser;
42  
43  /**
44   * Adapter for the Microsoft (r) MIDL Compiler
45   *
46   * @author Curt Arnold
47   */
48  public final class MsvcMIDLCompiler extends CommandLineCompiler {
49    private static final MsvcMIDLCompiler instance = new MsvcMIDLCompiler(false, null);
50  
51    public static MsvcMIDLCompiler getInstance() {
52      return instance;
53    }
54  
55    private MsvcMIDLCompiler(final boolean newEnvironment, final Environment env) {
56      super("midl", null, new String[] {
57          ".idl", ".odl"
58      }, new String[] {}, ".tlb", false, null, newEnvironment, env);
59    }
60  
61    @Override
62    protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
63        final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
64    }
65  
66    @Override
67    protected void addWarningSwitch(final Vector<String> args, final int level) {
68      MsvcProcessor.addWarningSwitch(args, level);
69    }
70  
71    @Override
72    public Processor changeEnvironment(final boolean newEnvironment, final Environment env) {
73      if (newEnvironment || env != null) {
74        return new MsvcMIDLCompiler(newEnvironment, env);
75      }
76      return this;
77    }
78    
79    @Override
80    protected CompilerConfiguration createConfiguration(final CCTask task, final LinkType linkType,
81        final ProcessorDef[] baseDefs, final CompilerDef specificDef, final TargetDef targetPlatform,
82        final VersionInfo versionInfo) {
83      return new CommandLineCompilerConfiguration((CommandLineCompilerConfiguration)super.createConfiguration(task, linkType, baseDefs, specificDef, targetPlatform, versionInfo), null, null, true);
84    }
85  
86    /**
87     * The include parser for C will work just fine, but we didn't want to
88     * inherit from CommandLineCCompiler
89     */
90    @Override
91    protected Parser createParser(final File source) {
92      return new CParser();
93    }
94  
95    @Override
96    protected int getArgumentCountPerInputFile() {
97      return 5;
98    }
99  
100   @Override
101   protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
102     MsvcProcessor.getDefineSwitch(buffer, define, value);
103   }
104 
105   @Override
106   protected File[] getEnvironmentIncludePath() {
107     return CUtil.getPathFromEnvironment("INCLUDE", ";");
108   }
109 
110   @Override
111   protected String getIncludeDirSwitch(final String includeDir) {
112     return MsvcProcessor.getIncludeDirSwitch(includeDir);
113   }
114 
115   @Override
116   public String[] getOutputFileNames(final String inputFile, final VersionInfo versionInfo) {
117     //
118     // if a recognized input file
119     //
120     if (bid(inputFile) > 1) {
121       final String baseName = getBaseOutputName(inputFile);
122       return new String[] {
123         baseName + getOutputSuffix()
124       };
125     }
126     return new String[0];
127   }
128   
129   @Override
130   protected String getInputFileArgument(final File outputDir, final String filename, final int index) {
131     switch (index) {
132       case 0:
133         return "/tlb";
134       case 1:
135         return new File(outputDir, getOutputFileNames(filename, null)[0]).getAbsolutePath();
136       case 2:
137         return "/out";
138       case 3:
139         return outputDir.getAbsolutePath();
140        
141     }
142     return filename;
143   }
144 
145   @Override
146   public Linker getLinker(final LinkType type) {
147     return MsvcLinker.getInstance().getLinker(type);
148   }
149 
150   @Override
151   public int getMaximumCommandLength() {
152     // FREEHEP stay on the safe side
153     return 32000; // 32767;
154   }
155 
156   @Override
157   protected int getMaximumInputFilesPerCommand() {
158     return 1;
159   }
160 
161   @Override
162   protected void getUndefineSwitch(final StringBuffer buffer, final String define) {
163     MsvcProcessor.getUndefineSwitch(buffer, define);
164   }
165 }