diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CANBusExecutable.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CANBusExecutable.java index da9df20b2446a2cb1f73071693d3af093394504e..411383e8b4846c9a3b2e2df867cbe57e0cb5ef46 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CANBusExecutable.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/generator/executable/CANBusExecutable.java @@ -28,8 +28,6 @@ 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; import org.fortiss.af3.platform.raspberry.templates.RaspberryTemplateLoader; /** @@ -54,8 +52,9 @@ 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) { - createMakeFile(pack, "test_targetName"); - createMakeMK(pack); + createMakeFileUsingTemplate(pack, "test_targetName"); + // createMakeMK(pack); + createMakeMKUsingTemplate(pack); } @@ -63,25 +62,14 @@ public class CANBusExecutable extends TransmissionUnitExecutableBase<Transmissio * More elegant way of creating files but not working right now. Problem with the special * characters (i.e. $) in MakeFileTemplate.stg */ - private void createMakeFileUsingTemplate(SourcePackage pack) { - String content = RaspberryTemplateLoader.getMakeFileTemplate("test_executable").toString(); + private void createMakeFileUsingTemplate(SourcePackage pack, String exName) { + String content = RaspberryTemplateLoader.getMakeFileTemplate(exName).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)); - + private void createMakeMKUsingTemplate(SourcePackage pack) { + String content = RaspberryTemplateLoader.getMakeMkFileTemplate().toString(); + pack.addUnit(createStaticContentSourceUnit("make.mk", content, 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)); - - } } diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MakeFileTemplate.stg b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MakeFileTemplate.stg index 1cc051ce4e17220aa8d6d6404f9abd2ec87b6df5..dfd5b042b58691e6230056ccaaa59294d232f3b8 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MakeFileTemplate.stg +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MakeFileTemplate.stg @@ -4,11 +4,11 @@ MakeFileTemplate(binaryName) ::= << SHELL := /bin/bash -TARGET = $binary_name$ +TARGET = $binaryName$ -C_SRC := $(wildcard *.c) -CPP_SRC := $(wildcard *.cpp) -H_SRC := $(wildcard *.h) +C_SRC := \$(wildcard *.c) +CPP_SRC := \$(wildcard *.cpp) +H_SRC := \$(wildcard *.h) LIBRARY := INCLUDE_PATH := -I. LIBRARY_PATH := -L. @@ -26,82 +26,82 @@ 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)) +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 = \$(RAMDISK_DIR)/objs OBJ_DIR = objs -OBJS = $(addprefix $(OBJ_DIR)/, $(OBJECTS)) -DEPS = $(patsubst %.o, %.o.d, $(OBJS)) +OBJS = \$(addprefix \$(OBJ_DIR)/, \$(OBJECTS)) +DEPS = \$(patsubst %.o, %.o.d, \$(OBJS)) -all: $(TARGET) silent +all: \$(TARGET) silent #include all rules generated by gcc into the makefile --include $(DEPS) +-include \$(DEPS) #dummy target to that we don't get unnecessary mesages ( target is up to date & co) silent: @: -$(TARGET): $(OBJS) +\$(TARGET): \$(OBJS) @echo Linking - @$(CCXX) $(LD_FLAGS) $(LIBRARY_PATH) -o $(TARGET) $^ $(LIBRARY) + @\$(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: %.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 +\$(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) + @rm -rf \$(OBJ_DIR) @echo Removing target - @rm -f $(TARGET) + @rm -f \$(TARGET) #http://blog.jgc.org/2015/04/the-one-line-you-should-add-to-every.html -print-%: ; @echo $*=$($*) +print-%: ; @echo \$*=\$(\$*) test: - @echo $(@D) - @echo $(DEPS) - @echo $(OBJECTS2) + @echo \$(@D) + @echo \$(DEPS) + @echo \$(OBJECTS2) @echo Test - @echo $(C_SRC) + @echo \$(C_SRC) @echo Test - @echo $(H_SRC) + @echo \$(H_SRC) @echo Test - @echo $(LIBRARY) + @echo \$(LIBRARY) run: all - @./$(TARGET) + @./\$(TARGET) ramdisk: - sudo mkdir $(RAMDISK_DIR) - sudo mount -t tmpfs -o size=512m tmpfs $(RAMDISK_DIR) + sudo mkdir \$(RAMDISK_DIR) + sudo mount -t tmpfs -o size=512m tmpfs \$(RAMDISK_DIR) .PHONY: test deploy all ramdisk diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MakeMkTemplate.stg b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MakeMkTemplate.stg new file mode 100644 index 0000000000000000000000000000000000000000..568ca1451d8858709ceecf6191e19ffa413a0141 --- /dev/null +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/MakeMkTemplate.stg @@ -0,0 +1,14 @@ +group MakeMkTemplate; + +MakeMkTemplate() ::= << + +SELF_DIR = \$(dir \$(lastword \$(MAKEFILE_LIST))) +C_SRC += \$(wildcard \$(SELF_DIR)/*.c) +CPP_SRC += \$(wildcard \$(SELF_DIR)/*.cpp) +H_SRC += \$(wildcard \$(SELF_DIR)/*.h) +INCLUDE_PATH += \$ -I"\$(SELF_DIR)" +LIBRARY_PATH += #-L"\$(SELF_DIR)" +#include makefile fragments in subdirectories if they exist +-include \$(SELF_DIR)/*/make.mk + +>> \ No newline at end of file diff --git a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/RaspberryTemplateLoader.java b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/RaspberryTemplateLoader.java index c69487b222b7a2049179b1b1665298611d3c02bd..6b83a00441c6338df9326c7a9dbde77c7c89a97a 100644 --- a/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/RaspberryTemplateLoader.java +++ b/org.fortiss.af3.platform.raspberry/trunk/src/org/fortiss/af3/platform/raspberry/templates/RaspberryTemplateLoader.java @@ -62,6 +62,14 @@ public class RaspberryTemplateLoader { return template; } + /** Returns the Template of make.mk file for the Raspberry Platform. */ + public static StringTemplate getMakeMkFileTemplate() { + StringTemplate template = + loadResourceSTG(RaspberryTemplateLoader.class, "MakeMkTemplate").getInstanceOf( + "MakeMkTemplate"); + return template; + } + /** * @param string * @return