1 GDK_LOG := $(strip $(GDK_LOG)) 2 3 # Check that we have at least GNU Make 3.81 4 # We do this by detecting whether 'lastword' is supported 5 # 6 MAKE_TEST := $(lastword a b c d e f) 7 ifneq ($(MAKE_TEST),f) 8 $(error Android GDK: GNU Make version $(MAKE_VERSION) is too low (should be >= 3.81)) 9 endif 10 ifdef GDK_LOG 11 $(info Android GDK: GNU Make version $(MAKE_VERSION) detected) 12 endif 13 14 # GDK_ROOT *must* be defined and point to the root of the GDK installation 15 GDK_ROOT := $(strip $(GDK_ROOT)) 16 ifndef GDK_ROOT 17 $(error ERROR while including init.mk: GDK_ROOT must be defined !) 18 endif 19 ifneq ($(words $(GDK_ROOT)),1) 20 $(info,The Android GDK installation path contains spaces: '$(GDK_ROOT)') 21 $(error,Please fix the problem by reinstalling to a different location.) 22 endif 23 24 # ==================================================================== 25 # 26 # Define a few useful variables and functions. 27 # More stuff will follow in definitions.mk. 28 # 29 # ==================================================================== 30 31 # Used to output warnings and error from the library, it's possible to 32 # disable any warnings or errors by overriding these definitions 33 # manually or by setting GDK_NO_WARNINGS or GDK_NO_ERRORS 34 35 __gdk_name := Android GDK 36 __gdk_info = $(info $(__gdk_name): $1 $2 $3 $4 $5) 37 __gdk_warning = $(warning $(__gdk_name): $1 $2 $3 $4 $5) 38 __gdk_error = $(error $(__gdk_name): $1 $2 $3 $4 $5) 39 40 ifdef GDK_NO_WARNINGS 41 __gdk_warning := 42 endif 43 ifdef GDK_NO_ERRORS 44 __gdk_error := 45 endif 46 47 # ----------------------------------------------------------------------------- 48 # Function : gdk_log 49 # Arguments: 1: text to print when GDK_LOG is defined 50 # Returns : None 51 # Usage : $(call gdk_log,<some text>) 52 # ----------------------------------------------------------------------------- 53 ifdef GDK_LOG 54 gdk_log = $(info $(__gdk_name): $1) 55 else 56 gdk_log := 57 endif 58 59 # ==================================================================== 60 # 61 # Host system auto-detection. 62 # 63 # ==================================================================== 64 65 # 66 # Determine host system and architecture from the environment 67 # 68 HOST_OS := $(strip $(HOST_OS)) 69 ifndef HOST_OS 70 # On all modern variants of Windows (including Cygwin and Wine) 71 # the OS environment variable is defined to 'Windows_NT' 72 # 73 # The value of PROCESSOR_ARCHITECTURE will be x86 or AMD64 74 # 75 ifeq ($(OS),Windows_NT) 76 HOST_OS := windows 77 else 78 # For other systems, use the `uname` output 79 UNAME := $(shell uname -s) 80 ifneq (,$(findstring Linux,$(UNAME))) 81 HOST_OS := linux 82 endif 83 ifneq (,$(findstring Darwin,$(UNAME))) 84 HOST_OS := darwin 85 endif 86 # We should not be there, but just in case ! 87 ifneq (,$(findstring CYGWIN,$(UNAME))) 88 HOST_OS := windows 89 endif 90 ifeq ($(HOST_OS),) 91 $(call __gdk_info,Unable to determine HOST_OS from uname -s: $(UNAME)) 92 $(call __gdk_info,Please define HOST_OS in your environment.) 93 $(call __gdk_error,Aborting.) 94 endif 95 endif 96 $(call gdk_log,Host OS was auto-detected: $(HOST_OS)) 97 else 98 $(call gdk_log,Host OS from environment: $(HOST_OS)) 99 endif 100 101 HOST_ARCH := $(strip $(HOST_ARCH)) 102 ifndef HOST_ARCH 103 ifeq ($(HOST_OS),windows) 104 HOST_ARCH := $(PROCESSOR_ARCHITECTURE) 105 ifeq ($(HOST_ARCH),AMD64) 106 HOST_ARCH := x86 107 endif 108 else # HOST_OS != windows 109 UNAME := $(shell uname -m) 110 ifneq (,$(findstring 86,$(UNAME))) 111 HOST_ARCH := x86 112 endif 113 # We should probably should not care at all 114 ifneq (,$(findstring Power,$(UNAME))) 115 HOST_ARCH := ppc 116 endif 117 ifeq ($(HOST_ARCH),) 118 $(call __gdk_info,Unsupported host architecture: $(UNAME)) 119 $(call __gdk_error,Aborting) 120 endif 121 endif # HOST_OS != windows 122 $(call gdk_log,Host CPU was auto-detected: $(HOST_ARCH)) 123 else 124 $(call gdk_log,Host CPU from environment: $(HOST_ARCH)) 125 endif 126 127 HOST_TAG := $(HOST_OS)-$(HOST_ARCH) 128 129 # The directory separator used on this host 130 HOST_DIRSEP := : 131 132 # For now always use ":" since Windows is Cygwin 133 #ifeq ($(HOST_OS),windows) 134 # HOST_DIRSEP := ; 135 #endif 136 137 # If we are on Windows, we need to check that we are not running 138 # Cygwin 1.5, which is deprecated and won't run our toolchain 139 # binaries properly. 140 # 141 ifeq ($(HOST_TAG),windows-x86) 142 # On cygwin, 'uname -r' returns something like 1.5.23(0.225/5/3) 143 # We recognize 1.5. as the prefix to look for then. 144 CYGWIN_VERSION := $(shell uname -r) 145 ifneq ($(filter XX1.5.%,XX$(CYGWIN_VERSION)),) 146 $(call __gdk_info,You seem to be running Cygwin 1.5, which is not supported.) 147 $(call __gdk_info,Please upgrade to Cygwin 1.7 or higher.) 148 $(call __gdk_error,Aborting.) 149 endif 150 # special-case the host-tag 151 HOST_TAG := windows 152 endif 153 $(call gdk_log,HOST_TAG set to $(HOST_TAG)) 154 155 # 156 # Verify that the 'awk' tool has the features we need. 157 # Both Nawk and Gawk do. 158 # 159 HOST_AWK := $(strip $(HOST_AWK)) 160 ifndef HOST_AWK 161 HOST_AWK := awk 162 $(call gdk_log,Host awk tool was auto-detected: $(HOST_AWK)) 163 else 164 $(call gdk_log,Host awk tool from environment: $(HOST_AWK)) 165 endif 166 167 # Location of all awk scripts we use 168 BUILD_AWK := $(GDK_ROOT)/build/awk 169 170 AWK_TEST := $(shell $(HOST_AWK) -f $(BUILD_AWK)/check-awk.awk) 171 $(call gdk_log,Host awk test returned: $(AWK_TEST)) 172 ifneq ($(AWK_TEST),Pass) 173 $(call __gdk_info,Host awk tool is outdated. Please define HOST_AWK to point to Gawk or Nawk !) 174 $(call __gdk_error,Aborting.) 175 endif 176 177 # 178 # On windows, define the 'cygwin-to-host-path' function here depending on the 179 # environment. The rules are the following: 180 # 181 # 1/ If "cygpath' is not in your path, do not use it at all. It looks like 182 # this allows to build with the GDK from MSys without problems. 183 # 184 # 2/ Since invoking 'cygpath -m' from GNU Make for each source file is 185 # _very_ slow, try to generate a Make function that performs the mapping 186 # from cygwin to host paths through simple substitutions. 187 # 188 # 3/ In case we fail horribly, allow the user to define GDK_USE_CYGPATH to '1' 189 # in order to use 'cygpath -m' nonetheless. This is only a backup plan in 190 # case our automatic substitution function doesn't work (only likely if you 191 # have a very weird cygwin setup). 192 # 193 # The function for 2/ is generated by an awk script. It's really a series 194 # of nested patsubst calls, that look like: 195 # 196 # cygwin-to-host-path = $(patsubst /cygdrive/c/%,c:/%,\ 197 # $(patsusbt /cygdrive/d/%,d:/%, \ 198 # $1) 199 # 200 # except that the actual definition is built from the list of mounted 201 # drives as reported by "mount" and deals with drive letter cases (i.e. 202 # '/cygdrive/c' and '/cygdrive/C') 203 # 204 ifeq ($(HOST_OS),windows) 205 CYGPATH := $(strip $(HOST_CYGPATH)) 206 ifndef CYGPATH 207 $(call gdk_log, Probing for 'cygpath' program) 208 CYGPATH := $(strip $(shell which cygpath 2>/dev/null)) 209 ifndef CYGPATH 210 $(call gdk_log, 'cygpath' was *not* found in your path) 211 else 212 $(call gdk_log, 'cygpath' found as: $(CYGPATH)) 213 endif 214 endif 215 ifndef CYGPATH 216 cygwin-to-host-path = $1 217 else 218 ifeq ($(GDK_USE_CYGPATH),1) 219 $(call gdk_log, Forced usage of 'cygpath -m' through GDK_USE_CYGPATH=1) 220 cygwin-to-host-path = $(strip $(shell $(CYGPATH) -m $1)) 221 else 222 # Call an awk script to generate a Makefile fragment used to define a function 223 WINDOWS_HOST_PATH_FRAGMENT := $(shell mount | $(HOST_AWK) -f $(BUILD_AWK)/gen-windows-host-path.awk) 224 ifeq ($(GDK_LOG),1) 225 $(info Using cygwin substitution rules:) 226 $(eval $(shell mount | $(HOST_AWK) -f $(BUILD_AWK)/gen-windows-host-path.awk -vVERBOSE=1)) 227 endif 228 $(eval cygwin-to-host-path = $(WINDOWS_HOST_PATH_FRAGMENT)) 229 endif 230 endif 231 endif # HOST_OS == windows 232 233 # The location of the build system files 234 BUILD_SYSTEM := $(GDK_ROOT)/build/core 235 236 # Include common definitions 237 include $(BUILD_SYSTEM)/definitions.mk 238 239 # ==================================================================== 240 # 241 # Read all toolchain-specific configuration files. 242 # 243 # Each toolchain must have a corresponding config.mk file located 244 # in build/toolchains/<name>/ that will be included here. 245 # 246 # Each one of these files should define the following variables: 247 # TOOLCHAIN_NAME toolchain name (e.g. arm-eabi-4.2.1) 248 # TOOLCHAIN_ABIS list of target ABIs supported by the toolchain. 249 # 250 # Then, it should include $(ADD_TOOLCHAIN) which will perform 251 # book-keeping for the build system. 252 # 253 # ==================================================================== 254 255 # the build script to include in each toolchain config.mk 256 ADD_TOOLCHAIN := $(BUILD_SYSTEM)/add-toolchain.mk 257 258 # the list of all toolchains in this GDK 259 GDK_ALL_TOOLCHAINS := 260 GDK_ALL_ABIS := 261 262 TOOLCHAIN_CONFIGS := $(wildcard $(GDK_ROOT)/toolchains/*/config.mk) 263 $(foreach _config_mk,$(TOOLCHAIN_CONFIGS),\ 264 $(eval include $(BUILD_SYSTEM)/add-toolchain.mk)\ 265 ) 266 267 GDK_ALL_TOOLCHAINS := $(call remove-duplicates,$(GDK_ALL_TOOLCHAINS)) 268 GDK_ALL_ABIS := $(call remove-duplicates,$(GDK_ALL_ABIS)) 269 270 # The default toolchain is now arm-eabi-4.4.0, however its 271 # C++ compiler is a tad bit more pedantic with certain 272 # constructs (e.g. templates) so allow users to switch back 273 # to the old 4.2.1 instead if they really want to. 274 # 275 # NOTE: you won't get armeabi-v7a support though ! 276 # 277 GDK_TOOLCHAIN := $(strip $(GDK_TOOLCHAIN)) 278 ifdef GDK_TOOLCHAIN 279 # check that the toolchain name is supported 280 $(if $(filter-out $(GDK_ALL_TOOLCHAINS),$(GDK_TOOLCHAIN)),\ 281 $(call __gdk_info,GDK_TOOLCHAIN is defined to the unsupported value $(GDK_TOOLCHAIN)) \ 282 $(call __gdk_info,Please use one of the following values: $(GDK_ALL_TOOLCHAINS))\ 283 $(call __gdk_error,Aborting)\ 284 ,) 285 $(call gdk_log, Using specific toolchain $(GDK_TOOLCHAIN)) 286 endif 287 288 $(call gdk_log, This GDK supports the following toolchains and target ABIs:) 289 $(foreach tc,$(GDK_ALL_TOOLCHAINS),\ 290 $(call gdk_log, $(space)$(space)$(tc): $(GDK_TOOLCHAIN.$(tc).abis))\ 291 ) 292 293 # ==================================================================== 294 # 295 # Read all platform-specific configuration files. 296 # 297 # Each platform must be located in build/platforms/android-<apilevel> 298 # where <apilevel> corresponds to an API level number, with: 299 # 3 -> Android 1.5 300 # 4 -> next platform release 301 # 302 # ==================================================================== 303 304 # The platform files were moved in the Android source tree from 305 # $TOP/gdk/build/platforms to $TOP/development/gdk/platforms. However, 306 # the official GDK release packages still place them under the old 307 # location for now, so deal with this here 308 # 309 GDK_PLATFORMS_ROOT := $(strip $(GDK_PLATFORMS_ROOT)) 310 ifndef GDK_PLATFORMS_ROOT 311 GDK_PLATFORMS_ROOT := $(strip $(wildcard $(GDK_ROOT)/platforms)) 312 ifndef GDK_PLATFORMS_ROOT 313 GDK_PLATFORMS_ROOT := $(strip $(wildcard $(GDK_ROOT)/build/platforms)) 314 endif 315 316 ifndef GDK_PLATFORMS_ROOT 317 $(call __gdk_info,Could not find platform files (headers and libraries)) 318 $(if $(strip $(wildcard $(GDK_ROOT)/RELEASE.TXT)),\ 319 $(call __gdk_info,Please define GDK_PLATFORMS_ROOT to point to a valid directory.)\ 320 ,\ 321 $(call __gdk_info,Please run build/tools/build-platforms.sh to build the corresponding directory.)\ 322 ) 323 $(call __gdk_error,Aborting) 324 endif 325 326 $(call gdk_log,Found platform root directory: $(GDK_PLATFORMS_ROOT)) 327 endif 328 ifeq ($(strip $(wildcard $(GDK_PLATFORMS_ROOT)/android-*)),) 329 $(call __gdk_info,Your GDK_PLATFORMS_ROOT points to an invalid directory) 330 $(call __gdk_info,Current value: $(GDK_PLATFORMS_ROOT)) 331 $(call __gdk_error,Aborting) 332 endif 333 334 GDK_ALL_PLATFORMS := $(strip $(notdir $(wildcard $(GDK_PLATFORMS_ROOT)/android-*))) 335 $(call gdk_log,Found supported platforms: $(GDK_ALL_PLATFORMS)) 336 337 $(foreach _platform,$(GDK_ALL_PLATFORMS),\ 338 $(eval include $(BUILD_SYSTEM)/add-platform.mk)\ 339 ) 340