mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Created a much simpler Gnu Makefile project template.
This commit is contained in:
parent
fa349eca76
commit
eca6010779
6 changed files with 148 additions and 15 deletions
|
@ -10,5 +10,6 @@ Export-Package: org.eclipse.cdt.managedbuilder.gnu.cygwin,
|
||||||
org.eclipse.cdt.managedbuilder.gnu.ui
|
org.eclipse.cdt.managedbuilder.gnu.ui
|
||||||
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
|
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
|
||||||
org.eclipse.cdt.managedbuilder.core;bundle-version="[4.0.0,5.0.0)",
|
org.eclipse.cdt.managedbuilder.core;bundle-version="[4.0.0,5.0.0)",
|
||||||
org.eclipse.cdt.core;bundle-version="[4.0.0,5.0.0)"
|
org.eclipse.cdt.core;bundle-version="[4.0.0,5.0.0)",
|
||||||
|
org.eclipse.core.resources
|
||||||
Eclipse-LazyStart: true
|
Eclipse-LazyStart: true
|
||||||
|
|
|
@ -3792,5 +3792,15 @@
|
||||||
<toolChain id="cdt.managedbuild.toolchain.gnu.solaris.base"/>
|
<toolChain id="cdt.managedbuild.toolchain.gnu.solaris.base"/>
|
||||||
</template>
|
</template>
|
||||||
</extension>
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.cdt.core.templateProcessTypes">
|
||||||
|
<processType
|
||||||
|
name="SimpleGNUMakefileGenerator"
|
||||||
|
processRunner="org.eclipse.cdt.managedbuilder.gnu.templates.SimpleMakefileGenerator">
|
||||||
|
<simple
|
||||||
|
name="projectName">
|
||||||
|
</simple>
|
||||||
|
</processType>
|
||||||
|
</extension>
|
||||||
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2007 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
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* QNX Software Systems - Initial API and implementation
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.managedbuilder.gnu.templates;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.templateengine.TemplateCore;
|
||||||
|
import org.eclipse.cdt.core.templateengine.TemplateEngineHelper;
|
||||||
|
import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
|
||||||
|
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
|
||||||
|
import org.eclipse.cdt.core.templateengine.process.ProcessHelper;
|
||||||
|
import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
|
||||||
|
import org.eclipse.cdt.core.templateengine.process.processes.Messages;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Doug Schaefer
|
||||||
|
*
|
||||||
|
* TODO - this is necessitated because the default macro format for
|
||||||
|
* the template engine is $( and ) which is the same as make macros.
|
||||||
|
* This replaces that with something more make friendly.
|
||||||
|
*
|
||||||
|
* But at the end of they day, we need a real macro replacement engine
|
||||||
|
* like JET, or something...
|
||||||
|
*/
|
||||||
|
public class SimpleMakefileGenerator extends ProcessRunner {
|
||||||
|
|
||||||
|
private static final String MAKEFILE = "Makefile"; //$NON-NLS-1$
|
||||||
|
public void process(TemplateCore template, ProcessArgument[] args,
|
||||||
|
String processId, IProgressMonitor monitor)
|
||||||
|
throws ProcessFailureException {
|
||||||
|
String projectName = args[0].getSimpleValue();
|
||||||
|
|
||||||
|
IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
|
||||||
|
URL path;
|
||||||
|
try {
|
||||||
|
path = TemplateEngineHelper.getTemplateResourceURLRelativeToTemplate(template, MAKEFILE);
|
||||||
|
if (path == null) {
|
||||||
|
throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.0") + MAKEFILE)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
} catch (IOException e1) {
|
||||||
|
throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.1") + MAKEFILE)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
InputStream contents = null;
|
||||||
|
String fileContents;
|
||||||
|
try {
|
||||||
|
fileContents = ProcessHelper.readFromFile(path);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.2") + MAKEFILE)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
|
||||||
|
Map macros = new HashMap(template.getValueStore());
|
||||||
|
if (Platform.getOS().equals(Platform.OS_WIN32))
|
||||||
|
macros.put("exe", ".exe");
|
||||||
|
|
||||||
|
fileContents = replaceMacros(fileContents, macros);
|
||||||
|
contents = new ByteArrayInputStream(fileContents.getBytes());
|
||||||
|
|
||||||
|
try {
|
||||||
|
IFile iFile = projectHandle.getFile(MAKEFILE);
|
||||||
|
if (!iFile.getParent().exists()) {
|
||||||
|
ProcessHelper.mkdirs(projectHandle, projectHandle.getFolder(iFile.getParent().getProjectRelativePath()));
|
||||||
|
}
|
||||||
|
iFile.create(contents, true, null);
|
||||||
|
iFile.refreshLocal(IResource.DEPTH_ONE, null);
|
||||||
|
projectHandle.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
throw new ProcessFailureException(getProcessMessage(processId, IStatus.ERROR, Messages.getString("AddFile.4") + e.getMessage()), e); //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String START = "{{";
|
||||||
|
private static final String END = "}}";
|
||||||
|
|
||||||
|
private String replaceMacros(String fileContents, Map valueStore) {
|
||||||
|
StringBuffer buffer = new StringBuffer(fileContents);
|
||||||
|
for (Iterator i = valueStore.keySet().iterator(); i.hasNext();) {
|
||||||
|
String key = (String)i.next();
|
||||||
|
String pattern = START + key +END;
|
||||||
|
if (!fileContents.contains(pattern))
|
||||||
|
// Not used
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// replace
|
||||||
|
int len = pattern.length();
|
||||||
|
int pos = 0;
|
||||||
|
while ((pos = buffer.indexOf(pattern, pos)) >= 0) {
|
||||||
|
buffer.replace(pos, pos + len, (String)valueStore.get(key));
|
||||||
|
pos += len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
CFLAGS = -O2 -g -Wall -fmessage-length=0
|
||||||
|
CXXFLAGS = -O2 -g -Wall -fmessage-length=0
|
||||||
|
|
||||||
|
OBJS = {{baseName}}.o
|
||||||
|
|
||||||
|
LIBS =
|
||||||
|
|
||||||
|
TARGET = {{baseName}}{{exe}}
|
||||||
|
|
||||||
|
$(TARGET): $(OBJS)
|
||||||
|
$(CC) -o $(TARGET) $(OBJS) $(LIBS)
|
||||||
|
|
||||||
|
all: $(TARGET)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJS) $(TARGET)
|
|
@ -30,29 +30,18 @@
|
||||||
persist="true"/>
|
persist="true"/>
|
||||||
</property-group>
|
</property-group>
|
||||||
|
|
||||||
<!--process type="org.eclipse.cdt.managedbuilder.core.NewManagedProject">
|
|
||||||
<simple name="name" value="$(projectName)" />
|
|
||||||
<simple name="artifactExtension" value="exe" />
|
|
||||||
<simple name="isCProject" value="true" />
|
|
||||||
</process-->
|
|
||||||
|
|
||||||
<process type="org.eclipse.cdt.core.CreateSourceFolder">
|
|
||||||
<simple name="projectName" value="$(projectName)"/>
|
|
||||||
<simple name="path" value="src"/>
|
|
||||||
</process>
|
|
||||||
|
|
||||||
<process type="org.eclipse.cdt.core.AddFiles">
|
<process type="org.eclipse.cdt.core.AddFiles">
|
||||||
<simple name="projectName" value="$(projectName)"/>
|
<simple name="projectName" value="$(projectName)"/>
|
||||||
<complex-array name="files">
|
<complex-array name="files">
|
||||||
<element>
|
<element>
|
||||||
<simple name="source" value="src/Basename.cpp"/>
|
<simple name="source" value="Basename.cpp"/>
|
||||||
<simple name="target" value="src/$(projectName).cpp"/>
|
<simple name="target" value="$(projectName).cpp"/>
|
||||||
<simple name="replaceable" value="true"/>
|
<simple name="replaceable" value="true"/>
|
||||||
</element>
|
</element>
|
||||||
</complex-array>
|
</complex-array>
|
||||||
</process>
|
</process>
|
||||||
|
|
||||||
<process type="org.eclipse.cdt.managedbuilder.core.GenerateMakefileWithBuildDescription">
|
<process type="org.eclipse.cdt.managedbuilder.gnu.ui.SimpleGNUMakefileGenerator">
|
||||||
<simple name="projectName" value="$(projectName)"/>
|
<simple name="projectName" value="$(projectName)"/>
|
||||||
</process>
|
</process>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue