-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
161 lines (133 loc) · 5.93 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
# Vairables for project configuration
FQBN ?=
PORT ?=
TESTS ?=
UNITY_PATH ?= Unity
BAUD_RATE ?= 115200
Q?=@
print_args:
@:
# Info for debugging
$(info )
$(info Test configuration)
$(info ----------------------------------)
$(info FQBN : $(FQBN))
$(info PORT : $(PORT))
$(info BAUD_RATE : $(BAUD_RATE))
$(info ----------------------------------)
$(info )
.PHONY: flash compile upload monitor
# Clean and create build directory for arduino compilation
clean:
$(Q) -rm -rf build/*
create_build_dir: clean
$(Q) mkdir -p build
# Check if UNITY_PATH variable is set
check_unity_path:
ifndef UNITY_PATH
$(error "Must set variable UNITY_PATH in order to be able to compile Arduino unit tests!")
endif
# Copy common files and test-specific files to build directory
define COPY_COMMON_FILES
$(Q) find $(UNITY_PATH) -name '*.[hc]' \( -path '*extras*' -a -path '*src*' -or -path '*src*' -a \! -path '*example*' \) -exec \cp {} build \;
$(Q) find src/utils -name '*.[hc]*' -exec \cp {} build \;
$(Q) find src -maxdepth 1 -name '*.[hc]*' -exec \cp {} build \;
$(Q) find ../ -maxdepth 1 -name 'test_config.h' -exec \cp {} build \;
$(Q) cp src/test_main.ino build/build.ino
endef
# Copy specific target C file to build directory
define COPY_TARGET_FILE
$(Q) find src/corelibs/$(call strip,$(1)) -name '$(call strip,$(2)).cpp' -exec \cp {} build \;
endef
# create build folder for test target
test_%: create_build_dir check_unity_path print_args
$(Q) $(call COPY_COMMON_FILES)
$(Q) $(call COPY_TARGET_FILE, $(shell echo $(@:test_%=%) | cut -d"_" -f1), $(@))
$(info )
$(info Testing $(@:test_%=%)...)
$(Q) $(MAKE) flash TESTS=$(TESTS) --no-print-directory
$(Q) $(MAKE) monitor PORT=$(PORT) FQBN=$(FQBN) --no-print-directory
# UART tests targets
test_uart_connected2_tx: TESTS=-DTEST_UART_CONNECTED2_TX
test_uart_connected2_rx: TESTS=-DTEST_UART_CONNECTED2_RX
# Time tests targets
test_time_single: TESTS=-DTEST_TIME_SINGLE
# Digital IO tests targets
test_digitalio_single: TESTS=-DTEST_DIGITALIO_SINGLE
# GPIO Interrupts tests targets
test_interrupts_single: TESTS=-DTEST_INTERRUPTS_SINGLE
## CAN tests targets
test_can_single: TESTS=-DTEST_CAN_SINGLE
test_can_connected2_node1: TESTS=-DTEST_CAN_CONNECTED2_NODE1
test_can_connected2_node2: TESTS=-DTEST_CAN_CONNECTED2_NODE2
## IIC tests targets
test_wire_connected1_pingpong: TESTS=-DTEST_WIRE_CONNECTED1_PINGPONG
test_wire_connected2_masterpingpong: TESTS=-DTEST_WIRE_CONNECTED2_MASTERPINGPONG
test_wire_connected2_slavepingpong: TESTS=-DTEST_WIRE_CONNECTED2_SLAVEPINGPONG
## WiFi tests targets
test_wifi_sta: TESTS=-DTEST_WIFI_STA
test_wifi_ap: TESTS=-DTEST_WIFI_AP
# Arduino-cli commands
# For WSL and Windows :
# download arduino-cli from : https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip
.PHONY: flash compile upload monitor
compile:
ifeq ($(FQBN),)
$(error "Must set variable FQBN in order to be able to compile Arduino sketches !")
else
# CAUTION : only use '=' when assigning values to vars, not '+='
$(info Compiling test...)
$(Q) arduino-cli compile \
--clean \
--warnings all \
--fqbn $(FQBN) \
--build-property "compiler.c.extra_flags=\"-DUNITY_INCLUDE_CONFIG_H=1\"" \
--build-property compiler.cpp.extra_flags="$(TESTS)" \
--export-binaries \
build
endif
compileLTO:
ifeq ($(FQBN),)
$(error "Must set variable FQBN in order to be able to compile Arduino sketches !")
else
# compiler.c.extra_flags : switch to -std=c23 whenever XMCLib is conforming; currently neither c99 nor c11 work !
# CAUTION : only use '=' when assigning values to vars, not '+='
$(Q) arduino-cli compile \
--clean \
--warnings all \
--fqbn $(FQBN) \
--build-property compiler.c.extra_flags="\"-DUNITY_INCLUDE_CONFIG_H=1\" -DNDEBUG -flto -fno-fat-lto-objects -Wextra -Wall -Wfloat-equal -Wconversion -Wredundant-decls -Wswitch-default -Wdouble-promotion -Wpedantic -Wunreachable-code -fanalyzer -std=c20 " \
--build-property compiler.cpp.extra_flags="$(TESTS) -DNDEBUG -flto -fno-fat-lto-objects -Wextra -Wall -Wfloat-equal -Wconversion -Wredundant-decls -Wswitch-default -Wdouble-promotion -Wpedantic -Wunreachable-code -fanalyzer -std=c++20 " \
--build-property compiler.ar.cmd=arm-none-eabi-gcc-ar \
--build-property compiler.libraries.ldflags=-lstdc++ \
--build-property compiler.arm.cmsis.path="-isystem{compiler.xmclib_include.path}/XMCLib/inc -isystem{compiler.dsp_include.path} -isystem{compiler.nn_include.path} -isystem{compiler.cmsis_include.path} -isystem{compiler.xmclib_include.path}/LIBS -isystem{build.variant.path} -isystem{build.variant.config_path}" \
--build-property compiler.usb.path="-isystem{runtime.platform.path}/cores/usblib -isystem{runtime.platform.path}/cores/usblib/Common -isystem{runtime.platform.path}/cores/usblib/Class -isystem{runtime.platform.path}/cores/usblib/Class/Common -isystem{runtime.platform.path}/cores/usblib/Class/Device -isystem{runtime.platform.path}/cores/usblib/Core -isystem{runtime.platform.path}/cores/usblib/Core/XMC4000" \
--export-binaries \
build
endif
upload: compile
ifeq ($(PORT),)
$(error "Must set variable PORT (Windows port naming convention, ie COM16) in order to be able to flash Arduino sketches !")
endif
ifeq ($(FQBN),)
$(error "Must set variable FQBN in order to be able to flash Arduino sketches !")
else
$(Q) arduino-cli upload \
-p $(PORT) \
--fqbn $(FQBN) \
build
endif
flash: compile upload
monitor:
ifeq ($(PORT),)
$(error "Must set variable PORT (Windows port naming convention, ie COM16) in order to be able to flash Arduino sketches !")
endif
ifeq ($(FQBN),)
$(error "Must set variable FQBN in order to be able to flash Arduino sketches !")
else
$(info Uploading test...)
$(Q) arduino-cli monitor \
-c baudrate=$(BAUD_RATE) \
-p $(PORT) \
--fqbn $(FQBN)
endif