1 # 2 # Copyright (C) 2006 The Android Open Source Project 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # 16 17 # Configuration for Darwin (Mac OS X) on x86. 18 # Included by combo/select.mk 19 20 ifneq ($(strip $(BUILD_HOST_64bit)),) 21 # By default we build everything in 32-bit, because it gives us 22 # more consistency between the host tools and the target. 23 # BUILD_HOST_64bit=1 overrides it for tool like emulator 24 # which can benefit from 64-bit host arch. 25 HOST_GLOBAL_CFLAGS += -m64 26 HOST_GLOBAL_LDFLAGS += -m64 27 else 28 HOST_GLOBAL_CFLAGS += -m32 29 HOST_GLOBAL_LDFLAGS += -m32 30 endif # BUILD_HOST_64bit 31 32 ifneq ($(strip $(BUILD_HOST_static)),) 33 # Statically-linked binaries are desirable for sandboxed environment 34 HOST_GLOBAL_LDFLAGS += -static 35 endif # BUILD_HOST_static 36 37 build_mac_version := $(shell sw_vers -productVersion) 38 39 mac_sdk_versions_supported := 10.6 10.7 10.8 40 ifneq ($(strip $(MAC_SDK_VERSION)),) 41 mac_sdk_version := $(MAC_SDK_VERSION) 42 ifeq ($(filter $(mac_sdk_version),$(mac_sdk_versions_supported)),) 43 $(warning ****************************************************************) 44 $(warning * MAC_SDK_VERSION $(MAC_SDK_VERSION) isn't one of the supported $(mac_sdk_versions_supported)) 45 $(warning ****************************************************************) 46 $(error Stop.) 47 endif 48 else 49 mac_sdk_versions_installed := $(shell xcodebuild -showsdks | grep macosx | sort | sed -e "s/.*macosx//g") 50 mac_sdk_version := $(firstword $(filter $(mac_sdk_versions_installed), $(mac_sdk_versions_supported))) 51 ifeq ($(mac_sdk_version),) 52 mac_sdk_version := $(firstword $(mac_sdk_versions_supported)) 53 endif 54 endif 55 56 mac_sdk_path := $(shell xcode-select -print-path) 57 # try /Applications/Xcode*.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.?.sdk 58 # or /Volume/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.?.sdk 59 mac_sdk_root := $(mac_sdk_path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(mac_sdk_version).sdk 60 ifeq ($(wildcard $(mac_sdk_root)),) 61 # try legacy /Developer/SDKs/MacOSX10.?.sdk 62 mac_sdk_root := /Developer/SDKs/MacOSX$(mac_sdk_version).sdk 63 endif 64 ifeq ($(wildcard $(mac_sdk_root)),) 65 $(warning *****************************************************) 66 $(warning * Can not find SDK $(mac_sdk_version) at $(mac_sdk_root)) 67 $(warning *****************************************************) 68 $(error Stop.) 69 endif 70 71 ifeq ($(mac_sdk_version),10.6) 72 gcc_darwin_version := 10 73 else 74 gcc_darwin_version := 11 75 endif 76 77 HOST_TOOLCHAIN_ROOT := prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1 78 HOST_TOOLCHAIN_PREFIX := $(HOST_TOOLCHAIN_ROOT)/bin/i686-apple-darwin$(gcc_darwin_version) 79 # Don't do anything if the toolchain is not there 80 ifneq (,$(strip $(wildcard $(HOST_TOOLCHAIN_PREFIX)-gcc))) 81 HOST_CC := $(HOST_TOOLCHAIN_PREFIX)-gcc 82 HOST_CXX := $(HOST_TOOLCHAIN_PREFIX)-g++ 83 ifeq ($(mac_sdk_version),10.8) 84 # Mac SDK 10.8 no longer has stdarg.h, etc 85 host_toolchain_header := $(HOST_TOOLCHAIN_ROOT)/lib/gcc/i686-apple-darwin$(gcc_darwin_version)/4.2.1/include 86 HOST_GLOBAL_CFLAGS += -isystem $(host_toolchain_header) 87 endif 88 else 89 HOST_CC := gcc 90 HOST_CXX := g++ 91 endif # $(HOST_TOOLCHAIN_PREFIX)-gcc exists 92 HOST_AR := $(AR) 93 HOST_STRIP := $(STRIP) 94 HOST_STRIP_COMMAND = $(HOST_STRIP) --strip-debug $< -o $@ 95 96 HOST_GLOBAL_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) -DMACOSX_DEPLOYMENT_TARGET=$(mac_sdk_version) 97 HOST_GLOBAL_LDFLAGS += -isysroot $(mac_sdk_root) -Wl,-syslibroot,$(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) 98 99 HOST_GLOBAL_CFLAGS += -fPIC -funwind-tables 100 HOST_NO_UNDEFINED_LDFLAGS := -Wl,-undefined,error 101 102 HOST_SHLIB_SUFFIX := .dylib 103 HOST_JNILIB_SUFFIX := .jnilib 104 105 HOST_GLOBAL_CFLAGS += \ 106 -include $(call select-android-config-h,darwin-x86) 107 108 ifneq ($(filter 10.7 10.7.% 10.8 10.8.%, $(build_mac_version)),) 109 HOST_RUN_RANLIB_AFTER_COPYING := false 110 else 111 HOST_RUN_RANLIB_AFTER_COPYING := true 112 PRE_LION_DYNAMIC_LINKER_OPTIONS := -Wl,-dynamic 113 endif 114 HOST_GLOBAL_ARFLAGS := cqs 115 116 HOST_CUSTOM_LD_COMMAND := true 117 118 define transform-host-o-to-shared-lib-inner 119 $(hide) $(PRIVATE_CXX) \ 120 -dynamiclib -single_module -read_only_relocs suppress \ 121 $(HOST_GLOBAL_LD_DIRS) \ 122 $(HOST_GLOBAL_LDFLAGS) \ 123 $(PRIVATE_ALL_OBJECTS) \ 124 $(addprefix -force_load , $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 125 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 126 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 127 $(PRIVATE_LDLIBS) \ 128 -o $@ \ 129 -install_name @rpath/$(notdir $@) \ 130 -Wl,-rpath,@loader_path/../lib \ 131 $(PRIVATE_LDFLAGS) \ 132 $(HOST_LIBGCC) 133 endef 134 135 define transform-host-o-to-executable-inner 136 $(hide) $(PRIVATE_CXX) \ 137 -Wl,-rpath,@loader_path/../lib \ 138 -o $@ \ 139 $(PRE_LION_DYNAMIC_LINKER_OPTIONS) -headerpad_max_install_names \ 140 $(HOST_GLOBAL_LD_DIRS) \ 141 $(HOST_GLOBAL_LDFLAGS) \ 142 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 143 $(PRIVATE_ALL_OBJECTS) \ 144 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 145 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 146 $(PRIVATE_LDFLAGS) \ 147 $(PRIVATE_LDLIBS) \ 148 $(HOST_LIBGCC) 149 endef 150 151 # $(1): The file to check 152 define get-file-size 153 stat -f "%z" $(1) 154 endef 155