-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
149 lines (121 loc) · 5.58 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
FQBN ?=
PORT ?=
TESTS ?=
UNITY_PATH ?=
BAUD_RATE ?= 115200
$(info FQBN : $(FQBN))
$(info PORT : $(PORT))
$(info UNITY_PATH : $(UNITY_PATH))
$(info BAUD_RATE : $(BAUD_RATE))
TESTS_CONNECTED=-DTEST_CAN_CONNECTED
TESTS_NOT_CONNECTED=-DTEST_CAN
CAN: TESTS=-DTEST_CAN
CAN_connected: TESTS=-DTEST_CAN -DTEST_CAN_CONNECTED
CAN_connected_node1: TESTS=-DTEST_CAN_CONNECTED_NODE1
CAN_connected_node2: TESTS=-DTEST_CAN_CONNECTED_NODE2
CAN_connected CAN CAN_connected_node1 CAN_connected_node2: unity_corelibs_can flash
test_all: TESTS=$(TESTS_CONNECTED) $(TESTS_NOT_CONNECTED)
test_connected: TESTS=$(TESTS_CONNECTED)
test: TESTS=$(TESTS_NOT_CONNECTED)
test_all \
test_connected \
test: unity_corelibs flash
EXAMPLES= CANReceiver CANReceiverCallback CANSender CANLoopBack
clean:
-rm -rf build/*
arduino: clean
mkdir -p build
# copy library files (not needed for bundled libraries)
# cp -r src/* build
# find src -name '*.[hc]*' -a \( \! -name '*mtb*' \) -print -exec cp {} build \;
.PHONY: CANReceiver CANReceiverCallback CANSender CANLoopBack
CANReceiver: arduino
cp examples/CANReceiver/CANReceiver.ino build/build.ino
CANReceiverCallback: arduino
cp examples/CANReceiverCallback/CANReceiverCallback.ino build/build.ino
CANSender: arduino
cp examples/CANSender/CANSender.ino build/build.ino
CANLoopBack: arduino
cp examples/CANLoopBack/CANLoopBack.ino build/build.ino
# install Unity from https://www.throwtheswitch.org/unity or git
unity_corelibs: arduino
ifeq ($(UNITY_PATH),)
$(error "Must set variable UNITY_PATH in order to be able to compile Arduino unit tests !")
else
find $(UNITY_PATH) -name '*.[hc]' \( -path '*extras*' -a -path '*src*' -or -path '*src*' -a \! -path '*example*' \) -exec \cp {} build \;
find src -name '*.[hc]*' -a \! -path '*mtb*' -a \! -path '*applibs*' -exec \cp {} build \;
cp src/corelibs/Test_main.ino build/build.ino
endif
unity_corelibs_can: arduino
ifeq ($(UNITY_PATH),)
$(error "Must set variable UNITY_PATH in order to be able to compile Arduino unit tests !")
else
find $(UNITY_PATH) -name '*.[hc]' \( -path '*extras*' -a -path '*src*' -or -path '*src*' -a \! -path '*example*' \) -exec \cp {} build \;
find src/corelibs/CAN -name '*.[hc]*' -exec \cp {} build \;
find src/utils -name '*.[hc]*' -exec \cp {} build \;
find src -maxdepth 1 -name '*.[hc]*' -exec \cp {} build \;
cp src/Test_main.ino build/build.ino
endif
# For WSL and Windows :
# download arduino-cli.exe from : https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip
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 '+='
arduino-cli.exe compile \
--clean \
--log \
--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 '+='
arduino-cli.exe compile \
--clean \
--log \
--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
arduino-cli.exe upload \
-p $(PORT) \
--fqbn $(FQBN) \
--verbose \
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
arduino-cli.exe monitor \
-c baudrate=$(BAUD_RATE) \
-p $(PORT) \
--fqbn $(FQBN)
endif