-
Notifications
You must be signed in to change notification settings - Fork 128
/
config.mk.in
186 lines (166 loc) · 5.71 KB
/
config.mk.in
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
# Copyright (c) 2021, 2023, Niklas Hauser
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
profile?=release
BUILDPATH_PREFIX := {{ build_path }}/make-
BUILDPATH := $(BUILDPATH_PREFIX)$(profile)
OUTPATH := {{outpath}}
MODM_PROJECT_NAME := {{ options[":build:project.name"] }}
PYTHON3 := PYTHONPATH=$(MODM_PATH) python3
ELF_FILE := $(BUILDPATH)/$(MODM_PROJECT_NAME).{{program_extension}}
BIN_FILE := $(BUILDPATH)/$(MODM_PROJECT_NAME).bin
HEX_FILE := $(BUILDPATH)/$(MODM_PROJECT_NAME).hex
LSS_FILE := $(BUILDPATH)/$(MODM_PROJECT_NAME).lss
MAP_FILE := $(BUILDPATH)/$(MODM_PROJECT_NAME).map
UF2_FILE := $(BUILDPATH)/$(MODM_PROJECT_NAME).uf2
CLEAN_FILES += $(BUILDPATH)
# Device configuration
CONFIG_DEVICE_NAME := {{ partname }}
%% if memories | length
CONFIG_DEVICE_MEMORY := "{{ memories }}"
%% endif
%% if core.startswith("avr")
CONFIG_AVRDUDE_DEVICE := {{ mcu }}
%% if avrdude_programmer
CONFIG_AVRDUDE_PROGRAMMER := -c {{ avrdude_programmer }}
%% endif
%% if avrdude_port
CONFIG_AVRDUDE_PORT := {{ avrdude_port }}
%% endif
%% if avrdude_options
CONFIG_AVRDUDE_OPTIONS := {{ avrdude_options }}
%% endif
%% if avrdude_baudrate
CONFIG_AVRDUDE_BAUDRATE := -b {{ avrdude_baudrate }}
%% endif
%% elif core.startswith("cortex-m")
MODM_OPENOCD_CONFIGFILES += $(MODM_PATH)/openocd.cfg
MODM_JLINK_DEVICE = "{{ jlink_partname }}"
MODM_GDB_COMMANDS = -x $(MODM_PATH)/gdbinit -ex "dir $(GCC_BASE)" -ex "modm_setup_tui"
MODM_GDB_COMMANDS_OPENOCD = -x $(MODM_PATH)/gdbinit_openocd
MODM_GDB_COMMANDS_JLINK = -x $(MODM_PATH)/gdbinit_jlink
MODM_GDB_COMMANDS_BMP = -x $(MODM_PATH)/gdbinit_bmp
CONFIG_FLASH_OFFSET := {{ flash_offset }}
CONFIG_FLASH_ADDRESS := {{ flash_address }}
%% if platform == "sam"
%% if bossac_offset
MODM_BOSSAC_OFFSET := {{ bossac_offset }}
%% endif
%% if bossac_options
MODM_BOSSAC_OPTIONS := {{ bossac_options }}
%% endif
%% endif
%% endif
%#
include $(MODM_PATH)/compiler.mk
# Application sources
APP_SRC := $(APP_SRC:./%=%)
%% for repo in repositories
APP_SRC := $(filter-out {{ repo | relocate }}/%,$(APP_SRC))
%% endfor
CPPDEFINES += -I.
%% if options["::info.git"] != "Disabled"
%#
# Git information
INFO_GIT_FILE := $(MODM_PATH)/src/info_git.c
$(INFO_GIT_FILE): $(shell $(PYTHON3) -m modm_tools.info \
-o $(INFO_GIT_FILE) -t {{ "git_status" if "Status" in options["::info.git"] else "git" }} --check-rebuild);
APP_SRC += $(INFO_GIT_FILE)
CLEAN_FILES += $(INFO_GIT_FILE)
CPPDEFINES += -DMODM_GIT_INFO{% if "Status" in options["::info.git"] %} -DMODM_GIT_STATUS{% endif %}
%% endif
%% if options["::info.build"]
%#
# Build information
INFO_BUILD_FILE := $(MODM_PATH)/src/info_build.c
$(INFO_BUILD_FILE):
@$(PYTHON3) -m modm_tools.info -o $(INFO_BUILD_FILE) -t build --compiler $(CC) \
--additions MODM_BUILD_PROJECT_NAME="$(MODM_PROJECT_NAME)"
APP_SRC += $(INFO_BUILD_FILE)
CLEAN_FILES += $(INFO_BUILD_FILE)
CPPDEFINES += -DMODM_BUILD_INFO
%% endif
%% if options["::image.source"]
%#
# Image generator
IMAGE_SOURCE := {{image_source}}
.PRECIOUS: $(IMAGE_SOURCE)/%.cpp
$(IMAGE_SOURCE)/%.cpp: $(IMAGE_SOURCE)/%.pbm
@$(PYTHON3) -m modm_tools.bitmap $^ -o $(dir $^)
IMAGE_PBM := $(wildcard $(IMAGE_SOURCE)/*.pbm)
APP_SRC += $(IMAGE_PBM:.pbm=.cpp)
CPPDEFINES += -I$(IMAGE_SOURCE)
CLEAN_FILES += $(IMAGE_PBM:.pbm=.cpp) $(IMAGE_PBM:.pbm=.hpp)
%% endif
%#
# Application objects
APP_OBJS := $(addprefix $(BUILDPATH)/,$(APP_SRC))
%% for suffix in ["cpp", "cxx", "c++", "cc", "c", "sx", "s", "S"]
APP_OBJS := $(APP_OBJS:.{{suffix}}=.o)
%% endfor
LIBRARIES :={% for repo in repositories %} $(BUILDPATH)/{{repo}}/lib{{repo}}.a{% endfor %}
# Application linking
.PRECIOUS: $(BUILDPATH)/%.{{program_extension}}
$(BUILDPATH)/%.{{program_extension}}: $(APP_OBJS) $(LIBRARIES){% if platform != "hosted" %} {{ linkerscript | relocate }}{% endif %}
@echo "Linking········" $@
@$(CXX) -o $@ $(LINKFLAGS) $(filter %.o,$^) $(LIBPATH) \
%% if platform != "hosted"
-Wl,--whole-archive -Wl,--start-group $(LIBS) -Wl,--end-group -Wl,--no-whole-archive
%% else
$(LIBS)
%% endif
%#
# Compiler invocations, -MMD is for header dependency tracking
compile_c = \
echo "Compiling C····" $(subst $(BUILDPATH_PREFIX),,$1); \
mkdir -p $(dir $1); \
$(CC) -MMD -o $1 -c $(CFLAGS) $(CCFLAGS) $(CPPDEFINES) $3 $2
compile_cpp = \
echo "Compiling C++··" $(subst $(BUILDPATH_PREFIX),,$1); \
mkdir -p $(dir $1); \
$(CXX) -MMD -o $1 -c $(CXXFLAGS) $(CCFLAGS) $(CPPDEFINES) $3 $2
compile_asm = \
echo "Assembling·····" $(subst $(BUILDPATH_PREFIX),,$1); \
mkdir -p $(dir $1); \
$(CXX) -MMD -o $1 -c $(ASFLAGS) $(CPPDEFINES) $3 $2
# Build rules with relocation
.PRECIOUS: $(BUILDPATH)/%.o $(BUILDPATH)/%.a
$(BUILDPATH)/%.o : %.c
@$(call compile_c,$@,$<,)
%% if outpath != "."
$(BUILDPATH)/%.o : $(OUTPATH)/%.c
@$(call compile_c,$@,$<,)
%% endif
%% for suffix in ["cc", "cpp", "cxx", "c++"]
$(BUILDPATH)/%.o : %.{{suffix}}
@$(call compile_cpp,$@,$<,)
%% if outpath != "."
$(BUILDPATH)/%.o : $(OUTPATH)/%.{{suffix}}
@$(call compile_cpp,$@,$<,)
%% endif
%% endfor
%% for suffix in ["sx", "s", "S"]
$(BUILDPATH)/%.o : %.{{suffix}}
@$(call compile_asm,$@,$<,)
%% if outpath != "."
$(BUILDPATH)/%.o : $(OUTPATH)/%.{{suffix}}
@$(call compile_asm,$@,$<,)
%% endif
%% endfor
%#
.PRECIOUS: $(BUILDPATH)/%.bin
$(BUILDPATH)/%.bin: $(BUILDPATH)/%.{{program_extension}}
@echo "Binary File····" $@
@$(OBJCOPY) -O binary $< $@
.PRECIOUS: $(BUILDPATH)/%.hex
$(BUILDPATH)/%.hex: $(BUILDPATH)/%.{{program_extension}}
@echo "Hex File·······" $@
@$(OBJCOPY) -O ihex $< $@
.PRECIOUS: $(BUILDPATH)/%.lss
$(BUILDPATH)/%.lss: $(BUILDPATH)/%.{{program_extension}}
@echo "Listing········" $@
@$(OBJDUMP) -x -S -l -w $< > $@