Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Schaefer2017-11-08 12:49:00 -0500
committerDoug Schaefer2017-11-08 14:11:31 -0500
commit4ce1f1ca16b0013298c51a5311528ae21cdfd645 (patch)
treea5e815687a2cc711b511bab788fa6ec48d9018e7 /build/org.eclipse.cdt.make.core
parent2bc9836f68a8597e552d4d5b42e15d85c6944e81 (diff)
downloadorg.eclipse.cdt-4ce1f1ca16b0013298c51a5311528ae21cdfd645.tar.gz
org.eclipse.cdt-4ce1f1ca16b0013298c51a5311528ae21cdfd645.tar.xz
org.eclipse.cdt-4ce1f1ca16b0013298c51a5311528ae21cdfd645.zip
Add Makefile Projects to collection of core build project types.
Reuses the old makeNature. Reuses the StandardBuildConfiguration. Generates a pretty simple project for now. Also handles the case where you don't want to generate anything, just create an empty or on an existing source tree. Change-Id: I2f3cddc85d55792a2c537e37d4bc236a3073d930
Diffstat (limited to 'build/org.eclipse.cdt.make.core')
-rw-r--r--build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF6
-rw-r--r--build/org.eclipse.cdt.make.core/plugin.xml8
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeCorePlugin.java11
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakefileProjectGenerator.java89
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakefileBuildConfigurationProvider.java66
-rw-r--r--build/org.eclipse.cdt.make.core/templates/simple/Makefile12
-rw-r--r--build/org.eclipse.cdt.make.core/templates/simple/main.cpp4
-rw-r--r--build/org.eclipse.cdt.make.core/templates/simple/manifest.xml7
8 files changed, 201 insertions, 2 deletions
diff --git a/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF
index fe09b183ab..7ccc94d010 100644
--- a/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF
+++ b/build/org.eclipse.cdt.make.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.make.core; singleton:=true
-Bundle-Version: 7.3.0.qualifier
+Bundle-Version: 7.4.0.qualifier
Bundle-Activator: org.eclipse.cdt.make.core.MakeCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@@ -23,7 +23,9 @@ Require-Bundle: org.eclipse.cdt.core;bundle-version="[5.0.0,7.0.0)",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.variables;bundle-version="[3.1.100,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
- org.eclipse.core.filesystem;bundle-version="1.2.0"
+ org.eclipse.core.filesystem;bundle-version="1.2.0",
+ org.eclipse.tools.templates.core;bundle-version="1.1.0",
+ org.eclipse.tools.templates.freemarker;bundle-version="1.0.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.ibm.icu.text
diff --git a/build/org.eclipse.cdt.make.core/plugin.xml b/build/org.eclipse.cdt.make.core/plugin.xml
index 2eded82431..63816b7021 100644
--- a/build/org.eclipse.cdt.make.core/plugin.xml
+++ b/build/org.eclipse.cdt.make.core/plugin.xml
@@ -194,5 +194,13 @@
<simple name="buildArguments" external="true" nullable="true"/>
</processType>
</extension>
+ <extension
+ point="org.eclipse.cdt.core.buildConfigProvider">
+ <provider
+ class="org.eclipse.cdt.make.internal.core.MakefileBuildConfigurationProvider"
+ id="org.eclipse.cdt.make.core.provider"
+ natureId="org.eclipse.cdt.make.core.makeNature">
+ </provider>
+ </extension>
</plugin>
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeCorePlugin.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeCorePlugin.java
index d3fd83f862..19e7a942ec 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeCorePlugin.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeCorePlugin.java
@@ -57,6 +57,7 @@ import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
/**
* The main plugin class to be used in the desktop.
@@ -427,4 +428,14 @@ public class MakeCorePlugin extends Plugin {
}
}
}
+
+ /**
+ * @since 7.4
+ */
+ public static <T> T getService(Class<T> service) {
+ BundleContext context = plugin.getBundle().getBundleContext();
+ ServiceReference<T> ref = context.getServiceReference(service);
+ return ref != null ? context.getService(ref) : null;
+ }
+
}
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakefileProjectGenerator.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakefileProjectGenerator.java
new file mode 100644
index 0000000000..69f6b544f4
--- /dev/null
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakefileProjectGenerator.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2017 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.cdt.make.core;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.cdt.core.CCProjectNature;
+import org.eclipse.cdt.core.CProjectNature;
+import org.eclipse.cdt.core.build.CBuilder;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.model.IPathEntry;
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.tools.templates.freemarker.FMProjectGenerator;
+import org.eclipse.tools.templates.freemarker.SourceRoot;
+import org.eclipse.tools.templates.freemarker.TemplateManifest;
+import org.osgi.framework.Bundle;
+
+/**
+ * Generator for Makefile projects.
+ *
+ * @since 7.4
+ */
+public class MakefileProjectGenerator extends FMProjectGenerator {
+
+ public MakefileProjectGenerator(String manifestPath) {
+ super(manifestPath);
+ }
+
+ @Override
+ protected Bundle getSourceBundle() {
+ return MakeCorePlugin.getDefault().getBundle();
+ }
+
+ @Override
+ protected void initProjectDescription(IProjectDescription description) throws CoreException {
+ description.setNatureIds(new String[] { CProjectNature.C_NATURE_ID, CCProjectNature.CC_NATURE_ID,
+ MakeProjectNature.NATURE_ID });
+ ICommand command = description.newCommand();
+ CBuilder.setupBuilder(command);
+ description.setBuildSpec(new ICommand[] { command });
+ }
+
+ @Override
+ public void generate(Map<String, Object> model, IProgressMonitor monitor) throws CoreException {
+ super.generate(model, monitor);
+
+ List<IPathEntry> entries = new ArrayList<>();
+ IProject project = getProject();
+
+ // Create the source and output folders
+ IFolder buildFolder = getProject().getFolder("build"); //$NON-NLS-1$
+
+ TemplateManifest manifest = getManifest();
+ if (manifest != null) {
+ List<SourceRoot> srcRoots = getManifest().getSrcRoots();
+ if (srcRoots != null && !srcRoots.isEmpty()) {
+ for (SourceRoot srcRoot : srcRoots) {
+ IFolder sourceFolder = project.getFolder(srcRoot.getDir());
+ if (!sourceFolder.exists()) {
+ sourceFolder.create(true, true, monitor);
+ }
+
+ entries.add(CoreModel.newSourceEntry(sourceFolder.getFullPath(),
+ new IPath[] { buildFolder.getFullPath() }));
+ }
+ } else {
+ entries.add(CoreModel.newSourceEntry(getProject().getFullPath()));
+ }
+ }
+
+ entries.add(CoreModel.newOutputEntry(buildFolder.getFullPath()));
+ CoreModel.getDefault().create(project)
+ .setRawPathEntries(entries.toArray(new IPathEntry[entries.size()]), monitor);
+ }
+
+}
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakefileBuildConfigurationProvider.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakefileBuildConfigurationProvider.java
new file mode 100644
index 0000000000..f820c4eb7e
--- /dev/null
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakefileBuildConfigurationProvider.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2017 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.cdt.make.internal.core;
+
+import org.eclipse.cdt.core.build.ICBuildConfiguration;
+import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
+import org.eclipse.cdt.core.build.ICBuildConfigurationProvider;
+import org.eclipse.cdt.core.build.IToolChain;
+import org.eclipse.cdt.core.build.StandardBuildConfiguration;
+import org.eclipse.cdt.make.core.MakeCorePlugin;
+import org.eclipse.core.resources.IBuildConfiguration;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class MakefileBuildConfigurationProvider implements ICBuildConfigurationProvider {
+
+ public static final String ID = "org.eclipse.cdt.make.core.provider"; //$NON-NLS-1$
+
+ @Override
+ public String getId() {
+ return ID;
+ }
+
+ @Override
+ public ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name)
+ throws CoreException {
+ return new StandardBuildConfiguration(config, name);
+ }
+
+ @Override
+ public ICBuildConfiguration createBuildConfiguration(IProject project, IToolChain toolChain,
+ String launchMode, IProgressMonitor monitor) throws CoreException {
+ ICBuildConfigurationManager configManager = MakeCorePlugin.getService(ICBuildConfigurationManager.class);
+
+ StringBuilder configName = new StringBuilder("make."); //$NON-NLS-1$
+ configName.append(launchMode);
+ String os = toolChain.getProperty(IToolChain.ATTR_OS);
+ if (os != null) {
+ configName.append('.');
+ configName.append(os);
+ }
+ String arch = toolChain.getProperty(IToolChain.ATTR_ARCH);
+ if (arch != null && !arch.isEmpty()) {
+ configName.append('.');
+ configName.append(arch);
+ }
+ String name = configName.toString();
+ int i = 0;
+ while (configManager.hasConfiguration(this, project, name)) {
+ name = configName.toString() + '.' + (++i);
+ }
+
+ IBuildConfiguration config = configManager.createBuildConfiguration(this, project, name, monitor);
+ StandardBuildConfiguration makeConfig = new StandardBuildConfiguration(config, name, toolChain,
+ launchMode);
+ configManager.addBuildConfiguration(config, makeConfig);
+ return makeConfig;
+ }
+
+}
diff --git a/build/org.eclipse.cdt.make.core/templates/simple/Makefile b/build/org.eclipse.cdt.make.core/templates/simple/Makefile
new file mode 100644
index 0000000000..02622849e1
--- /dev/null
+++ b/build/org.eclipse.cdt.make.core/templates/simple/Makefile
@@ -0,0 +1,12 @@
+OBJS = ${projectName}.o
+
+all: ${projectName}
+
+${projectName}: $(OBJS)
+ $(CC) -o $@ $^
+
+%.o: ../../%.cpp
+ $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
+
+clean:
+ rm -fr ${projectName} $(OBJS)
diff --git a/build/org.eclipse.cdt.make.core/templates/simple/main.cpp b/build/org.eclipse.cdt.make.core/templates/simple/main.cpp
new file mode 100644
index 0000000000..c493b4a556
--- /dev/null
+++ b/build/org.eclipse.cdt.make.core/templates/simple/main.cpp
@@ -0,0 +1,4 @@
+
+int main(int argc, char **argv) {
+ return 0;
+}
diff --git a/build/org.eclipse.cdt.make.core/templates/simple/manifest.xml b/build/org.eclipse.cdt.make.core/templates/simple/manifest.xml
new file mode 100644
index 0000000000..22491fe313
--- /dev/null
+++ b/build/org.eclipse.cdt.make.core/templates/simple/manifest.xml
@@ -0,0 +1,7 @@
+<templateManifest>
+ <file src="/templates/simple/Makefile"
+ dest="/${projectName}/Makefile"/>
+ <file src="/templates/simple/main.cpp"
+ dest="/${projectName}/${projectName}.cpp"
+ open="true"/>
+</templateManifest> \ No newline at end of file

Back to the top