HOST_darwin-x86.mk revision 76a6dc3a191e8800211eb49398d37deae731094e
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
32ifneq ($(strip $(BUILD_HOST_static)),)
33# Statically-linked binaries are desirable for sandboxed environment
34HOST_GLOBAL_LDFLAGS += -static
35endif # BUILD_HOST_static
36
37build_mac_version := $(shell sw_vers -productVersion)
38
39ifneq ($(strip $(BUILD_MAC_SDK_EXPERIMENTAL)),)
40# SDK 10.7 and higher is not fully compatible with Android.
41mac_sdk_versions_supported :=  10.7 10.8
42else
43mac_sdk_versions_supported :=  10.6
44endif # BUILD_MAC_SDK_EXPERIMENTAL
45mac_sdk_versions_installed := $(shell xcodebuild -showsdks |grep macosx | sort | sed -e "s/.*macosx//g")
46mac_sdk_version := $(firstword $(filter $(mac_sdk_versions_installed), $(mac_sdk_versions_supported)))
47ifeq ($(mac_sdk_version),)
48mac_sdk_version := $(firstword $(mac_sdk_versions_supported))
49endif
50
51mac_sdk_path := $(shell xcode-select -print-path)
52ifeq ($(findstring /Applications,$(mac_sdk_path)),)
53# Legacy Xcode
54mac_sdk_root := /Developer/SDKs/MacOSX$(mac_sdk_version).sdk
55else
56#  Xcode 4.4(App Store) or higher
57# /Applications/Xcode*.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.?.sdk
58mac_sdk_root := $(mac_sdk_path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(mac_sdk_version).sdk
59endif
60
61ifeq ($(wildcard $(mac_sdk_root)),)
62$(warning *****************************************************)
63$(warning * Cannot find SDK $(mac_sdk_version) at $(mac_sdk_root))
64ifeq ($(strip $(BUILD_MAC_SDK_EXPERIMENTAL)),)
65$(warning * If you wish to build using higher version of SDK, )
66$(warning * try setting BUILD_MAC_SDK_EXPERIMENTAL=1 before )
67$(warning * rerunning this command )
68endif
69$(warning *****************************************************)
70$(error Stop.)
71endif
72
73HOST_GLOBAL_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) -DMACOSX_DEPLOYMENT_TARGET=$(mac_sdk_version)
74HOST_GLOBAL_LDFLAGS += -isysroot $(mac_sdk_root) -Wl,-syslibroot,$(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version)
75
76HOST_GLOBAL_CFLAGS += -fPIC -funwind-tables
77HOST_NO_UNDEFINED_LDFLAGS := -Wl,-undefined,error
78
79HOST_CC := gcc
80HOST_CXX := g++
81HOST_AR := $(AR)
82HOST_STRIP := $(STRIP)
83HOST_STRIP_COMMAND = $(HOST_STRIP) --strip-debug $< -o $@
84
85HOST_SHLIB_SUFFIX := .dylib
86HOST_JNILIB_SUFFIX := .jnilib
87
88HOST_GLOBAL_CFLAGS += \
89    -include $(call select-android-config-h,darwin-x86)
90
91ifneq ($(filter 10.7 10.7.% 10.8 10.8.%, $(build_mac_version)),)
92       HOST_RUN_RANLIB_AFTER_COPYING := false
93else
94       HOST_RUN_RANLIB_AFTER_COPYING := true
95       PRE_LION_DYNAMIC_LINKER_OPTIONS := -Wl,-dynamic
96endif
97HOST_GLOBAL_ARFLAGS := cqs
98
99HOST_CUSTOM_LD_COMMAND := true
100
101define transform-host-o-to-shared-lib-inner
102$(hide) $(PRIVATE_CXX) \
103        -dynamiclib -single_module -read_only_relocs suppress \
104        $(HOST_GLOBAL_LD_DIRS) \
105        $(HOST_GLOBAL_LDFLAGS) \
106        $(PRIVATE_ALL_OBJECTS) \
107        $(addprefix -force_load , $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
108        $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
109        $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
110        $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
111        $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
112        $(PRIVATE_LDLIBS) \
113        -o $@ \
114        -install_name @rpath/$(notdir $@) \
115        -Wl,-rpath,@loader_path/../lib \
116        $(PRIVATE_LDFLAGS) \
117        $(HOST_LIBGCC)
118endef
119
120define transform-host-o-to-executable-inner
121$(hide) $(PRIVATE_CXX) \
122        -Wl,-rpath,@loader_path/../lib \
123        -o $@ \
124        $(PRE_LION_DYNAMIC_LINKER_OPTIONS) -headerpad_max_install_names \
125        $(HOST_GLOBAL_LD_DIRS) \
126        $(HOST_GLOBAL_LDFLAGS) \
127        $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
128        $(PRIVATE_ALL_OBJECTS) \
129        $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
130        $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
131        $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
132        $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
133        $(PRIVATE_LDFLAGS) \
134        $(PRIVATE_LDLIBS) \
135        $(HOST_LIBGCC)
136endef
137
138# $(1): The file to check
139define get-file-size
140stat -f "%z" $(1)
141endef
142