1 # Copyright (C) 2009-2010 The Android Open Source Project 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 16 # Initialization of the NDK build system. This file is included by 17 # several build scripts. 18 # 19 20 # Define NDK_LOG in your environment to display log traces when 21 # using the build scripts. See also the definition of ndk_log below. 22 # 23 NDK_LOG := $(strip $(NDK_LOG)) 24 25 # Check that we have at least GNU Make 3.81 26 # We do this by detecting whether 'lastword' is supported 27 # 28 MAKE_TEST := $(lastword a b c d e f) 29 ifneq ($(MAKE_TEST),f) 30 $(error Android NDK: GNU Make version $(MAKE_VERSION) is too low (should be >= 3.81) 31 endif 32 ifdef NDK_LOG 33 $(info Android NDK: GNU Make version $(MAKE_VERSION) detected) 34 endif 35 36 # NDK_ROOT *must* be defined and point to the root of the NDK installation 37 NDK_ROOT := $(strip $(NDK_ROOT)) 38 ifndef NDK_ROOT 39 $(error ERROR while including init.mk: NDK_ROOT must be defined !) 40 endif 41 ifneq ($(words $(NDK_ROOT)),1) 42 $(info,The Android NDK installation path contains spaces: '$(NDK_ROOT)') 43 $(error,Please fix the problem by reinstalling to a different location.) 44 endif 45 46 # ==================================================================== 47 # 48 # Define a few useful variables and functions. 49 # More stuff will follow in definitions.mk. 50 # 51 # ==================================================================== 52 53 # Used to output warnings and error from the library, it's possible to 54 # disable any warnings or errors by overriding these definitions 55 # manually or by setting NDK_NO_WARNINGS or NDK_NO_ERRORS 56 57 __ndk_name := Android NDK 58 __ndk_info = $(info $(__ndk_name): $1 $2 $3 $4 $5) 59 __ndk_warning = $(warning $(__ndk_name): $1 $2 $3 $4 $5) 60 __ndk_error = $(error $(__ndk_name): $1 $2 $3 $4 $5) 61 62 ifdef NDK_NO_WARNINGS 63 __ndk_warning := 64 endif 65 ifdef NDK_NO_ERRORS 66 __ndk_error := 67 endif 68 69 # ----------------------------------------------------------------------------- 70 # Function : ndk_log 71 # Arguments: 1: text to print when NDK_LOG is defined 72 # Returns : None 73 # Usage : $(call ndk_log,<some text>) 74 # ----------------------------------------------------------------------------- 75 ifdef NDK_LOG 76 ndk_log = $(info $(__ndk_name): $1) 77 else 78 ndk_log := 79 endif 80 81 # ==================================================================== 82 # 83 # Host system auto-detection. 84 # 85 # ==================================================================== 86 87 # 88 # Determine host system and architecture from the environment 89 # 90 HOST_OS := $(strip $(HOST_OS)) 91 ifndef HOST_OS 92 # On all modern variants of Windows (including Cygwin and Wine) 93 # the OS environment variable is defined to 'Windows_NT' 94 # 95 # The value of PROCESSOR_ARCHITECTURE will be x86 or AMD64 96 # 97 ifeq ($(OS),Windows_NT) 98 HOST_OS := windows 99 else 100 # For other systems, use the `uname` output 101 UNAME := $(shell uname -s) 102 ifneq (,$(findstring Linux,$(UNAME))) 103 HOST_OS := linux 104 endif 105 ifneq (,$(findstring Darwin,$(UNAME))) 106 HOST_OS := darwin 107 endif 108 # We should not be there, but just in case ! 109 ifneq (,$(findstring CYGWIN,$(UNAME))) 110 HOST_OS := windows 111 endif 112 ifeq ($(HOST_OS),) 113 $(call __ndk_info,Unable to determine HOST_OS from uname -s: $(UNAME)) 114 $(call __ndk_info,Please define HOST_OS in your environment.) 115 $(call __ndk_error,Aborting.) 116 endif 117 endif 118 $(call ndk_log,Host OS was auto-detected: $(HOST_OS)) 119 else 120 $(call ndk_log,Host OS from environment: $(HOST_OS)) 121 endif 122 123 HOST_ARCH := $(strip $(HOST_ARCH)) 124 ifndef HOST_ARCH 125 ifeq ($(HOST_OS),windows) 126 HOST_ARCH := $(PROCESSOR_ARCHITECTURE) 127 ifeq ($(HOST_ARCH),AMD64) 128 HOST_ARCH := x86 129 endif 130 else # HOST_OS != windows 131 UNAME := $(shell uname -m) 132 ifneq (,$(findstring 86,$(UNAME))) 133 HOST_ARCH := x86 134 endif 135 # We should probably should not care at all 136 ifneq (,$(findstring Power,$(UNAME))) 137 HOST_ARCH := ppc 138 endif 139 ifeq ($(HOST_ARCH),) 140 $(call __ndk_info,Unsupported host architecture: $(UNAME)) 141 $(call __ndk_error,Aborting) 142 endif 143 endif # HOST_OS != windows 144 $(call ndk_log,Host CPU was auto-detected: $(HOST_ARCH)) 145 else 146 $(call ndk_log,Host CPU from environment: $(HOST_ARCH)) 147 endif 148 149 HOST_TAG := $(HOST_OS)-$(HOST_ARCH) 150 151 # The directory separator used on this host 152 HOST_DIRSEP := : 153 154 # For now always use ":" since Windows is Cygwin 155 #ifeq ($(HOST_OS),windows) 156 # HOST_DIRSEP := ; 157 #endif 158 159 # If we are on Windows, we need to check that we are not running 160 # Cygwin 1.5, which is deprecated and won't run our toolchain 161 # binaries properly. 162 # 163 ifeq ($(HOST_TAG),windows-x86) 164 # On cygwin, 'uname -r' returns something like 1.5.23(0.225/5/3) 165 # We recognize 1.5. as the prefix to look for then. 166 CYGWIN_VERSION := $(shell uname -r) 167 ifneq ($(filter XX1.5.%,XX$(CYGWIN_VERSION)),) 168 $(call __ndk_info,You seem to be running Cygwin 1.5, which is not supported.) 169 $(call __ndk_info,Please upgrade to Cygwin 1.7 or higher.) 170 $(call __ndk_error,Aborting.) 171 endif 172 # special-case the host-tag 173 HOST_TAG := windows 174 endif 175 $(call ndk_log,HOST_TAG set to $(HOST_TAG)) 176 177 # 178 # Verify that the 'awk' tool has the features we need. 179 # Both Nawk and Gawk do. 180 # 181 HOST_AWK := $(strip $(HOST_AWK)) 182 ifndef HOST_AWK 183 HOST_AWK := awk 184 $(call ndk_log,Host awk tool was auto-detected: $(HOST_AWK)) 185 else 186 $(call ndk_log,Host awk tool from environment: $(HOST_AWK)) 187 endif 188 189 # Location of all awk scripts we use 190 BUILD_AWK := $(NDK_ROOT)/build/awk 191 192 AWK_TEST := $(shell $(HOST_AWK) -f $(BUILD_AWK)/check-awk.awk) 193 $(call ndk_log,Host awk test returned: $(AWK_TEST)) 194 ifneq ($(AWK_TEST),Pass) 195 $(call __ndk_info,Host awk tool is outdated. Please define HOST_AWK to point to Gawk or Nawk !) 196 $(call __ndk_error,Aborting.) 197 endif 198 199 # The location of the build system files 200 BUILD_SYSTEM := $(NDK_ROOT)/build/core 201 202 # Include common definitions 203 include $(BUILD_SYSTEM)/definitions.mk 204 205 # ==================================================================== 206 # 207 # Read all toolchain-specific configuration files. 208 # 209 # Each toolchain must have a corresponding config.mk file located 210 # in build/toolchains/<name>/ that will be included here. 211 # 212 # Each one of these files should define the following variables: 213 # TOOLCHAIN_NAME toolchain name (e.g. arm-eabi-4.2.1) 214 # TOOLCHAIN_ABIS list of target ABIs supported by the toolchain. 215 # 216 # Then, it should include $(ADD_TOOLCHAIN) which will perform 217 # book-keeping for the build system. 218 # 219 # ==================================================================== 220 221 # the build script to include in each toolchain config.mk 222 ADD_TOOLCHAIN := $(BUILD_SYSTEM)/add-toolchain.mk 223 224 # the list of all toolchains in this NDK 225 NDK_ALL_TOOLCHAINS := 226 NDK_ALL_ABIS := 227 228 TOOLCHAIN_CONFIGS := $(wildcard $(NDK_ROOT)/toolchains/*/config.mk) 229 $(foreach _config_mk,$(TOOLCHAIN_CONFIGS),\ 230 $(eval include $(BUILD_SYSTEM)/add-toolchain.mk)\ 231 ) 232 233 NDK_ALL_TOOLCHAINS := $(call uniq,$(NDK_ALL_TOOLCHAINS)) 234 NDK_ALL_ABIS := $(call uniq,$(NDK_ALL_ABIS)) 235 236 # The default toolchain is now arm-eabi-4.4.0, however its 237 # C++ compiler is a tad bit more pedantic with certain 238 # constructs (e.g. templates) so allow users to switch back 239 # to the old 4.2.1 instead if they really want to. 240 # 241 # NOTE: you won't get armeabi-v7a support though ! 242 # 243 NDK_TOOLCHAIN := $(strip $(NDK_TOOLCHAIN)) 244 ifdef NDK_TOOLCHAIN 245 # check that the toolchain name is supported 246 $(if $(filter-out $(NDK_ALL_TOOLCHAINS),$(NDK_TOOLCHAIN)),\ 247 $(call __ndk_info,NDK_TOOLCHAIN is defined to the unsupported value $(NDK_TOOLCHAIN)) \ 248 $(call __ndk_info,Please use one of the following values: $(NDK_ALL_TOOLCHAINS))\ 249 $(call __ndk_error,Aborting)\ 250 ,) 251 $(call ndk_log, Using specific toolchain $(NDK_TOOLCHAIN)) 252 endif 253 254 $(call ndk_log, This NDK supports the following toolchains and target ABIs:) 255 $(foreach tc,$(NDK_ALL_TOOLCHAINS),\ 256 $(call ndk_log, $(space)$(space)$(tc): $(NDK_TOOLCHAIN.$(tc).abis))\ 257 ) 258 259 # ==================================================================== 260 # 261 # Read all platform-specific configuration files. 262 # 263 # Each platform must be located in build/platforms/android-<apilevel> 264 # where <apilevel> corresponds to an API level number, with: 265 # 3 -> Android 1.5 266 # 4 -> next platform release 267 # 268 # ==================================================================== 269 270 # The platform files were moved in the Android source tree from 271 # $TOP/ndk/build/platforms to $TOP/development/ndk/platforms. However, 272 # the official NDK release packages still place them under the old 273 # location for now, so deal with this here 274 # 275 NDK_PLATFORMS_ROOT := $(strip $(NDK_PLATFORMS_ROOT)) 276 ifndef NDK_PLATFORMS_ROOT 277 NDK_PLATFORMS_ROOT := $(strip $(wildcard $(NDK_ROOT)/platforms)) 278 ifndef NDK_PLATFORMS_ROOT 279 NDK_PLATFORMS_ROOT := $(strip $(wildcard $(NDK_ROOT)/build/platforms)) 280 endif 281 282 ifndef NDK_PLATFORMS_ROOT 283 $(call __ndk_info,Could not find platform files (headers and libraries)) 284 $(if $(strip $(wildcard $(NDK_ROOT)/RELEASE.TXT)),\ 285 $(call __ndk_info,Please define NDK_PLATFORMS_ROOT to point to a valid directory.)\ 286 ,\ 287 $(call __ndk_info,Please run build/tools/build-platforms.sh to build the corresponding directory.)\ 288 ) 289 $(call __ndk_error,Aborting) 290 endif 291 292 $(call ndk_log,Found platform root directory: $(NDK_PLATFORMS_ROOT)) 293 else 294 ifeq ($(strip $(wildcard $(NDK_PLATFORMS_ROOT)/android-*)),) 295 $(call __ndk_info,Your NDK_PLATFORMS_ROOT points to an invalid directory) 296 $(call __ndk_info,Current value: $(NDK_PLATFORMS_ROOT)) 297 $(call __ndk_error,Aborting) 298 endif 299 endif 300 301 NDK_ALL_PLATFORMS := $(strip $(notdir $(wildcard $(NDK_PLATFORMS_ROOT)/android-*))) 302 $(call ndk_log,Found supported platforms: $(NDK_ALL_PLATFORMS)) 303 304 $(foreach _platform,$(NDK_ALL_PLATFORMS),\ 305 $(eval include $(BUILD_SYSTEM)/add-platform.mk)\ 306 ) 307 308 # we're going to find the maximum platform number of the form android-<number> 309 # ignore others, which could correspond to special and experimental cases 310 NDK_ALL_PLATFORM_LEVELS := $(filter android-%,$(NDK_ALL_PLATFORMS)) 311 NDK_ALL_PLATFORM_LEVELS := $(patsubst android-%,%,$(NDK_ALL_PLATFORM_LEVELS)) 312 $(call ndk_log,Found stable platform levels: $(NDK_ALL_PLATFORM_LEVELS)) 313 314 NDK_MAX_PLATFORM_LEVEL := 3 315 $(foreach level,$(NDK_ALL_PLATFORM_LEVELS),\ 316 $(eval NDK_MAX_PLATFORM_LEVEL := $$(call max,$$(NDK_MAX_PLATFORM_LEVEL),$$(level)))\ 317 ) 318 $(call ndk_log,Found max platform level: $(NDK_MAX_PLATFORM_LEVEL)) 319 320