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.configurations;
043:
044: import org.netbeans.modules.cnd.api.compilers.CompilerSet;
045: import org.netbeans.modules.cnd.api.compilers.CompilerSet.CompilerFlavor;
046: import org.netbeans.modules.cnd.api.compilers.CompilerSetManager;
047: import org.netbeans.modules.cnd.api.compilers.Tool;
048: import org.netbeans.modules.cnd.makeproject.configurations.ui.IntNodeProp;
049: import org.netbeans.modules.cnd.makeproject.configurations.ui.OptionsNodeProp;
050: import org.netbeans.modules.cnd.makeproject.configurations.ui.StringNodeProp;
051: import org.netbeans.modules.cnd.api.utils.CppUtils;
052: import org.netbeans.modules.cnd.makeproject.api.compilers.BasicCompiler;
053: import org.netbeans.modules.cnd.makeproject.api.compilers.CCCCompiler;
054: import org.openide.nodes.Sheet;
055: import org.openide.util.NbBundle;
056:
057: public class CCCompilerConfiguration extends CCCCompilerConfiguration
058: implements AllOptionsProvider {
059: // Constructors
060: public CCCompilerConfiguration(String baseDir,
061: CCCompilerConfiguration master) {
062: super (baseDir, master);
063: }
064:
065: // Clone and assign
066: public void assign(CCCompilerConfiguration conf) {
067: // From XCompiler
068: super .assign(conf);
069: }
070:
071: // Cloning
072: @Override
073: public Object clone() {
074: CCCompilerConfiguration clone = new CCCompilerConfiguration(
075: getBaseDir(), (CCCompilerConfiguration) getMaster());
076: // BasicCompilerConfiguration
077: clone
078: .setDevelopmentMode((IntConfiguration) getDevelopmentMode()
079: .clone());
080: clone.setWarningLevel((IntConfiguration) getWarningLevel()
081: .clone());
082: clone.setMTLevel((IntConfiguration) getMTLevel().clone());
083: clone.setSixtyfourBits((IntConfiguration) getSixtyfourBits()
084: .clone());
085: clone.setStrip((BooleanConfiguration) getStrip().clone());
086: clone
087: .setAdditionalDependencies((StringConfiguration) getAdditionalDependencies()
088: .clone());
089: clone.setTool((StringConfiguration) getTool().clone());
090: clone
091: .setCommandLineConfiguration((OptionsConfiguration) getCommandLineConfiguration()
092: .clone());
093: // From CCCCompiler
094: clone.setMTLevel((IntConfiguration) getMTLevel().clone());
095: clone.setLibraryLevel((IntConfiguration) getLibraryLevel()
096: .clone());
097: clone
098: .setStandardsEvolution((IntConfiguration) getStandardsEvolution()
099: .clone());
100: clone.setLanguageExt((IntConfiguration) getLanguageExt()
101: .clone());
102: clone
103: .setIncludeDirectories((VectorConfiguration) getIncludeDirectories()
104: .clone());
105: clone
106: .setInheritIncludes((BooleanConfiguration) getInheritIncludes()
107: .clone());
108: clone
109: .setPreprocessorConfiguration((VectorConfiguration) getPreprocessorConfiguration()
110: .clone());
111: clone
112: .setInheritPreprocessor((BooleanConfiguration) getInheritPreprocessor()
113: .clone());
114: return clone;
115: }
116:
117: // Interface OptionsProvider
118: @Override
119: public String getOptions(BasicCompiler compiler) {
120: String options = "$(COMPILE.cc) "; // NOI18N
121: options += getAllOptions2(compiler) + " "; // NOI18N
122: options += getCommandLineConfiguration().getValue() + " "; // NOI18N
123: return CppUtils.reformatWhitespaces(options);
124: }
125:
126: public String getCCFlagsBasic(BasicCompiler compiler) {
127: CCCCompiler cccCompiler = (CCCCompiler) compiler;
128: String options = ""; // NOI18N
129: options += cccCompiler.getMTLevelOptions(getMTLevel()
130: .getValue())
131: + " "; // NOI18N
132: options += cccCompiler.getLibraryLevelOptions(getLibraryLevel()
133: .getValue())
134: + " "; // NOI18N
135: options += cccCompiler
136: .getStandardsEvolutionOptions(getStandardsEvolution()
137: .getValue())
138: + " "; // NOI18N
139: options += cccCompiler.getLanguageExtOptions(getLanguageExt()
140: .getValue())
141: + " "; // NOI18N
142: //options += compiler.getStripOption(getStrip().getValue()) + " "; // NOI18N
143: options += compiler.getSixtyfourBitsOption(getSixtyfourBits()
144: .getValue())
145: + " "; // NOI18N
146: if (getDevelopmentMode().getValue() == DEVELOPMENT_MODE_TEST)
147: options += compiler
148: .getDevelopmentModeOptions(DEVELOPMENT_MODE_TEST);
149: return CppUtils.reformatWhitespaces(options);
150: }
151:
152: public String getCCFlags(BasicCompiler compiler) {
153: String options = getCCFlagsBasic(compiler) + " "; // NOI18N
154: options += getCommandLineConfiguration().getValue() + " "; // NOI18N
155: return CppUtils.reformatWhitespaces(options);
156: }
157:
158: public String getAllOptions(BasicCompiler compiler) {
159: CCCompilerConfiguration master;
160:
161: StringBuilder options = new StringBuilder();
162: options.append(getCCFlagsBasic(compiler));
163: options.append(" "); // NOI18N
164: master = (CCCompilerConfiguration) getMaster();
165: while (master != null) {
166: options.append(master.getCommandLineConfiguration()
167: .getValue());
168: options.append(" "); // NOI18N
169: master = (CCCompilerConfiguration) master.getMaster();
170: }
171: options.append(getAllOptions2(compiler));
172: options.append(" "); // NOI18N
173: return CppUtils.reformatWhitespaces(options.toString());
174: }
175:
176: public String getAllOptions2(BasicCompiler compiler) {
177: CCCompilerConfiguration master;
178:
179: String options = ""; // NOI18N
180: if (getDevelopmentMode().getValue() != DEVELOPMENT_MODE_TEST)
181: options += compiler
182: .getDevelopmentModeOptions(getDevelopmentMode()
183: .getValue())
184: + " "; // NOI18N
185: options += compiler.getWarningLevelOptions(getWarningLevel()
186: .getValue())
187: + " "; // NOI18N
188: options += compiler.getStripOption(getStrip().getValue()) + " "; // NOI18N
189: options += getPreprocessorOptions();
190: options += getIncludeDirectoriesOptions();
191: return CppUtils.reformatWhitespaces(options);
192: }
193:
194: public String getPreprocessorOptions() {
195: CCCompilerConfiguration master = (CCCompilerConfiguration) getMaster();
196: StringBuilder options = new StringBuilder(
197: getPreprocessorConfiguration().getOption("-D") + " "); // NOI18N
198: while (master != null && getInheritPreprocessor().getValue()) {
199: options.append(master.getPreprocessorConfiguration()
200: .getOption("-D")
201: + " "); // NOI18N
202: if (master.getInheritPreprocessor().getValue())
203: master = (CCCompilerConfiguration) master.getMaster();
204: else
205: master = null;
206: }
207: return options.toString();
208: }
209:
210: public String getIncludeDirectoriesOptions() {
211: CCCompilerConfiguration master = (CCCompilerConfiguration) getMaster();
212: StringBuilder options = new StringBuilder(
213: getIncludeDirectories().getOption("-I") + " "); // NOI18N
214: while (master != null && getInheritIncludes().getValue()) {
215: options.append(master.getIncludeDirectories().getOption(
216: "-I")
217: + " "); // NOI18N
218: if (master.getInheritIncludes().getValue())
219: master = (CCCompilerConfiguration) master.getMaster();
220: else
221: master = null;
222: }
223: return options.toString();
224: }
225:
226: // Sheet
227: public Sheet getSheet(MakeConfiguration conf, Folder folder) {
228: Sheet sheet = new Sheet();
229: CompilerSet compilerSet = CompilerSetManager.getDefault()
230: .getCompilerSet(conf.getCompilerSet().getValue());
231: BasicCompiler ccCompiler = (BasicCompiler) compilerSet
232: .getTool(Tool.CCCompiler);
233:
234: sheet.put(getSet());
235: if (conf.isCompileConfiguration() && folder == null) {
236: sheet.put(getBasicSet());
237: if (conf.getCompilerSet().getValue() == CompilerFlavor.Sun
238: .ordinal()) { // FIXUP: should be moved to SunCCompiler
239: Sheet.Set set2 = new Sheet.Set();
240: set2.setName("OtherOptions"); // NOI18N
241: set2.setDisplayName(getString("OtherOptionsTxt"));
242: set2.setShortDescription(getString("OtherOptionsHint"));
243: set2.put(new IntNodeProp(getMTLevel(),
244: getMaster() != null ? false : true,
245: "MultithreadingLevel",
246: getString("MultithreadingLevelTxt"),
247: getString("MultithreadingLevelHint"))); // NOI18N
248: set2.put(new IntNodeProp(getLibraryLevel(),
249: getMaster() != null ? false : true,
250: "LibraryLevel", getString("LibraryLevelTxt"),
251: getString("LibraryLevelHint"))); // NOI18N
252: set2.put(new IntNodeProp(getStandardsEvolution(),
253: getMaster() != null ? false : true,
254: "StandardsEvolution",
255: getString("StandardsEvolutionTxt"),
256: getString("StandardsEvolutionHint"))); // NOI18N
257: set2.put(new IntNodeProp(getLanguageExt(),
258: getMaster() != null ? false : true,
259: "LanguageExtensions",
260: getString("LanguageExtensionsTxt"),
261: getString("LanguageExtensionsHint"))); // NOI18N
262: sheet.put(set2);
263: }
264: if (getMaster() != null)
265: sheet.put(getInputSet());
266:
267: Sheet.Set set4 = new Sheet.Set();
268: set4.setName("Tool"); // NOI18N
269: set4.setDisplayName(getString("ToolTxt1"));
270: set4.setShortDescription(getString("ToolHint1"));
271: set4.put(new StringNodeProp(getTool(),
272: ccCompiler.getName(), false, "Tool",
273: getString("ToolTxt2"), getString("ToolHint2"))); // NOI18N
274: sheet.put(set4);
275:
276: String[] texts = new String[] {
277: getString("AdditionalOptionsTxt1"),
278: getString("AdditionalOptionsHint"),
279: getString("AdditionalOptionsTxt2"),
280: getString("AllOptionsTxt") };
281: Sheet.Set set2 = new Sheet.Set();
282: set2.setName("CommandLine"); // NOI18N
283: set2.setDisplayName(getString("CommandLineTxt"));
284: set2.setShortDescription(getString("CommandLineHint"));
285: set2.put(new OptionsNodeProp(getCommandLineConfiguration(),
286: null, this , ccCompiler, null, texts));
287: sheet.put(set2);
288:
289: }
290:
291: return sheet;
292: }
293:
294: /** Look up i18n strings here */
295: private static String getString(String s) {
296: return NbBundle.getMessage(CCCompilerConfiguration.class, s);
297: }
298: }
|