Use the cached value of useDshotTelemetry to ensure consistent runtime use if dshot_b...
[betaflight.git] / mk / tools.mk
blobe94cc5d19a6ec0915a063fde3215d355664dc984
1 ###############################################################
3 # Installers for tools
5 # NOTE: These are not tied to the default goals
6 # and must be invoked manually
8 # ARM SDK Version: 10.3-2021.10
10 ###############################################################
12 ##############################
14 # Check that environmental variables are sane
16 ##############################
18 # Set up ARM (STM32) SDK
19 ARM_SDK_DIR ?= $(TOOLS_DIR)/gcc-arm-none-eabi-10.3-2021.10
20 # Checked below, Should match the output of $(shell arm-none-eabi-gcc -dumpversion)
21 GCC_REQUIRED_VERSION ?= 10.3.1
23 .PHONY: arm_sdk_version
25 arm_sdk_version:
26 $(V1) $(ARM_SDK_PREFIX)gcc --version
28 ## arm_sdk_install : Install Arm SDK
29 .PHONY: arm_sdk_install
31 ARM_SDK_URL_BASE := https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10
32 # source: https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
33 ifeq ($(OSFAMILY), linux)
34 ARM_SDK_URL := $(ARM_SDK_URL_BASE)-$(shell uname -m)-linux.tar.bz2
35 endif
37 ifeq ($(OSFAMILY), macosx)
38 ARM_SDK_URL := $(ARM_SDK_URL_BASE)-mac.tar.bz2
39 endif
41 ifeq ($(OSFAMILY), windows)
42 ARM_SDK_URL := $(ARM_SDK_URL_BASE)-win32.zip
43 endif
45 ARM_SDK_FILE := $(notdir $(ARM_SDK_URL))
47 SDK_INSTALL_MARKER := $(ARM_SDK_DIR)/bin/arm-none-eabi-gcc-$(GCC_REQUIRED_VERSION)
49 # order-only prereq on directory existance:
50 arm_sdk_install: | $(TOOLS_DIR)
51 arm_sdk_install: arm_sdk_download $(SDK_INSTALL_MARKER)
53 $(SDK_INSTALL_MARKER):
54 ifneq ($(OSFAMILY), windows)
55 # binary only release so just extract it
56 $(V1) tar -C $(TOOLS_DIR) -xjf "$(DL_DIR)/$(ARM_SDK_FILE)"
57 else
58 $(V1) unzip -q -d $(ARM_SDK_DIR) "$(DL_DIR)/$(ARM_SDK_FILE)"
59 endif
61 .PHONY: arm_sdk_download
62 arm_sdk_download: | $(DL_DIR)
63 arm_sdk_download: $(DL_DIR)/$(ARM_SDK_FILE)
64 $(DL_DIR)/$(ARM_SDK_FILE):
65 # download the source only if it's newer than what we already have
66 $(V1) curl -L -k -o "$@" $(if $(wildcard $@), -z "$@",) "$(ARM_SDK_URL)"
68 ## arm_sdk_clean : Uninstall Arm SDK
69 .PHONY: arm_sdk_clean
70 arm_sdk_clean:
71 $(V1) [ ! -d "$(ARM_SDK_DIR)" ] || $(RM) -r $(ARM_SDK_DIR)
72 $(V1) [ ! -d "$(DL_DIR)" ] || $(RM) -r $(DL_DIR)
74 .PHONY: openocd_win_install
76 openocd_win_install: | $(DL_DIR) $(TOOLS_DIR)
77 openocd_win_install: OPENOCD_URL := git://git.code.sf.net/p/openocd/code
78 openocd_win_install: OPENOCD_REV := cf1418e9a85013bbf8dbcc2d2e9985695993d9f4
79 openocd_win_install: OPENOCD_OPTIONS :=
81 ifeq ($(OPENOCD_FTDI), yes)
82 openocd_win_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --enable-ft2232_ftd2xx --with-ftd2xx-win32-zipdir=$(FTD2XX_DIR)
83 endif
85 openocd_win_install: openocd_win_clean libusb_win_install ftd2xx_install
86 # download the source
87 @echo " DOWNLOAD $(OPENOCD_URL) @ $(OPENOCD_REV)"
88 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
89 $(V1) mkdir -p "$(OPENOCD_BUILD_DIR)"
90 $(V1) git clone --no-checkout $(OPENOCD_URL) "$(DL_DIR)/openocd-build"
91 $(V1) ( \
92 cd $(OPENOCD_BUILD_DIR) ; \
93 git checkout -q $(OPENOCD_REV) ; \
96 # apply patches
97 @echo " PATCH $(OPENOCD_BUILD_DIR)"
98 $(V1) ( \
99 cd $(OPENOCD_BUILD_DIR) ; \
100 git apply < $(ROOT_DIR)/flight/Project/OpenOCD/0003-freertos-cm4f-fpu-support.patch ; \
101 git apply < $(ROOT_DIR)/flight/Project/OpenOCD/0004-st-icdi-disable.patch ; \
104 # build and install
105 @echo " BUILD $(OPENOCD_WIN_DIR)"
106 $(V1) mkdir -p "$(OPENOCD_WIN_DIR)"
107 $(V1) ( \
108 cd $(OPENOCD_BUILD_DIR) ; \
109 ./bootstrap ; \
110 ./configure --enable-maintainer-mode --prefix="$(OPENOCD_WIN_DIR)" \
111 --build=i686-pc-linux-gnu --host=i586-mingw32msvc \
112 CPPFLAGS=-I$(LIBUSB_WIN_DIR)/include \
113 LDFLAGS=-L$(LIBUSB_WIN_DIR)/lib/gcc \
114 $(OPENOCD_OPTIONS) \
115 --disable-werror \
116 --enable-stlink ; \
117 $(MAKE) ; \
118 $(MAKE) install ; \
121 # delete the extracted source when we're done
122 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
124 .PHONY: openocd_win_clean
125 openocd_win_clean:
126 @echo " CLEAN $(OPENOCD_WIN_DIR)"
127 $(V1) [ ! -d "$(OPENOCD_WIN_DIR)" ] || $(RM) -r "$(OPENOCD_WIN_DIR)"
129 # Set up openocd tools
130 OPENOCD_DIR := $(TOOLS_DIR)/openocd
131 OPENOCD_WIN_DIR := $(TOOLS_DIR)/openocd_win
132 OPENOCD_BUILD_DIR := $(DL_DIR)/openocd-build
134 .PHONY: openocd_install
136 openocd_install: | $(DL_DIR) $(TOOLS_DIR)
137 openocd_install: OPENOCD_URL := git://git.code.sf.net/p/openocd/code
138 openocd_install: OPENOCD_TAG := v0.9.0
139 openocd_install: OPENOCD_OPTIONS := --enable-maintainer-mode --prefix="$(OPENOCD_DIR)" --enable-buspirate --enable-stlink
141 ifeq ($(OPENOCD_FTDI), yes)
142 openocd_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --enable-ftdi
143 endif
145 ifeq ($(UNAME), Darwin)
146 openocd_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --disable-option-checking
147 endif
149 openocd_install: openocd_clean
150 # download the source
151 @echo " DOWNLOAD $(OPENOCD_URL) @ $(OPENOCD_TAG)"
152 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
153 $(V1) mkdir -p "$(OPENOCD_BUILD_DIR)"
154 $(V1) git clone --no-checkout $(OPENOCD_URL) "$(OPENOCD_BUILD_DIR)"
155 $(V1) ( \
156 cd $(OPENOCD_BUILD_DIR) ; \
157 git checkout -q tags/$(OPENOCD_TAG) ; \
160 # build and install
161 @echo " BUILD $(OPENOCD_DIR)"
162 $(V1) mkdir -p "$(OPENOCD_DIR)"
163 $(V1) ( \
164 cd $(OPENOCD_BUILD_DIR) ; \
165 ./bootstrap ; \
166 ./configure $(OPENOCD_OPTIONS) ; \
167 $(MAKE) ; \
168 $(MAKE) install ; \
171 # delete the extracted source when we're done
172 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
174 .PHONY: openocd_clean
175 openocd_clean:
176 @echo " CLEAN $(OPENOCD_DIR)"
177 $(V1) [ ! -d "$(OPENOCD_DIR)" ] || $(RM) -r "$(OPENOCD_DIR)"
179 STM32FLASH_DIR := $(TOOLS_DIR)/stm32flash
181 .PHONY: stm32flash_install
182 stm32flash_install: STM32FLASH_URL := http://stm32flash.googlecode.com/svn/trunk
183 stm32flash_install: STM32FLASH_REV := 61
184 stm32flash_install: stm32flash_clean
185 # download the source
186 @echo " DOWNLOAD $(STM32FLASH_URL) @ r$(STM32FLASH_REV)"
187 $(V1) svn export -q -r "$(STM32FLASH_REV)" "$(STM32FLASH_URL)" "$(STM32FLASH_DIR)"
189 # build
190 @echo " BUILD $(STM32FLASH_DIR)"
191 $(V1) $(MAKE) --silent -C $(STM32FLASH_DIR) all
193 .PHONY: stm32flash_clean
194 stm32flash_clean:
195 @echo " CLEAN $(STM32FLASH_DIR)"
196 $(V1) [ ! -d "$(STM32FLASH_DIR)" ] || $(RM) -r "$(STM32FLASH_DIR)"
198 # Set up uncrustify tools
199 UNCRUSTIFY_DIR := $(TOOLS_DIR)/uncrustify-0.61
200 UNCRUSTIFY_BUILD_DIR := $(DL_DIR)/uncrustify
202 .PHONY: uncrustify_install
203 uncrustify_install: | $(DL_DIR) $(TOOLS_DIR)
204 uncrustify_install: UNCRUSTIFY_URL := http://downloads.sourceforge.net/project/uncrustify/uncrustify/uncrustify-0.61/uncrustify-0.61.tar.gz
205 uncrustify_install: UNCRUSTIFY_FILE := uncrustify-0.61.tar.gz
206 uncrustify_install: UNCRUSTIFY_OPTIONS := prefix=$(UNCRUSTIFY_DIR)
207 uncrustify_install: uncrustify_clean
208 ifneq ($(OSFAMILY), windows)
209 @echo " DOWNLOAD $(UNCRUSTIFY_URL)"
210 $(V1) curl -L -k -o "$(DL_DIR)/$(UNCRUSTIFY_FILE)" "$(UNCRUSTIFY_URL)"
211 endif
212 # extract the src
213 @echo " EXTRACT $(UNCRUSTIFY_FILE)"
214 $(V1) tar -C $(TOOLS_DIR) -xf "$(DL_DIR)/$(UNCRUSTIFY_FILE)"
216 @echo " BUILD $(UNCRUSTIFY_DIR)"
217 $(V1) ( \
218 cd $(UNCRUSTIFY_DIR) ; \
219 ./configure --prefix="$(UNCRUSTIFY_DIR)" ; \
220 $(MAKE) ; \
221 $(MAKE) install ; \
223 # delete the extracted source when we're done
224 $(V1) [ ! -d "$(UNCRUSTIFY_BUILD_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_BUILD_DIR)"
226 .PHONY: uncrustify_clean
227 uncrustify_clean:
228 @echo " CLEAN $(UNCRUSTIFY_DIR)"
229 $(V1) [ ! -d "$(UNCRUSTIFY_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_DIR)"
230 @echo " CLEAN $(UNCRUSTIFY_BUILD_DIR)"
231 $(V1) [ ! -d "$(UNCRUSTIFY_BUILD_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_BUILD_DIR)"
233 # ZIP download URL
234 zip_install: ZIP_URL := http://pkgs.fedoraproject.org/repo/pkgs/zip/zip30.tar.gz/7b74551e63f8ee6aab6fbc86676c0d37/zip30.tar.gz
236 zip_install: ZIP_FILE := $(notdir $(ZIP_URL))
238 ZIP_DIR = $(TOOLS_DIR)/zip30
240 # order-only prereq on directory existance:
241 zip_install : | $(DL_DIR) $(TOOLS_DIR)
242 zip_install: zip_clean
243 $(V1) curl -L -k -o "$(DL_DIR)/$(ZIP_FILE)" "$(ZIP_URL)"
244 $(V1) tar --force-local -C $(TOOLS_DIR) -xzf "$(DL_DIR)/$(ZIP_FILE)"
245 ifneq ($(OSFAMILY), windows)
246 $(V1) cd "$(ZIP_DIR)" && $(MAKE) -f unix/Makefile generic_gcc
247 else
248 $(V1) cd "$(ZIP_DIR)" && $(MAKE) -f win32/makefile.gcc
249 endif
251 .PHONY: zip_clean
252 zip_clean:
253 $(V1) [ ! -d "$(ZIP_DIR)" ] || $(RM) -rf $(ZIP_DIR)
255 ##############################
257 # Set up paths to tools
259 ##############################
261 ifeq ($(shell [ -d "$(ARM_SDK_DIR)" ] && echo "exists"), exists)
262 ARM_SDK_PREFIX := $(ARM_SDK_DIR)/bin/arm-none-eabi-
263 else ifeq (,$(filter %_install test% clean% %-print checks help configs, $(MAKECMDGOALS)))
264 GCC_VERSION = $(shell arm-none-eabi-gcc -dumpversion)
265 ifeq ($(GCC_VERSION),)
266 $(error **ERROR** arm-none-eabi-gcc not in the PATH. Run 'make arm_sdk_install' to install automatically in the tools folder of this repo)
267 else ifneq ($(GCC_VERSION), $(GCC_REQUIRED_VERSION))
268 $(error **ERROR** your arm-none-eabi-gcc is '$(GCC_VERSION)', but '$(GCC_REQUIRED_VERSION)' is expected. Override with 'GCC_REQUIRED_VERSION' in mk/local.mk or run 'make arm_sdk_install' to install the right version automatically in the tools folder of this repo)
269 endif
271 # ARM toolchain is in the path, and the version is what's required.
272 ARM_SDK_PREFIX ?= arm-none-eabi-
273 endif
275 ifeq ($(shell [ -d "$(ZIP_DIR)" ] && echo "exists"), exists)
276 export ZIPBIN := $(ZIP_DIR)/zip
277 else
278 export ZIPBIN := zip
279 endif
281 ifeq ($(shell [ -d "$(OPENOCD_DIR)" ] && echo "exists"), exists)
282 OPENOCD := $(OPENOCD_DIR)/bin/openocd
283 else
284 # not installed, hope it's in the path...
285 OPENOCD ?= openocd
286 endif
288 ifeq ($(shell [ -d "$(UNCRUSTIFY_DIR)" ] && echo "exists"), exists)
289 UNCRUSTIFY := $(UNCRUSTIFY_DIR)/bin/uncrustify
290 else
291 # not installed, hope it's in the path...
292 UNCRUSTIFY ?= uncrustify
293 endif
295 # Google Breakpad
296 DUMP_SYMBOLS_TOOL := $(TOOLS_DIR)/breakpad/$(OSFAMILY)-$(ARCHFAMILY)/dump_syms
297 BREAKPAD_URL := http://dronin.tracer.nz/tools/breakpad.zip
298 BREAKPAD_DL_FILE := $(DL_DIR)/$(notdir $(BREAKPAD_URL))
299 BREAKPAD_DIR := $(TOOLS_DIR)/breakpad
301 .PHONY: breakpad_install
302 breakpad_install: | $(DL_DIR) $(TOOLS_DIR)
303 breakpad_install: breakpad_clean
304 @echo " DOWNLOAD $(BREAKPAD_URL)"
305 $(V1) $(V1) curl -L -k -z "$(BREAKPAD_DL_FILE)" -o "$(BREAKPAD_DL_FILE)" "$(BREAKPAD_URL)"
306 @echo " EXTRACT $(notdir $(BREAKPAD_DL_FILE))"
307 $(V1) mkdir -p "$(BREAKPAD_DIR)"
308 $(V1) unzip -q -d $(BREAKPAD_DIR) "$(BREAKPAD_DL_FILE)"
309 ifeq ($(OSFAMILY), windows)
310 $(V1) ln -s "$(TOOLS_DIR)/breakpad/$(OSFAMILY)-i686" "$(TOOLS_DIR)/breakpad/$(OSFAMILY)-x86_64"
311 endif
313 .PHONY: breakpad_clean
314 breakpad_clean:
315 @echo " CLEAN $(BREAKPAD_DIR)"
316 $(V1) [ ! -d "$(BREAKPAD_DIR)" ] || $(RM) -rf $(BREAKPAD_DIR)
317 @echo " CLEAN $(BREAKPAD_DL_FILE)"
318 $(V1) $(RM) -f $(BREAKPAD_DL_FILE)