blob: 994196a1b271630d1f04634b978fd526955e2091 [file] [log] [blame]
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -08001#
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
Andrew Hsiehed6b8152012-02-27 21:03:30 -080020ifneq ($(strip $(BUILD_HOST_64bit)),)
21# By default we build everything in 32-bit, because it gives us
Jeff Hamiltonebc28692010-05-26 18:13:54 -050022# more consistency between the host tools and the target.
Andrew Hsiehed6b8152012-02-27 21:03:30 -080023# 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
Jeff Hamiltonebc28692010-05-26 18:13:54 -050028HOST_GLOBAL_CFLAGS += -m32
29HOST_GLOBAL_LDFLAGS += -m32
Andrew Hsiehed6b8152012-02-27 21:03:30 -080030endif # BUILD_HOST_64bit
Jeff Hamiltonebc28692010-05-26 18:13:54 -050031
Andrew Hsiehf9613a42012-04-28 00:35:19 +080032ifneq ($(strip $(BUILD_HOST_static)),)
33# Statically-linked binaries are desirable for sandboxed environment
34HOST_GLOBAL_LDFLAGS += -static
35endif # BUILD_HOST_static
36
Ian Rogers61e50592014-01-29 13:09:30 -080037# Workaround differences in inttypes.h between host and target.
38# See bug 12708004.
Ian Rogersaa540332014-03-10 16:49:41 -070039HOST_GLOBAL_CFLAGS += -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS
Ian Rogers61e50592014-01-29 13:09:30 -080040
SangWook Han02eb37c2012-06-08 14:55:05 +090041build_mac_version := $(shell sw_vers -productVersion)
SangWook Han691e0242012-07-31 02:09:38 +090042
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080043mac_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
SangWook Han691e0242012-07-31 02:09:38 +090052else
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080053mac_sdk_versions_installed := $(shell xcodebuild -showsdks | grep macosx | sort | sed -e "s/.*macosx//g")
SangWook Han691e0242012-07-31 02:09:38 +090054mac_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
SangWook Han691e0242012-07-31 02:09:38 +090058endif
Andrew Hsieh31ef1032012-08-21 14:40:16 +080059
60mac_sdk_path := $(shell xcode-select -print-path)
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080061# 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
SangWook Han691e0242012-07-31 02:09:38 +090063mac_sdk_root := $(mac_sdk_path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(mac_sdk_version).sdk
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080064ifeq ($(wildcard $(mac_sdk_root)),)
65# try legacy /Developer/SDKs/MacOSX10.?.sdk
66mac_sdk_root := /Developer/SDKs/MacOSX$(mac_sdk_version).sdk
SangWook Han691e0242012-07-31 02:09:38 +090067endif
Ying Wangabf72cf2012-05-25 15:14:12 -070068ifeq ($(wildcard $(mac_sdk_root)),)
Ying Wangd6683f02010-08-24 18:33:22 -070069$(warning *****************************************************)
Ying Wang644dc162012-05-25 15:14:12 -070070$(warning * Can not find SDK $(mac_sdk_version) at $(mac_sdk_root))
Ying Wangd6683f02010-08-24 18:33:22 -070071$(warning *****************************************************)
72$(error Stop.)
73endif
74
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080075ifeq ($(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
Ying Wang85e8cda2012-11-12 14:31:20 -080082HOST_TOOLCHAIN_PREFIX := $(HOST_TOOLCHAIN_ROOT)/bin/i686-apple-darwin$(gcc_darwin_version)
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080083# Don't do anything if the toolchain is not there
Ying Wang85e8cda2012-11-12 14:31:20 -080084ifneq (,$(strip $(wildcard $(HOST_TOOLCHAIN_PREFIX)-gcc)))
85HOST_CC := $(HOST_TOOLCHAIN_PREFIX)-gcc
86HOST_CXX := $(HOST_TOOLCHAIN_PREFIX)-g++
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080087ifeq ($(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++
Ying Wang85e8cda2012-11-12 14:31:20 -080095endif # $(HOST_TOOLCHAIN_PREFIX)-gcc exists
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080096HOST_AR := $(AR)
97HOST_STRIP := $(STRIP)
C. Sean Youngb47c8632014-02-19 12:53:43 -080098HOST_STRIP_COMMAND = $(HOST_STRIP) --strip-all $< -o $@
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080099
Ying Wang10f77532012-06-06 20:33:26 -0700100HOST_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)
Jeff Hamiltonebc28692010-05-26 18:13:54 -0500102
Elliott Hughes468d6a52012-05-23 17:32:32 -0700103HOST_GLOBAL_CFLAGS += -fPIC -funwind-tables
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800104HOST_NO_UNDEFINED_LDFLAGS := -Wl,-undefined,error
105
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800106HOST_SHLIB_SUFFIX := .dylib
107HOST_JNILIB_SUFFIX := .jnilib
108
109HOST_GLOBAL_CFLAGS += \
Ying Wang130ae6a2012-06-05 15:44:21 -0700110 -include $(call select-android-config-h,darwin-x86)
Ying Wang5bdf3052012-09-20 10:06:33 -0700111
Al Sutton35bb6422012-05-07 09:33:34 +0100112ifneq ($(filter 10.7 10.7.% 10.8 10.8.%, $(build_mac_version)),)
Al Sutton9ce06f12011-12-21 13:12:05 -0800113 HOST_RUN_RANLIB_AFTER_COPYING := false
114else
115 HOST_RUN_RANLIB_AFTER_COPYING := true
Al Sutton80cfc372012-01-04 15:16:50 -0800116 PRE_LION_DYNAMIC_LINKER_OPTIONS := -Wl,-dynamic
Al Sutton9ce06f12011-12-21 13:12:05 -0800117endif
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800118HOST_GLOBAL_ARFLAGS := cqs
119
120HOST_CUSTOM_LD_COMMAND := true
121
122define transform-host-o-to-shared-lib-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -0800123$(hide) $(PRIVATE_CXX) \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800124 -dynamiclib -single_module -read_only_relocs suppress \
125 $(HOST_GLOBAL_LD_DIRS) \
Jeff Hamiltonebc28692010-05-26 18:13:54 -0500126 $(HOST_GLOBAL_LDFLAGS) \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800127 $(PRIVATE_ALL_OBJECTS) \
Shih-wei Liaob2680752012-05-02 04:41:41 -0700128 $(addprefix -force_load , $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
Ying Wang80e6cce2011-01-24 23:25:36 -0800129 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
Ying Wang80e6cce2011-01-24 23:25:36 -0800130 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800131 $(PRIVATE_LDLIBS) \
132 -o $@ \
Ying Wang5dea6922012-02-01 13:18:20 -0800133 -install_name @rpath/$(notdir $@) \
134 -Wl,-rpath,@loader_path/../lib \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800135 $(PRIVATE_LDFLAGS) \
136 $(HOST_LIBGCC)
137endef
138
139define transform-host-o-to-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -0800140$(hide) $(PRIVATE_CXX) \
Ying Wang5dea6922012-02-01 13:18:20 -0800141 -Wl,-rpath,@loader_path/../lib \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800142 -o $@ \
Al Sutton80cfc372012-01-04 15:16:50 -0800143 $(PRE_LION_DYNAMIC_LINKER_OPTIONS) -headerpad_max_install_names \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800144 $(HOST_GLOBAL_LD_DIRS) \
Jeff Hamiltonebc28692010-05-26 18:13:54 -0500145 $(HOST_GLOBAL_LDFLAGS) \
Ying Wang80e6cce2011-01-24 23:25:36 -0800146 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800147 $(PRIVATE_ALL_OBJECTS) \
Ying Wang80e6cce2011-01-24 23:25:36 -0800148 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
149 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800150 $(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
Tim Murray02cefc92014-03-20 13:48:35 -0700159
160# gcc location for clang; to be updated when clang is updated
161# HOST_TOOLCHAIN_ROOT is a Darwin-specific define
162HOST_TOOLCHAIN_FOR_CLANG := $(HOST_TOOLCHAIN_ROOT)