-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
285 lines (241 loc) · 8.12 KB
/
Makefile
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
# 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/.
# Turn on increased build verbosity by using V=1 on the make command line.
ifeq ("$(origin V)", "command line")
BUILD_VERBOSE=$(V)
endif
ifndef BUILD_VERBOSE
BUILD_VERBOSE = 0
endif
ifeq ($(BUILD_VERBOSE),0)
Q = @
else
Q =
endif
ifeq ($(BUILD_VERBOSE),0)
$(info Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.)
endif
TARGET ?= sensorweb-nrf51
RM = rm
ECHO = @echo
comma := ,
empty :=
space := $(empty) $(empty)
# SDK 11.0.0 expects gcc 4.9.3
CROSS_COMPILE = arm-none-eabi-
AS = $(CROSS_COMPILE)as
CC = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
SDK = sdk-11.0.0
SDK_ZIP = nRF5_SDK_11.0.0_89a8197.zip
SDK_URL = https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v11.x.x/$(SDK_ZIP)
INC = -Iconfig
INC += -I$(SDK)/components/drivers_nrf/config
INC += -I$(SDK)/components/libraries/timer
INC += -I$(SDK)/components/libraries/fstorage/config
INC += -I$(SDK)/components/softdevice/s130/headers
INC += -I$(SDK)/components/drivers_nrf/delay
INC += -I$(SDK)/components/libraries/util
INC += -I$(SDK)/components/ble/device_manager
INC += -I$(SDK)/components/drivers_nrf/uart
INC += -I$(SDK)/components/ble/common
INC += -I$(SDK)/components/libraries/sensorsim
INC += -I$(SDK)/components/drivers_nrf/pstorage
INC += -I$(SDK)/components/libraries/uart
INC += -I$(SDK)/components/libraries/fifo
INC += -I$(SDK)/components/device
INC += -I$(SDK)/components/libraries/button
INC += -I$(SDK)/components/libraries/fstorage
INC += -I$(SDK)/components/libraries/experimental_section_vars
INC += -I$(SDK)/components/drivers_nrf/gpiote
INC += -I$(SDK)/external/segger_rtt
INC += -I$(SDK)/examples/bsp
INC += -I$(SDK)/components/toolchain/CMSIS/Include
INC += -I$(SDK)/components/drivers_nrf/hal
INC += -I$(SDK)/components/toolchain/gcc
INC += -I$(SDK)/components/toolchain
INC += -I$(SDK)/components/drivers_nrf/common
INC += -I$(SDK)/components/ble/ble_advertising
INC += -I$(SDK)/components/softdevice/s130/headers/nrf51
INC += -I$(SDK)/components/libraries/trace
INC += -I$(SDK)/components/softdevice/common/softdevice_handler
INC += -Icrypto
#CPPFLAGS = -DNRF_LOG_USES_RAW_UART=1
CPPFLAGS = -DNRF_LOG_USES_UART=1
CPPFLAGS += -DBOARD_CUSTOM
#CPPFLAGS += -DBOARD_PCA10028
CPPFLAGS += -DSOFTDEVICE_PRESENT
CPPFLAGS += -DNRF51
CPPFLAGS += -DS130
CPPFLAGS += -DBLE_STACK_SUPPORT_REQD
CPPFLAGS += -DSWI_DISABLE0
CFLAGS = $(CPPFLAGS)
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs
# Note: -O3 causes the flash image size to increase by 80K
CFLAGS += -Wall -Werror -Os -g3
CFLAGS += -mfloat-abi=soft
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin --short-enums
CXXFLAGS := $(CFLAGS)
# Using -fnoexceptions drops 6K off the flash image
CXXFLAGS += -fno-exceptions
# Using -fno-rtti drops another 6K off the flash image
CXXFLAGS += -fno-rtti
CFLAGS += --std=gnu99
# keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(OBJDIR)/$(TARGET).map -Wl,--cref
LDFLAGS += -mthumb -mabi=aapcs -L $(SDK)/components/toolchain/gcc -Tnrf51.ld
LDFLAGS += -mcpu=cortex-m0
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
#LDFLAGS += --specs=nano.specs -lc -lnosys
LDFLAGS += -lc -lnosys
AFLAGS = $(CPPFLAGS)
AFLAGS += -x assembler-with-cpp
AFLAGS += -D__STACK_SIZE=4096
OBJDIR ?= obj
C_SRC = \
main.c \
our_service.c \
system_nrf51.c \
$(SDK)/components/libraries/button/app_button.c \
$(SDK)/components/libraries/util/app_error.c \
$(SDK)/components/libraries/util/app_error_weak.c \
$(SDK)/components/libraries/timer/app_timer.c \
$(SDK)/components/libraries/trace/app_trace.c \
$(SDK)/components/libraries/util/app_util_platform.c \
$(SDK)/components/libraries/fstorage/fstorage.c \
$(SDK)/components/libraries/util/nrf_assert.c \
$(SDK)/components/libraries/util/nrf_log.c \
$(SDK)/components/libraries/uart/retarget.c \
$(SDK)/components/libraries/sensorsim/sensorsim.c \
$(SDK)/external/segger_rtt/RTT_Syscalls_GCC.c \
$(SDK)/external/segger_rtt/SEGGER_RTT.c \
$(SDK)/external/segger_rtt/SEGGER_RTT_printf.c \
$(SDK)/components/libraries/fifo/app_fifo.c \
$(SDK)/components/libraries/uart/app_uart_fifo.c \
$(SDK)/components/drivers_nrf/delay/nrf_delay.c \
$(SDK)/components/drivers_nrf/common/nrf_drv_common.c \
$(SDK)/components/drivers_nrf/gpiote/nrf_drv_gpiote.c \
$(SDK)/components/drivers_nrf/uart/nrf_drv_uart.c \
$(SDK)/components/drivers_nrf/pstorage/pstorage.c \
$(SDK)/examples/bsp/bsp.c \
$(SDK)/components/ble/common/ble_advdata.c \
$(SDK)/components/ble/ble_advertising/ble_advertising.c \
$(SDK)/components/ble/common/ble_conn_params.c \
$(SDK)/components/ble/common/ble_srv_common.c \
$(SDK)/components/ble/device_manager/device_manager_peripheral.c \
$(SDK)/components/softdevice/common/softdevice_handler/softdevice_handler.c \
$(SDK)/examples/bsp/bsp_btn_ble.c \
CPP_SRC = \
c_crypto.cpp \
crypto/AES128.o \
crypto/AESCommon.o \
crypto/BlockCipher.o \
crypto/Curve25519.o \
crypto/Ed25519.o \
crypto/BigNumberUtil.o \
crypto/RNG.o \
crypto/ChaCha.o \
crypto/Cipher.o \
crypto/Crypto.o \
crypto/SHA512.o \
crypto/Hash.o \
crypto/Arduino.o \
A_SRC = $(SDK)/components/toolchain/gcc/gcc_startup_nrf51.s
C_PATHS = $(sort $(dir $(C_SRC)))
CPP_PATHS = $(sort $(dir $(CPP_SRC)))
A_PATHS = $(sort $(dir $(A_SRC)))
vpath %.cpp $(CPP_PATHS)
vpath %.c $(C_PATHS)
vpath %.s $(A_PATHS)
CPP_FILES = $(notdir $(CPP_SRC))
C_FILES = $(notdir $(C_SRC))
A_FILES = $(notdir $(A_SRC))
OBJ = $(addprefix $(OBJDIR)/, $(CPP_FILES:.cpp=.o))
OBJ += $(addprefix $(OBJDIR)/, $(C_FILES:.c=.o))
OBJ += $(addprefix $(OBJDIR)/, $(A_FILES:.s=.o))
.PHONY: all
all: $(TARGET)
.PHONY: $(TARGET)
$(TARGET): $(OBJDIR)/$(TARGET).elf
OBJDIRS = $(sort $(dir $(OBJ)))
$(OBJ): | $(OBJDIRS) $(SDK)
$(OBJDIRS):
mkdir -p $@
$(SDK_ZIP):
wget $(SDK_URL)
.PHONY: sdk
sdk: $(SDK)
$(SDK): $(SDK_ZIP)
mkdir -p $(SDK)-unzipped
unzip -d $(SDK) $(SDK_ZIP)
for p in sdk-11.0.0-patches/*.patch; do patch -p0 < $$p; done
mv $(SDK)-unzipped $(SDK)
# The following tells make that it needs to unpack the SDK zipfile before
# the source files will actually exist. This is important the very first
# time you run make (i.e. on a freshly checked out repostitory).
#
# Making the depenen
$(C_SRC) $(A_SRC): | $(SDK)
define compile_c
$(ECHO) "CC $<"
$(Q)$(CC) $(CFLAGS) $(INC) -c -MD -o $@ $<
@# The following fixes the dependency file.
@# See http://make.paulandlesley.org/autodep.html for details.
@cp $(@:.o=.d) $(@:.o=.P); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
rm -f $(@:.o=.d)
endef
define compile_cpp
$(ECHO) "C++ $<"
$(Q)$(CXX) $(CXXFLAGS) $(INC) -c -MD -o $@ $<
@# The following fixes the dependency file.
@# See http://make.paulandlesley.org/autodep.html for details.
@cp $(@:.o=.d) $(@:.o=.P); \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
rm -f $(@:.o=.d)
endef
$(OBJDIR)/%.o: %.c
$(call compile_c)
$(OBJDIR)/%.o: %.cpp
$(call compile_cpp)
$(OBJDIR)/%.o: %.s
$(ECHO) "AS $<"
$(Q)$(CC) $(AFLAGS) $(INC) -c -o $@ $<
$(OBJDIR)/$(TARGET).elf: $(OBJ)
$(ECHO) "Linking $@"
$(Q)$(CXX) $(LDFLAGS) $^ $(LIBS) -lm -o $@
$(Q)$(SIZE) $@
%.bin: %.elf
$(ECHO) "Creating $@"
$(Q)$(OBJCOPY) -O binary $< $@
%.hex: %.elf
$(ECHO) "Creating $@"
$(Q)$(OBJCOPY) -O ihex $< $@
.PHONY: flash
flash: $(OBJDIR)/$(TARGET).hex
$(ECHO) "Flashing $<"
nrfjprog --program $< -f nrf51 --sectorerase
nrfjprog --reset -f nrf51
.PHONY: flash_softdevice
flash_softdevice: $(SDK)/components/softdevice/s130/hex/s130_nrf51_2.0.0_softdevice.hex
$(ECHO) "Flashing $<"
nrfjprog --program $< -f nrf51 --chiperase
nrfjprog --reset -f nrf51
.PHONY: clean
clean:
$(Q)$(RM) -rf $(OBJDIR)
.PHONY: distclean
distclean: clean
rm -rf $(SDK) $(SDK_ZIP)
-include $(OBJ:.o=.P)