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

makefile and make.mk are created using template

refs 2505
parent 0fd6c2e8
No related branches found
No related tags found
No related merge requests found
......@@ -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));
}
}
......@@ -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
......
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
......@@ -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
......
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