Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
231 lines (178 loc) · 6.19 KB
/
Copy pathMakefile
File metadata and controls
231 lines (178 loc) · 6.19 KB
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
T := $(dir $(lastword $(MAKEFILE_LIST)))
UNAME_S := $(shell uname -s)
-include local.mk
PLATFORM ?= host
# Set by platform .mk files (see include/mios/mcu_family.h); 0 = unknown.
MCU_FAMILY ?= 0
O ?= build.${PLATFORM}
# Base name for build artifacts. Apps set APPNAME so their outputs are
# self-describing (e.g. lynxpdu.elf / lynxpdu.debug / lynxpdu.bin); the
# bare kernel build falls back to "mios".
ifdef APPNAME
ARTIFACT := ${APPNAME}
else
ARTIFACT := mios
endif
.DEFAULT_GOAL := ${O}/${ARTIFACT}.elf
include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/mk/$(shell uname).mk
GLOBALDEPS += ${T}Makefile
SRC := ${T}src
MOS := ${O}/${T}src
#
# Include platform- (which in turn include CPU-) specific things
#
include ${SRC}/platform/${PLATFORM}/${PLATFORM}.mk
OPTLEVEL ?= 2
# Stack frame limit. MCU targets are tight; host overrides it.
FRAME_LIMIT ?= 192
CFLAGS += -Wframe-larger-than=${FRAME_LIMIT}
CFLAGS += ${CFLAGS-yes}
CFLAGS += -g3 -O${OPTLEVEL} -nostdinc -Wall -Werror -D__mios__
CPPFLAGS += -I${T}include -I${SRC} -I${O} -I${O}/include -include ${O}/include/config.h
# -n (nmagic) skips page alignment, right for MCU images. Host unsets it.
LD_NMAGIC ?= -n
LDFLAGS += -nostartfiles -nodefaultlibs ${CFLAGS} -lgcc ${LD_NMAGIC}
CFLAGS += -ffunction-sections -fdata-sections -Wno-attributes
LDFLAGS += -Wl,--gc-sections -Wl,--build-id=sha1
ifdef BTS
BUILD_TIMESTAMP := $(shell date "+%Y-%m-%d %H:%M:%S")
CFLAGS += -DMIOS_BUILD_TIMESTAMP="\"${BUILD_TIMESTAMP}\""
# Make sure the version.c gets recompiled for new timestamp
.PHONY: ${SRC}/version.c
endif
# Needed for linker script includes
LDFLAGS += -L${SRC}
#
# Various helpers
#
OR = $(if $(filter yes,$1),yes,no)
#
# Set defaults for all variables
#
ENABLE_SYSTIM ?= no
ENABLE_MATH ?= yes
ENABLE_TASK_WCHAN ?= yes
ENABLE_TASK_DEBUG ?= no
ENABLE_TASK_ACCOUNTING ?= yes
ENABLE_NET_CORE ?= no
ENABLE_NET_IPV4 ?= no
ENABLE_NET_RTP ?= no
ENABLE_NET_MBUS ?= no
ENABLE_NET_MBUS_GW ?= no
ENABLE_NET_BLE ?= no
ENABLE_BLE_INSECURE ?= no
ENABLE_BLE_CS ?= no
ENABLE_NET_CAN ?= no
ENABLE_NET_FPU_USAGE ?= no
ENABLE_METRIC ?= no
ENABLE_BUILTIN_BOOTLOADER ?= no
ENABLE_NET_TIMESTAMPING ?= no
ENABLE_PROFILE ?= no
ENABLE_PERFTEST ?= no
ENABLE_VCON ?= no
ENABLE_HEAP_MMAP ?= no
# The VLLP client role (vllp_client_create and friends). Only a client can
# establish a link and open channels, so a device that merely *serves*
# VLLP does not need it. Costs ~2 KB of flash and 48 bytes per link
# endpoint, and it cannot be linker-GC'd when compiled in because the
# client paths hang off the shared rx and timer callbacks.
ENABLE_VLLP_CLIENT ?= no
CONFIG_H := ${O}/include/config.h
#
# Core
#
include ${SRC}/kernel/kernel.mk
include ${SRC}/shell/shell.mk
include ${SRC}/lib/crypto/crypto.mk
include ${SRC}/lib/libc/libc.mk
include ${SRC}/lib/math/math.mk
include ${SRC}/lib/fixmath.mk
include ${SRC}/lib/littlefs.mk
include ${SRC}/lib/gui/gui.mk
include ${SRC}/lib/tig/tig.mk
include ${SRC}/lib/metric/metric.mk
include ${SRC}/lib/diag/diag.mk
include ${SRC}/lib/hw/hw.mk
include ${SRC}/lib/rpc/rpc.mk
include ${SRC}/drivers/drivers.mk
include ${SRC}/net/net.mk
include ${SRC}/util/util.mk
include ${SRC}/lib/usb/usb.mk
include ${T}/support/version/gitver.mk
ALL_ENABLE_VARS := $(filter ENABLE_%, $(.VARIABLES))
SRCS += ${SRC}/version.c
SRCS += ${SRCS-yes}
SRCS += ${SRCS-yes-yes}
SRCS := $(sort $(SRCS))
OBJS += ${SRCS:%.c=${O}/%.o}
OBJS := ${OBJS:%.s=${O}/%.o}
DEPS += ${OBJS:%.o=%.d}
# Full link, with symbols and debug info. Intermediate: not shipped, but
# kept (.PRECIOUS) so the debug sidecar and crc/img steps can feed off it.
${O}/${ARTIFACT}.full.elf: ${OBJS} ${GLOBALDEPS} ${LDSCRIPT} ${MIOSVER} ${APPVER}
@mkdir -p $(dir $@)
@echo "\tLINK\t$@"
${TOOLCHAIN}gcc -Wl,-T${LDSCRIPT} ${OBJS} -o $@ ${LDFLAGS}
${TOOLCHAIN}objcopy --update-section .miosversion=${MIOSVER} $@
ifdef APPNAME
${TOOLCHAIN}objcopy --update-section .appversion=${APPVER} $@
endif
# Detached debug symbols. Lives next to the stripped .elf; gdb/objdump
# resolve it via the .gnu_debuglink section embedded below.
${O}/${ARTIFACT}.debug: ${O}/${ARTIFACT}.full.elf
@echo "\tDEBUG\t$@"
${TOOLCHAIN}objcopy --only-keep-debug $< $@
# Default deliverable: fully stripped (no symtab, no DWARF), with a
# debuglink pointing back to the .debug sidecar by basename only.
${O}/${ARTIFACT}.elf: ${O}/${ARTIFACT}.full.elf ${O}/${ARTIFACT}.debug
@echo "\tSTRIP\t$@"
${TOOLCHAIN}strip -s -o $@ $<
${TOOLCHAIN}objcopy --add-gnu-debuglink=${O}/${ARTIFACT}.debug $@
${O}/${ARTIFACT}.bin: ${O}/${ARTIFACT}.elf
@echo "\tBIN\t$@"
${TOOLCHAIN}objcopy -O binary $< $@
${O}/%.o: %.c ${GLOBALDEPS} ${CONFIG_H} ${CDEPS} | toolchain
@mkdir -p $(dir $@)
@echo "\tCC\t$<"
${TOOLCHAIN}gcc -MD -MP ${CPPFLAGS} ${CFLAGS} -c $< -o $@
${O}/%.o: %.S ${GLOBALDEPS} ${CONFIG_H} | toolchain
@mkdir -p $(dir $@)
@echo "\tASM\t$<"
${TOOLCHAIN}gcc -MD -MP -DASM ${CPPFLAGS} ${CFLAGS} -c $< -o $@
HASH := \#
CONFIG_H_CONTENTS := $(foreach K,$(ALL_ENABLE_VARS), \
$(if $(subst no,,${${K}}),"${HASH}define ${K}\n",""))
${CONFIG_H}: ${GLOBALDEPS}
@mkdir -p $(dir $@)
@echo "\tGEN\t$@"
@echo >$@ ${CONFIG_H_CONTENTS}
@echo >>$@ "#define APPNAME \"${APPNAME}\""
@echo >>$@ "#define MCU_FAMILY ${MCU_FAMILY}"
clean::
rm -rf "${O}" build.host
bin: ${O}/${ARTIFACT}.bin
# Load firmware onto a target. Platform .mk files set FLASH_METHOD
# (jlink, dfu, openocd); auto probes for a J-Link, then falls back to DFU.
# Extra mios-flash options can be passed via FLASH_OPTS.
FLASH_METHOD ?= auto
flash: ${O}/${ARTIFACT}.elf
@${MAKE} --no-print-directory -C ${T}host/flash
${T}host/flash/mios-flash -m ${FLASH_METHOD} ${FLASH_OPTS} $<
toolchain:
@which >/dev/null ${TOOLCHAIN}gcc || \
(echo "\nERROR: Toolchain misconfigured, \
${TOOLCHAIN}gcc is not in path\n" && exit 1)
builtindefs:
${TOOLCHAIN}gcc ${CFLAGS} -dM -E - < /dev/null
build.host/cli_test: ${SRC}/shell/cli.c ${SRC}/shell/cli_edit.c ${SRC}/shell/cli_edit.h
@mkdir -p $(dir $@)
@echo "\tHOSTCC\t$@"
cc -DCLI_STANDALONE -O2 -Wall -Wextra -o $@ ${SRC}/shell/cli.c ${SRC}/shell/cli_edit.c
cli_test: build.host/cli_test
build.host/cli_test
cli_run: build.host/cli_test
build.host/cli_test -i
include ${SRC}/platform/platforms.mk
.PRECIOUS: ${O}/${ARTIFACT}.full.elf ${O}/${ARTIFACT}.debug
-include ${DEPS}
$(V).SILENT: