Skip to content
Snippets Groups Projects
Commit a3a62d90 authored by Sergey Zverlov's avatar Sergey Zverlov
Browse files

templates for file generation

refs 2505
parent a593e7ff
No related branches found
No related tags found
No related merge requests found
Showing with 334 additions and 2 deletions
......@@ -14,7 +14,7 @@ Require-Bundle: org.fortiss.af3.project,
org.eclipse.emf.ecore;visibility:=reexport,
org.eclipse.emf.ecore.xmi;visibility:=reexport,
org.fortiss.tooling.kernel;visibility:=reexport,
org.fortiss.af3.platform;bundle-version="2.5.0",
org.fortiss.af3.platform;bundle-version="2.5.0";visibility:=reexport,
org.fortiss.tooling.base;visibility:=reexport,
org.fortiss.af3.expression,
org.eclipse.jface;bundle-version="3.9.1"
......
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2016 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generated.files;
/**
*
* @author zverlov
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class RaspberryMakeMKGeneration {
/** Contents of make.mk. */
private String content;
/** Constructor. */
public RaspberryMakeMKGeneration() {
this.content = "";
}
/** Main methods for creation of make.mk. */
public void createMakeMK() {
// TODO: needs to be implemented
}
/** Return content. */
public String getContent() {
return this.content;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2016 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generated.files;
/**
*
* @author zverlov
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class RaspberryMakefileGeneration {
/** The name of the executable. */
private String binaryTargetName;
/** Contents of the Makefile. */
private String content;
/** Constructor. */
public RaspberryMakefileGeneration(String targetName) {
this.binaryTargetName = targetName;
this.content = "";
}
/** Calls the methods that create the Makefile. */
public void createMakefile() {
// TODO: needs to be implemented
printFirstTwoLines();
// ....
}
/** This methods is only an example. */
private void printFirstTwoLines() {
content += "SHELL := /bin/bash" + "\n\n";
content += "TARGET = " + binaryTargetName + "\n";
}
/** Return the current content of the Makefile. */
public String getContent() {
return this.content;
}
}
......@@ -17,6 +17,8 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.generator.executable;
import static org.fortiss.af3.generator.common.utils.SourceModelElementFactory.createStaticContentSourceUnit;
import java.util.List;
import java.util.Map;
......@@ -26,6 +28,8 @@ import org.fortiss.af3.generator.common.model.source.SourcePackage;
import org.fortiss.af3.platform.language.executable.TransmissionUnitExecutableBase;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.af3.platform.model.TransmissionUnit;
import org.fortiss.af3.platform.raspberry.generated.files.RaspberryMakeMKGeneration;
import org.fortiss.af3.platform.raspberry.generated.files.RaspberryMakefileGeneration;
/**
*
......@@ -49,8 +53,30 @@ public class CANBusExecutable extends TransmissionUnitExecutableBase<Transmissio
public void createAllFiles(SourcePackage pack, Map<ExecutionUnit, List<Port>> euPortsPair,
Map<ExecutionUnit, List<Component>> euComponentList, Component topComponent,
int deploymentID) {
// TODO Auto-generated method stub
createMakeFile(pack, "test_targetName");
createMakeMK(pack);
}
// private void createMakeFile(SourcePackage pack) {
// String content = RaspberryTemplateLoader.getMakeFileTemplate("test_executable").toString();
// pack.addUnit(createStaticContentSourceUnit("Makefile", content, false));
// }
/** Creates a Makefile for an executable with a certain targetname. */
private void createMakeFile(SourcePackage pack, String targetname) {
RaspberryMakefileGeneration rspMakefileGen = new RaspberryMakefileGeneration(targetname);
rspMakefileGen.createMakefile();
pack.addUnit(createStaticContentSourceUnit("Makefile", rspMakefileGen.getContent(), false));
}
/** Creates the make.mk file. */
private void createMakeMK(SourcePackage pack) {
// TODO: needs to be implemented similar to createMakeFile methods
RaspberryMakeMKGeneration rspMakeMK = new RaspberryMakeMKGeneration();
rspMakeMK.createMakeMK();
pack.addUnit(createStaticContentSourceUnit("make.mk", rspMakeMK.getContent(), false));
}
}
group MainFileTemplate;
MainFileTemplate(headerFile) ::= <<
#include "$headerFile$"
int main(int argc, char *argv[]) {
initialize_ports();
initialize_system();
while (1) {
run_system();
}
}
>>
\ No newline at end of file
group MakeFileTemplate;
MakeFileTemplate(binaryName) ::= <<
SHELL := /bin/bash
TARGET = $binary_name$
C_SRC := $(wildcard *.c)
CPP_SRC := $(wildcard *.cpp)
H_SRC := $(wildcard *.h)
LIBRARY :=
INCLUDE_PATH := -I.
LIBRARY_PATH := -L.
CC = gcc
CC_FLAGS = -Wall -O3 -Wno-unused-variable
CCXX = g++
CCXX_FLAGS = -Wall -O3 -Wno-unused-variable
LIBRARY := -lwiringPi -lwiringPiDev
LD = ld
LD_FLAGS =
#include makefile fragments in subdirectories if they exist
-include ./*/make.mk
OBJECTS = $(patsubst %.c, %.o, $(C_SRC))
OBJECTS += $(patsubst %.cpp, %.o, $(CPP_SRC))
RAMDISK_DIR = /mnt/ramdisk
# make ramdisj target creates and mounts a tempfs drive
#OBJ_DIR = $(RAMDISK_DIR)/objs
OBJ_DIR = objs
OBJS = $(addprefix $(OBJ_DIR)/, $(OBJECTS))
DEPS = $(patsubst %.o, %.o.d, $(OBJS))
all: $(TARGET) silent
#include all rules generated by gcc into the makefile
-include $(DEPS)
#dummy target to that we don't get unnecessary mesages ( target is up to date & co)
silent:
@:
$(TARGET): $(OBJS)
@echo Linking
@$(CCXX) $(LD_FLAGS) $(LIBRARY_PATH) -o $(TARGET) $^ $(LIBRARY)
#create output directory if it doesn't exist
#generate dependency file for current file
# .o and .d are targets of the rule
# create blank targets for each source/header file. Used to update .d files when you delete a file
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(@D)
@echo Building $<
@$(CC) $(CC_FLAGS) $(INCLUDE_PATH) $(ARGS) -c $< -o $@
@echo -n "$@.d $(@D)/" > $@.d
@$(CC) $(CC_FLAGS) $(INCLUDE_PATH) $(ARGS) -MM $< >> $@.d
@cp $@.d $<.tp
@sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $<.tp >> $@.d
@rm -f $<.tp
$(OBJ_DIR)/%.o: %.cpp
@mkdir -p $(@D)
@echo Building $<
@$(CCXX) $(CCXX_FLAGS) $(INCLUDE_PATH) $(ARGS) -c $< -o $@
@echo -n "$@.d $(@D)/" > $@.d
@$(CCXX) $(CCXX_FLAGS) $(INCLUDE_PATH) $(ARGS) -MM $< >> $@.d
@cp $@.d $<.tp
@sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $<.tp >> $@.d
@rm -f $<.tp
clean:
@echo Removing objects directory
@rm -rf $(OBJ_DIR)
@echo Removing target
@rm -f $(TARGET)
#http://blog.jgc.org/2015/04/the-one-line-you-should-add-to-every.html
print-%: ; @echo $*=$($*)
test:
@echo $(@D)
@echo $(DEPS)
@echo $(OBJECTS2)
@echo Test
@echo $(C_SRC)
@echo Test
@echo $(H_SRC)
@echo Test
@echo $(LIBRARY)
run: all
@./$(TARGET)
ramdisk:
sudo mkdir $(RAMDISK_DIR)
sudo mount -t tmpfs -o size=512m tmpfs $(RAMDISK_DIR)
.PHONY: test deploy all ramdisk
>>
\ No newline at end of file
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2016 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.platform.raspberry.templates;
import static org.fortiss.af3.generator.common.AF3GeneratorCommonActivator.getDefault;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.io.IOException;
import java.io.InputStreamReader;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.antlr.stringtemplate.language.DefaultTemplateLexer;
/**
*
* @author zverlov
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class RaspberryTemplateLoader {
/**
* @param contextClass
* @param stgName
* @return the string template group for a given context class and template group name
*/
public static StringTemplateGroup loadResourceSTG(Class<?> contextClass, String stgName) {
InputStreamReader in =
new InputStreamReader(contextClass.getResourceAsStream(stgName +
(stgName.contains(".") ? "" : ".stg")));
StringTemplateGroup templates = new StringTemplateGroup(in, DefaultTemplateLexer.class);
try {
in.close();
} catch(IOException e) {
error(getDefault(), "AF3 generator could not load stringtemplate " + stgName + ".", e);
}
return templates;
}
/** Returns the Template of a Makefile for the Raspberry Platform. */
public static StringTemplate getMakeFileTemplate(String binaryName) {
StringTemplate template =
loadResourceSTG(RaspberryTemplateLoader.class, "MakeFileTemplate").getInstanceOf(
"MakeFileTemplate");
template.setAttribute("binaryName", binaryName);
return template;
}
/**
* @param string
* @return
*/
public static StringTemplate getMainFileTemplate(String headerFile) {
StringTemplate template =
loadResourceSTG(RaspberryTemplateLoader.class, "MainFileTemplate").getInstanceOf(
"MainFileTemplate");
template.setAttribute("headerFile", headerFile);
return template;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment