Cleanup of defines for motor protocols (#11993)
[betaflight.git] / make / tools.mk
blobf4041232aa567b47126f4080b4d0100496f6f94f
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)-x86_64-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)
52 arm_sdk_install: arm_sdk_download $(SDK_INSTALL_MARKER)
54 $(SDK_INSTALL_MARKER):
55 ifneq ($(OSFAMILY), windows)
56 # binary only release so just extract it
57 $(V1) tar -C $(TOOLS_DIR) -xjf "$(DL_DIR)/$(ARM_SDK_FILE)"
58 else
59 $(V1) unzip -q -d $(ARM_SDK_DIR) "$(DL_DIR)/$(ARM_SDK_FILE)"
60 endif
62 .PHONY: arm_sdk_download
63 arm_sdk_download: | $(DL_DIR)
64 arm_sdk_download: $(DL_DIR)/$(ARM_SDK_FILE)
65 $(DL_DIR)/$(ARM_SDK_FILE):
66 # download the source only if it's newer than what we already have
67 $(V1) curl -L -k -o "$(DL_DIR)/$(ARM_SDK_FILE)" -z "$(DL_DIR)/$(ARM_SDK_FILE)" "$(ARM_SDK_URL)"
70 ## arm_sdk_clean : Uninstall Arm SDK
71 .PHONY: arm_sdk_clean
72 arm_sdk_clean:
73 $(V1) [ ! -d "$(ARM_SDK_DIR)" ] || $(RM) -r $(ARM_SDK_DIR)
74 $(V1) [ ! -d "$(DL_DIR)" ] || $(RM) -r $(DL_DIR)
76 .PHONY: openocd_win_install
78 openocd_win_install: | $(DL_DIR) $(TOOLS_DIR)
79 openocd_win_install: OPENOCD_URL := git://git.code.sf.net/p/openocd/code
80 openocd_win_install: OPENOCD_REV := cf1418e9a85013bbf8dbcc2d2e9985695993d9f4
81 openocd_win_install: OPENOCD_OPTIONS :=
83 ifeq ($(OPENOCD_FTDI), yes)
84 openocd_win_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --enable-ft2232_ftd2xx --with-ftd2xx-win32-zipdir=$(FTD2XX_DIR)
85 endif
87 openocd_win_install: openocd_win_clean libusb_win_install ftd2xx_install
88 # download the source
89 @echo " DOWNLOAD $(OPENOCD_URL) @ $(OPENOCD_REV)"
90 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
91 $(V1) mkdir -p "$(OPENOCD_BUILD_DIR)"
92 $(V1) git clone --no-checkout $(OPENOCD_URL) "$(DL_DIR)/openocd-build"
93 $(V1) ( \
94 cd $(OPENOCD_BUILD_DIR) ; \
95 git checkout -q $(OPENOCD_REV) ; \
98 # apply patches
99 @echo " PATCH $(OPENOCD_BUILD_DIR)"
100 $(V1) ( \
101 cd $(OPENOCD_BUILD_DIR) ; \
102 git apply < $(ROOT_DIR)/flight/Project/OpenOCD/0003-freertos-cm4f-fpu-support.patch ; \
103 git apply < $(ROOT_DIR)/flight/Project/OpenOCD/0004-st-icdi-disable.patch ; \
106 # build and install
107 @echo " BUILD $(OPENOCD_WIN_DIR)"
108 $(V1) mkdir -p "$(OPENOCD_WIN_DIR)"
109 $(V1) ( \
110 cd $(OPENOCD_BUILD_DIR) ; \
111 ./bootstrap ; \
112 ./configure --enable-maintainer-mode --prefix="$(OPENOCD_WIN_DIR)" \
113 --build=i686-pc-linux-gnu --host=i586-mingw32msvc \
114 CPPFLAGS=-I$(LIBUSB_WIN_DIR)/include \
115 LDFLAGS=-L$(LIBUSB_WIN_DIR)/lib/gcc \
116 $(OPENOCD_OPTIONS) \
117 --disable-werror \
118 --enable-stlink ; \
119 $(MAKE) ; \
120 $(MAKE) install ; \
123 # delete the extracted source when we're done
124 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
126 .PHONY: openocd_win_clean
127 openocd_win_clean:
128 @echo " CLEAN $(OPENOCD_WIN_DIR)"
129 $(V1) [ ! -d "$(OPENOCD_WIN_DIR)" ] || $(RM) -r "$(OPENOCD_WIN_DIR)"
131 # Set up openocd tools
132 OPENOCD_DIR := $(TOOLS_DIR)/openocd
133 OPENOCD_WIN_DIR := $(TOOLS_DIR)/openocd_win
134 OPENOCD_BUILD_DIR := $(DL_DIR)/openocd-build
136 .PHONY: openocd_install
138 openocd_install: | $(DL_DIR) $(TOOLS_DIR)
139 openocd_install: OPENOCD_URL := git://git.code.sf.net/p/openocd/code
140 openocd_install: OPENOCD_TAG := v0.9.0
141 openocd_install: OPENOCD_OPTIONS := --enable-maintainer-mode --prefix="$(OPENOCD_DIR)" --enable-buspirate --enable-stlink
143 ifeq ($(OPENOCD_FTDI), yes)
144 openocd_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --enable-ftdi
145 endif
147 ifeq ($(UNAME), Darwin)
148 openocd_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --disable-option-checking
149 endif
151 openocd_install: openocd_clean
152 # download the source
153 @echo " DOWNLOAD $(OPENOCD_URL) @ $(OPENOCD_TAG)"
154 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
155 $(V1) mkdir -p "$(OPENOCD_BUILD_DIR)"
156 $(V1) git clone --no-checkout $(OPENOCD_URL) "$(OPENOCD_BUILD_DIR)"
157 $(V1) ( \
158 cd $(OPENOCD_BUILD_DIR) ; \
159 git checkout -q tags/$(OPENOCD_TAG) ; \
162 # build and install
163 @echo " BUILD $(OPENOCD_DIR)"
164 $(V1) mkdir -p "$(OPENOCD_DIR)"
165 $(V1) ( \
166 cd $(OPENOCD_BUILD_DIR) ; \
167 ./bootstrap ; \
168 ./configure $(OPENOCD_OPTIONS) ; \
169 $(MAKE) ; \
170 $(MAKE) install ; \
173 # delete the extracted source when we're done
174 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
176 .PHONY: openocd_clean
177 openocd_clean:
178 @echo " CLEAN $(OPENOCD_DIR)"
179 $(V1) [ ! -d "$(OPENOCD_DIR)" ] || $(RM) -r "$(OPENOCD_DIR)"
181 STM32FLASH_DIR := $(TOOLS_DIR)/stm32flash
183 .PHONY: stm32flash_install
184 stm32flash_install: STM32FLASH_URL := http://stm32flash.googlecode.com/svn/trunk
185 stm32flash_install: STM32FLASH_REV := 61
186 stm32flash_install: stm32flash_clean
187 # download the source
188 @echo " DOWNLOAD $(STM32FLASH_URL) @ r$(STM32FLASH_REV)"
189 $(V1) svn export -q -r "$(STM32FLASH_REV)" "$(STM32FLASH_URL)" "$(STM32FLASH_DIR)"
191 # build
192 @echo " BUILD $(STM32FLASH_DIR)"
193 $(V1) $(MAKE) --silent -C $(STM32FLASH_DIR) all
195 .PHONY: stm32flash_clean
196 stm32flash_clean:
197 @echo " CLEAN $(STM32FLASH_DIR)"
198 $(V1) [ ! -d "$(STM32FLASH_DIR)" ] || $(RM) -r "$(STM32FLASH_DIR)"
200 # Set up uncrustify tools
201 UNCRUSTIFY_DIR := $(TOOLS_DIR)/uncrustify-0.61
202 UNCRUSTIFY_BUILD_DIR := $(DL_DIR)/uncrustify
204 .PHONY: uncrustify_install
205 uncrustify_install: | $(DL_DIR) $(TOOLS_DIR)
206 uncrustify_install: UNCRUSTIFY_URL := http://downloads.sourceforge.net/project/uncrustify/uncrustify/uncrustify-0.61/uncrustify-0.61.tar.gz
207 uncrustify_install: UNCRUSTIFY_FILE := uncrustify-0.61.tar.gz
208 uncrustify_install: UNCRUSTIFY_OPTIONS := prefix=$(UNCRUSTIFY_DIR)
209 uncrustify_install: uncrustify_clean
210 ifneq ($(OSFAMILY), windows)
211 @echo " DOWNLOAD $(UNCRUSTIFY_URL)"
212 $(V1) curl -L -k -o "$(DL_DIR)/$(UNCRUSTIFY_FILE)" "$(UNCRUSTIFY_URL)"
213 endif
214 # extract the src
215 @echo " EXTRACT $(UNCRUSTIFY_FILE)"
216 $(V1) tar -C $(TOOLS_DIR) -xf "$(DL_DIR)/$(UNCRUSTIFY_FILE)"
218 @echo " BUILD $(UNCRUSTIFY_DIR)"
219 $(V1) ( \
220 cd $(UNCRUSTIFY_DIR) ; \
221 ./configure --prefix="$(UNCRUSTIFY_DIR)" ; \
222 $(MAKE) ; \
223 $(MAKE) install ; \
225 # delete the extracted source when we're done
226 $(V1) [ ! -d "$(UNCRUSTIFY_BUILD_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_BUILD_DIR)"
228 .PHONY: uncrustify_clean
229 uncrustify_clean:
230 @echo " CLEAN $(UNCRUSTIFY_DIR)"
231 $(V1) [ ! -d "$(UNCRUSTIFY_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_DIR)"
232 @echo " CLEAN $(UNCRUSTIFY_BUILD_DIR)"
233 $(V1) [ ! -d "$(UNCRUSTIFY_BUILD_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_BUILD_DIR)"
235 # ZIP download URL
236 zip_install: ZIP_URL := http://pkgs.fedoraproject.org/repo/pkgs/zip/zip30.tar.gz/7b74551e63f8ee6aab6fbc86676c0d37/zip30.tar.gz
238 zip_install: ZIP_FILE := $(notdir $(ZIP_URL))
240 ZIP_DIR = $(TOOLS_DIR)/zip30
242 # order-only prereq on directory existance:
243 zip_install : | $(DL_DIR) $(TOOLS_DIR)
244 zip_install: zip_clean
245 $(V1) curl -L -k -o "$(DL_DIR)/$(ZIP_FILE)" "$(ZIP_URL)"
246 $(V1) tar --force-local -C $(TOOLS_DIR) -xzf "$(DL_DIR)/$(ZIP_FILE)"
247 ifneq ($(OSFAMILY), windows)
248 $(V1) cd "$(ZIP_DIR)" && $(MAKE) -f unix/Makefile generic_gcc
249 else
250 $(V1) cd "$(ZIP_DIR)" && $(MAKE) -f win32/makefile.gcc
251 endif
253 .PHONY: zip_clean
254 zip_clean:
255 $(V1) [ ! -d "$(ZIP_DIR)" ] || $(RM) -rf $(ZIP_DIR)
257 ##############################
259 # Set up paths to tools
261 ##############################
263 ifeq ($(shell [ -d "$(ARM_SDK_DIR)" ] && echo "exists"), exists)
264 ARM_SDK_PREFIX := $(ARM_SDK_DIR)/bin/arm-none-eabi-
265 else ifeq (,$(filter %_install test% clean% %-print checks help, $(MAKECMDGOALS)))
266 GCC_VERSION = $(shell arm-none-eabi-gcc -dumpversion)
267 ifeq ($(GCC_VERSION),)
268 $(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)
269 else ifneq ($(GCC_VERSION), $(GCC_REQUIRED_VERSION))
270 $(error **ERROR** your arm-none-eabi-gcc is '$(GCC_VERSION)', but '$(GCC_REQUIRED_VERSION)' is expected. Override with 'GCC_REQUIRED_VERSION' in make/local.mk or run 'make arm_sdk_install' to install the right version automatically in the tools folder of this repo)
271 endif
273 # ARM tookchain is in the path, and the version is what's required.
274 ARM_SDK_PREFIX ?= arm-none-eabi-
275 endif
277 ifeq ($(shell [ -d "$(ZIP_DIR)" ] && echo "exists"), exists)
278 export ZIPBIN := $(ZIP_DIR)/zip
279 else
280 export ZIPBIN := zip
281 endif
283 ifeq ($(shell [ -d "$(OPENOCD_DIR)" ] && echo "exists"), exists)
284 OPENOCD := $(OPENOCD_DIR)/bin/openocd
285 else
286 # not installed, hope it's in the path...
287 OPENOCD ?= openocd
288 endif
290 ifeq ($(shell [ -d "$(UNCRUSTIFY_DIR)" ] && echo "exists"), exists)
291 UNCRUSTIFY := $(UNCRUSTIFY_DIR)/bin/uncrustify
292 else
293 # not installed, hope it's in the path...
294 UNCRUSTIFY ?= uncrustify
295 endif
297 # Google Breakpad
298 DUMP_SYMBOLS_TOOL := $(TOOLS_DIR)/breakpad/$(OSFAMILY)-$(ARCHFAMILY)/dump_syms
299 BREAKPAD_URL := http://dronin.tracer.nz/tools/breakpad.zip
300 BREAKPAD_DL_FILE := $(DL_DIR)/$(notdir $(BREAKPAD_URL))
301 BREAKPAD_DIR := $(TOOLS_DIR)/breakpad
303 .PHONY: breakpad_install
304 breakpad_install: | $(DL_DIR) $(TOOLS_DIR)
305 breakpad_install: breakpad_clean
306 @echo " DOWNLOAD $(BREAKPAD_URL)"
307 $(V1) $(V1) curl -L -k -z "$(BREAKPAD_DL_FILE)" -o "$(BREAKPAD_DL_FILE)" "$(BREAKPAD_URL)"
308 @echo " EXTRACT $(notdir $(BREAKPAD_DL_FILE))"
309 $(V1) mkdir -p "$(BREAKPAD_DIR)"
310 $(V1) unzip -q -d $(BREAKPAD_DIR) "$(BREAKPAD_DL_FILE)"
311 ifeq ($(OSFAMILY), windows)
312 $(V1) ln -s "$(TOOLS_DIR)/breakpad/$(OSFAMILY)-i686" "$(TOOLS_DIR)/breakpad/$(OSFAMILY)-x86_64"
313 endif
315 .PHONY: breakpad_clean
316 breakpad_clean:
317 @echo " CLEAN $(BREAKPAD_DIR)"
318 $(V1) [ ! -d "$(BREAKPAD_DIR)" ] || $(RM) -rf $(BREAKPAD_DIR)
319 @echo " CLEAN $(BREAKPAD_DL_FILE)"
320 $(V1) $(RM) -f $(BREAKPAD_DL_FILE)