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.configurations;
043:
044: import java.io.BufferedReader;
045: import java.io.BufferedWriter;
046: import java.io.File;
047: import java.io.FileOutputStream;
048: import java.io.IOException;
049: import java.io.InputStream;
050: import java.io.InputStreamReader;
051: import java.io.OutputStreamWriter;
052: import java.net.URL;
053: import org.netbeans.modules.cnd.makeproject.api.MakeArtifact;
054: import org.netbeans.modules.cnd.makeproject.api.configurations.ArchiverConfiguration;
055: import org.netbeans.modules.cnd.makeproject.api.configurations.BasicCompilerConfiguration;
056: import org.netbeans.modules.cnd.makeproject.api.configurations.CCCCompilerConfiguration;
057: import org.netbeans.modules.cnd.makeproject.api.configurations.Configuration;
058: import org.netbeans.modules.cnd.makeproject.api.configurations.CustomToolConfiguration;
059: import org.netbeans.modules.cnd.makeproject.api.configurations.Item;
060: import org.netbeans.modules.cnd.makeproject.api.configurations.ItemConfiguration;
061: import org.netbeans.modules.cnd.makeproject.api.configurations.LibrariesConfiguration;
062: import org.netbeans.modules.cnd.makeproject.api.configurations.LibraryItem;
063: import org.netbeans.modules.cnd.makeproject.api.configurations.LinkerConfiguration;
064: import org.netbeans.modules.cnd.makeproject.api.configurations.MakeConfiguration;
065: import org.netbeans.modules.cnd.makeproject.api.configurations.MakeConfigurationDescriptor;
066: import org.netbeans.modules.cnd.makeproject.api.configurations.MakefileConfiguration;
067: import org.netbeans.modules.cnd.api.utils.IpeUtils;
068: import org.netbeans.modules.cnd.makeproject.api.compilers.BasicCompiler;
069: import org.netbeans.modules.cnd.api.compilers.CompilerSetManager;
070: import org.netbeans.modules.cnd.api.compilers.CompilerSet;
071: import org.netbeans.modules.cnd.api.compilers.Tool;
072: import org.netbeans.modules.cnd.makeproject.api.platforms.Platform;
073: import org.netbeans.modules.cnd.makeproject.api.configurations.FortranCompilerConfiguration;
074:
075: public class ConfigurationMakefileWriter {
076: private MakeConfigurationDescriptor projectDescriptor;
077:
078: public ConfigurationMakefileWriter(
079: MakeConfigurationDescriptor projectDescriptor) {
080: this .projectDescriptor = projectDescriptor;
081: }
082:
083: public void write() {
084: cleanup();
085: writeMakefileImpl();
086: Configuration[] confs = projectDescriptor.getConfs().getConfs();
087: for (int i = 0; i < confs.length; i++)
088: writeMakefileConf((MakeConfiguration) confs[i]);
089: }
090:
091: private void cleanup() {
092: // Remove all Makefile-* files
093: File folder = new File(projectDescriptor.getBaseDir() + '/'
094: + "nbproject"); // UNIX path // NOI18N
095: File[] children = folder.listFiles();
096: for (int i = 0; i < children.length; i++) {
097: if (children[i].getName().startsWith("Makefile-")) { // NOI18N
098: children[i].delete();
099: }
100: }
101: }
102:
103: private void writeMakefileImpl() {
104: InputStream is = null;
105: FileOutputStream os = null;
106: try {
107: URL url = new URL(
108: "nbresloc:/org/netbeans/modules/cnd/makeproject/resources/MasterMakefile-impl.mk"); // NOI18N
109: is = url.openStream();
110: String outputFileName = projectDescriptor.getBaseDir()
111: + '/' + "nbproject" + '/'
112: + MakeConfiguration.MAKEFILE_IMPL; // UNIX path // NOI18N
113: os = new FileOutputStream(outputFileName);
114: } catch (Exception e) {
115: // FIXUP
116: }
117: if (is == null || os == null) {
118: // FIXUP: ERROR
119: return;
120: }
121:
122: BufferedReader br = new BufferedReader(
123: new InputStreamReader(is));
124: BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
125: os));
126:
127: // Project name
128: String projectName = IpeUtils.getBaseName(projectDescriptor
129: .getBaseDir());
130:
131: // Configurations
132: StringBuilder configurations = new StringBuilder();
133: for (int i = 0; i < projectDescriptor.getConfs().getConfs().length; i++) {
134: configurations.append(projectDescriptor.getConfs()
135: .getConfs()[i].getName());
136: configurations.append(" "); // NOI18N
137: }
138:
139: try {
140: while (true) {
141: String line = br.readLine();
142: if (line == null)
143: break;
144: if (line.indexOf("<PN>") >= 0) { // NOI18N
145: line = line.replaceFirst("<PN>", projectName); // NOI18N
146: } else if (line.indexOf("<CNS>") >= 0) { // NOI18N
147: line = line.replaceFirst("<CNS>", configurations
148: .toString()); // NOI18N
149: } else if (line.indexOf("<CN>") >= 0) { // NOI18N
150: line = line.replaceFirst("<CN>", projectDescriptor
151: .getConfs().getConf(0).getName()); // NOI18N
152: }
153: bw.write(line + "\n"); // NOI18N
154: }
155: br.close();
156: bw.flush();
157: bw.close();
158: } catch (Exception e) {
159: }
160:
161: }
162:
163: private void writeMakefileConf(MakeConfiguration conf) {
164: String outputFileName = projectDescriptor.getBaseDir() + '/'
165: + "nbproject" + '/' + "Makefile-" + conf.getName()
166: + ".mk"; // UNIX path // NOI18N
167:
168: FileOutputStream os = null;
169: try {
170: os = new FileOutputStream(outputFileName);
171: } catch (Exception e) {
172: // FIXUP
173: }
174: BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
175: os));
176: try {
177: writePrelude(conf, bw);
178: writeBuildTarget(conf, bw);
179: writeCleanTarget(conf, bw);
180: writeDependencyChecking(conf, bw);
181: bw.flush();
182: bw.close();
183: } catch (IOException e) {
184: // FIXUP
185: }
186: }
187:
188: private void writePrelude(MakeConfiguration conf, BufferedWriter bw)
189: throws IOException {
190: CCCCompilerConfiguration cCompilerConfiguration = conf
191: .getCCompilerConfiguration();
192: CCCCompilerConfiguration ccCompilerConfiguration = conf
193: .getCCCompilerConfiguration();
194: FortranCompilerConfiguration fortranCompilerConfiguration = conf
195: .getFortranCompilerConfiguration();
196: CompilerSet compilerSet = CompilerSetManager.getDefault()
197: .getCompilerSet(conf.getCompilerSet().getValue()); // GRP -
198: BasicCompiler cCompiler = (BasicCompiler) compilerSet
199: .getTool(Tool.CCompiler);
200: BasicCompiler ccCompiler = (BasicCompiler) compilerSet
201: .getTool(Tool.CCCompiler);
202: BasicCompiler fortranCompiler = (BasicCompiler) compilerSet
203: .getTool(Tool.FortranCompiler);
204: String cCompilerName = ""; // NOI18N
205: String ccCompilerName = ""; // NOI18N
206: String fortranCompilerName = ""; // NOI18N
207: if (cCompiler != null) {
208: if (cCompilerConfiguration.getTool().getModified())
209: cCompilerName = cCompilerConfiguration.getTool()
210: .getValue();
211: else
212: cCompilerName = cCompiler.getName();
213: }
214: if (ccCompiler != null) {
215: if (ccCompilerConfiguration.getTool().getModified())
216: ccCompilerName = ccCompilerConfiguration.getTool()
217: .getValue();
218: else {
219: ccCompilerName = ccCompiler.getName();
220: }
221: }
222: if (fortranCompiler != null) {
223: if (fortranCompilerConfiguration.getTool().getModified())
224: fortranCompilerName = fortranCompilerConfiguration
225: .getTool().getValue();
226: else
227: fortranCompilerName = fortranCompiler.getName();
228: }
229:
230: bw.write("#\n"); // NOI18N
231: bw.write("# Gererated Makefile - do not edit!\n"); // NOI18N
232: bw.write("#\n"); // NOI18N
233: bw
234: .write("# Edit the Makefile in the project folder instead (../Makefile). Each target\n"); // NOI18N
235: bw
236: .write("# has a -pre and a -post target defined where you can add customized code.\n"); // NOI18N
237: bw.write("#\n"); // NOI18N
238: bw
239: .write("# This makefile implements configuration specific macros and targets.\n"); // NOI18N
240: bw.write("\n"); // NOI18N
241: bw.write("\n"); // NOI18N
242: bw.write("# Environment\n"); // NOI18N
243: bw.write("MKDIR=mkdir\n"); // NOI18N
244: bw.write("CP=cp\n"); // NOI18N
245: bw.write("CCADMIN=CCadmin\n"); // NOI18N
246: bw.write("RANLIB=ranlib\n"); // NOI18N
247: bw.write("CC=" + cCompilerName + "\n"); // NOI18N
248: bw.write("CCC=" + ccCompilerName + "\n"); // NOI18N
249: bw.write("CXX=" + ccCompilerName + "\n"); // NOI18N
250: bw.write("FC=" + fortranCompilerName + "\n"); // NOI18N
251: if (conf.getArchiverConfiguration().getTool().getModified())
252: bw.write("AR="
253: + conf.getArchiverConfiguration().getTool()
254: .getValue() + "\n"); // NOI18N
255: bw.write("\n"); // NOI18N
256: bw.write("# Include project Makefile\n"); // NOI18N
257: bw.write("include "
258: + projectDescriptor.getProjectMakefileName() + "\n"); // NOI18N
259: bw.write("\n"); // NOI18N
260: bw.write("# Object Directory\n"); // NOI18N
261: bw.write(MakeConfiguration.OBJECTDIR_MACRO_NAME + "="
262: + getObjectDir(conf) + "\n"); // NOI18N
263: bw.write("\n"); // NOI18N
264: bw.write("# Object Files\n"); // NOI18N
265: bw.write("OBJECTFILES="
266: + getObjectFiles(projectDescriptor, conf) + "\n"); // NOI18N
267: bw.write("\n"); // NOI18N
268: if (cCompiler != null) {
269: bw.write("# C Compiler Flags\n"); // NOI18N
270: bw.write("CFLAGS="
271: + conf.getCCompilerConfiguration().getCFlags(
272: cCompiler) + "\n"); // NOI18N
273: bw.write("\n"); // NOI18N
274: }
275: if (ccCompiler != null) {
276: bw.write("# CC Compiler Flags\n"); // NOI18N
277: bw.write("CCFLAGS="
278: + conf.getCCCompilerConfiguration().getCCFlags(
279: ccCompiler) + "\n"); // NOI18N
280: bw.write("CXXFLAGS="
281: + conf.getCCCompilerConfiguration().getCCFlags(
282: ccCompiler) + "\n"); // NOI18N
283: bw.write("\n"); // NOI18N
284: }
285: if (fortranCompiler != null) {
286: bw.write("# Fortran Compiler Flags\n"); // NOI18N
287: bw.write("FFLAGS="
288: + conf.getFortranCompilerConfiguration().getFFlags(
289: fortranCompiler) + "\n"); // NOI18N
290: bw.write("\n"); // NOI18N
291: }
292: bw.write("# Link Libraries and Options\n"); // NOI18N
293: bw.write("LDLIBSOPTIONS="
294: + conf.getLinkerConfiguration().getLibraryItems()
295: + "\n"); // NOI18N
296: bw.write("\n"); // NOI18N
297: }
298:
299: private void writeBuildTarget(MakeConfiguration conf,
300: BufferedWriter bw) throws IOException {
301: String output = getOutput(conf);
302: bw.write("# Build Targets\n"); // NOI18N
303: if (conf.isCompileConfiguration()) {
304: bw.write(".build-conf: " + "${BUILD_SUBPROJECTS} " + output
305: + "\n"); // NOI18N
306: bw.write("\n"); // NOI18N
307: if (hasSubprojects(conf)) {
308: bw.write(output + ": " + "${BUILD_SUBPROJECTS}" + "\n"); // NOI18N
309: bw.write("\n"); // NOI18N
310: }
311: if (conf.isLinkerConfiguration())
312: writeLinkTarget(conf, bw, output);
313: if (conf.isArchiverConfiguration())
314: writeArchiveTarget(conf, bw, output);
315: if (conf.isCompileConfiguration())
316: writeCompileTargets(conf, bw);
317: } else if (conf.isMakefileConfiguration()) {
318: bw.write(".build-conf: " + "${BUILD_SUBPROJECTS} " + "\n"); // NOI18N
319: writeMakefileTargets(conf, bw);
320: }
321: writeSubProjectBuildTargets(conf, bw);
322: bw.write("\n"); // NOI18N
323: }
324:
325: private void writeLinkTarget(MakeConfiguration conf,
326: BufferedWriter bw, String output) throws IOException {
327: LinkerConfiguration linkerConfiguration = conf
328: .getLinkerConfiguration();
329: String command = ""; // NOI18N
330: if (linkerConfiguration.getTool().getModified())
331: command += linkerConfiguration.getTool().getValue() + " "; // NOI18N
332: // else if (conf.isDynamicLibraryConfiguration())
333: // command += "${CCC}" + " "; // NOI18N
334: else if (conf.hasCPPFiles(projectDescriptor))
335: command += "${LINK.cc}" + " "; // NOI18N
336: else if (conf.hasFortranFiles(projectDescriptor))
337: command += "${LINK.f}" + " "; // NOI18N
338: else
339: command += "${LINK.c}" + " "; // NOI18N
340: command += linkerConfiguration.getOptions() + " "; // NOI18N
341: command += "${OBJECTFILES}" + " "; // NOI18N
342: command += "${LDLIBSOPTIONS}" + " "; // NOI18N
343: String[] additionalDependencies = linkerConfiguration
344: .getAdditionalDependencies().getValues();
345: for (int i = 0; i < additionalDependencies.length; i++) {
346: bw
347: .write(output + ": " + additionalDependencies[i]
348: + "\n\n"); // NOI18N
349: }
350: bw.write(output + ": " + "${OBJECTFILES}" + "\n"); // NOI18N
351: String folders = IpeUtils.getDirName(output);
352: if (folders != null)
353: bw.write("\t${MKDIR} -p " + folders + "\n"); // NOI18N
354: bw.write("\t" + command + "\n"); // NOI18N
355: }
356:
357: private void writeArchiveTarget(MakeConfiguration conf,
358: BufferedWriter bw, String output) throws IOException {
359: ArchiverConfiguration archiverConfiguration = conf
360: .getArchiverConfiguration();
361: String command = "${AR}" + " "; // NOI18N
362: command += archiverConfiguration.getOptions() + " "; // NOI18N
363: command += "${OBJECTFILES}" + " "; // NOI18N
364: bw.write(output + ": " + "${OBJECTFILES}" + "\n"); // NOI18N
365: String folders = IpeUtils.getDirName(output);
366: if (folders != null)
367: bw.write("\t${MKDIR} -p " + folders + "\n"); // NOI18N
368: bw.write("\t" + "${RM}" + " " + output + "\n"); // NOI18N
369: bw.write("\t" + command + "\n"); // NOI18N
370: if (archiverConfiguration.getRunRanlib().getValue())
371: bw.write("\t"
372: + archiverConfiguration.getRunRanlib().getOption()
373: + " " + output + "\n"); // NOI18N
374: }
375:
376: private void writeCompileTargets(MakeConfiguration conf,
377: BufferedWriter bw) throws IOException {
378: Item[] items = projectDescriptor.getProjectItems();
379: if (conf.isCompileConfiguration()) {
380: String target = null;
381: String folders = null;
382: String file = null;
383: String command = null;
384: String comment = null;
385: String additionalDep = null;
386: for (int i = 0; i < items.length; i++) {
387: ItemConfiguration itemConfiguration = items[i]
388: .getItemConfiguration(conf); //ItemConfiguration)conf.getAuxObject(ItemConfiguration.getId(items[i].getPath()));
389: if (itemConfiguration.getExcluded().getValue())
390: continue;
391: CompilerSet compilerSet = CompilerSetManager
392: .getDefault().getCompilerSet(
393: conf.getCompilerSet().getValue());
394: file = IpeUtils.escapeOddCharacters(compilerSet
395: .normalizeDriveLetter(items[i].getPath()));
396: command = ""; // NOI18N
397: comment = null;
398: additionalDep = null;
399: if (itemConfiguration.isCompilerToolConfiguration()) {
400: BasicCompiler compiler = (BasicCompiler) compilerSet
401: .getTool(itemConfiguration.getTool());
402: BasicCompilerConfiguration compilerConfiguration = itemConfiguration
403: .getCompilerConfiguration();
404: target = compilerConfiguration.getOutputFile(
405: items[i].getPath(true), conf, false);
406: if (compiler != null) {
407: String fromLinker = ""; // NOI18N
408: if (conf.getConfigurationType().getValue() == MakeConfiguration.TYPE_DYNAMIC_LIB) {
409: if (conf.getLinkerConfiguration()
410: .getPICOption().getValue()) {
411: fromLinker = " "
412: + conf.getLinkerConfiguration()
413: .getPICOption(
414: compilerSet); // NOI18N
415: }
416: }
417: command += compilerConfiguration
418: .getOptions(compiler)
419: + fromLinker + " "; // NOI18N
420: command += "-o " + target + " "; // NOI18N
421: command += IpeUtils
422: .escapeOddCharacters(items[i]
423: .getPath(true));
424: }
425: additionalDep = compilerConfiguration
426: .getAdditionalDependencies().getValue();
427: } else if (itemConfiguration.getTool() == Tool.CustomTool) {
428: CustomToolConfiguration customToolConfiguration = itemConfiguration
429: .getCustomToolConfiguration();
430: if (customToolConfiguration.getModified()) {
431: target = customToolConfiguration.getOutputs()
432: .getValue(" + "); // NOI18N
433: command = customToolConfiguration
434: .getCommandLine().getValue();
435: comment = customToolConfiguration
436: .getDescription().getValue();
437: additionalDep = customToolConfiguration
438: .getAdditionalDependencies().getValue();
439: } else {
440: continue;
441: }
442: } else {
443: assert false;
444: }
445: folders = IpeUtils.getDirName(target);
446: bw.write("\n"); // NOI18N
447: if (additionalDep != null)
448: bw.write(target + ": " + file + " " + additionalDep
449: + "\n"); // NOI18N
450: else
451: bw.write(target + ": " + file + "\n"); // NOI18N
452: if (folders != null)
453: bw.write("\t${MKDIR} -p " + folders + "\n"); // NOI18N
454: if (comment != null)
455: bw.write("\t@echo " + comment + "\n"); // NOI18N
456: bw.write("\t" + command + "\n"); // NOI18N
457: }
458: }
459: }
460:
461: private void writeMakefileTargets(MakeConfiguration conf,
462: BufferedWriter bw) throws IOException {
463: MakefileConfiguration makefileConfiguration = conf
464: .getMakefileConfiguration();
465: String target = makefileConfiguration.getOutput().getValue();
466: String cwd = makefileConfiguration
467: .getBuildCommandWorkingDirValue();
468: String command = makefileConfiguration.getBuildCommand()
469: .getValue();
470: //bw.write(target + ":" + "\n"); // NOI18N
471: bw.write("\tcd " + IpeUtils.escapeOddCharacters(cwd) + " && "
472: + command + "\n"); // NOI18N
473: }
474:
475: private void writeSubProjectBuildTargets(MakeConfiguration conf,
476: BufferedWriter bw) throws IOException {
477: bw.write("\n"); // NOI18N
478: bw.write("# Subprojects\n"); // NOI18N
479: bw.write(".build-subprojects:" + "\n"); // NOI18N
480: LibrariesConfiguration librariesConfiguration = null;
481: if (conf.isLinkerConfiguration()) {
482: librariesConfiguration = conf.getLinkerConfiguration()
483: .getLibrariesConfiguration();
484:
485: LibraryItem[] libraryItems = librariesConfiguration
486: .getLibraryItemsAsArray();
487: for (int j = 0; j < libraryItems.length; j++) {
488: if (libraryItems[j] instanceof LibraryItem.ProjectItem) {
489: LibraryItem.ProjectItem projectItem = (LibraryItem.ProjectItem) libraryItems[j];
490: MakeArtifact makeArtifact = projectItem
491: .getMakeArtifact();
492: String location = makeArtifact
493: .getWorkingDirectory();
494: if (!makeArtifact.getBuild())
495: continue;
496: bw.write("\tcd "
497: + IpeUtils.escapeOddCharacters(location)
498: + " && " + makeArtifact.getBuildCommand()
499: + "\n"); // NOI18N
500: }
501: }
502: }
503:
504: LibraryItem.ProjectItem[] projectItems = conf
505: .getRequiredProjectsConfiguration()
506: .getRequiredProjectItemsAsArray();
507: for (int i = 0; i < projectItems.length; i++) {
508: MakeArtifact makeArtifact = projectItems[i]
509: .getMakeArtifact();
510: String location = makeArtifact.getWorkingDirectory();
511: if (!makeArtifact.getBuild())
512: continue;
513: bw.write("\tcd " + IpeUtils.escapeOddCharacters(location)
514: + " && " + makeArtifact.getBuildCommand() + "\n"); // NOI18N
515: }
516: }
517:
518: private void writeSubProjectCleanTargets(MakeConfiguration conf,
519: BufferedWriter bw) throws IOException {
520: bw.write("\n"); // NOI18N
521: bw.write("# Subprojects\n"); // NOI18N
522: bw.write(".clean-subprojects:" + "\n"); // NOI18N
523: LibrariesConfiguration librariesConfiguration = null;
524: if (conf.isLinkerConfiguration()) {
525: librariesConfiguration = conf.getLinkerConfiguration()
526: .getLibrariesConfiguration();
527:
528: LibraryItem[] libraryItems = librariesConfiguration
529: .getLibraryItemsAsArray();
530: for (int j = 0; j < libraryItems.length; j++) {
531: if (libraryItems[j] instanceof LibraryItem.ProjectItem) {
532: LibraryItem.ProjectItem projectItem = (LibraryItem.ProjectItem) libraryItems[j];
533: MakeArtifact makeArtifact = projectItem
534: .getMakeArtifact();
535: String location = makeArtifact
536: .getWorkingDirectory();
537: if (!makeArtifact.getBuild())
538: continue;
539: bw.write("\tcd "
540: + IpeUtils.escapeOddCharacters(location)
541: + " && " + makeArtifact.getCleanCommand()
542: + "\n"); // NOI18N
543: }
544: }
545: }
546:
547: LibraryItem.ProjectItem[] projectItems = conf
548: .getRequiredProjectsConfiguration()
549: .getRequiredProjectItemsAsArray();
550: for (int i = 0; i < projectItems.length; i++) {
551: MakeArtifact makeArtifact = projectItems[i]
552: .getMakeArtifact();
553: String location = makeArtifact.getWorkingDirectory();
554: if (!makeArtifact.getBuild())
555: continue;
556: bw.write("\tcd " + IpeUtils.escapeOddCharacters(location)
557: + " && " + makeArtifact.getCleanCommand() + "\n"); // NOI18N
558: }
559: }
560:
561: private void writeCleanTarget(MakeConfiguration conf,
562: BufferedWriter bw) throws IOException {
563: bw.write("# Clean Targets\n"); // NOI18N
564: if (hasSubprojects(conf))
565: bw.write(".clean-conf: ${CLEAN_SUBPROJECTS}\n"); // NOI18N
566: else
567: bw.write(".clean-conf:\n"); // NOI18N
568: if (conf.isCompileConfiguration()) {
569: bw.write("\t${RM} -r " + MakeConfiguration.BUILD_FOLDER
570: + '/' + conf.getName() + "\n"); // UNIX path // NOI18N
571: bw.write("\t${RM} " + getOutput(conf) + "\n"); // NOI18N
572: if (CompilerSetManager.getDefault().getCompilerSet(
573: conf.getCompilerSet().getValue()).isSunCompiler()
574: && conf.hasCPPFiles(projectDescriptor))
575: bw.write("\t${CCADMIN} -clean" + "\n"); // NOI18N
576: if (conf.hasFortranFiles(projectDescriptor))
577: bw.write("\t${RM} *.mod" + "\n"); // NOI18N
578:
579: // Also clean output from custom tool
580: Item[] items = projectDescriptor.getProjectItems();
581: for (int i = 0; i < items.length; i++) {
582: ItemConfiguration itemConfiguration = items[i]
583: .getItemConfiguration(conf); //ItemConfiguration)conf.getAuxObject(ItemConfiguration.getId(items[i].getPath()));
584: if (itemConfiguration.getExcluded().getValue())
585: continue;
586: if (itemConfiguration.getTool() == Tool.CustomTool
587: && itemConfiguration
588: .getCustomToolConfiguration()
589: .getModified()) {
590: bw.write("\t${RM} "
591: + itemConfiguration
592: .getCustomToolConfiguration()
593: .getOutputs().getValue() + "\n"); // NOI18N
594: }
595: }
596: } else if (conf.isMakefileConfiguration()) {
597: MakefileConfiguration makefileConfiguration = conf
598: .getMakefileConfiguration();
599: String target = makefileConfiguration.getOutput()
600: .getValue();
601: String cwd = makefileConfiguration
602: .getBuildCommandWorkingDirValue();
603: String command = makefileConfiguration.getCleanCommand()
604: .getValue();
605:
606: bw.write("\tcd " + IpeUtils.escapeOddCharacters(cwd)
607: + " && " + command + "\n"); // NOI18N
608: }
609:
610: writeSubProjectCleanTargets(conf, bw);
611: }
612:
613: private void writeDependencyChecking(MakeConfiguration conf,
614: BufferedWriter bw) throws IOException {
615: if (conf.getDependencyChecking().getValue()) {
616: bw.write("\n"); // NOI18N
617: bw.write("# Enable dependency checking\n"); // NOI18N
618: bw.write(".KEEP_STATE:\n"); // NOI18N
619: bw.write(".KEEP_STATE_FILE:.make.state.${CONF}\n"); // NOI18N
620: }
621: }
622:
623: private String getOutput(MakeConfiguration conf) {
624: if (conf.isLinkerConfiguration()) {
625: String output = conf.getLinkerConfiguration()
626: .getOutputValue();
627: if (conf.isApplicationConfiguration()
628: && conf.getPlatform().getValue() == Platform.PLATFORM_WINDOWS)
629: output += ".exe"; // NOI18N
630: return output;
631: } else if (conf.isArchiverConfiguration())
632: return conf.getArchiverConfiguration().getOutputValue();
633: else if (conf.isMakefileConfiguration())
634: return conf.getMakefileConfiguration().getOutput()
635: .getValue();
636: assert false;
637: return null;
638: }
639:
640: public static String getObjectDir(MakeConfiguration conf) {
641: return MakeConfiguration.BUILD_FOLDER + '/' + conf.getName()
642: + '/' + conf.getVariant(); // UNIX path
643: }
644:
645: private String getObjectFiles(
646: MakeConfigurationDescriptor projectDescriptor,
647: MakeConfiguration conf) {
648: Item[] items = projectDescriptor.getProjectItems();
649: StringBuilder linkObjects = new StringBuilder();
650: if (conf.isCompileConfiguration()) {
651: for (int x = 0; x < items.length; x++) {
652: ItemConfiguration itemConfiguration = items[x]
653: .getItemConfiguration(conf); //ItemConfiguration)conf.getAuxObject(ItemConfiguration.getId(items[x].getPath()));
654: //String commandLine = ""; // NOI18N
655: if (itemConfiguration.getExcluded().getValue())
656: continue;
657: if (!itemConfiguration.isCompilerToolConfiguration())
658: continue;
659: BasicCompilerConfiguration compilerConfiguration = itemConfiguration
660: .getCompilerConfiguration();
661: linkObjects.append(" \\\n\t"); // NOI18N
662: linkObjects.append(compilerConfiguration.getOutputFile(
663: items[x].getPath(true), conf, false));
664: }
665: }
666: return linkObjects.toString();
667: }
668:
669: private boolean hasSubprojects(MakeConfiguration conf) {
670: LibrariesConfiguration librariesConfiguration = conf
671: .getLinkerConfiguration().getLibrariesConfiguration();
672: LibraryItem[] libraryItems = librariesConfiguration
673: .getLibraryItemsAsArray();
674: for (int j = 0; j < libraryItems.length; j++) {
675: if (libraryItems[j] instanceof LibraryItem.ProjectItem) {
676: return true;
677: }
678: }
679: return false;
680: }
681: }
|