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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
|
#
# 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 %}
CPP = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN){% block CPP %}{% endblock %}
OBJCOPY = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN){% block OBJCOPY %}{% endblock %}
OBJDUMP = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN){% block OBJDUMP %}{% endblock %}
SIZE = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN){% block SIZE %}{% endblock %}
NM = $(TOOLCHAIN_BINPATH)$(TOOLCHAIN){% block NM %}{% endblock %}
# application specific
INSTRUCTION_MODE = thumb
TARGET = {{name}}
{% if output_type == 'exe' %}
TARGET_EXT = {% block TARGET_EXE_EXT %}{% endblock %}
# Executables also produce hex and binary outputs.
ALL_TARGET_OUT_FILES = $(TARGET_OUT) $(TARGET_HEX) $(TARGET_BIN)
{% else %}
TARGET_EXT = .a
ALL_TARGET_OUT_FILES = $(TARGET_OUT)
{% endif %}
TARGET_OUT = $(OBJ_FOLDER)$(TARGET)$(TARGET_EXT)
TARGET_HEX = $(OBJ_FOLDER)$(TARGET).hex
TARGET_BIN = $(OBJ_FOLDER)$(TARGET).bin
LINKER_EXT = {{linker_extension}}
{% if preprocess_linker_file %}
LD_SCRIPT_IN = {{linker_file}}
LD_SCRIPT = $(OUT_DIR)/$(TARGET).generated$(LINKER_EXT)
{% else %}
LD_SCRIPT = {{linker_file}}
{% endif %}
CC_SYMBOLS = {% for symbol in macros %} -D{{symbol}} {% endfor %}
ASM_SYMBOLS = {% block ASM_SYMBOLS %}{% endblock %}
{% block LIBS %}
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 %}
{% endblock %}
{% block LIB_PATHS %}
LIB_PATHS = {% for path in lib_paths %} -L{{path}} {% endfor %}
{% endblock %}
# 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 = {% block CFLAGS %}{% endblock %}
CXXFLAGS = {% block CXXFLAGS %}{% endblock %}
ASFLAGS = {% block ASFLAGS %}{% endblock %}
GENASMFLAGS = {% block GENASMFLAGS %}{% endblock %}
OBJDUMPFLAGS = {% block OBJDUMPFLAGS %}{% endblock %}
SIZEFLAGS = {% block SIZEFLAGS %}{% endblock %}
NMFLAGS = {% block NMFLAGS %}{% endblock %}
# Linker options
LD_OPTIONS += {% for option in ld_flags %} {{option}} {% endfor %}
LD_OPTIONS += {% block LD_OPTIONS %}{% endblock %}
# Flags to run only preprocessor
CPP_FLAGS = {% block CPP_FLAGS %}{% endblock %}
{% if preprocess_linker_file %}
# Flags to preprocess the linker script
LD_CPP_FLAGS = {% block LD_CPP_FLAGS %}{% endblock %}
{% endif %}
ARFLAGS = cr
ifeq ($(OS),Windows_NT)
RM = cmd /c rd /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 %}
ALL_OBJS := $(C_OBJS) \
$(CPP_OBJS) \
$(S_OBJS) \
$(O_OBJS)
VPATH := $(SRC_DIRS)
#-------------------------------------------------------------------------------
# Logging options
#-------------------------------------------------------------------------------
# Enable color output by default.
USE_COLOR ?= 1
# Normally, commands in recipes are prefixed with '@' so the command itself
# is not echoed by make. But if VERBOSE is defined (set to anything non-empty),
# then the '@' is removed from recipes. The 'at' variable is used to control
# this.
ifeq "$(VERBOSE)" "1"
at :=
else
at := @
endif
# These colors must be printed with the printf command. echo won't handle the
# escape sequences.
color_default = \033[00m
color_bold = \033[01m
color_red = \033[31m
color_green = \033[32m
color_yellow = \033[33m
color_blue = \033[34m
color_magenta = \033[35m
color_cyan = \033[36m
color_orange = \033[38;5;172m
color_light_blue = \033[38;5;039m
color_gray = \033[38;5;008m
color_purple = \033[38;5;097m
ifeq "$(USE_COLOR)" "1"
color_build := $(color_light_blue)
color_c := $(color_green)
color_cxx := $(color_green)
color_cpp := $(color_orange)
color_asm := $(color_magenta)
color_ar := $(color_yellow)
color_link := $(color_cyan)
color_convert := $(color_gray)
endif
# Used in printmessage if the color args are not present.
color_ :=
# Use in recipes to print color messages if printing to a terminal. If
# USE_COLOR is not set to 1, this reverts to a simple uncolorized printf.
# A newline is added to the end of the printed message.
#
# Arguments:
# 1 - name of the color variable (see above), minus the "color_" prefix
# 2 - first colorized part of the message
# 3 - first uncolorized part of the message
# 4 - color name for second colorized message
# 5 - second colorized message
# 6 - second uncolorized part of the message
# 7 - uncolorized prefix on the whole line; this is last because it is expected to be used rarely
#
# All arguments are optional.
#
# Use like:
# $(call printmessage,cyan,Building, remainder of the message...)
ifeq ($(OS),Windows_NT)
define printmessage
echo $(7)$(2)$(3)$(5)$(6)
endef
else
ifeq "$(USE_COLOR)" "1"
define printmessage
if [ -t 1 ]; then printf "$(7)$(color_$(1))$(2)$(color_default)$(3)$(color_$(4))$(5)$(color_default)$(6)\n" ; \
else printf "$(7)$(2)$(3)$(5)$(6)\n" ; fi
endef
else
define printmessage
printf "$(7)$(2)$(3)$(5)$(6)\n"
endef
endif
endif
#-------------------------------------------------------------------------------
# Recipes
#-------------------------------------------------------------------------------
{% block RECIPES %}
# Compile C sources.
$(OBJ_FOLDER)%.o : %.c
@$(call printmessage,c,Compiling, $<)
ifeq ($(GENERATE_ASSEMBLY),1)
$(at)$(CC) $(CFLAGS) $(GENASMFLAGS) $<
endif
$(at)$(CC) $(CFLAGS) $< -o $@
ifeq ($(DISASSEMBLE_OBJECTS),1)
$(at)$(OBJDUMP) $(OBJDUMPFLAGS) $@ {% block objdump_output %}{% endblock %} $(@:%.o=%.lst)
endif
# Compile C++ sources.
$(OBJ_FOLDER)%.o : %.cpp
@$(call printmessage,cxx,Compiling, $<)
ifeq ($(GENERATE_ASSEMBLY),1)
$(at)$(CXX) $(CFLAGS) $(GENASMFLAGS) $<
endif
$(at)$(CXX) $(CXXFLAGS) $< -o $@
ifeq ($(DISASSEMBLE_OBJECTS),1)
$(at)$(OBJDUMP) $(OBJDUMPFLAGS) $@ {{ self.objdump_output() }} $(@:%.o=%.lst)
endif
# Preprocess and assemble .S sources.
$(OBJ_FOLDER)%.o : %.S
@$(call printmessage,asm,Assembling, $<)
$(at)$(AS) $(ASFLAGS) $< -o $@
# Assemble .s sources.
$(OBJ_FOLDER)%.o : %.s
@$(call printmessage,asm,Assembling, $<)
$(at)$(AS) $(ASFLAGS) $< -o $@
{% endblock %}
#-------------------------------------------------------------------------------
# Rules
#-------------------------------------------------------------------------------
PRE_BUILD_SCRIPT :={% for command in pre_build_script %} \
$(shell {{output_dir.rel_path}}{{command}}){% endfor %}
all: $(ALL_TARGET_OUT_FILES){% for command in post_build_script %}
$(at)-{{output_dir.rel_path}}{{command}}{% endfor %}
# Make the build directory an order-only prerequisite for everything that goes in it.
$(ALL_TARGET_OUT_FILES) $(ALL_OBJS) $(LD_SCRIPT): | $(OUT_DIR)
$(OUT_DIR):
ifeq ($(OS),Windows_NT)
$(at)-mkdir $(OUT_DIR)
else
$(at)$(shell mkdir $(OBJ_FOLDER) 2>/dev/null)
endif
{% if output_type == 'exe' %}
# Tool invocations
{% if preprocess_linker_file %}
$(LD_SCRIPT): $(LD_SCRIPT_IN)
@$(call printmessage,cpp,Preprocessing, $<)
$(at)$(CPP) $(CPP_FLAGS) $(LD_CPP_FLAGS) $(INC_DIRS_F) $(CC_SYMBOLS) $< -o $@
{% endif %}
$(TARGET_OUT): $(LD_SCRIPT) $(C_OBJS) $(CPP_OBJS) $(S_OBJS)
@$(call printmessage,link,Linking, $@)
$(at)$(LD) $(LIB_PATHS) -o $@ $(CPP_OBJS) $(C_OBJS) $(S_OBJS) $(O_OBJS) $(LIBS) $(LD_OPTIONS)
$(at)$(SIZE) $(SIZEFLAGS) $(TARGET_OUT)
$(at)-$(NM) $(NMFLAGS) $(TARGET_OUT) {% block nm_output %}{% endblock %} $(OBJ_FOLDER)$(TARGET)-symbol-table.txt
$(TARGET_HEX): $(TARGET_OUT)
@$(call printmessage,convert,Converting, $@)
$(at)@$(OBJCOPY) {% block TOHEX %}{% endblock %} $(TARGET_OUT) {% block objcopy_output %}{% endblock %} $(TARGET_HEX)
$(TARGET_BIN): $(TARGET_OUT)
@$(call printmessage,convert,Converting, $@)
$(at)@$(OBJCOPY) {% block TOBIN %}{% endblock %} $(TARGET_OUT) {{ self.objcopy_output() }} $(TARGET_BIN)
{% else %}
$(TARGET_OUT): $(C_OBJS) $(CPP_OBJS) $(S_OBJS)
@$(call printmessage,ar,Archiving, $@)
$(at)$(AR) rcs $(TARGET_OUT) $(CPP_OBJS) $(C_OBJS) $(S_OBJS)
@$(SIZE) $(SIZEFLAGS) $(TARGET_OUT)
{% endif %}
# Other Targets
clean:
@echo 'Removing entire out directory'
ifeq ($(OS),Windows_NT)
$(at)-$(RM) $(subst /,\\,$(OBJ_FOLDER))
else
$(at)$(RM) $(OBJ_FOLDER)* $(OBJ_FOLDER)
endif
@echo ' '
help:
@echo "Useful targets:"
@echo " - all (default)"
@echo " - clean"
@echo " - help"
@echo
@echo "Options:"
@echo " - VERBOSE={0|1} to show full command lines."
@echo " - USE_COLOR={0|1} to override color output."
.PHONY: all clean help
# Include dependencies
-include $(ALL_OBJS:.o=.d)
{% if preprocess_linker_file %}
# Include the linker script dependencies
-include $(LD_SCRIPT:{{linker_extension}}=.d)
{% endif %}
|