forked from westlicht/performer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
151 lines (114 loc) · 4.45 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# This Makefile is used to setup the toolchain and application builds
# The application itself is configured and built using CMake
# Parts of this Makefile are based on https://github.com/cleanflight/cleanflight
# Directories
ROOT := $(CURDIR)/$(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
TOOLS_DIR ?= $(ROOT)/tools
DL_DIR := $(ROOT)/downloads
$(TOOLS_DIR):
mkdir -p $@
$(DL_DIR):
mkdir -p $@
# Determine host OS
UNAME := $(shell uname)
# Linux
ifeq ($(UNAME), Linux)
OSFAMILY := linux
LINUX := 1
endif
# Mac OSX
ifeq ($(UNAME), Darwin)
OSFAMILY := macosx
MACOSX := 1
endif
# Report error if no OS was determined
ifndef OSFAMILY
$(info uname reports $(UNAME))
$(info uname -m reports $(ARCH))
$(error failed to detect operating system)
endif
# Tools
.PHONY: tools_install
tools_install: arm_sdk_install openocd_install
.PHONY: tools_clean
tools_clean: arm_sdk_clean openocd_clean
# ARM toolchain
.PHONY: arm_sdk_install
# Source: https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
ARM_SDK_URL_BASE := https://developer.arm.com/-/media/Files/downloads/gnu-rm/6-2017q2/gcc-arm-none-eabi-6-2017-q2-update
ifdef LINUX
ARM_SDK_URL := $(ARM_SDK_URL_BASE)-linux.tar.bz2
endif
ifdef MACOSX
ARM_SDK_URL := $(ARM_SDK_URL_BASE)-mac.tar.bz2
endif
ARM_SDK_FILE := $(notdir $(ARM_SDK_URL))
ARM_SDK_DIR := $(TOOLS_DIR)/gcc-arm-none-eabi
GCC_REQUIRED_VERSION := 6.3.1
ARM_SDK_INSTALL_MARKER := $(ARM_SDK_DIR)/bin/arm-none-eabi-gcc-$(GCC_REQUIRED_VERSION)
arm_sdk_install: | $(TOOLS_DIR)
arm_sdk_install: arm_sdk_download $(ARM_SDK_INSTALL_MARKER)
$(ARM_SDK_INSTALL_MARKER):
$(V1) mkdir -p $(ARM_SDK_DIR)
$(V1) tar -C $(ARM_SDK_DIR) --strip-components=1 -xjf "$(DL_DIR)/$(ARM_SDK_FILE)"
.PHONY: arm_sdk_download
arm_sdk_download: | $(DL_DIR)
arm_sdk_download: $(DL_DIR)/$(ARM_SDK_FILE)
$(DL_DIR)/$(ARM_SDK_FILE):
$(V1) curl -L -k -o "$(DL_DIR)/$(ARM_SDK_FILE)" -z "$(DL_DIR)/$(ARM_SDK_FILE)" "$(ARM_SDK_URL)"
.PHONY: arm_sdk_clean
arm_sdk_clean:
$(V1) [ ! -d "$(ARM_SDK_DIR)" ] || $(RM) -r $(ARM_SDK_DIR)
$(V1) [ ! -f "$(DL_DIR)/$(ARM_SDK_FILE)" ] || $(RM) $(DL_DIR)/$(ARM_SDK_FILE)
# OpenOCD
.PHONY: openocd_install
OPENOCD_URL := https://downloads.sourceforge.net/project/openocd/openocd/0.10.0/openocd-0.10.0.tar.bz2
OPENOCD_FILE := $(notdir $(OPENOCD_URL))
OPENOCD_DIR := $(TOOLS_DIR)/openocd
OPENOCD_BUILD_DIR := $(TOOLS_DIR)/openocd-build
OPENOCD_INSTALL_MARKER := $(OPENOCD_DIR)/bin/openocd
OPENOCD_OPTIONS := --enable-maintainer-mode --prefix="$(OPENOCD_DIR)" --enable-buspirate --enable-stlink --enable-ftdi
openocd_install: | $(TOOLS_DIR)
openocd_install: openocd_download $(OPENOCD_INSTALL_MARKER)
$(OPENOCD_INSTALL_MARKER):
$(V1) mkdir -p $(OPENOCD_BUILD_DIR)
$(V1) tar -C $(OPENOCD_BUILD_DIR) --strip-components=1 -xjf "$(DL_DIR)/$(OPENOCD_FILE)"
# build and install
$(V1) mkdir -p $(OPENOCD_DIR)
$(V1) ( \
cd $(OPENOCD_BUILD_DIR) ; \
./bootstrap ; \
./configure $(OPENOCD_OPTIONS) ; \
$(MAKE) -j ; \
$(MAKE) install ; \
)
$(V1) $(RM) -r $(OPENOCD_BUILD_DIR)
.PHONY: openocd_download
openocd_download: | $(DL_DIR)
openocd_download: $(DL_DIR)/$(OPENOCD_FILE)
$(DL_DIR)/$(OPENOCD_FILE):
$(V1) curl -L -k -o "$(DL_DIR)/$(OPENOCD_FILE)" -z "$(DL_DIR)/$(OPENOCD_FILE)" "$(OPENOCD_URL)"
.PHONY: openocd_clean
openocd_clean:
$(V1) [ ! -d "$(OPENOCD_DIR)" ] || $(RM) -r $(OPENOCD_DIR)
$(V1) [ ! -f "$(DL_DIR)/$(OPENOCD_FILE)" ] || $(RM) $(DL_DIR)/$(OPENOCD_FILE)
# Setup CMake projects
.PHONY: setup_stm32
setup_stm32: arm_sdk_install
$(eval export PATH=$(ARM_SDK_DIR)/bin:$(OPENOCD_DIR)/bin:$(PATH))
(mkdir -p $(ROOT)/build/stm32/debug && cd $(ROOT)/build/stm32/debug && cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/arm.cmake -DCMAKE_BUILD_TYPE=Debug -DPLATFORM=stm32 ../../..)
(mkdir -p $(ROOT)/build/stm32/release && cd $(ROOT)/build/stm32/release && cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/arm.cmake -DCMAKE_BUILD_TYPE=Release -DPLATFORM=stm32 ../../..)
.PHONY: setup_sim
setup_sim:
(mkdir -p build/sim/debug && cd build/sim/debug && cmake -DCMAKE_BUILD_TYPE=Debug -DPLATFORM=sim ../../..)
(mkdir -p build/sim/release && cd build/sim/release && cmake -DCMAKE_BUILD_TYPE=Release -DPLATFORM=sim ../../..)
.PHONY: setup_www
setup_www:
(mkdir -p build/sim/www && cd build/sim/www && cmake -DCMAKE_TOOLCHAIN_FILE="${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" -DCMAKE_BUILD_TYPE=Release -DPLATFORM=sim ../../..)
# Deployment
.PHONY: deploy
deploy:
./scripts/deploy
.PHONY: deploy-simulator
deploy-simulator:
./scripts/deploy-simulator