forked from mavlink/MAVSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
181 lines (144 loc) · 4.67 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Makefile to build the Dronecode SDK library
#
# The targets are mostly for convenience around cmake.
#
ifndef VERBOSE
# Don't show make output about changing directories
MAKEFLAGS += --no-print-directory
endif
# Check for ninja and use it if available
NINJA_BUILD := $(shell ninja --version 2>/dev/null)
NPROCS := 1
OS := $(shell uname -s)
ifeq ($(OS),Linux)
NPROCS := $(shell grep -c ^processor /proc/cpuinfo)
endif
ifeq ($(OS),Darwin) #Mac OS
NPROCS := $(shell sysctl -n hw.ncpu || echo 1)
endif
ifdef NINJA_BUILD
CMAKE_GENERATOR ?= "Ninja"
MAKE = ninja
MAKE_ARGS =
else
CMAKE_GENERATOR ?= "Unix Makefiles"
MAKE = make
MAKE_ARGS = -j$(NPROCS)
endif
# Get additional arguments after target argument. (e.g. make release install)
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# and turn them into do-nothing targets
$(eval $(ARGS):;@:)
# Default is "Debug", also possible is "Release"
BUILD_TYPE ?= "Debug"
# Default is no DROPDEBUG
DROP_DEBUG ?= 0
# To enable MAVLink passthrough plugin build
ENABLE_MAVLINK_PASSTHROUGH ?= 0
CURRENT_DIR := $(shell pwd)
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
CURL_BUILD_DIR := $(ROOT_DIR)/core/third_party/curl-android-ios
# Set default cmake here but replace with special version for Android build.
CMAKE_BIN = cmake
INSTALL_PREFIX ?= /usr/local
BUILD_BACKEND ?= NO
# Function to create build_* directory and call make there.
define cmake-build
+@$(eval BUILD_DIR = build/$@)
+@if [ ! -e $(BUILD_DIR)/CMakeCache.txt ]; then \
mkdir -p $(BUILD_DIR) \
&& (cd $(BUILD_DIR) \
&& $(CMAKE_BIN) $(ROOT_DIR) $(1) \
-DEXTERNAL_DIR:STRING=$(EXTERNAL_DIR) \
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX) \
-DCMAKE_BUILD_BACKEND=$(BUILD_BACKEND) \
-DDROP_DEBUG=$(DROP_DEBUG) \
-DENABLE_MAVLINK_PASSTHROUGH=$(ENABLE_MAVLINK_PASSTHROUGH) \
-G$(CMAKE_GENERATOR)) \
|| (rm -rf $(BUILD_DIR)) \
fi
+@(echo "Build dir: $(BUILD_DIR)" \
&& (cd $(BUILD_DIR) && $(MAKE) $(MAKE_ARGS) $(ARGS)) \
)
endef
all: default
default:
$(call cmake-build)
ios: ios_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=iOS.cmake \
-DIOS_PLATFORM:STRING=OS)
ios_simulator: ios_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=iOS.cmake \
-DIOS_PLATFORM:STRING=SIMULATOR)
android_x86: android_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_TOOLCHAIN_CMAKE) \
-DANDROID_STL:STRING=c++_static \
-DANDROID_ABI=x86)
android_x86_64: android_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_TOOLCHAIN_CMAKE) \
-DANDROID_STL:STRING=c++_static \
-DANDROID_ABI=x86_64)
android_armeabi-v7a: android_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_TOOLCHAIN_CMAKE) \
-DANDROID_STL:STRING=c++_static \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_PLATFORM=android-16)
android_arm64-v8a: android_curl default
$(call cmake-build, \
-DCMAKE_TOOLCHAIN_FILE=$(ANDROID_TOOLCHAIN_CMAKE) \
-DANDROID_STL:STRING=c++_static \
-DANDROID_ABI=arm64-v8a)
android_curl: android_env_check
+@if [ ! -e $(CURL_BUILD_DIR)/prebuilt-with-ssl/android ]; then \
$(CURL_BUILD_DIR)/curl-compile-scripts/build_Android.sh; \
fi
ios_curl:
+@if [ ! -e $(CURL_BUILD_DIR)/prebuilt-with-ssl/ios ]; then \
$(CURL_BUILD_DIR)/curl-compile-scripts/build_iOS.sh; \
fi
android: \
android_x86 \
android_x86_64 \
android_armeabi-v7a \
android_arm64-v8a
fix_style:
@$(ROOT_DIR)/fix_style.sh $(ROOT_DIR)
ifdef EXTERNAL_DIR
@$(ROOT_DIR)/fix_style.sh $(EXTERNAL_DIR)
endif
run_all_tests: default
${MAKE} -C build/default check
run_unit_tests: default
build/default/unit_tests_runner
run_unit_tests_offline: default
build/default/unit_tests_runner --gtest_filter="-CurlTest.*"
run_integration_tests: default
build/default/integration_tests/integration_tests_runner
distclean:
@rm -rf build/
@rm -rf logs/
clean:
@if [ -d build ]; then find build -mindepth 2 ! -regex 'build/[a-zA-Z_]*/third_party.*' -delete; fi
android_env_check:
ifndef ANDROID_TOOLCHAIN_CMAKE
$(error ANDROID_TOOLCHAIN_CMAKE is undefined, please point the \
environment variable to build/cmake/android.toolchain.cmake from android-ndk.)
endif
ifndef NDK_ROOT
$(error NDK_ROOT is undefined, please point the environment variable to android-ndk root.)
endif
ifndef ANDROID_CMAKE_BIN
$(error ANDROID_CMAKE_BIN is undefined, please point the \
environment variable to cmake/3.6.3155560/bin/cmake from android-sdk.)
else
@# We need cmake from the Android SDK (currently at 3.6 because 3.7 fails the test).
$(eval CMAKE_BIN = $(ANDROID_CMAKE_BIN))
endif
.PHONY:
clean fix_style run_all_tests run_unit_tests run_integration_tests android_env_check