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.ti;
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.CommandLineCCompiler;
30 import com.github.maven_nar.cpptasks.compiler.LinkType;
31 import com.github.maven_nar.cpptasks.compiler.Linker;
32
33
34
35
36
37
38 public class ClxxCCompiler extends CommandLineCCompiler {
39
40
41
42 private static final String[] headerExtensions = new String[] {
43 ".h", ".hpp", ".inl"
44 };
45
46
47
48 private static final String[] sourceExtensions = new String[] {
49 ".c", ".cc", ".cpp", ".cxx", ".c++"
50 };
51
52
53
54 private static final ClxxCCompiler cl55 = new ClxxCCompiler("cl55", false, null);
55
56
57
58 private static final ClxxCCompiler cl6x = new ClxxCCompiler("cl6x", false, null);
59
60 public static ClxxCCompiler getCl55Instance() {
61 return cl55;
62 }
63
64 public static ClxxCCompiler getCl6xInstance() {
65 return cl6x;
66 }
67
68
69
70
71
72
73
74
75
76
77
78 private ClxxCCompiler(final String command, final boolean newEnvironment, final Environment env) {
79 super(command, "-h", sourceExtensions, headerExtensions, ".o", false, null, newEnvironment, env);
80 }
81
82 @Override
83 protected void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
84 final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
85 if (debug) {
86 args.addElement("-gw");
87 }
88 }
89
90 @Override
91 protected void addWarningSwitch(final Vector<String> args, final int warnings) {
92
93 }
94
95 @Override
96 protected void getDefineSwitch(final StringBuffer buffer, final String define, final String value) {
97 buffer.append("-d");
98 buffer.append(define);
99 if (value != null) {
100 buffer.append('=');
101 buffer.append(value);
102 }
103 }
104
105 @Override
106 protected File[] getEnvironmentIncludePath() {
107 final File[] c_dir = CUtil.getPathFromEnvironment("C_DIR", ";");
108 final File[] cx_dir = CUtil.getPathFromEnvironment("C6X_C_DIR", ";");
109 if (c_dir.length == 0) {
110 return cx_dir;
111 }
112 if (cx_dir.length == 0) {
113 return c_dir;
114 }
115 final File[] combo = new File[c_dir.length + cx_dir.length];
116 System.arraycopy(cx_dir, 0, combo, 0, cx_dir.length);
117 System.arraycopy(c_dir, 0, combo, 0 + cx_dir.length, c_dir.length);
118 return combo;
119 }
120
121 @Override
122 protected String getIncludeDirSwitch(final String source) {
123 return "-I" + source;
124 }
125
126 @Override
127 public Linker getLinker(final LinkType type) {
128 if (type.isStaticLibrary()) {
129 if (this == cl6x) {
130 return ClxxLibrarian.getCl6xInstance();
131 }
132 return ClxxLibrarian.getCl55Instance();
133 }
134 if (type.isSharedLibrary()) {
135 if (this == cl6x) {
136 return ClxxLinker.getCl6xDllInstance();
137 }
138 return ClxxLinker.getCl55DllInstance();
139 }
140 if (this == cl6x) {
141 return ClxxLinker.getCl6xInstance();
142 }
143 return ClxxLinker.getCl55Instance();
144 }
145
146 @Override
147 public int getMaximumCommandLength() {
148 return 1024;
149 }
150
151 @Override
152 protected void getUndefineSwitch(final StringBuffer buffer, final String define) {
153 buffer.append("-u");
154 buffer.append(define);
155 }
156 }