HOST_darwin-x86.mk revision b47c863ec7d7b0d6806d7ea85887c662893a2c70
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
37# Workaround differences in inttypes.h between host and target.
38# See bug 12708004.
39HOST_GLOBAL_CFLAGS += -D__STDC_FORMAT_MACROS
40
41build_mac_version := $(shell sw_vers -productVersion)
42
43mac_sdk_versions_supported :=  10.6 10.7 10.8
44ifneq ($(strip $(MAC_SDK_VERSION)),)
45mac_sdk_version := $(MAC_SDK_VERSION)
46ifeq ($(filter $(mac_sdk_version),$(mac_sdk_versions_supported)),)
47$(warning ****************************************************************)
48$(warning * MAC_SDK_VERSION $(MAC_SDK_VERSION) isn't one of the supported $(mac_sdk_versions_supported))
49$(warning ****************************************************************)
50$(error Stop.)
51endif
52else
53mac_sdk_versions_installed := $(shell xcodebuild -showsdks | grep macosx | sort | sed -e "s/.*macosx//g")
54mac_sdk_version := $(firstword $(filter $(mac_sdk_versions_installed), $(mac_sdk_versions_supported)))
55ifeq ($(mac_sdk_version),)
56mac_sdk_version := $(firstword $(mac_sdk_versions_supported))
57endif
58endif
59
60mac_sdk_path := $(shell xcode-select -print-path)
61# try /Applications/Xcode*.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.?.sdk
62#  or /Volume/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.?.sdk
63mac_sdk_root := $(mac_sdk_path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(mac_sdk_version).sdk
64ifeq ($(wildcard $(mac_sdk_root)),)
65# try legacy /Developer/SDKs/MacOSX10.?.sdk
66mac_sdk_root := /Developer/SDKs/MacOSX$(mac_sdk_version).sdk
67endif
68ifeq ($(wildcard $(mac_sdk_root)),)
69$(warning *****************************************************)
70$(warning * Can not find SDK $(mac_sdk_version) at $(mac_sdk_root))
71$(warning *****************************************************)
72$(error Stop.)
73endif
74
75ifeq ($(mac_sdk_version),10.6)
76  gcc_darwin_version := 10
77else
78  gcc_darwin_version := 11
79endif
80
81HOST_TOOLCHAIN_ROOT := prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1
82HOST_TOOLCHAIN_PREFIX := $(HOST_TOOLCHAIN_ROOT)/bin/i686-apple-darwin$(gcc_darwin_version)
83# Don't do anything if the toolchain is not there
84ifneq (,$(strip $(wildcard $(HOST_TOOLCHAIN_PREFIX)-gcc)))
85HOST_CC  := $(HOST_TOOLCHAIN_PREFIX)-gcc
86HOST_CXX := $(HOST_TOOLCHAIN_PREFIX)-g++
87ifeq ($(mac_sdk_version),10.8)
88# Mac SDK 10.8 no longer has stdarg.h, etc
89host_toolchain_header := $(HOST_TOOLCHAIN_ROOT)/lib/gcc/i686-apple-darwin$(gcc_darwin_version)/4.2.1/include
90HOST_GLOBAL_CFLAGS += -isystem $(host_toolchain_header)
91endif
92else
93HOST_CC := gcc
94HOST_CXX := g++
95endif # $(HOST_TOOLCHAIN_PREFIX)-gcc exists
96HOST_AR := $(AR)
97HOST_STRIP := $(STRIP)
98HOST_STRIP_COMMAND = $(HOST_STRIP) --strip-all $< -o $@
99
100HOST_GLOBAL_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) -DMACOSX_DEPLOYMENT_TARGET=$(mac_sdk_version)
101HOST_GLOBAL_LDFLAGS += -isysroot $(mac_sdk_root) -Wl,-syslibroot,$(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version)
102
103HOST_GLOBAL_CFLAGS += -fPIC -funwind-tables
104HOST_NO_UNDEFINED_LDFLAGS := -Wl,-undefined,error
105
106HOST_SHLIB_SUFFIX := .dylib
107HOST_JNILIB_SUFFIX := .jnilib
108
109HOST_GLOBAL_CFLAGS += \
110    -include $(call select-android-config-h,darwin-x86)
111
112ifneq ($(filter 10.7 10.7.% 10.8 10.8.%, $(build_mac_version)),)
113       HOST_RUN_RANLIB_AFTER_COPYING := false
114else
115       HOST_RUN_RANLIB_AFTER_COPYING := true
116       PRE_LION_DYNAMIC_LINKER_OPTIONS := -Wl,-dynamic
117endif
118HOST_GLOBAL_ARFLAGS := cqs
119
120HOST_CUSTOM_LD_COMMAND := true
121
122define transform-host-o-to-shared-lib-inner
123$(hide) $(PRIVATE_CXX) \
124        -dynamiclib -single_module -read_only_relocs suppress \
125        $(HOST_GLOBAL_LD_DIRS) \
126        $(HOST_GLOBAL_LDFLAGS) \
127        $(PRIVATE_ALL_OBJECTS) \
128        $(addprefix -force_load , $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
129        $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
130        $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
131        $(PRIVATE_LDLIBS) \
132        -o $@ \
133        -install_name @rpath/$(notdir $@) \
134        -Wl,-rpath,@loader_path/../lib \
135        $(PRIVATE_LDFLAGS) \
136        $(HOST_LIBGCC)
137endef
138
139define transform-host-o-to-executable-inner
140$(hide) $(PRIVATE_CXX) \
141        -Wl,-rpath,@loader_path/../lib \
142        -o $@ \
143        $(PRE_LION_DYNAMIC_LINKER_OPTIONS) -headerpad_max_install_names \
144        $(HOST_GLOBAL_LD_DIRS) \
145        $(HOST_GLOBAL_LDFLAGS) \
146        $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
147        $(PRIVATE_ALL_OBJECTS) \
148        $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
149        $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
150        $(PRIVATE_LDFLAGS) \
151        $(PRIVATE_LDLIBS) \
152        $(HOST_LIBGCC)
153endef
154
155# $(1): The file to check
156define get-file-size
157stat -f "%z" $(1)
158endef
159