1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
#
# Copyright (c) 2014-2015 0xc0170
#
# 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.
# This project was exported via the project generator. More information https://github.com/project-generator/project_generator
CPU = {{core}}
# toolchain specific
TOOLCHAIN = {{toolchain}}
TOOLCHAIN_BINPATH = {{toolchain_bin_path}}
CC = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN){% block CC %}{% endblock %}
CXX = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN){% block CXX %}{% endblock %}
AS = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN){% block AS %}{% endblock %}
LD = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN){% block LD %}{% endblock %}
AR = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN){% block AR %}{% endblock %}
SIZE = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN)size
OBJCOPY = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN){% block OBJCOPY %}{% endblock %}
OBJDUMP = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN)objdump
NM = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN)nm
# application specific
INSTRUCTION_MODE = thumb
TARGET = {{name}}
{% if output_type == 'exe' %}
TARGET_EXT = .elf
{% else %}
TARGET_EXT = .a
{% endif %}
LD_SCRIPT = {{linker_file}}
CC_SYMBOLS = {% for symbol in macros %} -D{{symbol}} {% endfor %}
ASM_SYMBOLS = {% block ASM_SYMBOLS %}{% endblock %}
LIBS = {% for library in libraries %} -l{{library}} {% endfor %}
{% if standard_libraries %}
LIBS += -Wl,--start-group {% for library in standard_libraries %} -l{{library}} {% endfor %} -Wl,--end-group
{% endif %}
LIB_PATHS = {% for path in lib_paths %} -L{{path}} {% endfor %}
# directories
INC_DIRS = {% for path in include_paths %} {{path}} {% endfor %}
OUT_DIR = {{build_dir}}
INC_DIRS_F = -I. $(patsubst %, -I%, $(INC_DIRS))
SRC_DIRS = {% for path in source_paths %} {{path}} {% endfor %}
ifeq ($(strip $(OUT_DIR)), )
OBJ_FOLDER =
else
OBJ_FOLDER = $(strip $(OUT_DIR))/
endif
# Flags
COMMON_FLAGS = {% for option in common_flags %} {{option}} {% endfor %}
COMMON_FLAGS += {% block COMMON_FLAGS %}{% endblock %}
C_FLAGS = {% for option in c_flags %} {{option}} {% endfor %}
CXX_FLAGS = {% for option in cxx_flags %} {{option}} {% endfor %}
ASM_FLAGS = {% for option in asm_flags %} {{option}} {% endfor %}
CFLAGS = $(C_FLAGS) $(INC_DIRS_F) -c $(CC_SYMBOLS)
CXXFLAGS = $(CXX_FLAGS) $(INC_DIRS_F) -c $(CC_SYMBOLS)
ASFLAGS = $(ASM_FLAGS) $(INC_DIRS_F) -c $(ASM_SYMBOLS)
# Linker options
LD_OPTIONS += {% for option in ld_flags %} {{option}} {% endfor %}
LD_OPTIONS += {% block LD_OPTIONS %}{% endblock %}
OBJCPFLAGS = -O ihex
ARFLAGS = cr
ifeq ($(OS),Windows_NT)
RM = rmdir /s /q
else
RM = rm -rf
endif
C_SRCS := {% for file in source_files_c %} {{file}} {% endfor %}
C_OBJS := $(patsubst %.c,$(OBJ_FOLDER)%.o,$(notdir $(C_SRCS)))
CPP_SRCS := {% for file in source_files_cpp %} {{file}} {% endfor %}
CPP_OBJS := $(patsubst %.cpp,$(OBJ_FOLDER)%.o,$(notdir $(CPP_SRCS)))
S_SRCS := {% for file in source_files_s %} {{file}} {% endfor %}
S_OBJS = $(patsubst %.s,$(OBJ_FOLDER)%.o,$(filter %.s,$(notdir $(S_SRCS))))
S_OBJS += $(patsubst %.S,$(OBJ_FOLDER)%.o,$(filter %.S,$(notdir $(S_SRCS))))
O_OBJS := {% for file in source_files_obj %} {{file}} {% endfor %}
VPATH := $(SRC_DIRS)
$(OBJ_FOLDER)%.o : %.c
@echo 'Building file: $(@F)'
@echo 'Invoking: MCU C Compiler'
$(CC) $(CFLAGS) $(COMMON_FLAGS) $< -o $@
@echo 'Finished building: $(@F)'
@echo ' '
$(OBJ_FOLDER)%.o : %.cpp
@echo 'Building file: $(@F)'
@echo 'Invoking: MCU C++ Compiler'
$(CXX) $(CXXFLAGS) $(COMMON_FLAGS) $< -o $@
@echo 'Finished building: $(@F)'
@echo ' '
$(OBJ_FOLDER)%.o : %.s
@echo 'Building file: $(@F)'
@echo 'Invoking: MCU Assembler'
$(AS) $(ASFLAGS) $(COMMON_FLAGS) $< -o $@
@echo 'Finished building: $(@F)'
@echo ' '
PRE_BUILD_SCRIPT := $(shell{% for command in pre_build_script %} ../../../{{command}} && {% endfor %} true)
all: create_outputdir $(OBJ_FOLDER)$(TARGET)$(TARGET_EXT) print_info
{% for command in post_build_script %} ../../../{{command}} && {% endfor %} true
create_outputdir:
ifeq ($(OS),Windows_NT)
-mkdir $(OUT_DIR)
else
$(shell mkdir $(OBJ_FOLDER) 2>/dev/null)
endif
{% if output_type == 'exe' %}
# Tool invocations
$(OBJ_FOLDER)$(TARGET)$(TARGET_EXT): $(LD_SCRIPT) $(C_OBJS) $(CPP_OBJS) $(S_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: MCU Linker'
$(LD) $(LIB_PATHS) -o $@ $(CPP_OBJS) $(C_OBJS) $(S_OBJS) $(O_OBJS) $(LIBS) $(LD_OPTIONS)
@echo 'Finished building target: $@'
@echo ' '
print_info: $(OBJ_FOLDER)$(TARGET)$(TARGET_EXT)
@echo 'Printing size'
$(SIZE) --totals $(OBJ_FOLDER)$(TARGET)$(TARGET_EXT)
$(OBJCOPY) {% block TOHEX %}{% endblock %} $(OBJ_FOLDER)$(TARGET)$(TARGET_EXT) {% block objcopy_output %}{% endblock %} $(OBJ_FOLDER)$(TARGET).hex
$(OBJCOPY) {% block TOBIN %}{% endblock %} -v $(OBJ_FOLDER)$(TARGET)$(TARGET_EXT) {{ self.objcopy_output() }} $(OBJ_FOLDER)$(TARGET).bin
-$(OBJDUMP) -D $(OBJ_FOLDER)$(TARGET)$(TARGET_EXT) > $(OBJ_FOLDER)$(TARGET).lst
-$(NM) $(OBJ_FOLDER)$(TARGET)$(TARGET_EXT) > $(OBJ_FOLDER)$(TARGET)-symbol-table.txt
@echo ' '
{% else %}
$(OBJ_FOLDER)$(TARGET)$(TARGET_EXT): $(C_OBJS) $(CPP_OBJS) $(S_OBJS)
@echo 'Building library: $@'
$(AR) rcs $(OBJ_FOLDER)$(TARGET)$(TARGET_EXT) $(CPP_OBJS) $(C_OBJS) $(S_OBJS)
@echo 'Finished building library: $@'
@echo ' '
print_info: $(OBJ_FOLDER)$(TARGET)$(TARGET_EXT)
@echo 'Printing size'
$(SIZE) --totals $(OBJ_FOLDER)$(TARGET)$(TARGET_EXT)
@echo ' '
{% endif %}
# Other Targets
clean:
@echo 'Removing entire out directory'
$(RM) $(TARGET)$(TARGET_EXT) $(TARGET).bin $(TARGET).map $(OBJ_FOLDER)*.* $(OBJ_FOLDER)
@echo ' '
.PHONY: clean print_info
|