blob: 28122cde8268f87049de4c70528683a450c219cd [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 Hsieh31ef1032012-08-21 14:40:16 +080032ifneq ($(strip $(BUILD_HOST_static)),)
33# Statically-linked binaries are desirable for sandboxed environment
34HOST_GLOBAL_LDFLAGS += -static
35endif # BUILD_HOST_static
36
SangWook Han02eb37c2012-06-08 14:55:05 +090037build_mac_version := $(shell sw_vers -productVersion)
SangWook Han691e0242012-07-31 02:09:38 +090038
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080039mac_sdk_versions_supported := 10.6 10.7 10.8
40ifneq ($(strip $(MAC_SDK_VERSION)),)
41mac_sdk_version := $(MAC_SDK_VERSION)
42ifeq ($(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.)
47endif
SangWook Han691e0242012-07-31 02:09:38 +090048else
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080049mac_sdk_versions_installed := $(shell xcodebuild -showsdks | grep macosx | sort | sed -e "s/.*macosx//g")
SangWook Han691e0242012-07-31 02:09:38 +090050mac_sdk_version := $(firstword $(filter $(mac_sdk_versions_installed), $(mac_sdk_versions_supported)))
51ifeq ($(mac_sdk_version),)
52mac_sdk_version := $(firstword $(mac_sdk_versions_supported))
53endif
SangWook Han691e0242012-07-31 02:09:38 +090054endif
55
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080056mac_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
59mac_sdk_root := $(mac_sdk_path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(mac_sdk_version).sdk
60ifeq ($(wildcard $(mac_sdk_root)),)
61# try legacy /Developer/SDKs/MacOSX10.?.sdk
62mac_sdk_root := /Developer/SDKs/MacOSX$(mac_sdk_version).sdk
63endif
Ying Wang644dc162012-05-25 15:14:12 -070064ifeq ($(wildcard $(mac_sdk_root)),)
Ying Wangd6683f02010-08-24 18:33:22 -070065$(warning *****************************************************)
Ying Wang644dc162012-05-25 15:14:12 -070066$(warning * Can not find SDK $(mac_sdk_version) at $(mac_sdk_root))
Ying Wangd6683f02010-08-24 18:33:22 -070067$(warning *****************************************************)
68$(error Stop.)
69endif
70
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080071ifeq ($(mac_sdk_version),10.6)
72 gcc_darwin_version := 10
73else
74 gcc_darwin_version := 11
75endif
76
77HOST_TOOLCHAIN_ROOT := prebuilts/gcc/darwin-x86/host/i686-apple-darwin-4.2.1
Ying Wang85e8cda2012-11-12 14:31:20 -080078HOST_TOOLCHAIN_PREFIX := $(HOST_TOOLCHAIN_ROOT)/bin/i686-apple-darwin$(gcc_darwin_version)
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080079# Don't do anything if the toolchain is not there
Ying Wang85e8cda2012-11-12 14:31:20 -080080ifneq (,$(strip $(wildcard $(HOST_TOOLCHAIN_PREFIX)-gcc)))
81HOST_CC := $(HOST_TOOLCHAIN_PREFIX)-gcc
82HOST_CXX := $(HOST_TOOLCHAIN_PREFIX)-g++
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080083ifeq ($(mac_sdk_version),10.8)
84# Mac SDK 10.8 no longer has stdarg.h, etc
85host_toolchain_header := $(HOST_TOOLCHAIN_ROOT)/lib/gcc/i686-apple-darwin$(gcc_darwin_version)/4.2.1/include
86HOST_GLOBAL_CFLAGS += -isystem $(host_toolchain_header)
87endif
88else
89HOST_CC := gcc
90HOST_CXX := g++
Ying Wang85e8cda2012-11-12 14:31:20 -080091endif # $(HOST_TOOLCHAIN_PREFIX)-gcc exists
Andrew Hsiehe2e28f62012-11-09 21:12:02 -080092HOST_AR := $(AR)
93HOST_STRIP := $(STRIP)
94HOST_STRIP_COMMAND = $(HOST_STRIP) --strip-debug $< -o $@
95
Ying Wang644dc162012-05-25 15:14:12 -070096HOST_GLOBAL_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version)
97HOST_GLOBAL_LDFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version)
Jeff Hamiltonebc28692010-05-26 18:13:54 -050098
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -080099HOST_GLOBAL_CFLAGS += -fPIC
100HOST_NO_UNDEFINED_LDFLAGS := -Wl,-undefined,error
101
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800102HOST_SHLIB_SUFFIX := .dylib
103HOST_JNILIB_SUFFIX := .jnilib
104
105HOST_GLOBAL_CFLAGS += \
106 -include $(call select-android-config-h,darwin-x86)
Al Sutton35bb6422012-05-07 09:33:34 +0100107ifneq ($(filter 10.7 10.7.% 10.8 10.8.%, $(build_mac_version)),)
Al Sutton9ce06f12011-12-21 13:12:05 -0800108 HOST_RUN_RANLIB_AFTER_COPYING := false
109else
110 HOST_RUN_RANLIB_AFTER_COPYING := true
Al Sutton80cfc372012-01-04 15:16:50 -0800111 PRE_LION_DYNAMIC_LINKER_OPTIONS := -Wl,-dynamic
Al Sutton9ce06f12011-12-21 13:12:05 -0800112endif
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800113HOST_GLOBAL_ARFLAGS := cqs
114
115HOST_CUSTOM_LD_COMMAND := true
116
Ying Wangfcf246c2012-01-20 12:22:49 -0800117# Workaround for lack of "-Wl,--whole-archive" in MacOS's linker.
118define _darwin-extract-and-include-single-whole-static-lib
119@echo "preparing StaticLib: $(PRIVATE_MODULE) [including $(1)]"
120$(hide) ldir=$(PRIVATE_INTERMEDIATES_DIR)/WHOLE/$(basename $(notdir $(1)))_objs;\
121 mkdir -p $$ldir; \
Ying Wang92ca6092012-02-23 16:27:43 -0800122 for f in `$(HOST_AR) t $(1)`; do \
123 $(HOST_AR) p $(1) $$f > $$ldir/$$f; \
Ying Wangfcf246c2012-01-20 12:22:49 -0800124 done ;
125
126endef
127
128define darwin-extract-and-include-whole-static-libs
129$(if $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), $(hide) rm -rf $(PRIVATE_INTERMEDIATES_DIR)/WHOLE)
130$(foreach lib,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), \
131 $(call _darwin-extract-and-include-single-whole-static-lib, $(lib)))
132endef
133
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800134define transform-host-o-to-shared-lib-inner
Ying Wangfcf246c2012-01-20 12:22:49 -0800135$(call darwin-extract-and-include-whole-static-libs)
Ying Wang3a7e4cc2011-01-28 14:14:47 -0800136$(hide) $(PRIVATE_CXX) \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800137 -dynamiclib -single_module -read_only_relocs suppress \
138 $(HOST_GLOBAL_LD_DIRS) \
Jeff Hamiltonebc28692010-05-26 18:13:54 -0500139 $(HOST_GLOBAL_LDFLAGS) \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800140 $(PRIVATE_ALL_OBJECTS) \
Ying Wangfcf246c2012-01-20 12:22:49 -0800141 $(if $(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES), `find $(PRIVATE_INTERMEDIATES_DIR)/WHOLE -name '*.o' 2>/dev/null`) \
Ying Wang80e6cce2011-01-24 23:25:36 -0800142 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -0700143 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
Ying Wang80e6cce2011-01-24 23:25:36 -0800144 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -0700145 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800146 $(PRIVATE_LDLIBS) \
147 -o $@ \
Ying Wang5dea6922012-02-01 13:18:20 -0800148 -install_name @rpath/$(notdir $@) \
149 -Wl,-rpath,@loader_path/../lib \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800150 $(PRIVATE_LDFLAGS) \
151 $(HOST_LIBGCC)
152endef
153
154define transform-host-o-to-executable-inner
Ying Wang3a7e4cc2011-01-28 14:14:47 -0800155$(hide) $(PRIVATE_CXX) \
Ying Wang5dea6922012-02-01 13:18:20 -0800156 -Wl,-rpath,@loader_path/../lib \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800157 -o $@ \
Al Sutton80cfc372012-01-04 15:16:50 -0800158 $(PRE_LION_DYNAMIC_LINKER_OPTIONS) -headerpad_max_install_names \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800159 $(HOST_GLOBAL_LD_DIRS) \
Jeff Hamiltonebc28692010-05-26 18:13:54 -0500160 $(HOST_GLOBAL_LDFLAGS) \
Ying Wang80e6cce2011-01-24 23:25:36 -0800161 $(call normalize-host-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800162 $(PRIVATE_ALL_OBJECTS) \
Ying Wang80e6cce2011-01-24 23:25:36 -0800163 $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -0700164 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--start-group) \
Ying Wang80e6cce2011-01-24 23:25:36 -0800165 $(call normalize-host-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
Ying Wangfcdabd42011-04-25 14:22:41 -0700166 $(if $(PRIVATE_GROUP_STATIC_LIBRARIES),-Wl$(comma)--end-group) \
Jean-Baptiste Queru9b4a8122010-02-23 12:36:56 -0800167 $(PRIVATE_LDFLAGS) \
168 $(PRIVATE_LDLIBS) \
169 $(HOST_LIBGCC)
170endef
171
172# $(1): The file to check
173define get-file-size
174stat -f "%z" $(1)
175endef