Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidated export templates for gcc_arm target and maintained purity of the source folders #1769

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions workspace_tools/export/gcc_arm_common.tmpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
# This file was automagically generated by mbed.org. For more information,
# see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded

ifeq ($(OS),Windows_NT)
MKDIR := mkdir
else
MKDIR := mkdir -p
endif

ifeq (,$(filter bin,$(notdir $(CURDIR))))
.SUFFIXES:
OBJDIR := bin
MAKETARGET = $(MAKE) --no-print-directory -C $@ -f $(CURDIR)/Makefile \
Copy link
Contributor

@adamgreen adamgreen Jun 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit hacky. Would it be better to add the bin/ prefix to your OBJECTS and switch to pattern based rules for compiling/assembling that take into account the slight difference in pathname? That way you don't need to recursively call make.

$(OBJDIR)/%.o: %.s
    @[ -d $(dir $@)] || $(MKDIR) $(dir $@)
    $(CC) $(CPU) -c -x assembler-with-cpp -o $@ $<

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that style of rules does have a drawback: any rule added to the makefile also has to have that style. On the other hand, the way I am recursively calling make has few drawbacks, as I remove all of the rules from the first invocation of make.

SRCDIR=$(CURDIR) $(MAKECMDGOALS)
.PHONY: $(OBJDIR) clean
$(OBJDIR):
+@[ -d $@ ] || $(MKDIR) $@
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the [ -d $@ ] || stuff here valid for Windows? That looks like a bash conditional to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is a bash conditional. do you know how to do the same thing on windows?

+@$(MAKETARGET)
Makefile : ;
% :: $(OBJDIR) ; :
clean :
rm -rf $(OBJDIR)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this clean target work on Windows? I would expect rd /s /q $(OBJDIR) to be used for Windows.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it works. You wont have to use rd since Atmel Studio comes with shellutils which in turn supports a list of commands for Linux.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akhilpanayamparambil Thanks. we need to assume also windows only. I'll give it a run in the cmd windows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably going to break horribly, I assumed bash was the shell make was running. I have to ask for my curiosity though: how does someone install make without bash?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gnu packages like make for windows :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well then. I'm all ears for suggestions regarding how to do an equivalent of [ -d $@ ] || mkdir -p $@ on windows. I'll just add it to the MKDIR variable.

{% block target_clean -%}
{% endblock %}
else

VPATH = $(SRCDIR)


GCC_BIN =
PROJECT = {{name}}
OBJECTS = {% for f in to_be_compiled %}{{f}} {% endfor %}
SYS_OBJECTS = {% for f in object_files %}{{f}} {% endfor %}
INCLUDE_PATHS = {% for p in include_paths %}-I{{p}} {% endfor %}
LIBRARY_PATHS = {% for p in library_paths %}-L{{p}} {% endfor %}
INCLUDE_PATHS = {% for p in include_paths %}-I../{{p}} {% endfor %}
LIBRARY_PATHS = {% for p in library_paths %}-L../{{p}} {% endfor %}
LIBRARIES = {% for lib in libraries %}-l{{lib}} {% endfor %}
LINKER_SCRIPT = {{linker_script}}
{%- block additional_variables -%}{% endblock %}
Expand Down Expand Up @@ -54,34 +80,34 @@ else
CC_FLAGS += -DNDEBUG -Os
endif

.PHONY: all clean lst size
.PHONY: all lst size

{% block target_all -%}
all: $(PROJECT).bin $(PROJECT).hex size
{% endblock %}

{% block target_clean -%}
clean:
rm -f $(PROJECT).bin $(PROJECT).elf $(PROJECT).hex $(PROJECT).map $(PROJECT).lst $(OBJECTS) $(DEPS)
{% endblock %}

.asm.o:
@[ -d $(dir $@)] || $(MKDIR) $(dir $@)
$(CC) $(CPU) -c -x assembler-with-cpp -o $@ $<
.s.o:
@[ -d $(dir $@)] || $(MKDIR) $(dir $@)
$(CC) $(CPU) -c -x assembler-with-cpp -o $@ $<
.S.o:
@[ -d $(dir $@)] || $(MKDIR) $(dir $@)
$(CC) $(CPU) -c -x assembler-with-cpp -o $@ $<

.c.o:
@[ -d $(dir $@)] || $(MKDIR) $(dir $@)
$(CC) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu99 $(INCLUDE_PATHS) -o $@ $<

.cpp.o:
@[ -d $(dir $@)] || $(MKDIR) $(dir $@)
$(CPP) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu++98 -fno-rtti $(INCLUDE_PATHS) -o $@ $<


{% block target_project_elf %}
$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS)
$(LD) $(LD_FLAGS) -T$(LINKER_SCRIPT) $(LIBRARY_PATHS) -o $@ $^ -Wl,--start-group $(LIBRARIES) $(LD_SYS_LIBS) -Wl,--end-group
$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) $(LINKER_SCRIPT)
$(LD) $(LD_FLAGS) -T$(filter-out %.o,$^) $(LIBRARY_PATHS) -o $@ $(filter %.o,$^) -Wl,--start-group $(LIBRARIES) $(LD_SYS_LIBS) -Wl,--end-group
{% endblock %}

$(PROJECT).bin: $(PROJECT).elf
Expand All @@ -103,3 +129,4 @@ DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d)

{% block additional_targets %}{% endblock %}

endif
115 changes: 0 additions & 115 deletions workspace_tools/export/gcc_arm_efm32_common.tmpl

This file was deleted.

9 changes: 8 additions & 1 deletion workspace_tools/export/gcc_arm_efm32gg_stk3700.tmpl
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{% extends "gcc_arm_efm32_common.tmpl" %}
{% extends "gcc_arm_common.tmpl" %}

{% block target_project_elf %} {{ super() }} @echo ""
@echo "*****"
@echo "***** You must modify vector checksum value in *.bin and *.hex files."
@echo "*****"
@echo ""
{%- endblock %}
9 changes: 8 additions & 1 deletion workspace_tools/export/gcc_arm_efm32hg_stk3400.tmpl
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{% extends "gcc_arm_efm32_common.tmpl" %}
{% extends "gcc_arm_common.tmpl" %}

{% block target_project_elf %} {{ super() }} @echo ""
@echo "*****"
@echo "***** You must modify vector checksum value in *.bin and *.hex files."
@echo "*****"
@echo ""
{%- endblock %}
9 changes: 8 additions & 1 deletion workspace_tools/export/gcc_arm_efm32lg_stk3600.tmpl
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{% extends "gcc_arm_efm32_common.tmpl" %}
{% extends "gcc_arm_common.tmpl" %}

{% block target_project_elf %} {{ super() }} @echo ""
@echo "*****"
@echo "***** You must modify vector checksum value in *.bin and *.hex files."
@echo "*****"
@echo ""
{%- endblock %}
9 changes: 8 additions & 1 deletion workspace_tools/export/gcc_arm_efm32pg_stk3401.tmpl
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{% extends "gcc_arm_efm32_common.tmpl" %}
{% extends "gcc_arm_common.tmpl" %}

{% block target_project_elf %} {{ super() }} @echo ""
@echo "*****"
@echo "***** You must modify vector checksum value in *.bin and *.hex files."
@echo "*****"
@echo ""
{%- endblock %}
9 changes: 8 additions & 1 deletion workspace_tools/export/gcc_arm_efm32wg_stk3800.tmpl
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{% extends "gcc_arm_efm32_common.tmpl" %}
{% extends "gcc_arm_common.tmpl" %}

{% block target_project_elf %} {{ super() }} @echo ""
@echo "*****"
@echo "***** You must modify vector checksum value in *.bin and *.hex files."
@echo "*****"
@echo ""
{%- endblock %}
9 changes: 8 additions & 1 deletion workspace_tools/export/gcc_arm_efm32zg_stk3200.tmpl
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{% extends "gcc_arm_efm32_common.tmpl" %}
{% extends "gcc_arm_common.tmpl" %}

{% block target_project_elf %} {{ super() }} @echo ""
@echo "*****"
@echo "***** You must modify vector checksum value in *.bin and *.hex files."
@echo "*****"
@echo ""
{%- endblock %}
75 changes: 3 additions & 72 deletions workspace_tools/export/gcc_arm_samd21g18a.tmpl
Original file line number Diff line number Diff line change
@@ -1,72 +1,3 @@
# This file was automagically generated by mbed.org. For more information,
# see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded

GCC_BIN =
PROJECT = {{name}}
OBJECTS = {% for f in to_be_compiled %}{{f}} {% endfor %}
SYS_OBJECTS = {% for f in object_files %}{{f}} {% endfor %}
INCLUDE_PATHS = {% for p in include_paths %}-I{{p}} {% endfor %}
LIBRARY_PATHS = {% for p in library_paths %}-L{{p}} {% endfor %}
LIBRARIES = {% for lib in libraries %}-l{{lib}} {% endfor %}
LINKER_SCRIPT = {{linker_script}}

###############################################################################
AS = $(GCC_BIN)arm-none-eabi-as
CC = $(GCC_BIN)arm-none-eabi-gcc
CPP = $(GCC_BIN)arm-none-eabi-g++
LD = $(GCC_BIN)arm-none-eabi-g++
OBJCOPY = $(GCC_BIN)arm-none-eabi-objcopy
OBJDUMP = $(GCC_BIN)arm-none-eabi-objdump
SIZE = $(GCC_BIN)arm-none-eabi-size

CPU = -mcpu=cortex-m0plus -mthumb
CC_FLAGS = $(CPU) -c -g -fno-common -fmessage-length=0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -fomit-frame-pointer
CC_FLAGS += -MMD -MP
CC_SYMBOLS = {% for s in symbols %}-D{{s}} {% endfor %}

LD_FLAGS = $(CPU) -Wl,--gc-sections --specs=nano.specs -u _printf_float -u _scanf_float -Wl,--wrap,main
LD_FLAGS += -Wl,-Map=$(PROJECT).map,--cref
LD_SYS_LIBS = -lstdc++ -lsupc++ -lm -lgcc -Wl,--start-group -lc -lc -lnosys -Wl,--end-group

ifeq ($(DEBUG), 1)
CC_FLAGS += -DDEBUG -O0
else
CC_FLAGS += -DNDEBUG -Os
endif

all: $(PROJECT).bin $(PROJECT).hex

clean:
rm -f $(PROJECT).bin $(PROJECT).elf $(PROJECT).hex $(PROJECT).map $(PROJECT).lst $(OBJECTS) $(DEPS)

.s.o:
$(AS) $(CPU) -o $@ $<

.c.o:
$(CC) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu99 $(INCLUDE_PATHS) -o $@ $<

.cpp.o:
$(CPP) $(CC_FLAGS) $(CC_SYMBOLS) -std=gnu++98 -fno-rtti $(INCLUDE_PATHS) -o $@ $<


$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS)
$(LD) $(LD_FLAGS) -T$(LINKER_SCRIPT) $(LIBRARY_PATHS) -o $@ $^ $(LIBRARIES) $(LD_SYS_LIBS) $(LIBRARIES) $(LD_SYS_LIBS)
$(SIZE) $@

$(PROJECT).bin: $(PROJECT).elf
@$(OBJCOPY) -O binary $< $@

$(PROJECT).hex: $(PROJECT).elf
@$(OBJCOPY) -O ihex $< $@

$(PROJECT).lst: $(PROJECT).elf
@$(OBJDUMP) -Sdh $< > $@

lst: $(PROJECT).lst

size:
$(SIZE) $(PROJECT).elf

DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d)
-include $(DEPS)

{% extends "gcc_arm_common.tmpl" %}
{% block cpu %} -mcpu=cortex-m0plus -mthumb {% endblock %}
{% block ld_sys_libs %}{{ super() }} -Wl,--start-group -lc -lc -lnosys -Wl,--end-group {% endblock %}
Loading