-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
72 lines (58 loc) · 2.17 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
.PHONY: all help
HAS_DEBUG ?= 0
HAS_BATTERY ?= 0
MAX_KEYS ?= 500
KEY_ROTATION_INTERVAL ?= 3600
ADVERTISING_INTERVAL ?= 1000
RANDOM_ROTATE_KEYS ?= 1
GNU_INSTALL_ROOT ?= $(CURDIR)/nrf-sdk/gcc-arm-none-eabi-6-2017-q2-update
TARGETS := \
nrf51822_xxac \
nrf51822_xxac-dcdc \
nrf52810_xxaa \
nrf52810_xxaa-dcdc \
nrf52832_xxaa \
nrf52832_xxaa-dcdc \
nrf52832_yj17024
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " all - build all targets"
@echo " clean - clean all targets"
# Define a recipe to build each target individually
define build_target
.PHONY: $(1)
DIR_$(1) := $(shell echo $(1) | cut -d'_' -f1)
GNU_INSTALL_ROOT_NO_SLASH := $(patsubst %/,%,$$(GNU_INSTALL_ROOT))
TOOLCHAIN_DIR := $(shell dirname $(GNU_INSTALL_ROOT_NO_SLASH))
$(1):
$$(MAKE) -C $$(DIR_$(1))/armgcc \
GNU_INSTALL_ROOT=$$(if $$(findstring nrf51,$$(DIR_$(1))),$$(GNU_INSTALL_ROOT)/,$$(GNU_INSTALL_ROOT)/bin/) \
MAX_KEYS=$(MAX_KEYS) \
HAS_DEBUG=$(HAS_DEBUG) \
HAS_BATTERY=$(HAS_BATTERY) \
KEY_ROTATION_INTERVAL=$(KEY_ROTATION_INTERVAL) \
ADVERTISING_INTERVAL=$(ADVERTISING_INTERVAL) \
RANDOM_ROTATE_KEYS=$(RANDOM_ROTATE_KEYS) \
$(1) bin_$(1)
mkdir -p ./release
cp $$(DIR_$(1))/armgcc/_build/*_s???.bin ./release/
@echo "# Build options for $(1)" > ./release/$(1).txt
@echo "GNU_INSTALL_ROOT=$$(shell basename $$(GNU_INSTALL_ROOT))" >> ./release/$(1).txt
@echo "MAX_KEYS=$(MAX_KEYS)" >> ./release/$(1).txt
@echo "HAS_DEBUG=$(HAS_DEBUG)" >> ./release/$(1).txt
@echo "HAS_BATTERY=$(HAS_BATTERY)" >> ./release/$(1).txt
@echo "KEY_ROTATION_INTERVAL=$(KEY_ROTATION_INTERVAL)" >> ./release/$(1).txt
@echo "ADVERTISING_INTERVAL=$(ADVERTISING_INTERVAL)" >> ./release/$(1).txt
@echo "RANDOM_ROTATE_KEYS=$(RANDOM_ROTATE_KEYS)" >> ./release/$(1).txt
$(1)-clean:
$$(MAKE) -C $$(DIR_$(1))/armgcc clean \
GNU_INSTALL_ROOT=$$(if $$(findstring nrf51,$$(DIR_$(1))),$$(GNU_INSTALL_ROOT),$$(GNU_INSTALL_ROOT)/bin/)
endef
# Generate rules for each target in the TARGETS list
$(foreach target,$(TARGETS),$(eval $(call build_target,$(target))))
# Define all target to depend on all individual targets
all: $(TARGETS)
clean: $(foreach target,$(TARGETS),$(target)-clean)
rm -rf ./release