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.api.project.Project;
045: import org.netbeans.modules.cnd.makeproject.configurations.ui.StringListNodeProp;
046: import org.netbeans.modules.cnd.makeproject.configurations.ui.VectorNodeProp;
047: import org.openide.nodes.Sheet;
048: import org.openide.util.HelpCtx;
049: import org.openide.util.NbBundle;
050:
051: public class CCCCompilerConfiguration extends
052: BasicCompilerConfiguration {
053: public static int MT_LEVEL_NONE = 0;
054: public static int MT_LEVEL_SAFE = 1;
055: public static int MT_LEVEL_AUTOMATIC = 2;
056: public static int MT_LEVEL_OPENMP = 3;
057: private static final String[] MT_LEVEL_NAMES = {
058: getString("NoneTxt"), getString("SafeTxt"),
059: getString("AutomaticTxt"), getString("OpenMPTxt"), };
060: private static final String[] MT_LEVEL_OPTIONS = null;
061: private IntConfiguration mpLevel;
062:
063: public static int LIBRARY_LEVEL_NONE = 0;
064: public static int LIBRARY_LEVEL_RUNTIME = 1;
065: public static int LIBRARY_LEVEL_CLASSIC = 2;
066: public static int LIBRARY_LEVEL_BINARY = 3;
067: public static int LIBRARY_LEVEL_CONFORMING = 4;
068: private static final String[] LIBRARY_LEVEL_NAMES = {
069: getString("NoneTxt"), getString("RuntimeOnlyTxt"),
070: getString("ClassicIostreamsTxt"),
071: getString("BinaryStandardTxt"),
072: getString("ConformingStandardTxt"), };
073: private static final String[] LIBRARY_LEVEL_OPTIONS = null;
074: private IntConfiguration libraryLevel;
075:
076: public static int STANDARDS_OLD = 0;
077: public static int STANDARDS_LEGACY = 1;
078: public static int STANDARDS_DEFAULT = 2;
079: public static int STANDARDS_MODERN = 3;
080: private static final String[] STANDARDS_NAMES = {
081: getString("OldTxt"), getString("LegacyTxt"),
082: getString("DefaultTxt"), getString("ModernTxt"), };
083: private static final String[] STANDARD_OPTIONS = null;
084: private IntConfiguration standardsEvolution;
085:
086: public static int LANGUAGE_EXT_NONE = 0;
087: public static int LANGUAGE_EXT_DEFAULT = 1;
088: public static int LANGUAGE_EXT_ALL = 2;
089: private static final String[] LANGUAGE_EXT_NAMES = {
090: getString("NoneTxt"), getString("DefaultTxt"),
091: getString("AllTxt"), };
092: private static final String[] LANGUAGE_EXT_OPTIONS = null;
093: private IntConfiguration languageExt;
094:
095: private VectorConfiguration includeDirectories;
096: private BooleanConfiguration inheritIncludes;
097: private VectorConfiguration preprocessorConfiguration;
098: private BooleanConfiguration inheritPreprocessor;
099:
100: // Constructors
101: public CCCCompilerConfiguration(String baseDir,
102: CCCCompilerConfiguration master) {
103: super (baseDir, master);
104: mpLevel = new IntConfiguration(master != null ? master
105: .getMTLevel() : null, MT_LEVEL_NONE, MT_LEVEL_NAMES,
106: null);
107: libraryLevel = new IntConfiguration(master != null ? master
108: .getLibraryLevel() : null, LIBRARY_LEVEL_BINARY,
109: LIBRARY_LEVEL_NAMES, getLibraryLevelOptions());
110: standardsEvolution = new IntConfiguration(
111: master != null ? master.getStandardsEvolution() : null,
112: STANDARDS_DEFAULT, STANDARDS_NAMES,
113: getStandardsEvolutionOptions());
114: languageExt = new IntConfiguration(master != null ? master
115: .getLanguageExt() : null, LANGUAGE_EXT_DEFAULT,
116: LANGUAGE_EXT_NAMES, getLanguageExtOptions());
117: includeDirectories = new VectorConfiguration(
118: master != null ? master.getIncludeDirectories() : null);
119: inheritIncludes = new BooleanConfiguration(null, true, null,
120: null);
121: preprocessorConfiguration = new VectorConfiguration(
122: master != null ? master.getPreprocessorConfiguration()
123: : null);
124: inheritPreprocessor = new BooleanConfiguration(null, true,
125: null, null);
126: }
127:
128: @Override
129: public boolean getModified() {
130: return super .getModified() || mpLevel.getModified()
131: || libraryLevel.getModified()
132: || standardsEvolution.getModified()
133: || languageExt.getModified()
134: || includeDirectories.getModified()
135: || inheritIncludes.getModified()
136: || preprocessorConfiguration.getModified()
137: || inheritPreprocessor.getModified();
138: }
139:
140: // To be overridden
141: protected String[] getMTLevelOptions() {
142: return MT_LEVEL_OPTIONS;
143: }
144:
145: // To be overridden
146: protected String[] getLibraryLevelOptions() {
147: return LIBRARY_LEVEL_OPTIONS;
148: }
149:
150: // To be overridden
151: protected String[] getStandardsEvolutionOptions() {
152: return STANDARD_OPTIONS;
153: }
154:
155: // To be overridden
156: protected String[] getLanguageExtOptions() {
157: return LANGUAGE_EXT_OPTIONS;
158: }
159:
160: // MT Level
161: public void setMTLevel(IntConfiguration mpLevel) {
162: this .mpLevel = mpLevel;
163: }
164:
165: public IntConfiguration getMTLevel() {
166: return mpLevel;
167: }
168:
169: // Library Level
170: public void setLibraryLevel(IntConfiguration libraryLevel) {
171: this .libraryLevel = libraryLevel;
172: }
173:
174: public IntConfiguration getLibraryLevel() {
175: return libraryLevel;
176: }
177:
178: // Standards Evolution
179: public void setStandardsEvolution(
180: IntConfiguration standardsEvolution) {
181: this .standardsEvolution = standardsEvolution;
182: }
183:
184: public IntConfiguration getStandardsEvolution() {
185: return standardsEvolution;
186: }
187:
188: // languageExt
189: public void setLanguageExt(IntConfiguration languageExt) {
190: this .languageExt = languageExt;
191: }
192:
193: public IntConfiguration getLanguageExt() {
194: return languageExt;
195: }
196:
197: // Include Directories
198: public VectorConfiguration getIncludeDirectories() {
199: return includeDirectories;
200: }
201:
202: public void setIncludeDirectories(
203: VectorConfiguration includeDirectories) {
204: this .includeDirectories = includeDirectories;
205: }
206:
207: // Inherit Include Directories
208: public BooleanConfiguration getInheritIncludes() {
209: return inheritIncludes;
210: }
211:
212: public void setInheritIncludes(BooleanConfiguration inheritIncludes) {
213: this .inheritIncludes = inheritIncludes;
214: }
215:
216: // Preprocessor
217: public VectorConfiguration getPreprocessorConfiguration() {
218: return preprocessorConfiguration;
219: }
220:
221: public void setPreprocessorConfiguration(
222: VectorConfiguration preprocessorConfiguration) {
223: this .preprocessorConfiguration = preprocessorConfiguration;
224: }
225:
226: // Inherit Include Directories
227: public BooleanConfiguration getInheritPreprocessor() {
228: return inheritPreprocessor;
229: }
230:
231: public void setInheritPreprocessor(
232: BooleanConfiguration inheritPreprocessor) {
233: this .inheritPreprocessor = inheritPreprocessor;
234: }
235:
236: // Clone and assign
237: public void assign(CCCCompilerConfiguration conf) {
238: // BasicCompilerConfiguration
239: super .assign(conf);
240: // XCompilerConfiguration
241: getMTLevel().assign(conf.getMTLevel());
242: getLibraryLevel().assign(conf.getLibraryLevel());
243: getStandardsEvolution().assign(conf.getStandardsEvolution());
244: getLanguageExt().assign(conf.getLanguageExt());
245: getIncludeDirectories().assign(conf.getIncludeDirectories());
246: getInheritIncludes().assign(conf.getInheritIncludes());
247: getPreprocessorConfiguration().assign(
248: conf.getPreprocessorConfiguration());
249: getInheritPreprocessor().assign(conf.getInheritPreprocessor());
250: }
251:
252: @Override
253: public Object clone() {
254: CCCCompilerConfiguration clone = new CCCCompilerConfiguration(
255: getBaseDir(), (CCCCompilerConfiguration) getMaster());
256: // BasicCompilerConfiguration
257: clone
258: .setDevelopmentMode((IntConfiguration) getDevelopmentMode()
259: .clone());
260: clone.setWarningLevel((IntConfiguration) getWarningLevel()
261: .clone());
262: clone.setSixtyfourBits((IntConfiguration) getSixtyfourBits()
263: .clone());
264: clone.setStrip((BooleanConfiguration) getStrip().clone());
265: clone
266: .setAdditionalDependencies((StringConfiguration) getAdditionalDependencies()
267: .clone());
268: clone.setTool((StringConfiguration) getTool().clone());
269: clone
270: .setCommandLineConfiguration((OptionsConfiguration) getCommandLineConfiguration()
271: .clone());
272: // XCompilerConfiguration
273: clone.setMTLevel((IntConfiguration) getMTLevel().clone());
274: clone.setLibraryLevel((IntConfiguration) getLibraryLevel()
275: .clone());
276: clone
277: .setStandardsEvolution((IntConfiguration) getStandardsEvolution()
278: .clone());
279: clone.setLanguageExt((IntConfiguration) getLanguageExt()
280: .clone());
281: clone
282: .setIncludeDirectories((VectorConfiguration) getIncludeDirectories()
283: .clone());
284: clone
285: .setInheritIncludes((BooleanConfiguration) getInheritIncludes()
286: .clone());
287: clone
288: .setPreprocessorConfiguration((VectorConfiguration) getPreprocessorConfiguration()
289: .clone());
290: clone
291: .setInheritPreprocessor((BooleanConfiguration) getInheritPreprocessor()
292: .clone());
293: return clone;
294: }
295:
296: // Sheet
297: public Sheet.Set getSet() {
298: CCCCompilerConfiguration master;
299:
300: Sheet.Set set1 = new Sheet.Set();
301: set1.setName("General"); // NOI18N
302: set1.setDisplayName(getString("GeneralTxt"));
303: set1.setShortDescription(getString("GeneralHint"));
304: // Include Dirctories
305: StringBuilder inheritedValues = new StringBuilder();
306: master = (CCCCompilerConfiguration) getMaster();
307: while (master != null) {
308: inheritedValues.append(master.getIncludeDirectories()
309: .getOption("")); // NOI18N
310: if (master.getInheritIncludes().getValue())
311: master = (CCCCompilerConfiguration) master.getMaster();
312: else
313: master = null;
314: }
315: set1.put(new VectorNodeProp(getIncludeDirectories(),
316: getInheritIncludes(), getBaseDir(), new String[] {
317: "IncludeDirectories",
318: getString("IncludeDirectoriesTxt"),
319: getString("IncludeDirectoriesHint"),
320: inheritedValues.toString() }, true,
321: new HelpCtx("AddtlIncludeDirectories"))); // NOI18N
322: // Preprocessor Macros
323: inheritedValues = new StringBuilder();
324: master = (CCCCompilerConfiguration) getMaster();
325: while (master != null) {
326: inheritedValues.append(master
327: .getPreprocessorConfiguration().getOption("")); // NOI18N
328: if (master.getInheritPreprocessor().getValue())
329: master = (CCCCompilerConfiguration) master.getMaster();
330: else
331: master = null;
332: }
333: set1.put(new StringListNodeProp(getPreprocessorConfiguration(),
334: getInheritPreprocessor(), new String[] {
335: "PreprocessorDefinitions",
336: getString("PreprocessorDefinitionsTxt"),
337: getString("PreprocessorDefinitionsHint"),
338: inheritedValues.toString() }, true,
339: new HelpCtx("AddtlIncludeDirectories"))); // NOI18N
340:
341: return set1;
342: }
343:
344: // private class PreprocessorOptions implements AllOptionsProvider {
345: // public String getAllOptions(BasicCompiler compiler) {
346: // CCCCompilerConfiguration master = (CCCCompilerConfiguration)getMaster();
347: //
348: // StringBuilder options = new StringBuilder();
349: // while (master != null) {
350: // options.append(master.getPreprocessorConfiguration().getValue());
351: // options.append(" "); // NOI18N
352: // if (master.getInheritPreprocessor().getValue())
353: // master = (CCCCompilerConfiguration)master.getMaster();
354: // else
355: // master = null;
356: // }
357: // return CppUtils.reformatWhitespaces(options.toString());
358: // }
359: // }
360:
361: // Sheet
362: public Sheet getSheet(Project project) {
363: Sheet sheet = new Sheet();
364: sheet.put(getSet());
365: return sheet;
366: }
367:
368: /** Look up i18n strings here */
369: private static String getString(String s) {
370: return NbBundle.getMessage(CCCCompilerConfiguration.class, s);
371: }
372: }
|