1 ###############################################################
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-9-2019-q4-major
18 # Checked below, Should match the output of $(shell arm-none-eabi-gcc -dumpversion)
19 GCC_REQUIRED_VERSION ?
= 9.2.1
21 .PHONY
: arm_sdk_version
24 $(V1
) $(ARM_SDK_PREFIX
)gcc
--version
26 ## arm_sdk_install : Install Arm SDK
27 .PHONY
: arm_sdk_install
29 ARM_SDK_URL_BASE
:= https
://developer.arm.com
/-/media
/Files
/downloads
/gnu-rm
/9-2019q4
/RC2.1
/gcc-arm-none-eabi-9-2019-q4-major
31 # source: https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
33 ARM_SDK_URL
:= $(ARM_SDK_URL_BASE
)-x86_64-linux.
tar.bz2
37 ARM_SDK_URL
:= $(ARM_SDK_URL_BASE
)-mac.
tar.bz2
41 ARM_SDK_URL
:= $(ARM_SDK_URL_BASE
)-win32.zip.bz2
44 ARM_SDK_FILE
:= $(notdir $(ARM_SDK_URL
))
46 SDK_INSTALL_MARKER
:= $(ARM_SDK_DIR
)/bin
/arm-none-eabi-gcc-
$(GCC_REQUIRED_VERSION
)
48 # order-only prereq on directory existance:
49 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)"
58 $(V1
) unzip
-q
-d
$(ARM_SDK_DIR
) "$(DL_DIR)/$(ARM_SDK_FILE)"
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
"$(DL_DIR)/$(ARM_SDK_FILE)" -z
"$(DL_DIR)/$(ARM_SDK_FILE)" "$(ARM_SDK_URL)"
69 ## arm_sdk_clean : Uninstall Arm SDK
72 $(V1
) [ ! -d
"$(ARM_SDK_DIR)" ] ||
$(RM
) -r
$(ARM_SDK_DIR
)
73 $(V1
) [ ! -d
"$(DL_DIR)" ] ||
$(RM
) -r
$(DL_DIR
)
75 .PHONY
: openocd_win_install
77 openocd_win_install
: |
$(DL_DIR
) $(TOOLS_DIR
)
78 openocd_win_install
: OPENOCD_URL
:= git
://git.code.sf.net
/p
/openocd
/code
79 openocd_win_install
: OPENOCD_REV
:= cf1418e9a85013bbf8dbcc2d2e9985695993d9f4
80 openocd_win_install
: OPENOCD_OPTIONS
:=
82 ifeq ($(OPENOCD_FTDI
), yes
)
83 openocd_win_install
: OPENOCD_OPTIONS
:= $(OPENOCD_OPTIONS
) --enable-ft2232_ftd2xx
--with-ftd2xx-win32-zipdir
=$(FTD2XX_DIR
)
86 openocd_win_install
: openocd_win_clean libusb_win_install ftd2xx_install
88 @echo
" DOWNLOAD $(OPENOCD_URL) @ $(OPENOCD_REV)"
89 $(V1
) [ ! -d
"$(OPENOCD_BUILD_DIR)" ] ||
$(RM
) -rf
"$(OPENOCD_BUILD_DIR)"
90 $(V1
) mkdir
-p
"$(OPENOCD_BUILD_DIR)"
91 $(V1
) git clone
--no-checkout
$(OPENOCD_URL
) "$(DL_DIR)/openocd-build"
93 cd
$(OPENOCD_BUILD_DIR
) ; \
94 git checkout
-q
$(OPENOCD_REV
) ; \
98 @echo
" PATCH $(OPENOCD_BUILD_DIR)"
100 cd
$(OPENOCD_BUILD_DIR
) ; \
101 git apply
< $(ROOT_DIR
)/flight
/Project
/OpenOCD
/0003-freertos-cm4f-fpu-support.patch
; \
102 git apply
< $(ROOT_DIR
)/flight
/Project
/OpenOCD
/0004-st-icdi-disable.patch
; \
106 @echo
" BUILD $(OPENOCD_WIN_DIR)"
107 $(V1
) mkdir
-p
"$(OPENOCD_WIN_DIR)"
109 cd
$(OPENOCD_BUILD_DIR
) ; \
111 .
/configure
--enable-maintainer-mode
--prefix="$(OPENOCD_WIN_DIR)" \
112 --build
=i686-pc-linux-gnu
--host
=i586-mingw32msvc \
113 CPPFLAGS
=-I
$(LIBUSB_WIN_DIR
)/include \
114 LDFLAGS
=-L
$(LIBUSB_WIN_DIR
)/lib
/gcc \
122 # delete the extracted source when we're done
123 $(V1
) [ ! -d
"$(OPENOCD_BUILD_DIR)" ] ||
$(RM
) -rf
"$(OPENOCD_BUILD_DIR)"
125 .PHONY
: openocd_win_clean
127 @echo
" CLEAN $(OPENOCD_WIN_DIR)"
128 $(V1
) [ ! -d
"$(OPENOCD_WIN_DIR)" ] ||
$(RM
) -r
"$(OPENOCD_WIN_DIR)"
130 # Set up openocd tools
131 OPENOCD_DIR
:= $(TOOLS_DIR
)/openocd
132 OPENOCD_WIN_DIR
:= $(TOOLS_DIR
)/openocd_win
133 OPENOCD_BUILD_DIR
:= $(DL_DIR
)/openocd-build
135 .PHONY
: openocd_install
137 openocd_install
: |
$(DL_DIR
) $(TOOLS_DIR
)
138 openocd_install
: OPENOCD_URL
:= git
://git.code.sf.net
/p
/openocd
/code
139 openocd_install
: OPENOCD_TAG
:= v0.9
.0
140 openocd_install
: OPENOCD_OPTIONS
:= --enable-maintainer-mode
--prefix="$(OPENOCD_DIR)" --enable-buspirate
--enable-stlink
142 ifeq ($(OPENOCD_FTDI
), yes
)
143 openocd_install
: OPENOCD_OPTIONS
:= $(OPENOCD_OPTIONS
) --enable-ftdi
146 ifeq ($(UNAME
), Darwin
)
147 openocd_install
: OPENOCD_OPTIONS
:= $(OPENOCD_OPTIONS
) --disable-option-checking
150 openocd_install
: openocd_clean
151 # download the source
152 @echo
" DOWNLOAD $(OPENOCD_URL) @ $(OPENOCD_TAG)"
153 $(V1
) [ ! -d
"$(OPENOCD_BUILD_DIR)" ] ||
$(RM
) -rf
"$(OPENOCD_BUILD_DIR)"
154 $(V1
) mkdir
-p
"$(OPENOCD_BUILD_DIR)"
155 $(V1
) git clone
--no-checkout
$(OPENOCD_URL
) "$(OPENOCD_BUILD_DIR)"
157 cd
$(OPENOCD_BUILD_DIR
) ; \
158 git checkout
-q
tags/$(OPENOCD_TAG
) ; \
162 @echo
" BUILD $(OPENOCD_DIR)"
163 $(V1
) mkdir
-p
"$(OPENOCD_DIR)"
165 cd
$(OPENOCD_BUILD_DIR
) ; \
167 .
/configure
$(OPENOCD_OPTIONS
) ; \
172 # delete the extracted source when we're done
173 $(V1
) [ ! -d
"$(OPENOCD_BUILD_DIR)" ] ||
$(RM
) -rf
"$(OPENOCD_BUILD_DIR)"
175 .PHONY
: openocd_clean
177 @echo
" CLEAN $(OPENOCD_DIR)"
178 $(V1
) [ ! -d
"$(OPENOCD_DIR)" ] ||
$(RM
) -r
"$(OPENOCD_DIR)"
180 STM32FLASH_DIR
:= $(TOOLS_DIR
)/stm32flash
182 .PHONY
: stm32flash_install
183 stm32flash_install
: STM32FLASH_URL
:= http
://stm32flash.googlecode.com
/svn
/trunk
184 stm32flash_install
: STM32FLASH_REV
:= 61
185 stm32flash_install
: stm32flash_clean
186 # download the source
187 @echo
" DOWNLOAD $(STM32FLASH_URL) @ r$(STM32FLASH_REV)"
188 $(V1
) svn
export -q
-r
"$(STM32FLASH_REV)" "$(STM32FLASH_URL)" "$(STM32FLASH_DIR)"
191 @echo
" BUILD $(STM32FLASH_DIR)"
192 $(V1
) $(MAKE
) --silent
-C
$(STM32FLASH_DIR
) all
194 .PHONY
: stm32flash_clean
196 @echo
" CLEAN $(STM32FLASH_DIR)"
197 $(V1
) [ ! -d
"$(STM32FLASH_DIR)" ] ||
$(RM
) -r
"$(STM32FLASH_DIR)"
199 DFUUTIL_DIR
:= $(TOOLS_DIR
)/dfu-util
201 .PHONY
: dfuutil_install
202 dfuutil_install
: DFUUTIL_URL
:= http
://dfu-util.sourceforge.net
/releases
/dfu-util-0.8.
tar.gz
203 dfuutil_install
: DFUUTIL_FILE
:= $(notdir $(DFUUTIL_URL
))
204 dfuutil_install
: |
$(DL_DIR
) $(TOOLS_DIR
)
205 dfuutil_install
: dfuutil_clean
206 # download the source
207 @echo
" DOWNLOAD $(DFUUTIL_URL)"
208 $(V1
) curl
-L
-k
-o
"$(DL_DIR)/$(DFUUTIL_FILE)" "$(DFUUTIL_URL)"
211 @echo
" EXTRACT $(DFUUTIL_FILE)"
212 $(V1
) [ ! -d
"$(DL_DIR)/dfuutil-build" ] ||
$(RM
) -r
"$(DL_DIR)/dfuutil-build"
213 $(V1
) mkdir
-p
"$(DL_DIR)/dfuutil-build"
214 $(V1
) tar -C
$(DL_DIR
)/dfuutil-build
-xf
"$(DL_DIR)/$(DFUUTIL_FILE)"
217 @echo
" BUILD $(DFUUTIL_DIR)"
218 $(V1
) mkdir
-p
"$(DFUUTIL_DIR)"
220 cd
$(DL_DIR
)/dfuutil-build
/dfu-util-0.8
; \
221 .
/configure
--prefix="$(DFUUTIL_DIR)" ; \
226 .PHONY
: dfuutil_clean
228 @echo
" CLEAN $(DFUUTIL_DIR)"
229 $(V1
) [ ! -d
"$(DFUUTIL_DIR)" ] ||
$(RM
) -r
"$(DFUUTIL_DIR)"
231 # Set up uncrustify tools
232 UNCRUSTIFY_DIR
:= $(TOOLS_DIR
)/uncrustify-0.61
233 UNCRUSTIFY_BUILD_DIR
:= $(DL_DIR
)/uncrustify
235 .PHONY
: uncrustify_install
236 uncrustify_install
: |
$(DL_DIR
) $(TOOLS_DIR
)
237 uncrustify_install
: UNCRUSTIFY_URL
:= http
://downloads.sourceforge.net
/project
/uncrustify
/uncrustify
/uncrustify-0.61
/uncrustify-0.61.
tar.gz
238 uncrustify_install
: UNCRUSTIFY_FILE
:= uncrustify-0.61.
tar.gz
239 uncrustify_install
: UNCRUSTIFY_OPTIONS
:= prefix=$(UNCRUSTIFY_DIR
)
240 uncrustify_install
: uncrustify_clean
241 ifneq ($(OSFAMILY
), windows
)
242 @echo
" DOWNLOAD $(UNCRUSTIFY_URL)"
243 $(V1
) curl
-L
-k
-o
"$(DL_DIR)/$(UNCRUSTIFY_FILE)" "$(UNCRUSTIFY_URL)"
246 @echo
" EXTRACT $(UNCRUSTIFY_FILE)"
247 $(V1
) tar -C
$(TOOLS_DIR
) -xf
"$(DL_DIR)/$(UNCRUSTIFY_FILE)"
249 @echo
" BUILD $(UNCRUSTIFY_DIR)"
251 cd
$(UNCRUSTIFY_DIR
) ; \
252 .
/configure
--prefix="$(UNCRUSTIFY_DIR)" ; \
256 # delete the extracted source when we're done
257 $(V1
) [ ! -d
"$(UNCRUSTIFY_BUILD_DIR)" ] ||
$(RM
) -r
"$(UNCRUSTIFY_BUILD_DIR)"
259 .PHONY
: uncrustify_clean
261 @echo
" CLEAN $(UNCRUSTIFY_DIR)"
262 $(V1
) [ ! -d
"$(UNCRUSTIFY_DIR)" ] ||
$(RM
) -r
"$(UNCRUSTIFY_DIR)"
263 @echo
" CLEAN $(UNCRUSTIFY_BUILD_DIR)"
264 $(V1
) [ ! -d
"$(UNCRUSTIFY_BUILD_DIR)" ] ||
$(RM
) -r
"$(UNCRUSTIFY_BUILD_DIR)"
267 zip_install
: ZIP_URL
:= http
://pkgs.fedoraproject.org
/repo
/pkgs
/zip
/zip30.
tar.gz
/7b74551e63f8ee6aab6fbc86676c0d37
/zip30.
tar.gz
269 zip_install
: ZIP_FILE
:= $(notdir $(ZIP_URL
))
271 ZIP_DIR
= $(TOOLS_DIR
)/zip30
273 # order-only prereq on directory existance:
274 zip_install
: |
$(DL_DIR
) $(TOOLS_DIR
)
275 zip_install
: zip_clean
276 $(V1
) curl
-L
-k
-o
"$(DL_DIR)/$(ZIP_FILE)" "$(ZIP_URL)"
277 $(V1
) tar --force-local
-C
$(TOOLS_DIR
) -xzf
"$(DL_DIR)/$(ZIP_FILE)"
278 ifneq ($(OSFAMILY
), windows
)
279 $(V1
) cd
"$(ZIP_DIR)" && $(MAKE
) -f unix
/Makefile generic_gcc
281 $(V1
) cd
"$(ZIP_DIR)" && $(MAKE
) -f win32
/makefile.gcc
286 $(V1
) [ ! -d
"$(ZIP_DIR)" ] ||
$(RM
) -rf
$(ZIP_DIR
)
288 ##############################
290 # Set up paths to tools
292 ##############################
294 ifeq ($(shell [ -d
"$(ARM_SDK_DIR)" ] && echo
"exists"), exists
)
295 ARM_SDK_PREFIX
:= $(ARM_SDK_DIR
)/bin
/arm-none-eabi-
296 else ifeq (,$(findstring _install
,$(MAKECMDGOALS
)))
297 GCC_VERSION
= $(shell arm-none-eabi-gcc
-dumpversion
)
298 ifeq ($(GCC_VERSION
),)
299 $(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
)
300 else ifneq ($(GCC_VERSION
), $(GCC_REQUIRED_VERSION
))
301 $(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
)
304 # ARM tookchain is in the path, and the version is what's required.
305 ARM_SDK_PREFIX ?
= arm-none-eabi-
308 ifeq ($(shell [ -d
"$(ZIP_DIR)" ] && echo
"exists"), exists
)
309 export ZIPBIN
:= $(ZIP_DIR
)/zip
314 ifeq ($(shell [ -d
"$(OPENOCD_DIR)" ] && echo
"exists"), exists
)
315 OPENOCD
:= $(OPENOCD_DIR
)/bin
/openocd
317 # not installed, hope it's in the path...
321 ifeq ($(shell [ -d
"$(UNCRUSTIFY_DIR)" ] && echo
"exists"), exists
)
322 UNCRUSTIFY
:= $(UNCRUSTIFY_DIR
)/bin
/uncrustify
324 # not installed, hope it's in the path...
325 UNCRUSTIFY ?
= uncrustify
329 DUMP_SYMBOLS_TOOL
:= $(TOOLS_DIR
)/breakpad
/$(OSFAMILY
)-$(ARCHFAMILY
)/dump_syms
330 BREAKPAD_URL
:= http
://dronin.tracer.nz
/tools
/breakpad.zip
331 BREAKPAD_DL_FILE
:= $(DL_DIR
)/$(notdir $(BREAKPAD_URL
))
332 BREAKPAD_DIR
:= $(TOOLS_DIR
)/breakpad
334 .PHONY
: breakpad_install
335 breakpad_install
: |
$(DL_DIR
) $(TOOLS_DIR
)
336 breakpad_install
: breakpad_clean
337 @echo
" DOWNLOAD $(BREAKPAD_URL)"
338 $(V1
) $(V1
) curl
-L
-k
-z
"$(BREAKPAD_DL_FILE)" -o
"$(BREAKPAD_DL_FILE)" "$(BREAKPAD_URL)"
339 @echo
" EXTRACT $(notdir $(BREAKPAD_DL_FILE))"
340 $(V1
) mkdir
-p
"$(BREAKPAD_DIR)"
341 $(V1
) unzip
-q
-d
$(BREAKPAD_DIR
) "$(BREAKPAD_DL_FILE)"
342 ifeq ($(OSFAMILY
), windows
)
343 $(V1
) ln
-s
"$(TOOLS_DIR)/breakpad/$(OSFAMILY)-i686" "$(TOOLS_DIR)/breakpad/$(OSFAMILY)-x86_64"
346 .PHONY
: breakpad_clean
348 @echo
" CLEAN $(BREAKPAD_DIR)"
349 $(V1
) [ ! -d
"$(BREAKPAD_DIR)" ] ||
$(RM
) -rf
$(BREAKPAD_DIR
)
350 @echo
" CLEAN $(BREAKPAD_DL_FILE)"
351 $(V1
) $(RM
) -f
$(BREAKPAD_DL_FILE
)