1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
38
39
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
82
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
132 return 32000;
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 }