001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.cnd.makeproject.api.compilers;
043:
044: import java.io.BufferedReader;
045: import java.io.File;
046: import java.io.IOException;
047: import java.io.InputStream;
048: import java.io.InputStreamReader;
049: import java.util.List;
050: import org.netbeans.modules.cnd.api.compilers.CompilerSet.CompilerFlavor;
051: import org.netbeans.modules.cnd.makeproject.api.configurations.BasicCompilerConfiguration;
052: import org.netbeans.modules.cnd.makeproject.api.platforms.Platform;
053: import org.openide.DialogDisplayer;
054: import org.openide.ErrorManager;
055: import org.openide.NotifyDescriptor;
056: import org.openide.util.NbBundle;
057:
058: public class SunCCCompiler extends SunCCCCompiler {
059: private static final String compilerStderrCommand = " -xdryrun -E"; // NOI18N
060: private static final String compilerStderrCommand2 = " -xdumpmacros=defs,sys -E"; // NOI18N
061:
062: private static final String[] DEVELOPMENT_MODE_OPTIONS = {
063: "", // Fast Build // NOI18N
064: "-g", // Debug" // NOI18N
065: "-g0 -xO3 -xhwcprof", // Performance Debug" // NOI18N
066: "-xprofile=tcov +d -xinline=", // Test Coverage // NOI18N
067: "-g0 -xO2", // Dianosable Release // NOI18N
068: "-xO3", // Release // NOI18N
069: "-xO5 -xipo=1 -xdepend -fsimple=1 -xlibmil -xlibmopt -xvector -xbuiltin -sync_stdio=no -xalias_level=simple -sync_stdio=no", // Performance Release // NOI18N
070: };
071:
072: private static final String[] WARNING_LEVEL_OPTIONS = { "-w", // No Warnings // NOI18N
073: "", // Default // NOI18N
074: "+w", // More Warnings // NOI18N
075: "-xwe", // Convert Warnings to Errors // NOI18N
076: };
077:
078: private static final String[] LIBRARY_LEVEL_OPTIONS = {
079: "-library=no%Cstd,no%Crun -filt=no%stdlib", // NOI18N
080: "-library=no%Cstd -filt=no%stdlib", // NOI18N
081: "-library=iostream,no%Cstd -filt=no%stdlib", // NOI18N
082: "", // NOI18N
083: "-library=stlport4,no%Cstd", // NOI18N
084: };
085:
086: private static final String[] MT_LEVEL_OPTIONS = { "", // None // NOI18N
087: "-mt", // Safe // NOI18N
088: "-xautopar -xvector -xreduction -xloopinfo", // Automatic // NOI18N
089: "-xopenmp", // Open MP // NOI18N
090: };
091:
092: private static final String[] STANDARD_OPTIONS = { "-compat", // Old // NOI18N
093: "-features=no%localfor,no%extinl,no%conststrings", // Legacy // NOI18N
094: "", // Default // NOI18N
095: "-features=no%anachronisms,no%transitions,tmplife", // Modern // NOI18N
096: };
097:
098: private static final String[] LANGUAGE_EXT_OPTIONS = {
099: "-features=no%longlong", // None // NOI18N
100: "", // Default // NOI18N
101: "-features=extensions,tmplrefstatic,iddollar", // All // NOI18N
102: };
103:
104: /** Creates a new instance of SunCCompiler */
105: public SunCCCompiler(CompilerFlavor flavor, int kind, String name,
106: String displayName, String path) {
107: super (flavor, kind, name, displayName, path);
108: }
109:
110: @Override
111: public String getDevelopmentModeOptions(int value) {
112: return DEVELOPMENT_MODE_OPTIONS[value];
113: }
114:
115: @Override
116: public String getWarningLevelOptions(int value) {
117: if (value < WARNING_LEVEL_OPTIONS.length)
118: return WARNING_LEVEL_OPTIONS[value];
119: else
120: return ""; // NOI18N
121: }
122:
123: @Override
124: public String getSixtyfourBitsOption(int value) {
125: if (getFlavor() == CompilerFlavor.Sun12) {
126: if (value == BasicCompilerConfiguration.BITS_DEFAULT)
127: return ""; // NOI18N
128: else if (value == BasicCompilerConfiguration.BITS_32)
129: return "-m32"; // NOI18N
130: else if (value == BasicCompilerConfiguration.BITS_64)
131: return "-m64"; // NOI18N
132: else
133: return ""; // NOI18N
134: } else {
135: if (value == BasicCompilerConfiguration.BITS_DEFAULT)
136: return ""; // NOI18N
137: else if (value == BasicCompilerConfiguration.BITS_32)
138: return ""; // NOI18N
139: else if (value == BasicCompilerConfiguration.BITS_64)
140: return "-xarch=generic64"; // NOI18N
141: else
142: return ""; // NOI18N
143: }
144: }
145:
146: @Override
147: public String getStripOption(boolean value) {
148: return value ? "-s" : ""; // NOI18N
149: }
150:
151: // To be overridden
152: @Override
153: public String getMTLevelOptions(int value) {
154: return MT_LEVEL_OPTIONS[value];
155: }
156:
157: // To be overridden
158: @Override
159: public String getLibraryLevelOptions(int value) {
160: return LIBRARY_LEVEL_OPTIONS[value];
161: }
162:
163: // To be overridden
164: @Override
165: public String getStandardsEvolutionOptions(int value) {
166: return STANDARD_OPTIONS[value];
167: }
168:
169: // To be overridden
170: @Override
171: public String getLanguageExtOptions(int value) {
172: return LANGUAGE_EXT_OPTIONS[value];
173: }
174:
175: @Override
176: protected void parseCompilerOutput(InputStream is) {
177: BufferedReader reader = new BufferedReader(
178: new InputStreamReader(is));
179: try {
180: String line;
181: while ((line = reader.readLine()) != null) {
182: //System.out.println(line);
183: int includeIndex = line.indexOf("-I"); // NOI18N
184: while (includeIndex > 0) {
185: String token;
186: int spaceIndex = line
187: .indexOf(" ", includeIndex + 1); // NOI18N
188: if (spaceIndex > 0) {
189: token = line.substring(includeIndex + 2,
190: spaceIndex);
191: } else {
192: token = line.substring(includeIndex + 2);
193: }
194: if (!token.equals("-xbuiltin")) { //NOI18N
195: systemIncludeDirectoriesList
196: .addUnique(normalizePath(token));
197: }
198: if (token.endsWith("Cstd")) { // NOI18N
199: // See 89872 "Parser Settings" for Sun Compilers Collection are incorrect
200: systemIncludeDirectoriesList
201: .addUnique(normalizePath(token
202: .substring(0,
203: token.length() - 4)
204: + "std")); // NOI18N
205: }
206: // Hack to handle -compat flag. If this flag is added,
207: // the compiler looks in in CC4 and not in CC. Just adding CC4 doesn't
208: // fix this problem but it may work for some include files
209: // if (token.endsWith("include/CC")) // NOI18N
210: // systemIncludeDirectoriesList.addUnique(normalizePath(token + "4")); // NOI18N
211: if (spaceIndex > 0) {
212: includeIndex = line.indexOf("-I", spaceIndex); // NOI18N
213: } else {
214: break;
215: }
216: }
217: parseUserMacros(line, systemPreprocessorSymbolsList);
218: if (line.startsWith("#define ")) { // NOI18N
219: int i = line.indexOf(' ', 8);
220: if (i > 0) {
221: String token = line.substring(8, i) + "="
222: + line.substring(i + 1); // NOI18N
223: systemPreprocessorSymbolsList.add(token);
224: }
225: }
226: }
227: is.close();
228: reader.close();
229: } catch (IOException ioe) {
230: ErrorManager.getDefault().notify(ErrorManager.WARNING, ioe); // FIXUP
231: }
232: }
233:
234: private void dumpLists() {
235: System.out.println("=================================="
236: + getDisplayName()); // NOI18N
237: for (int i = 0; i < systemIncludeDirectoriesList.size(); i++) {
238: System.out.println("-I"
239: + systemIncludeDirectoriesList.get(i)); // NOI18N
240: }
241: for (int i = 0; i < systemPreprocessorSymbolsList.size(); i++) {
242: System.out.println("-D"
243: + systemPreprocessorSymbolsList.get(i)); // NOI18N
244: }
245: }
246:
247: @Override
248: protected String getDefaultPath() {
249: return "CC"; // NOI18N
250: }
251:
252: @Override
253: protected String getCompilerStderrCommand() {
254: return compilerStderrCommand;
255: }
256:
257: @Override
258: protected String getCompilerStderrCommand2() {
259: return compilerStderrCommand2;
260: }
261: }
|