-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile-Android
399 lines (328 loc) · 13.8 KB
/
Makefile-Android
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#
# Copyright (c) 2014-2017 Nest Labs, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Description:
# This file implements a glue makefile for building the Weave SDK
# for Android devices and simulators for multiple architectures.
#
# This was largely directed and inspired by two Android NDK
# documents:
#
# * Android NDK Programmer's Guide: Standalone Toolchain
# * Android NDK Programmer's Guide: C++ Support
#
# Don't allow this top-level makefile's targets to be built in parallel.
.NOTPARALLEL:
DEBUG ?= 0
ENABLE_TARGETED_LISTEN ?= 0
ANDROID_ROOT ?= /usr/local/android
ANDROID_NDK_HOME ?= ${ANDROID_ROOT}/android-ndk-r10
ANDROID_HOME ?= ${ANDROID_ROOT}/android-sdk-linux-r23.0.2
ifndef JAVA_HOME
$(error ERROR: JAVA_HOME not set)
endif
$(info note: JAVA_HOME is "${JAVA_HOME}" and comes from "$(origin JAVA_HOME)")
$(info note: ANDROID_NDK_HOME is "${ANDROID_NDK_HOME}" and comes from "$(origin ANDROID_NDK_HOME)")
$(info note: ANDROID_HOME is "${ANDROID_HOME}" and comes from "$(origin ANDROID_HOME)")
ANDROID_RELEASE ?= 19
ANDROID_CXXROOT = ${ANDROID_NDK_HOME}/sources/cxx-stl
ANDROID_GABIXX_CXXHEADERS = ${ANDROID_CXXROOT}/gabi++/include
ANDROID_SYSTEM_CXXHEADERS = ${ANDROID_CXXROOT}/system/include
ANDROID_STLPORT_CXXHEADERS = ${ANDROID_CXXROOT}/stlport/stlport
ANDROID_LLVMSTL_CXXHEADERS = ${ANDROID_CXXROOT}/llvm-libc++/libcxx/include
ANDROID_GNUSTL_4_6_CXXHEADERS = ${ANDROID_CXXROOT}/gnu-libstdc++/4.6/include
ANDROID_GNUSTL_4_8_CXXHEADERS = ${ANDROID_CXXROOT}/gnu-libstdc++/4.8/include
ANDROID_GNUSTL_4_9_CXXHEADERS = ${ANDROID_CXXROOT}/gnu-libstdc++/4.9/include
ANDROID_CXX ?= SYSTEM
ANDROID_CXXHEADERS = ${ANDROID_${ANDROID_CXX}_CXXHEADERS}
# NB: Regardless of where JAVA_HOME points, always use the JNI headers from the Android NDK,
# and only include the top-most directory (include), not the system directory (include/linux).
# Because the NDK mixes the JNI headers in with the linux headers, listing the system
# directory in the -I flags will result in strange compilation errors. And unlike the standard
# Java jni.h, the jni.h that comes with the Android NDK does not depend on any system-specific
# JNI header files (e.g. jni_md.h). Thus only the top-level include directory is needed.
JNI_INCLUDE_DIRS = ${ANDROID_SYSROOT}/usr/include
android-ndk-which = $(shell ${AbsTopSourceDir}/build/scripts/android-ndk-which --ndk-home ${ANDROID_NDK_HOME} $(1) ${ANDROID_NDK_ABI})
AR = $(call android-ndk-which,ar)
AS = $(call android-ndk-which,as)
CPP = $(call android-ndk-which,cpp)
CC = $(call android-ndk-which,gcc)
CXX = $(call android-ndk-which,g++)
LD = $(call android-ndk-which,ld)
STRIP = $(call android-ndk-which,strip)
NM = $(call android-ndk-which,nm)
RANLIB = $(call android-ndk-which,ranlib)
OBJCOPY = $(call android-ndk-which,objcopy)
ifeq ($(DEBUG),1)
DEFINES = -DDEBUG=$(DEBUG) -UNDEBUG
configure_OPTIONS += --enable-debug --enable-optimization=no
else
DEFINES = -DNDEBUG=1 -UDEBUG
configure_OPTIONS +=
endif
DEFINES += \
-DWEAVE_CONFIG_ENABLE_TARGETED_LISTEN=$(ENABLE_TARGETED_LISTEN) \
-DWEAVE_PROGRESS_LOGGING=$(DEBUG) \
-DWEAVE_ERROR_LOGGING=$(DEBUG) \
-DWEAVE_DETAIL_LOGGING=$(DEBUG)
CPPFLAGS = $(DEFINES) --sysroot=${ANDROID_SYSROOT} -I${ANDROID_CXXHEADERS} $(target_CPPFLAGS)
CFLAGS = ${CPPFLAGS} -ffunction-sections -funwind-tables $(target_CFLAGS)
CXXFLAGS = ${CPPFLAGS} -fno-rtti $(target_CXXFLAGS)
LDFLAGS = -Wl,--gc-sections $(target_LDFLAGS)
ECHO := @echo
MAKE := make
MKDIR_P := mkdir -p
LN_S := ln -s
RM_F := rm -f
INSTALL := /usr/bin/install
INSTALLFLAGS := -p
TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST))))
AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
BuildPath = build
TopBuildDir = $(BuildPath)
AbsTopBuildDir = $(PWD)/$(TopBuildDir)
ResultPath = output
TopResultDir = $(ResultPath)
AbsTopResultDir = $(PWD)/$(TopResultDir)
TargetTupleStem = unknown-linux
TargetTuple = $(TargetTupleStem)-android
ARCHS = arm armv7 i386
TopTargetLibDir = $(TopResultDir)/$(if $(1),$(1)-,)$(TargetTuple)/lib
ifndef BuildJobs
BuildJobs := $(shell getconf _NPROCESSORS_ONLN)
endif
JOBSFLAG := -j$(BuildJobs)
configure_OPTIONS = --disable-cocoa \
--disable-docs \
--enable-java \
--disable-python \
--enable-shared \
--disable-tests \
--disable-tools
ifeq ($(DEBUG),1)
configure_OPTIONS += --enable-debug --enable-optimization=no
else
configure_OPTIONS +=
endif
#
# configure-arch <arch>
#
# Configure the Weave SDK for the specified architecture.
#
# arch - The architecture to configure.
#
define configure-arch
$(ECHO) " CONFIG $(1)-$(TargetTuple)..."
(cd $(BuildPath)/$(1)-$(TargetTuple) && $(AbsTopSourceDir)/configure \
CPP="$(CPP)" CC="$(CC)" CXX="$(CXX)" OBJC="$(OBJC)" OBJCXX="$(OBJCXX)" AR="$(AR)" RANLIB="$(RANLIB)" NM="$(NM)" STRIP="$(STRIP)" \
INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
CPPFLAGS="$(CPPFLAGS)" \
CFLAGS="$(CFLAGS)" \
CXXFLAGS="$(CXXFLAGS)" \
OBJCFLAGS="$(OBJCFLAGS)" \
OBJCXXFLAGS="$(OBJCXXFLAGS)" \
LDFLAGS="$(LDFLAGS)" \
JAVA_HOME="${JAVA_HOME}" \
JNI_INCLUDE_DIRS="${JNI_INCLUDE_DIRS}" \
--build=$(shell $(AbsTopSourceDir)/third_party/nlbuild-autotools/repo/autoconf/config.guess) \
--host=$(1)-$(TargetTuple) \
--target=$(1)-$(TargetTuple) \
--with-sysroot=${ANDROID_SYSROOT} \
--with-weave-project-includes=$(AbsTopSourceDir)/build/config/android \
--prefix=/ \
--exec-prefix=/$(1)-$(TargetTuple) \
$(configure_OPTIONS))
endef # configure-arch
#
# build-arch <arch>
#
# Build the Weave SDK intermediate build products for the specified
# architecture.
#
# arch - The architecture to build.
#
define build-arch
$(ECHO) " BUILD $(1)-$(TargetTuple)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1)-$(TargetTuple) --no-print-directory \
all
endef # build-arch
#
# stage-arch <arch>
#
# Stage (install) the Weave SDK final build products for the specified
# architecture.
#
# arch - The architecture to stage.
#
define stage-arch
$(ECHO) " STAGE $(1)-$(TargetTuple)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1)-$(TargetTuple) --no-print-directory \
DESTDIR=$(AbsTopResultDir) \
install
endef # stage-arch
#
# pretty-arch <arch>
#
# Prettyify the Weave SDK source code for the specified architecture.
#
# arch - The architecture to prettify.
#
define pretty-arch
$(ECHO) " PRETTY $(1)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1)-$(TargetTuple) --no-print-directory \
pretty
endef # pretty-arch
#
# pretty-check-arch <arch>
#
# Pretty-check (lint) the Weave SDK source code for the specified
# architecture.
#
# arch - The architecture to pretty-check (lint).
#
define pretty-check-arch
$(ECHO) " PRETTY $(1)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1)-$(TargetTuple) --no-print-directory \
pretty-check
endef # pretty-check-arch
#
# ARCH_template <arch>
#
# Define macros, targets and rules to configure, build, and stage the
# Weave SDK for a single architecture.
#
# arch - The architecture to instantiate the template for.
#
define ARCH_template
CONFIGURE_TARGETS += configure-$(1)
BUILD_TARGETS += do-build-$(1)
STAGE_TARGETS += stage-$(1)
PRETTY_TARGETS += pretty-$(1)
PRETTY_CHECK_TARGETS += pretty-check-$(1)
BUILD_DIRS += $(BuildPath)/$(1)-$(TargetTuple)
DIRECTORIES += $(BuildPath)/$(1)-$(TargetTuple)
configure-$(1): ANDROID_NDK_ABI=$($(1)_target_ABI)
configure-$(1): ANDROID_SYSROOT=$($(1)_target_SYSROOT)
configure-$(1): target_CPPFLAGS=$($(1)_target_CPPFLAGS)
configure-$(1): target_CFLAGS=$($(1)_target_CFLAGS)
configure-$(1): target_CXXFLAGS=$($(1)_target_CXXFLAGS)
configure-$(1): target_LDFLAGS=$($(1)_target_LDFLAGS)
configure-$(1): $(BuildPath)/$(1)-$(TargetTuple)/config.status
$(BuildPath)/$(1)-$(TargetTuple)/config.status: | $(BuildPath)/$(1)-$(TargetTuple)
$$(call configure-arch,$(1))
do-build-$(1): configure-$(1)
do-build-$(1):
$$(call build-arch,$(1))
stage-$(1): do-build-$(1)
stage-$(1): | $(TopResultDir)
$$(call stage-arch,$(1))
pretty-$(1): configure-$(1)
$$(call pretty-arch,$(1))
lint-$(1) pretty-check-$(1): configure-$(1)
$$(call pretty-check-arch,$(1))
$(1): stage-$(1)
endef # ARCH_template
.DEFAULT_GOAL := all
all: stage
#
# ARMv5
#
arm_target_ABI = armeabi
arm_target_SYSROOT = ${ANDROID_NDK_HOME}/platforms/android-${ANDROID_RELEASE}/arch-arm
arm_target_CPPFLAGS = -march=armv5te -mtune=xscale -msoft-float
arm_target_CFLAGS = -fstack-protector
arm_target_CXXFLAGS = -I${ANDROID_NDK_HOME}/platforms/android-${ANDROID_RELEASE}/arch-arm/usr/include
arm_target_LDFLAGS =
#
# ARMv7
#
armv7_target_ABI = armeabi-v7a
armv7_target_SYSROOT = ${ANDROID_NDK_HOME}/platforms/android-${ANDROID_RELEASE}/arch-arm
armv7_target_CPPFLAGS = -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=softfp
armv7_target_CFLAGS = -fstack-protector
armv7_target_CXXFLAGS = -I${ANDROID_NDK_HOME}/platforms/android-${ANDROID_RELEASE}/arch-arm/usr/include
armv7_target_LDFLAGS = -march=armv7-a -Wl,--fix-cortex-a8
#
# i386
#
i386_target_ABI = x86
i386_target_SYSROOT = ${ANDROID_NDK_HOME}/platforms/android-${ANDROID_RELEASE}/arch-x86
i386_target_CPPFLAGS =
i386_target_CFLAGS =
i386_target_CXXFLAGS = -I${ANDROID_NDK_HOME}/platforms/android-${ANDROID_RELEASE}/arch-x86/usr/include
i386_target_LDFLAGS =
#
# x86_64
#
x86_64_target_ABI = x86_64
x86_64_target_SYSROOT = ${ANDROID_NDK_HOME}/platforms/android-${ANDROID_RELEASE}/arch-x86
x86_64_target_CPPFLAGS =
x86_64_target_CFLAGS =
x86_64_target_CXXFLAGS = -I${ANDROID_NDK_HOME}/platforms/android-${ANDROID_RELEASE}/arch-x86/usr/include
x86_64_target_LDFLAGS =
# Instantiate an architecture-specific build template for each target
# architecture.
$(foreach arch,$(ARCHS),$(eval $(call ARCH_template,$(arch))))
#
# Common / Finalization
#
configure: $(CONFIGURE_TARGETS)
build: $(BUILD_TARGETS)
stage: $(STAGE_TARGETS)
pretty: $(PRETTY_TARGETS)
lint pretty-check: $(PRETTY_CHECK_TARGETS)
DIRECTORIES = $(TopResultDir) $(TopResultDir)/$(TargetTuple)/lib $(BUILD_DIRS)
CLEAN_DIRS = $(TopResultDir) $(BUILD_DIRS)
all: stage
.PHONY : clean help
$(DIRECTORIES):
$(ECHO) " MKDIR $@"
@$(MKDIR_P) "$@"
clean:
$(ECHO) " CLEAN"
@$(RM_F) -r $(CLEAN_DIRS)
help:
$(ECHO) "Simply type 'make -f $(firstword $(MAKEFILE_LIST))' to build Weave for Android for the following "
$(ECHO) "architectures: "
$(ECHO) ""
$(ECHO) " $(ARCHS)"
$(ECHO) ""
$(ECHO) "To build only a particular architecture, specify: "
$(ECHO) ""
$(ECHO) " make -f $(firstword $(MAKEFILE_LIST)) <architecture>"
$(ECHO) ""
$(ECHO) "You may want or need to override the following make variables either on the "
$(ECHO) "command line or in the environment: "
$(ECHO) ""
$(ECHO) " DEBUG Enable Weave debug code and logging (default: '$(DEBUG)')."
$(ECHO) " ENABLE_TARGETED_LISTEN Enable Weave support for listening on particular "
$(ECHO) " addresses or interfaces. This allows testing multiple "
$(ECHO) " instances of the Weave stack running on a single host "
$(ECHO) " '(default: $(ENABLE_TARGETED_LISTEN)')."
$(ECHO) ""
$(ECHO) " JAVA_HOME Directory in which the Java runtime is located."
$(ECHO) ""
$(ECHO) " ANDROID_ROOT Directory where Android NDK and SDK are installed (if "
$(ECHO) " the same) (default: '$(ANDROID_ROOT)')."
$(ECHO) " ANDROID_NDK_HOME Directory where Android NDK is installed (default: "
$(ECHO) " '$(ANDROID_NDK_HOME)')."
$(ECHO) " ANDROID_HOME Directory where Android SDK is installed (default: "
$(ECHO) " '$(ANDROID_HOME)')."
$(ECHO) " ANDROID_RELEASE Android NDK API release to build against (default: "
$(ECHO) " '$(ANDROID_RELEASE)')."
$(ECHO) " ANDROID_CXX Android NDK C++ library to build against (default: "
$(ECHO) " '$(ANDROID_CXX)')."