CF/BF - Further reduce osd slave dependencies on FC code.
[betaflight.git] / make / tools.mk
blobc3f251404d0d6ea794a53433abd48c24b26ff8e5
1 ###############################################################
3 # Installers for tools
5 # NOTE: These are not tied to the default goals
6 # and must be invoked manually
8 ###############################################################
10 ##############################
12 # Check that environmental variables are sane
14 ##############################
16 # Set up ARM (STM32) SDK
17 ARM_SDK_DIR ?= $(TOOLS_DIR)/gcc-arm-none-eabi-6-2017-q1-update
18 # Checked below, Should match the output of $(shell arm-none-eabi-gcc -dumpversion)
19 GCC_REQUIRED_VERSION ?= 6.3.1
21 ## arm_sdk_install : Install Arm SDK
22 .PHONY: arm_sdk_install
24 ARM_SDK_URL_BASE := https://developer.arm.com/-/media/Files/downloads/gnu-rm/6_1-2017q1/gcc-arm-none-eabi-6-2017-q1-update
26 # source: https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
27 ifdef LINUX
28 ARM_SDK_URL := $(ARM_SDK_URL_BASE)-linux.tar.bz2
29 endif
31 ifdef MACOSX
32 ARM_SDK_URL := $(ARM_SDK_URL_BASE)-mac.tar.bz2
33 endif
35 ifdef WINDOWS
36 ARM_SDK_URL := $(ARM_SDK_URL_BASE)-win32-zip.zip
37 endif
39 ARM_SDK_FILE := $(notdir $(ARM_SDK_URL))
41 SDK_INSTALL_MARKER := $(ARM_SDK_DIR)/bin/arm-none-eabi-gcc-$(GCC_REQUIRED_VERSION)
43 # order-only prereq on directory existance:
44 arm_sdk_install: | $(TOOLS_DIR)
46 arm_sdk_install: arm_sdk_download $(SDK_INSTALL_MARKER)
48 $(SDK_INSTALL_MARKER):
49 ifneq ($(OSFAMILY), windows)
50 # binary only release so just extract it
51 $(V1) tar -C $(TOOLS_DIR) -xjf "$(DL_DIR)/$(ARM_SDK_FILE)"
52 else
53 $(V1) unzip -q -d $(ARM_SDK_DIR) "$(DL_DIR)/$(ARM_SDK_FILE)"
54 endif
56 .PHONY: arm_sdk_download
57 arm_sdk_download: | $(DL_DIR)
58 arm_sdk_download: $(DL_DIR)/$(ARM_SDK_FILE)
59 $(DL_DIR)/$(ARM_SDK_FILE):
60 # download the source only if it's newer than what we already have
61 $(V1) curl -L -k -o "$(DL_DIR)/$(ARM_SDK_FILE)" -z "$(DL_DIR)/$(ARM_SDK_FILE)" "$(ARM_SDK_URL)"
64 ## arm_sdk_clean : Uninstall Arm SDK
65 .PHONY: arm_sdk_clean
66 arm_sdk_clean:
67 $(V1) [ ! -d "$(ARM_SDK_DIR)" ] || $(RM) -r $(ARM_SDK_DIR)
68 $(V1) [ ! -d "$(DL_DIR)" ] || $(RM) -r $(DL_DIR)
70 .PHONY: openocd_win_install
72 openocd_win_install: | $(DL_DIR) $(TOOLS_DIR)
73 openocd_win_install: OPENOCD_URL := git://git.code.sf.net/p/openocd/code
74 openocd_win_install: OPENOCD_REV := cf1418e9a85013bbf8dbcc2d2e9985695993d9f4
75 openocd_win_install: OPENOCD_OPTIONS :=
77 ifeq ($(OPENOCD_FTDI), yes)
78 openocd_win_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --enable-ft2232_ftd2xx --with-ftd2xx-win32-zipdir=$(FTD2XX_DIR)
79 endif
81 openocd_win_install: openocd_win_clean libusb_win_install ftd2xx_install
82 # download the source
83 $(V0) @echo " DOWNLOAD $(OPENOCD_URL) @ $(OPENOCD_REV)"
84 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
85 $(V1) mkdir -p "$(OPENOCD_BUILD_DIR)"
86 $(V1) git clone --no-checkout $(OPENOCD_URL) "$(DL_DIR)/openocd-build"
87 $(V1) ( \
88 cd $(OPENOCD_BUILD_DIR) ; \
89 git checkout -q $(OPENOCD_REV) ; \
92 # apply patches
93 $(V0) @echo " PATCH $(OPENOCD_BUILD_DIR)"
94 $(V1) ( \
95 cd $(OPENOCD_BUILD_DIR) ; \
96 git apply < $(ROOT_DIR)/flight/Project/OpenOCD/0003-freertos-cm4f-fpu-support.patch ; \
97 git apply < $(ROOT_DIR)/flight/Project/OpenOCD/0004-st-icdi-disable.patch ; \
100 # build and install
101 $(V0) @echo " BUILD $(OPENOCD_WIN_DIR)"
102 $(V1) mkdir -p "$(OPENOCD_WIN_DIR)"
103 $(V1) ( \
104 cd $(OPENOCD_BUILD_DIR) ; \
105 ./bootstrap ; \
106 ./configure --enable-maintainer-mode --prefix="$(OPENOCD_WIN_DIR)" \
107 --build=i686-pc-linux-gnu --host=i586-mingw32msvc \
108 CPPFLAGS=-I$(LIBUSB_WIN_DIR)/include \
109 LDFLAGS=-L$(LIBUSB_WIN_DIR)/lib/gcc \
110 $(OPENOCD_OPTIONS) \
111 --disable-werror \
112 --enable-stlink ; \
113 $(MAKE) ; \
114 $(MAKE) install ; \
117 # delete the extracted source when we're done
118 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
120 .PHONY: openocd_win_clean
121 openocd_win_clean:
122 $(V0) @echo " CLEAN $(OPENOCD_WIN_DIR)"
123 $(V1) [ ! -d "$(OPENOCD_WIN_DIR)" ] || $(RM) -r "$(OPENOCD_WIN_DIR)"
125 # Set up openocd tools
126 OPENOCD_DIR := $(TOOLS_DIR)/openocd
127 OPENOCD_WIN_DIR := $(TOOLS_DIR)/openocd_win
128 OPENOCD_BUILD_DIR := $(DL_DIR)/openocd-build
130 .PHONY: openocd_install
132 openocd_install: | $(DL_DIR) $(TOOLS_DIR)
133 openocd_install: OPENOCD_URL := git://git.code.sf.net/p/openocd/code
134 openocd_install: OPENOCD_TAG := v0.9.0
135 openocd_install: OPENOCD_OPTIONS := --enable-maintainer-mode --prefix="$(OPENOCD_DIR)" --enable-buspirate --enable-stlink
137 ifeq ($(OPENOCD_FTDI), yes)
138 openocd_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --enable-ftdi
139 endif
141 ifeq ($(UNAME), Darwin)
142 openocd_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --disable-option-checking
143 endif
145 openocd_install: openocd_clean
146 # download the source
147 $(V0) @echo " DOWNLOAD $(OPENOCD_URL) @ $(OPENOCD_TAG)"
148 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
149 $(V1) mkdir -p "$(OPENOCD_BUILD_DIR)"
150 $(V1) git clone --no-checkout $(OPENOCD_URL) "$(OPENOCD_BUILD_DIR)"
151 $(V1) ( \
152 cd $(OPENOCD_BUILD_DIR) ; \
153 git checkout -q tags/$(OPENOCD_TAG) ; \
156 # build and install
157 $(V0) @echo " BUILD $(OPENOCD_DIR)"
158 $(V1) mkdir -p "$(OPENOCD_DIR)"
159 $(V1) ( \
160 cd $(OPENOCD_BUILD_DIR) ; \
161 ./bootstrap ; \
162 ./configure $(OPENOCD_OPTIONS) ; \
163 $(MAKE) ; \
164 $(MAKE) install ; \
167 # delete the extracted source when we're done
168 $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)"
170 .PHONY: openocd_clean
171 openocd_clean:
172 $(V0) @echo " CLEAN $(OPENOCD_DIR)"
173 $(V1) [ ! -d "$(OPENOCD_DIR)" ] || $(RM) -r "$(OPENOCD_DIR)"
175 STM32FLASH_DIR := $(TOOLS_DIR)/stm32flash
177 .PHONY: stm32flash_install
178 stm32flash_install: STM32FLASH_URL := http://stm32flash.googlecode.com/svn/trunk
179 stm32flash_install: STM32FLASH_REV := 61
180 stm32flash_install: stm32flash_clean
181 # download the source
182 $(V0) @echo " DOWNLOAD $(STM32FLASH_URL) @ r$(STM32FLASH_REV)"
183 $(V1) svn export -q -r "$(STM32FLASH_REV)" "$(STM32FLASH_URL)" "$(STM32FLASH_DIR)"
185 # build
186 $(V0) @echo " BUILD $(STM32FLASH_DIR)"
187 $(V1) $(MAKE) --silent -C $(STM32FLASH_DIR) all
189 .PHONY: stm32flash_clean
190 stm32flash_clean:
191 $(V0) @echo " CLEAN $(STM32FLASH_DIR)"
192 $(V1) [ ! -d "$(STM32FLASH_DIR)" ] || $(RM) -r "$(STM32FLASH_DIR)"
194 DFUUTIL_DIR := $(TOOLS_DIR)/dfu-util
196 .PHONY: dfuutil_install
197 dfuutil_install: DFUUTIL_URL := http://dfu-util.sourceforge.net/releases/dfu-util-0.8.tar.gz
198 dfuutil_install: DFUUTIL_FILE := $(notdir $(DFUUTIL_URL))
199 dfuutil_install: | $(DL_DIR) $(TOOLS_DIR)
200 dfuutil_install: dfuutil_clean
201 # download the source
202 $(V0) @echo " DOWNLOAD $(DFUUTIL_URL)"
203 $(V1) curl -L -k -o "$(DL_DIR)/$(DFUUTIL_FILE)" "$(DFUUTIL_URL)"
205 # extract the source
206 $(V0) @echo " EXTRACT $(DFUUTIL_FILE)"
207 $(V1) [ ! -d "$(DL_DIR)/dfuutil-build" ] || $(RM) -r "$(DL_DIR)/dfuutil-build"
208 $(V1) mkdir -p "$(DL_DIR)/dfuutil-build"
209 $(V1) tar -C $(DL_DIR)/dfuutil-build -xf "$(DL_DIR)/$(DFUUTIL_FILE)"
211 # build
212 $(V0) @echo " BUILD $(DFUUTIL_DIR)"
213 $(V1) mkdir -p "$(DFUUTIL_DIR)"
214 $(V1) ( \
215 cd $(DL_DIR)/dfuutil-build/dfu-util-0.8 ; \
216 ./configure --prefix="$(DFUUTIL_DIR)" ; \
217 $(MAKE) ; \
218 $(MAKE) install ; \
221 .PHONY: dfuutil_clean
222 dfuutil_clean:
223 $(V0) @echo " CLEAN $(DFUUTIL_DIR)"
224 $(V1) [ ! -d "$(DFUUTIL_DIR)" ] || $(RM) -r "$(DFUUTIL_DIR)"
226 # Set up uncrustify tools
227 UNCRUSTIFY_DIR := $(TOOLS_DIR)/uncrustify-0.61
228 UNCRUSTIFY_BUILD_DIR := $(DL_DIR)/uncrustify
230 .PHONY: uncrustify_install
231 uncrustify_install: | $(DL_DIR) $(TOOLS_DIR)
232 uncrustify_install: UNCRUSTIFY_URL := http://downloads.sourceforge.net/project/uncrustify/uncrustify/uncrustify-0.61/uncrustify-0.61.tar.gz
233 uncrustify_install: UNCRUSTIFY_FILE := uncrustify-0.61.tar.gz
234 uncrustify_install: UNCRUSTIFY_OPTIONS := prefix=$(UNCRUSTIFY_DIR)
235 uncrustify_install: uncrustify_clean
236 ifneq ($(OSFAMILY), windows)
237 $(V0) @echo " DOWNLOAD $(UNCRUSTIFY_URL)"
238 $(V1) curl -L -k -o "$(DL_DIR)/$(UNCRUSTIFY_FILE)" "$(UNCRUSTIFY_URL)"
239 endif
240 # extract the src
241 $(V0) @echo " EXTRACT $(UNCRUSTIFY_FILE)"
242 $(V1) tar -C $(TOOLS_DIR) -xf "$(DL_DIR)/$(UNCRUSTIFY_FILE)"
244 $(V0) @echo " BUILD $(UNCRUSTIFY_DIR)"
245 $(V1) ( \
246 cd $(UNCRUSTIFY_DIR) ; \
247 ./configure --prefix="$(UNCRUSTIFY_DIR)" ; \
248 $(MAKE) ; \
249 $(MAKE) install ; \
251 # delete the extracted source when we're done
252 $(V1) [ ! -d "$(UNCRUSTIFY_BUILD_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_BUILD_DIR)"
254 .PHONY: uncrustify_clean
255 uncrustify_clean:
256 $(V0) @echo " CLEAN $(UNCRUSTIFY_DIR)"
257 $(V1) [ ! -d "$(UNCRUSTIFY_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_DIR)"
258 $(V0) @echo " CLEAN $(UNCRUSTIFY_BUILD_DIR)"
259 $(V1) [ ! -d "$(UNCRUSTIFY_BUILD_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_BUILD_DIR)"
261 # ZIP download URL
262 zip_install: ZIP_URL := http://pkgs.fedoraproject.org/repo/pkgs/zip/zip30.tar.gz/7b74551e63f8ee6aab6fbc86676c0d37/zip30.tar.gz
264 zip_install: ZIP_FILE := $(notdir $(ZIP_URL))
266 ZIP_DIR = $(TOOLS_DIR)/zip30
268 # order-only prereq on directory existance:
269 zip_install : | $(DL_DIR) $(TOOLS_DIR)
270 zip_install: zip_clean
271 $(V1) curl -L -k -o "$(DL_DIR)/$(ZIP_FILE)" "$(ZIP_URL)"
272 $(V1) tar --force-local -C $(TOOLS_DIR) -xzf "$(DL_DIR)/$(ZIP_FILE)"
273 ifneq ($(OSFAMILY), windows)
274 $(V1) cd "$(ZIP_DIR)" && $(MAKE) -f unix/Makefile generic_gcc
275 else
276 $(V1) cd "$(ZIP_DIR)" && $(MAKE) -f win32/makefile.gcc
277 endif
279 .PHONY: zip_clean
280 zip_clean:
281 $(V1) [ ! -d "$(ZIP_DIR)" ] || $(RM) -rf $(ZIP_DIR)
283 ##############################
285 # Set up paths to tools
287 ##############################
289 ifeq ($(shell [ -d "$(ARM_SDK_DIR)" ] && echo "exists"), exists)
290 ARM_SDK_PREFIX := $(ARM_SDK_DIR)/bin/arm-none-eabi-
291 else ifeq (,$(findstring _install,$(MAKECMDGOALS)))
292 GCC_VERSION = $(shell arm-none-eabi-gcc -dumpversion)
293 ifeq ($(GCC_VERSION),)
294 $(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)
295 else ifneq ($(GCC_VERSION), $(GCC_REQUIRED_VERSION))
296 $(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)
297 endif
299 # ARM tookchain is in the path, and the version is what's required.
300 ARM_SDK_PREFIX ?= arm-none-eabi-
301 endif
303 ifeq ($(shell [ -d "$(ZIP_DIR)" ] && echo "exists"), exists)
304 export ZIPBIN := $(ZIP_DIR)/zip
305 else
306 export ZIPBIN := zip
307 endif
309 ifeq ($(shell [ -d "$(OPENOCD_DIR)" ] && echo "exists"), exists)
310 OPENOCD := $(OPENOCD_DIR)/bin/openocd
311 else
312 # not installed, hope it's in the path...
313 OPENOCD ?= openocd
314 endif
316 ifeq ($(shell [ -d "$(UNCRUSTIFY_DIR)" ] && echo "exists"), exists)
317 UNCRUSTIFY := $(UNCRUSTIFY_DIR)/bin/uncrustify
318 else
319 # not installed, hope it's in the path...
320 UNCRUSTIFY ?= uncrustify
321 endif
323 # Google Breakpad
324 DUMP_SYMBOLS_TOOL := $(TOOLS_DIR)/breakpad/$(OSFAMILY)-$(ARCHFAMILY)/dump_syms
325 BREAKPAD_URL := http://dronin.tracer.nz/tools/breakpad.zip
326 BREAKPAD_DL_FILE := $(DL_DIR)/$(notdir $(BREAKPAD_URL))
327 BREAKPAD_DIR := $(TOOLS_DIR)/breakpad
329 .PHONY: breakpad_install
330 breakpad_install: | $(DL_DIR) $(TOOLS_DIR)
331 breakpad_install: breakpad_clean
332 $(V0) @echo " DOWNLOAD $(BREAKPAD_URL)"
333 $(V1) $(V1) curl -L -k -z "$(BREAKPAD_DL_FILE)" -o "$(BREAKPAD_DL_FILE)" "$(BREAKPAD_URL)"
334 $(V0) @echo " EXTRACT $(notdir $(BREAKPAD_DL_FILE))"
335 $(V1) mkdir -p "$(BREAKPAD_DIR)"
336 $(V1) unzip -q -d $(BREAKPAD_DIR) "$(BREAKPAD_DL_FILE)"
337 ifeq ($(OSFAMILY), windows)
338 $(V1) ln -s "$(TOOLS_DIR)/breakpad/$(OSFAMILY)-i686" "$(TOOLS_DIR)/breakpad/$(OSFAMILY)-x86_64"
339 endif
341 .PHONY: breakpad_clean
342 breakpad_clean:
343 $(V0) @echo " CLEAN $(BREAKPAD_DIR)"
344 $(V1) [ ! -d "$(BREAKPAD_DIR)" ] || $(RM) -rf $(BREAKPAD_DIR)
345 $(V0) @echo " CLEAN $(BREAKPAD_DL_FILE)"
346 $(V1) $(RM) -f $(BREAKPAD_DL_FILE)