HOST_darwin-x86.mk revision 691e0243ca880722f5dd86a1052fc7ffbc55f8c4
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 20ifneq ($(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. 25HOST_GLOBAL_CFLAGS += -m64 26HOST_GLOBAL_LDFLAGS += -m64 27else 28HOST_GLOBAL_CFLAGS += -m32 29HOST_GLOBAL_LDFLAGS += -m32 30endif # BUILD_HOST_64bit 31 32build_mac_version := $(shell sw_vers -productVersion) 33 34ifneq ($(strip $(BUILD_MAC_SDK_EXPERIMENTAL)),) 35# SDK 10.7 and higher is not fully compatible with Android. 36mac_sdk_versions_supported := 10.7 10.8 37else 38mac_sdk_versions_supported := 10.6 39endif # BUILD_MAC_SDK_EXPERIMENTAL 40mac_sdk_versions_installed := $(shell xcodebuild -showsdks |grep macosx | sort | sed -e "s/.*macosx//g") 41mac_sdk_version := $(firstword $(filter $(mac_sdk_versions_installed), $(mac_sdk_versions_supported))) 42ifeq ($(mac_sdk_version),) 43mac_sdk_version := $(firstword $(mac_sdk_versions_supported)) 44endif 45 46mac_sdk_path := $(shell xcode-select -print-path) 47ifeq ($(findstring /Applications,$(mac_sdk_path)),) 48# Legacy Xcode 49mac_sdk_root := /Developer/SDKs/MacOSX$(mac_sdk_version).sdk 50else 51# Xcode 4.4(App Store) or higher 52# /Applications/Xcode*.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.?.sdk 53mac_sdk_root := $(mac_sdk_path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(mac_sdk_version).sdk 54endif 55 56ifeq ($(wildcard $(mac_sdk_root)),) 57$(warning *****************************************************) 58$(warning * Can not find SDK $(mac_sdk_version) at $(mac_sdk_root)) 59ifeq ($(strip $(BUILD_MAC_SDK_EXPERIMENTAL)),) 60$(warning * If you wish to build using higher version of SDK, ) 61$(warning * try setting BUILD_MAC_SDK_EXPERIMENTAL=1 before ) 62$(warning * rerunning this command ) 63endif 64$(warning *****************************************************) 65$(error Stop.) 66endif 67 68HOST_GLOBAL_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) 69HOST_GLOBAL_LDFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) 70 71HOST_GLOBAL_CFLAGS += -fPIC 72HOST_NO_UNDEFINED_LDFLAGS := -Wl,-undefined,error 73 74HOST_CC := gcc 75HOST_CXX := g++ 76HOST_AR := $(AR) 77HOST_STRIP := $(STRIP) 78HOST_STRIP_COMMAND = $(HOST_STRIP) --strip-debug $< -o $@ 79 80HOST_SHLIB_SUFFIX := .dylib 81HOST_JNILIB_SUFFIX := .jnilib 82 83HOST_GLOBAL_CFLAGS += \ 84 -include $(call select-android-config-h,darwin-x86) 85ifneq ($(filter 10.7 10.7.% 10.8 10.8.%, $(build_mac_version)),) 86 HOST_RUN_RANLIB_AFTER_COPYING := false 87else 88 HOST_RUN_RANLIB_AFTER_COPYING := true 89 PRE_LION_DYNAMIC_LINKER_OPTIONS := -Wl,-dynamic 90endif 91HOST_GLOBAL_ARFLAGS := cqs 92 93HOST_CUSTOM_LD_COMMAND := true 94 95# Workaround for lack of "-Wl,--whole-archive" in MacOS's linker. 96define _darwin-extract-and-include-single-whole-static-lib 97@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]" 98$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\ 99 mkdir -p $$ldir; \ 100 for f in `$(HOST_AR) t $(1)`; do \ 101 $(HOST_AR) p $(1) $$f > $$ldir/$$f; \ 102 done ; 103 104endef 105 106define darwin-extract-and-include-whole-static-libs 107$(if $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), $(hide) rm -rf $(PRIVATE_INTERMEDIATES_DIR)/WHOLE) 108$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \ 109 $(call _darwin-extract-and-include-single-whole-static-lib, $(lib))) 110endef 111 112define transform-host-o-to-shared-lib-inner 113$(call darwin-extract-and-include-whole-static-libs) 114$(hide) $(PRIVATE_CXX) \ 115 -dynamiclib -single_module -read_only_relocs suppress \ 116 $(HOST_GLOBAL_LD_DIRS) \ 117 $(HOST_GLOBAL_LDFLAGS) \ 118 $(PRIVATE_ALL_OBJECTS) \ 119 $(if $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), `find $(PRIVATE_INTERMEDIATES_DIR)/WHOLE -name '*.o' 2>/dev/null`) \ 120 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 121 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 122 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 123 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 124 $(PRIVATE_LDLIBS) \ 125 -o $@ \ 126 -install_name @rpath/$(notdir $@) \ 127 -Wl,-rpath,@loader_path/../lib \ 128 $(PRIVATE_LDFLAGS) \ 129 $(HOST_LIBGCC) 130endef 131 132define transform-host-o-to-executable-inner 133$(hide) $(PRIVATE_CXX) \ 134 -Wl,-rpath,@loader_path/../lib \ 135 -o $@ \ 136 $(PRE_LION_DYNAMIC_LINKER_OPTIONS) -headerpad_max_install_names \ 137 $(HOST_GLOBAL_LD_DIRS) \ 138 $(HOST_GLOBAL_LDFLAGS) \ 139 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \ 140 $(PRIVATE_ALL_OBJECTS) \ 141 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \ 142 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \ 143 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \ 144 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \ 145 $(PRIVATE_LDFLAGS) \ 146 $(PRIVATE_LDLIBS) \ 147 $(HOST_LIBGCC) 148endef 149 150# $(1): The file to check 151define get-file-size 152stat -f "%z" $(1) 153endef 154