|
| 1 | +############################################################### |
| 2 | +# |
| 3 | +# Installers for tools |
| 4 | +# |
| 5 | +# NOTE: These are not tied to the default goals |
| 6 | +# and must be invoked manually |
| 7 | +# |
| 8 | +############################################################### |
| 9 | + |
| 10 | +############################## |
| 11 | +# |
| 12 | +# Check that environmental variables are sane |
| 13 | +# |
| 14 | +############################## |
| 15 | + |
| 16 | +# Set up ARM (STM32) SDK |
| 17 | +ARM_SDK_DIR ?= $(TOOLS_DIR)/gcc-arm-none-eabi-9-2020-q2-update |
| 18 | +# Checked below, Should match the output of $(shell arm-none-eabi-gcc -dumpversion) |
| 19 | +GCC_REQUIRED_VERSION ?= 9.3.1 |
| 20 | + |
| 21 | +.PHONY: arm_sdk_version |
| 22 | + |
| 23 | +arm_sdk_version: |
| 24 | + $(V1) $(ARM_SDK_PREFIX)gcc --version |
| 25 | + |
| 26 | +## arm_sdk_install : Install Arm SDK |
| 27 | +.PHONY: arm_sdk_install |
| 28 | + |
| 29 | +ARM_SDK_URL_BASE := https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update |
| 30 | + |
| 31 | +# source: https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads |
| 32 | +ifeq ($(OSFAMILY), linux) |
| 33 | + ARM_SDK_URL := $(ARM_SDK_URL_BASE)-x86_64-linux.tar.bz2 |
| 34 | +endif |
| 35 | + |
| 36 | +ifeq ($(OSFAMILY), macosx) |
| 37 | + ARM_SDK_URL := $(ARM_SDK_URL_BASE)-mac.tar.bz2 |
| 38 | +endif |
| 39 | + |
| 40 | +ifeq ($(OSFAMILY), windows) |
| 41 | + ARM_SDK_URL := $(ARM_SDK_URL_BASE)-win32.zip |
| 42 | +endif |
| 43 | + |
| 44 | +ARM_SDK_FILE := $(notdir $(ARM_SDK_URL)) |
| 45 | + |
| 46 | +SDK_INSTALL_MARKER := $(ARM_SDK_DIR)/bin/arm-none-eabi-gcc-$(GCC_REQUIRED_VERSION) |
| 47 | + |
| 48 | +# order-only prereq on directory existance: |
| 49 | +arm_sdk_install: | $(TOOLS_DIR) |
| 50 | + |
| 51 | +arm_sdk_install: arm_sdk_download $(SDK_INSTALL_MARKER) |
| 52 | + |
| 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 |
| 60 | + |
| 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)" |
| 67 | + |
| 68 | + |
| 69 | +## arm_sdk_clean : Uninstall Arm SDK |
| 70 | +.PHONY: arm_sdk_clean |
| 71 | +arm_sdk_clean: |
| 72 | + $(V1) [ ! -d "$(ARM_SDK_DIR)" ] || $(RM) -r $(ARM_SDK_DIR) |
| 73 | + $(V1) [ ! -d "$(DL_DIR)" ] || $(RM) -r $(DL_DIR) |
| 74 | + |
| 75 | +.PHONY: openocd_win_install |
| 76 | + |
| 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 := |
| 81 | + |
| 82 | +ifeq ($(OPENOCD_FTDI), yes) |
| 83 | +openocd_win_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --enable-ft2232_ftd2xx --with-ftd2xx-win32-zipdir=$(FTD2XX_DIR) |
| 84 | +endif |
| 85 | + |
| 86 | +openocd_win_install: openocd_win_clean libusb_win_install ftd2xx_install |
| 87 | + # download the source |
| 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" |
| 92 | + $(V1) ( \ |
| 93 | + cd $(OPENOCD_BUILD_DIR) ; \ |
| 94 | + git checkout -q $(OPENOCD_REV) ; \ |
| 95 | + ) |
| 96 | + |
| 97 | + # apply patches |
| 98 | + @echo " PATCH $(OPENOCD_BUILD_DIR)" |
| 99 | + $(V1) ( \ |
| 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 ; \ |
| 103 | + ) |
| 104 | + |
| 105 | + # build and install |
| 106 | + @echo " BUILD $(OPENOCD_WIN_DIR)" |
| 107 | + $(V1) mkdir -p "$(OPENOCD_WIN_DIR)" |
| 108 | + $(V1) ( \ |
| 109 | + cd $(OPENOCD_BUILD_DIR) ; \ |
| 110 | + ./bootstrap ; \ |
| 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 \ |
| 115 | + $(OPENOCD_OPTIONS) \ |
| 116 | + --disable-werror \ |
| 117 | + --enable-stlink ; \ |
| 118 | + $(MAKE) ; \ |
| 119 | + $(MAKE) install ; \ |
| 120 | + ) |
| 121 | + |
| 122 | + # delete the extracted source when we're done |
| 123 | + $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)" |
| 124 | + |
| 125 | +.PHONY: openocd_win_clean |
| 126 | +openocd_win_clean: |
| 127 | + @echo " CLEAN $(OPENOCD_WIN_DIR)" |
| 128 | + $(V1) [ ! -d "$(OPENOCD_WIN_DIR)" ] || $(RM) -r "$(OPENOCD_WIN_DIR)" |
| 129 | + |
| 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 |
| 134 | + |
| 135 | +.PHONY: openocd_install |
| 136 | + |
| 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 |
| 141 | + |
| 142 | +ifeq ($(OPENOCD_FTDI), yes) |
| 143 | +openocd_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --enable-ftdi |
| 144 | +endif |
| 145 | + |
| 146 | +ifeq ($(UNAME), Darwin) |
| 147 | +openocd_install: OPENOCD_OPTIONS := $(OPENOCD_OPTIONS) --disable-option-checking |
| 148 | +endif |
| 149 | + |
| 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)" |
| 156 | + $(V1) ( \ |
| 157 | + cd $(OPENOCD_BUILD_DIR) ; \ |
| 158 | + git checkout -q tags/$(OPENOCD_TAG) ; \ |
| 159 | + ) |
| 160 | + |
| 161 | + # build and install |
| 162 | + @echo " BUILD $(OPENOCD_DIR)" |
| 163 | + $(V1) mkdir -p "$(OPENOCD_DIR)" |
| 164 | + $(V1) ( \ |
| 165 | + cd $(OPENOCD_BUILD_DIR) ; \ |
| 166 | + ./bootstrap ; \ |
| 167 | + ./configure $(OPENOCD_OPTIONS) ; \ |
| 168 | + $(MAKE) ; \ |
| 169 | + $(MAKE) install ; \ |
| 170 | + ) |
| 171 | + |
| 172 | + # delete the extracted source when we're done |
| 173 | + $(V1) [ ! -d "$(OPENOCD_BUILD_DIR)" ] || $(RM) -rf "$(OPENOCD_BUILD_DIR)" |
| 174 | + |
| 175 | +.PHONY: openocd_clean |
| 176 | +openocd_clean: |
| 177 | + @echo " CLEAN $(OPENOCD_DIR)" |
| 178 | + $(V1) [ ! -d "$(OPENOCD_DIR)" ] || $(RM) -r "$(OPENOCD_DIR)" |
| 179 | + |
| 180 | +STM32FLASH_DIR := $(TOOLS_DIR)/stm32flash |
| 181 | + |
| 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)" |
| 189 | + |
| 190 | + # build |
| 191 | + @echo " BUILD $(STM32FLASH_DIR)" |
| 192 | + $(V1) $(MAKE) --silent -C $(STM32FLASH_DIR) all |
| 193 | + |
| 194 | +.PHONY: stm32flash_clean |
| 195 | +stm32flash_clean: |
| 196 | + @echo " CLEAN $(STM32FLASH_DIR)" |
| 197 | + $(V1) [ ! -d "$(STM32FLASH_DIR)" ] || $(RM) -r "$(STM32FLASH_DIR)" |
| 198 | + |
| 199 | +# Set up uncrustify tools |
| 200 | +UNCRUSTIFY_DIR := $(TOOLS_DIR)/uncrustify-0.61 |
| 201 | +UNCRUSTIFY_BUILD_DIR := $(DL_DIR)/uncrustify |
| 202 | + |
| 203 | +.PHONY: uncrustify_install |
| 204 | +uncrustify_install: | $(DL_DIR) $(TOOLS_DIR) |
| 205 | +uncrustify_install: UNCRUSTIFY_URL := http://downloads.sourceforge.net/project/uncrustify/uncrustify/uncrustify-0.61/uncrustify-0.61.tar.gz |
| 206 | +uncrustify_install: UNCRUSTIFY_FILE := uncrustify-0.61.tar.gz |
| 207 | +uncrustify_install: UNCRUSTIFY_OPTIONS := prefix=$(UNCRUSTIFY_DIR) |
| 208 | +uncrustify_install: uncrustify_clean |
| 209 | +ifneq ($(OSFAMILY), windows) |
| 210 | + @echo " DOWNLOAD $(UNCRUSTIFY_URL)" |
| 211 | + $(V1) curl -L -k -o "$(DL_DIR)/$(UNCRUSTIFY_FILE)" "$(UNCRUSTIFY_URL)" |
| 212 | +endif |
| 213 | + # extract the src |
| 214 | + @echo " EXTRACT $(UNCRUSTIFY_FILE)" |
| 215 | + $(V1) tar -C $(TOOLS_DIR) -xf "$(DL_DIR)/$(UNCRUSTIFY_FILE)" |
| 216 | + |
| 217 | + @echo " BUILD $(UNCRUSTIFY_DIR)" |
| 218 | + $(V1) ( \ |
| 219 | + cd $(UNCRUSTIFY_DIR) ; \ |
| 220 | + ./configure --prefix="$(UNCRUSTIFY_DIR)" ; \ |
| 221 | + $(MAKE) ; \ |
| 222 | + $(MAKE) install ; \ |
| 223 | + ) |
| 224 | + # delete the extracted source when we're done |
| 225 | + $(V1) [ ! -d "$(UNCRUSTIFY_BUILD_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_BUILD_DIR)" |
| 226 | + |
| 227 | +.PHONY: uncrustify_clean |
| 228 | +uncrustify_clean: |
| 229 | + @echo " CLEAN $(UNCRUSTIFY_DIR)" |
| 230 | + $(V1) [ ! -d "$(UNCRUSTIFY_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_DIR)" |
| 231 | + @echo " CLEAN $(UNCRUSTIFY_BUILD_DIR)" |
| 232 | + $(V1) [ ! -d "$(UNCRUSTIFY_BUILD_DIR)" ] || $(RM) -r "$(UNCRUSTIFY_BUILD_DIR)" |
| 233 | + |
| 234 | +# ZIP download URL |
| 235 | +zip_install: ZIP_URL := http://pkgs.fedoraproject.org/repo/pkgs/zip/zip30.tar.gz/7b74551e63f8ee6aab6fbc86676c0d37/zip30.tar.gz |
| 236 | + |
| 237 | +zip_install: ZIP_FILE := $(notdir $(ZIP_URL)) |
| 238 | + |
| 239 | +ZIP_DIR = $(TOOLS_DIR)/zip30 |
| 240 | + |
| 241 | +# order-only prereq on directory existance: |
| 242 | +zip_install : | $(DL_DIR) $(TOOLS_DIR) |
| 243 | +zip_install: zip_clean |
| 244 | + $(V1) curl -L -k -o "$(DL_DIR)/$(ZIP_FILE)" "$(ZIP_URL)" |
| 245 | + $(V1) tar --force-local -C $(TOOLS_DIR) -xzf "$(DL_DIR)/$(ZIP_FILE)" |
| 246 | +ifneq ($(OSFAMILY), windows) |
| 247 | + $(V1) cd "$(ZIP_DIR)" && $(MAKE) -f unix/Makefile generic_gcc |
| 248 | +else |
| 249 | + $(V1) cd "$(ZIP_DIR)" && $(MAKE) -f win32/makefile.gcc |
| 250 | +endif |
| 251 | + |
| 252 | +.PHONY: zip_clean |
| 253 | +zip_clean: |
| 254 | + $(V1) [ ! -d "$(ZIP_DIR)" ] || $(RM) -rf $(ZIP_DIR) |
| 255 | + |
| 256 | +############################## |
| 257 | +# |
| 258 | +# Set up paths to tools |
| 259 | +# |
| 260 | +############################## |
| 261 | + |
| 262 | +ifeq ($(shell [ -d "$(ARM_SDK_DIR)" ] && echo "exists"), exists) |
| 263 | + ARM_SDK_PREFIX := $(ARM_SDK_DIR)/bin/arm-none-eabi- |
| 264 | +else ifeq (,$(findstring _install,$(MAKECMDGOALS))) |
| 265 | + GCC_VERSION = $(shell arm-none-eabi-gcc -dumpversion) |
| 266 | + ifeq ($(GCC_VERSION),) |
| 267 | + $(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) |
| 268 | + else ifneq ($(GCC_VERSION), $(GCC_REQUIRED_VERSION)) |
| 269 | + $(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) |
| 270 | + endif |
| 271 | + |
| 272 | + # ARM tookchain is in the path, and the version is what's required. |
| 273 | + ARM_SDK_PREFIX ?= arm-none-eabi- |
| 274 | +endif |
| 275 | + |
| 276 | +ifeq ($(shell [ -d "$(ZIP_DIR)" ] && echo "exists"), exists) |
| 277 | + export ZIPBIN := $(ZIP_DIR)/zip |
| 278 | +else |
| 279 | + export ZIPBIN := zip |
| 280 | +endif |
| 281 | + |
| 282 | +ifeq ($(shell [ -d "$(OPENOCD_DIR)" ] && echo "exists"), exists) |
| 283 | + OPENOCD := $(OPENOCD_DIR)/bin/openocd |
| 284 | +else |
| 285 | + # not installed, hope it's in the path... |
| 286 | + OPENOCD ?= openocd |
| 287 | +endif |
| 288 | + |
| 289 | +ifeq ($(shell [ -d "$(UNCRUSTIFY_DIR)" ] && echo "exists"), exists) |
| 290 | + UNCRUSTIFY := $(UNCRUSTIFY_DIR)/bin/uncrustify |
| 291 | +else |
| 292 | + # not installed, hope it's in the path... |
| 293 | + UNCRUSTIFY ?= uncrustify |
| 294 | +endif |
| 295 | + |
| 296 | +# Google Breakpad |
| 297 | +DUMP_SYMBOLS_TOOL := $(TOOLS_DIR)/breakpad/$(OSFAMILY)-$(ARCHFAMILY)/dump_syms |
| 298 | +BREAKPAD_URL := http://dronin.tracer.nz/tools/breakpad.zip |
| 299 | +BREAKPAD_DL_FILE := $(DL_DIR)/$(notdir $(BREAKPAD_URL)) |
| 300 | +BREAKPAD_DIR := $(TOOLS_DIR)/breakpad |
| 301 | + |
| 302 | +.PHONY: breakpad_install |
| 303 | +breakpad_install: | $(DL_DIR) $(TOOLS_DIR) |
| 304 | +breakpad_install: breakpad_clean |
| 305 | + @echo " DOWNLOAD $(BREAKPAD_URL)" |
| 306 | + $(V1) $(V1) curl -L -k -z "$(BREAKPAD_DL_FILE)" -o "$(BREAKPAD_DL_FILE)" "$(BREAKPAD_URL)" |
| 307 | + @echo " EXTRACT $(notdir $(BREAKPAD_DL_FILE))" |
| 308 | + $(V1) mkdir -p "$(BREAKPAD_DIR)" |
| 309 | + $(V1) unzip -q -d $(BREAKPAD_DIR) "$(BREAKPAD_DL_FILE)" |
| 310 | +ifeq ($(OSFAMILY), windows) |
| 311 | + $(V1) ln -s "$(TOOLS_DIR)/breakpad/$(OSFAMILY)-i686" "$(TOOLS_DIR)/breakpad/$(OSFAMILY)-x86_64" |
| 312 | +endif |
| 313 | + |
| 314 | +.PHONY: breakpad_clean |
| 315 | +breakpad_clean: |
| 316 | + @echo " CLEAN $(BREAKPAD_DIR)" |
| 317 | + $(V1) [ ! -d "$(BREAKPAD_DIR)" ] || $(RM) -rf $(BREAKPAD_DIR) |
| 318 | + @echo " CLEAN $(BREAKPAD_DL_FILE)" |
| 319 | + $(V1) $(RM) -f $(BREAKPAD_DL_FILE) |
0 commit comments