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.sun;
21
22 import java.io.File;
23 import java.util.Vector;
24
25 import com.github.maven_nar.cpptasks.CUtil;
26 import com.github.maven_nar.cpptasks.OptimizationEnum;
27 import com.github.maven_nar.cpptasks.compiler.LinkType;
28 import com.github.maven_nar.cpptasks.compiler.Linker;
29 import com.github.maven_nar.cpptasks.gcc.GccCompatibleCCompiler;
30
31
32
33
34
35
36 public final class ForteCCCompiler extends GccCompatibleCCompiler {
37 private final static String[] headerExtensions = new String[] {
38 ".h", ".hpp", ".inl"
39 };
40 private final static String[] sourceExtensions = new String[] {
41 ".c", ".cc", ".cxx", ".cpp", ".c++", ".i", ".s"
42 };
43
44 private static final ForteCCCompiler instance = new ForteCCCompiler("CC", sourceExtensions, headerExtensions);
45
46
47
48
49 public static ForteCCCompiler getInstance() {
50 return instance;
51 }
52
53 private String identifier;
54 private File[] includePath;
55
56
57
58
59
60 private ForteCCCompiler(final String command, final String[] sourceExtensions, final String[] headerExtensions) {
61 super(command, "-V", sourceExtensions, headerExtensions, false, null, false, null);
62 }
63
64 @Override
65 public void addImpliedArgs(final Vector<String> args, final boolean debug, final boolean multithreaded,
66 final boolean exceptions, final LinkType linkType, final Boolean rtti, final OptimizationEnum optimization) {
67 args.addElement("-c");
68 if (debug) {
69 args.addElement("-g");
70 }
71 if (optimization != null) {
72 if (optimization.isSpeed()) {
73 args.addElement("-xO2");
74 }
75 }
76 if (rtti != null) {
77 if (rtti.booleanValue()) {
78 args.addElement("-features=rtti");
79 } else {
80 args.addElement("-features=no%rtti");
81 }
82 }
83 if (multithreaded) {
84 args.addElement("-mt");
85 }
86 if (linkType.isSharedLibrary()) {
87 args.addElement("-KPIC");
88 }
89
90 }
91
92 @Override
93 public void addWarningSwitch(final Vector<String> args, final int level) {
94 switch (level) {
95 case 0:
96 args.addElement("-w");
97 break;
98 case 1:
99 case 2:
100 break;
101 case 3:
102 args.addElement("+w");
103 break;
104 case 4:
105 args.addElement("+w2");
106 break;
107 case 5:
108 args.addElement("+w2");
109 args.addElement("-xwe");
110 }
111 }
112
113 @Override
114 public File[] getEnvironmentIncludePath() {
115 if (this.includePath == null) {
116 final File ccLoc = CUtil.getExecutableLocation("CC");
117 if (ccLoc != null) {
118 final File compilerIncludeDir = new File(new File(ccLoc, "../include").getAbsolutePath());
119 if (compilerIncludeDir.exists()) {
120 this.includePath = new File[2];
121 this.includePath[0] = compilerIncludeDir;
122 }
123 }
124 if (this.includePath == null) {
125 this.includePath = new File[1];
126 }
127 this.includePath[this.includePath.length - 1] = new File("/usr/include");
128 }
129 return this.includePath;
130 }
131
132 @Override
133 public Linker getLinker(final LinkType linkType) {
134 return ForteCCLinker.getInstance().getLinker(linkType);
135 }
136
137 @Override
138 public int getMaximumCommandLength() {
139 return Integer.MAX_VALUE;
140 }
141 }