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.openide.DialogDisplayer;
053: import org.openide.ErrorManager;
054: import org.openide.NotifyDescriptor;
055: import org.openide.util.NbBundle;
056:
057: public class SunCCompiler extends SunCCCCompiler {
058: private static final String compilerStderrCommand = " -xdryrun -E"; // NOI18N
059:
060: private static final String[] DEVELOPMENT_MODE_OPTIONS = {
061: "", // Fast Build // NOI18N
062: "-g", // Debug" // NOI18N
063: "-g -xO3 -xhwcprof", // Performance Debug" // NOI18N
064: "-xprofile=tcov -xinline=", // Test Coverage // NOI18N
065: "-g -xO2", // Dianosable Release // NOI18N
066: "-xO3 -xstrconst", // Release // NOI18N
067: "-xO5 -xipo=1 -xdepend -fsimple=1 -xlibmil -xlibmopt -xvector -xbuiltin -xalias_level=basic", // Performance Release // NOI18N
068: };
069:
070: private static final String[] WARNING_LEVEL_OPTIONS = { "-w", // No Warnings // NOI18N
071: "", // Default // NOI18N
072: "+w", // More Warnings // NOI18N
073: "-errwarn=%all", // Convert Warnings to Errors // NOI18N
074: };
075:
076: private static final String[] MT_LEVEL_OPTIONS = { "", // None // NOI18N
077: "-mt", // Safe // NOI18N
078: "-xautopar -xvector -xreduction -xloopinfo", // Automatic // NOI18N
079: "-xopenmp", // Open MP // NOI18N
080: };
081:
082: private static final String[] STANDARD_OPTIONS = { "-xc99=none", // Old // NOI18N
083: "-xc99=none", // Legacy // NOI18N
084: "", // Default // NOI18N
085: "-xstrconst -xc99", // Modern // NOI18N
086: };
087:
088: private static final String[] LANGUAGE_EXT_OPTIONS = { "-Xc", // None // NOI18N
089: "", // Default // NOI18N
090: "", // All // NOI18N
091: };
092:
093: /** Creates a new instance of SunCCompiler */
094: public SunCCompiler(CompilerFlavor flavor, int kind, String name,
095: String displayName, String path) {
096: super (flavor, kind, name, displayName, path);
097: }
098:
099: @Override
100: public String getDevelopmentModeOptions(int value) {
101: return DEVELOPMENT_MODE_OPTIONS[value];
102: }
103:
104: @Override
105: public String getWarningLevelOptions(int value) {
106: if (value < WARNING_LEVEL_OPTIONS.length)
107: return WARNING_LEVEL_OPTIONS[value];
108: else
109: return ""; // NOI18N
110: }
111:
112: @Override
113: public String getSixtyfourBitsOption(int value) {
114: if (getFlavor() == CompilerFlavor.Sun12) {
115: if (value == BasicCompilerConfiguration.BITS_DEFAULT)
116: return ""; // NOI18N
117: else if (value == BasicCompilerConfiguration.BITS_32)
118: return "-m32"; // NOI18N
119: else if (value == BasicCompilerConfiguration.BITS_64)
120: return "-m64"; // NOI18N
121: else
122: return ""; // NOI18N
123: } else {
124: if (value == BasicCompilerConfiguration.BITS_DEFAULT)
125: return ""; // NOI18N
126: else if (value == BasicCompilerConfiguration.BITS_32)
127: return ""; // NOI18N
128: else if (value == BasicCompilerConfiguration.BITS_64)
129: return "-xarch=generic64"; // NOI18N
130: else
131: return ""; // NOI18N
132: }
133: }
134:
135: @Override
136: public String getStripOption(boolean value) {
137: return value ? "-s" : ""; // NOI18N
138: }
139:
140: // To be overridden
141: @Override
142: public String getMTLevelOptions(int value) {
143: return MT_LEVEL_OPTIONS[value];
144: }
145:
146: // To be overridden
147: @Override
148: public String getStandardsEvolutionOptions(int value) {
149: return STANDARD_OPTIONS[value];
150: }
151:
152: // To be overridden
153: @Override
154: public String getLanguageExtOptions(int value) {
155: return LANGUAGE_EXT_OPTIONS[value];
156: }
157:
158: @Override
159: protected void parseCompilerOutput(InputStream is) {
160: BufferedReader reader = new BufferedReader(
161: new InputStreamReader(is));
162: try {
163: String line;
164: while ((line = reader.readLine()) != null) {
165: //System.out.println(line);
166: int includeIndex = line.indexOf("-I"); // NOI18N
167: while (includeIndex > 0) {
168: String token;
169: int spaceIndex = line
170: .indexOf(" ", includeIndex + 1); // NOI18N
171: if (spaceIndex > 0) {
172: token = line.substring(includeIndex + 2,
173: spaceIndex);
174: systemIncludeDirectoriesList
175: .addUnique(normalizePath(token));
176: includeIndex = line.indexOf("-I", spaceIndex); // NOI18N
177: } else {
178: token = line.substring(includeIndex + 2);
179: systemIncludeDirectoriesList
180: .addUnique(normalizePath(token));
181: break;
182: }
183: }
184: parseUserMacros(line, systemPreprocessorSymbolsList);
185: }
186: // Adding "__STDC__=0". It's missing from dryrun output
187: systemPreprocessorSymbolsList.add("__STDC__=0"); // NOI18N
188:
189: is.close();
190: reader.close();
191: } catch (IOException ioe) {
192: ErrorManager.getDefault().notify(ErrorManager.WARNING, ioe); // FIXUP
193: }
194: }
195:
196: private void dumpLists() {
197: System.out.println("=================================="
198: + getDisplayName()); // NOI18N
199: for (int i = 0; i < systemIncludeDirectoriesList.size(); i++) {
200: System.out.println("-I"
201: + systemIncludeDirectoriesList.get(i)); // NOI18N
202: }
203: for (int i = 0; i < systemPreprocessorSymbolsList.size(); i++) {
204: System.out.println("-D"
205: + systemPreprocessorSymbolsList.get(i)); // NOI18N
206: }
207: }
208:
209: @Override
210: protected String getDefaultPath() {
211: return "cc"; // NOI18N
212: }
213:
214: @Override
215: protected String getCompilerStderrCommand() {
216: return compilerStderrCommand;
217: }
218:
219: @Override
220: protected String getCompilerStderrCommand2() {
221: return null;
222: }
223: }
|