summaryrefslogtreecommitdiffstats
path: root/org.rtems.cdt/src/org/rtems/cdt/build/CommandLineGenerator.java
blob: a3f551f81323b7553ad29408e1536cfa15e0ddbe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (c) 2008 Embedded Brains GmbH and others.
 *
 *   Embedded Brains GmbH
 *   Obere Lagerstr. 30
 *   D-82178 Puchheim
 *   Germany
 *   rtems@embedded-brains.de
 *
 * All rights reserved.  This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License Version 1.0 ("EPL")
 * which accompanies this distribution and is available at
 *
 *   http://www.eclipse.org/legal/epl-v10.html
 *
 * For purposes of the EPL, "Program" will mean the Content.
 *
 * Contributors:
 *
 *   Sebastian Huber (Embedded Brains GmbH) - Initial API and implementation.
 */

package org.rtems.cdt.build;

import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator;
import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedCommandLineGenerator;
import org.eclipse.core.resources.IProject;
import org.rtems.cdt.Constants;
import org.rtems.cdt.Storage;

public class CommandLineGenerator extends ManagedCommandLineGenerator implements IManagedCommandLineGenerator {
	protected String getPlatform() {
		return Constants.PLATFORM_DEFAULT;
	}

	public IManagedCommandLineInfo generateCommandLineInfo(
		ITool tool,
		String commandName,
		String [] options,
		String outputFlag,
		String outputPrefix,
		String outputName,
		String [] inputResources,
		String commandLinePattern
	) {
		// Get associated project of the tool
		IProject project = (IProject) tool.getParentResourceInfo().getParent().getOwner();

		// Change platform
		Storage.changePlatform(project, getPlatform());

		// Determine tool key via the tool ID
		String id = tool.getId();
		String toolKey = "gcc";
		if (id.contains("archiver")) {
			toolKey = Constants.TOOL_ARCHIVER_KEY;
		} else if (id.contains("assembler.gcc")) {
			toolKey = Constants.TOOL_COMPILER_C_KEY;
		} else if (id.contains("assembler")) {
			toolKey = Constants.TOOL_ASSEMBLER_KEY;
		} else if (id.contains("compiler.cpp")) {
			toolKey = Constants.TOOL_COMPILER_CPP_KEY;
		} else if (id.contains("compiler.c")) {
			toolKey = Constants.TOOL_COMPILER_C_KEY;
		} else if (id.contains("linker.cpp")) {
			toolKey = Constants.TOOL_LINKER_CPP_KEY;
		} else if (id.contains("linker.c")) {
			toolKey = Constants.TOOL_LINKER_C_KEY;
		}

		// Set command name
		commandName = Storage.getProperty(project, toolKey);
		tool.setToolCommand(commandName);

		// Combine tool options and options
		if (Storage.areToolOptionsEnabled(project)) {
			String [] toolOptions = Storage.getToolOptions(project, toolKey);
			String combinedOptions [] = new String [toolOptions.length + options.length];
			System.arraycopy(toolOptions, 0, combinedOptions, 0, toolOptions.length);
			System.arraycopy(options, 0, combinedOptions, toolOptions.length, options.length);
			options = combinedOptions;
		}

		return super.generateCommandLineInfo(
			tool,
			commandName,
			options,
			outputFlag,
			outputPrefix,
			outputName,
			inputResources,
			commandLinePattern
		);
	}
}