16feb6d5607ce86a446645564212043964628f540Ying Wang# Detect Mac OS X and SDK versions.
26feb6d5607ce86a446645564212043964628f540Ying Wang# Output variables:
36feb6d5607ce86a446645564212043964628f540Ying Wang#   build_mac_version
46feb6d5607ce86a446645564212043964628f540Ying Wang#   mac_sdk_version
56feb6d5607ce86a446645564212043964628f540Ying Wang#   mac_sdk_root
66feb6d5607ce86a446645564212043964628f540Ying Wang#   gcc_darwin_version
76feb6d5607ce86a446645564212043964628f540Ying Wang
86feb6d5607ce86a446645564212043964628f540Ying Wangifndef build_mac_version
96feb6d5607ce86a446645564212043964628f540Ying Wang
106feb6d5607ce86a446645564212043964628f540Ying Wangbuild_mac_version := $(shell sw_vers -productVersion)
116feb6d5607ce86a446645564212043964628f540Ying Wang
126feb6d5607ce86a446645564212043964628f540Ying Wangmac_sdk_versions_supported :=  10.6 10.7 10.8
136feb6d5607ce86a446645564212043964628f540Ying Wangifneq ($(strip $(MAC_SDK_VERSION)),)
146feb6d5607ce86a446645564212043964628f540Ying Wangmac_sdk_version := $(MAC_SDK_VERSION)
156feb6d5607ce86a446645564212043964628f540Ying Wangifeq ($(filter $(mac_sdk_version),$(mac_sdk_versions_supported)),)
166feb6d5607ce86a446645564212043964628f540Ying Wang$(warning ****************************************************************)
176feb6d5607ce86a446645564212043964628f540Ying Wang$(warning * MAC_SDK_VERSION $(MAC_SDK_VERSION) isn't one of the supported $(mac_sdk_versions_supported))
186feb6d5607ce86a446645564212043964628f540Ying Wang$(warning ****************************************************************)
196feb6d5607ce86a446645564212043964628f540Ying Wang$(error Stop.)
206feb6d5607ce86a446645564212043964628f540Ying Wangendif
216feb6d5607ce86a446645564212043964628f540Ying Wangelse
226feb6d5607ce86a446645564212043964628f540Ying Wangmac_sdk_versions_installed := $(shell xcodebuild -showsdks | grep macosx | sort | sed -e "s/.*macosx//g")
236feb6d5607ce86a446645564212043964628f540Ying Wangmac_sdk_version := $(firstword $(filter $(mac_sdk_versions_installed), $(mac_sdk_versions_supported)))
246feb6d5607ce86a446645564212043964628f540Ying Wangifeq ($(mac_sdk_version),)
256feb6d5607ce86a446645564212043964628f540Ying Wangmac_sdk_version := $(firstword $(mac_sdk_versions_supported))
266feb6d5607ce86a446645564212043964628f540Ying Wangendif
276feb6d5607ce86a446645564212043964628f540Ying Wangendif
286feb6d5607ce86a446645564212043964628f540Ying Wang
296feb6d5607ce86a446645564212043964628f540Ying Wangmac_sdk_path := $(shell xcode-select -print-path)
306feb6d5607ce86a446645564212043964628f540Ying Wang# try /Applications/Xcode*.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.?.sdk
316feb6d5607ce86a446645564212043964628f540Ying Wang#  or /Volume/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.?.sdk
326feb6d5607ce86a446645564212043964628f540Ying Wangmac_sdk_root := $(mac_sdk_path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(mac_sdk_version).sdk
336feb6d5607ce86a446645564212043964628f540Ying Wangifeq ($(wildcard $(mac_sdk_root)),)
346feb6d5607ce86a446645564212043964628f540Ying Wang# try legacy /Developer/SDKs/MacOSX10.?.sdk
356feb6d5607ce86a446645564212043964628f540Ying Wangmac_sdk_root := /Developer/SDKs/MacOSX$(mac_sdk_version).sdk
366feb6d5607ce86a446645564212043964628f540Ying Wangendif
376feb6d5607ce86a446645564212043964628f540Ying Wangifeq ($(wildcard $(mac_sdk_root)),)
386feb6d5607ce86a446645564212043964628f540Ying Wang$(warning *****************************************************)
396feb6d5607ce86a446645564212043964628f540Ying Wang$(warning * Can not find SDK $(mac_sdk_version) at $(mac_sdk_root))
406feb6d5607ce86a446645564212043964628f540Ying Wang$(warning *****************************************************)
416feb6d5607ce86a446645564212043964628f540Ying Wang$(error Stop.)
426feb6d5607ce86a446645564212043964628f540Ying Wangendif
436feb6d5607ce86a446645564212043964628f540Ying Wang
446feb6d5607ce86a446645564212043964628f540Ying Wangifeq ($(mac_sdk_version),10.6)
456feb6d5607ce86a446645564212043964628f540Ying Wang  gcc_darwin_version := 10
466feb6d5607ce86a446645564212043964628f540Ying Wangelse
476feb6d5607ce86a446645564212043964628f540Ying Wang  gcc_darwin_version := 11
486feb6d5607ce86a446645564212043964628f540Ying Wangendif
496feb6d5607ce86a446645564212043964628f540Ying Wang
506feb6d5607ce86a446645564212043964628f540Ying Wangendif  # ifndef build_mac_version
51