2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-14 12:42:11 +00:00
Files
build/src/tools/darwin.jam
Vladimir Prus 5873b7bc23 When deciding what options compiler accepts, use the version number the
compiler has reported, as opposed to the version number specified by the
user in user-config.jam.


[SVN r51326]
2009-02-19 09:17:20 +00:00

394 lines
14 KiB
Plaintext

# Copyright 2003 Christopher Currie
# Copyright 2006 Dave Abrahams
# Copyright 2003, 2004, 2005, 2006 Vladimir Prus
# Copyright 2005-2007 Mat Marcus
# Copyright 2005-2007 Adobe Systems Incorporated
# Copyright 2007-2008 Rene Rivera
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
# Please see http://article.gmane.org/gmane.comp.lib.boost.build/3389/
# for explanation why it's a separate toolset.
import feature : feature ;
import toolset : flags ;
import type ;
import common ;
import generators ;
import path : basename ;
## Use a framework.
feature framework : : free ;
## The MacOSX versions we can target.
.macosx-versions =
10.6 10.5 10.4 10.3 10.2 10.1
iphone-2.3 iphonesim-2.3
iphone-2.2 iphonesim-2.2
iphone-2.1 iphonesim-2.1
iphone-2.0 iphonesim-2.0
iphone-1.x
;
## The MacOSX version to compile for, which maps to the SDK to use (sysroot).
feature macosx-version
: $(.macosx-versions)
: propagated link-incompatible symmetric optional ;
## The minimal MacOSX version to target.
feature macosx-version-min
: $(.macosx-versions)
: propagated optional ;
#############################################################################
if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
{
.debug-configuration = true ;
}
feature.extend toolset : darwin ;
import gcc ;
toolset.inherit-generators darwin : gcc : gcc.mingw.link gcc.mingw.link.dll ;
generators.override darwin.prebuilt : builtin.prebuilt ;
generators.override darwin.searched-lib-generator : searched-lib-generator ;
# Override default do-nothing generators.
generators.override darwin.compile.c.pch : pch.default-c-pch-generator ;
generators.override darwin.compile.c++.pch : pch.default-cpp-pch-generator ;
type.set-generated-target-suffix PCH : <toolset>darwin : gch ;
toolset.inherit-rules darwin : gcc ;
toolset.inherit-flags darwin : gcc
: <runtime-link>static
<architecture>arm/<address-model>32
<architecture>arm/<address-model>64
<architecture>arm/<instruction-set>
<architecture>x86/<address-model>32
<architecture>x86/<address-model>64
<architecture>x86/<instruction-set>
<architecture>power/<address-model>32
<architecture>power/<address-model>64
<architecture>power/<instruction-set> ;
# Options:
#
# <root>PATH
# Platform root path. The common autodetection will set this to
# "/Developer". And when a command is given it will be set to
# the corresponding "*.platform/Developer" directory.
#
rule init ( version ? : command * : options * : requirement * )
{
# - The root directory of the tool install.
local root = [ feature.get-values <root> : $(options) ] ;
# - The bin directory where to find the commands to execute.
local bin ;
# - The configured compile driver command.
local command = [ common.get-invocation-command darwin : g++ : $(command) ] ;
# The version as reported by the compiler
local real-version ;
# - Autodetect the root and bin dir if not given.
if $(command)
{
bin ?= [ common.get-absolute-tool-path $(command[1]) ] ;
if $(bin) = "/usr/bin"
{
root ?= /Developer ;
}
else
{
local r = $(bin:D) ;
r = $(r:D) ;
root ?= $(r) ;
}
}
# - Autodetect the version if not given.
if $(command)
{
# - The 'command' variable can have multiple elements. When calling
# the SHELL builtin we need a single string.
local command-string = $(command:J=" ") ;
real-version = [ MATCH "^([0-9.]+)"
: [ SHELL "$(command-string) -dumpversion" ] ] ;
version ?= $(real-version) ;
}
# - Define the condition for this toolset instance.
local condition =
[ common.check-init-parameters darwin $(requirement) : version $(version) ] ;
# - Set the toolset generic common options.
common.handle-options darwin : $(condition) : $(command) : $(options) ;
# - GCC 4.0 and higher in Darwin does not have -fcoalesce-templates.
if $(real-version) < "4.0.0"
{
flags darwin.compile.c++ OPTIONS $(condition) : -fcoalesce-templates ;
}
# - GCC 4.2 and higher in Darwin does not have -Wno-long-double.
if $(real-version) < "4.2.0"
{
flags darwin.compile OPTIONS $(condition) : -Wno-long-double ;
}
# - Set the link flags common with the GCC toolset.
gcc.init-link-flags darwin darwin $(condition) ;
# - The symbol strip program.
local strip ;
if <striper> in $(options)
{
# We can turn off strip by specifying it as empty. In which
# case we switch to using the linker to do the strip.
flags darwin.link.dll OPTIONS
$(condition)/<main-target-type>LIB/<link>shared/<address-model>32/<debug-symbols>off : -Wl,-x ;
flags darwin.link.dll OPTIONS
$(condition)/<main-target-type>LIB/<link>shared/<address-model>/<debug-symbols>off : -Wl,-x ;
flags darwin.link OPTIONS
$(condition)/<main-target-type>EXE/<address-model>32/<debug-symbols>off : -s ;
flags darwin.link OPTIONS
$(condition)/<main-target-type>EXE/<address-model>/<debug-symbols>off : -s ;
}
else
{
# Otherwise we need to find a strip program to use. And hence
# also tell the link action that we need to use a strip
# post-process.
flags darwin.link NEED_STRIP $(condition)/<debug-symbols>off : "" ;
strip =
[ common.get-invocation-command darwin
: strip : [ feature.get-values <striper> : $(options) ] : $(bin) : search-path ] ;
flags darwin.link .STRIP $(condition) : $(strip[1]) ;
if $(.debug-configuration)
{
ECHO notice: using strip :: $(condition) :: $(strip[1]) ;
}
}
# - The archive builder (libtool is the default as creating
# archives in darwin is complicated.
local archiver =
[ common.get-invocation-command darwin
: libtool : [ feature.get-values <archiver> : $(options) ] : $(bin) : search-path ] ;
flags darwin.archive .LIBTOOL $(condition) : $(archiver[1]) ;
if $(.debug-configuration)
{
ECHO notice: using archiver :: $(condition) :: $(archiver[1]) ;
}
# - Initialize the SDKs available in the root for this tool.
local sdks = [ init-available-sdk-versions $(condition) : $(root) ] ;
#~ ECHO --- ;
#~ ECHO --- bin :: $(bin) ;
#~ ECHO --- root :: $(root) ;
#~ ECHO --- version :: $(version) ;
#~ ECHO --- condition :: $(condition) ;
#~ ECHO --- strip :: $(strip) ;
#~ ECHO --- archiver :: $(archiver) ;
#~ ECHO --- sdks :: $(sdks) ;
#~ ECHO --- ;
#~ EXIT ;
}
# Determine the MacOSX SDK versions installed and their locations.
local rule init-available-sdk-versions ( condition * : root ? )
{
root ?= /Developer ;
local sdks-root = $(root)/SDKs ;
local sdks = [ GLOB $(sdks-root) : MacOSX*.sdk iPhoneOS*.sdk iPhoneSimulator*.sdk ] ;
local result ;
for local sdk in $(sdks)
{
local sdk-match = [ MATCH ([^0-9]+)([0-9]+)[.]([0-9x]+)[.]?([0-9x]+)? : $(sdk:D=) ] ;
local sdk-platform = $(sdk-match[1]:L) ;
local sdk-version = $(sdk-match[2]).$(sdk-match[3]) ;
if $(sdk-version)
{
switch $(sdk-platform)
{
case macosx :
{
sdk-version = $(sdk-version) ;
}
case iphoneos :
{
sdk-version = iphone-$(sdk-version) ;
}
case iphonesimulator :
{
sdk-version = iphonesim-$(sdk-version) ;
}
case * :
{
sdk-version = $(sdk-version:J=-) ;
}
}
result += $(sdk-version) ;
flags darwin.compile OPTIONS $(condition)/<macosx-version>$(sdk-version)
: -isysroot $(sdk) ;
flags darwin.link OPTIONS $(condition)/<macosx-version>$(sdk-version)
: -isysroot $(sdk) ;
if $(.debug-configuration)
{
ECHO notice: available sdk :: $(condition)/<macosx-version>$(sdk-version) :: $(sdk) ;
}
}
}
return $(result) ;
}
# Generic options.
flags darwin.compile OPTIONS <flags> ;
# Minimal OSX target option. Note that the default is for the min-version
# option to not be included to let the compiler default take hold.
for local macosx-version in $(.macosx-versions)
{
flags darwin.compile OPTIONS <macosx-version-min>$(macosx-version)
: -mmacosx-version-min=$(macosx-version) ;
flags darwin.link OPTIONS <macosx-version-min>$(macosx-version)
: -mmacosx-version-min=$(macosx-version) ;
}
# The following adds objective-c support to darwin.
# Thanks to http://thread.gmane.org/gmane.comp.lib.boost.build/13759
generators.register-c-compiler darwin.compile.m : OBJECTIVE_C : OBJ : <toolset>darwin ;
generators.register-c-compiler darwin.compile.mm : OBJECTIVE_CPP : OBJ : <toolset>darwin ;
rule compile.m
{
LANG on $(<) = "-x objective-c" ;
gcc.setup-fpic $(targets) : $(sources) : $(properties) ;
}
actions compile.m
{
"$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
}
rule compile.mm ( targets * : sources * : properties * )
{
LANG on $(<) = "-x objective-c++" ;
gcc.setup-fpic $(targets) : $(sources) : $(properties) ;
}
actions compile.mm
{
"$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
}
# Add option selection for combined and specific architecture combinations.
local rule arch-addr-flags ( toolset variable
: architecture : address-model + : values + : default ? )
{
if $(default)
{
flags $(toolset) $(variable)
<architecture>$(architecture)/<address-model>
: $(values) ;
}
flags $(toolset) $(variable)
<architecture>/<address-model>$(address-model)
<architecture>$(architecture)/<address-model>$(address-model)
: $(values) ;
}
arch-addr-flags darwin OPTIONS : combined : 32 : -arch i386 -arch ppc : default ;
arch-addr-flags darwin OPTIONS : combined : 64 : -arch x86_64 -arch ppc64 ;
arch-addr-flags darwin OPTIONS : combined : 32_64 : -arch i386 -arch ppc -arch x86_64 -arch ppc64 ;
arch-addr-flags darwin OPTIONS : x86 : 32 : -arch i386 : default ;
arch-addr-flags darwin OPTIONS : x86 : 64 : -arch x86_64 ;
arch-addr-flags darwin OPTIONS : x86 : 32_64 : -arch i386 -arch x86_64 ;
arch-addr-flags darwin OPTIONS : power : 32 : -arch ppc : default ;
arch-addr-flags darwin OPTIONS : power : 64 : -arch ppc64 ;
arch-addr-flags darwin OPTIONS : power : 32_64 : -arch ppc -arch ppc64 ;
arch-addr-flags darwin OPTIONS : arm : 32 : -arch armv6 : default ;
# Set the max header padding to allow renaming of libs for installation.
flags darwin.link.dll OPTIONS : -headerpad_max_install_names ;
# To link the static runtime we need to link to all the core runtime libraries.
flags darwin.link OPTIONS <runtime-link>static
: -nodefaultlibs -shared-libgcc -lstdc++-static -lgcc_eh -lgcc -lSystem ;
# Strip as much as possible when optimizing.
flags darwin.link OPTIONS <optimization>speed : -Wl,-dead_strip -no_dead_strip_inits_and_terms ;
flags darwin.link OPTIONS <optimization>space : -Wl,-dead_strip -no_dead_strip_inits_and_terms ;
# Dynamic/shared linking.
flags darwin.compile OPTIONS <link>shared : -dynamic ;
# Misc options.
flags darwin.compile OPTIONS : -no-cpp-precomp -gdwarf-2 ;
# Add the framework names to use.
flags darwin.link FRAMEWORK <framework> ;
# This is flag is useful for debugging the link step
# uncomment to see what libtool is doing under the hood
#~ flags darwin.link.dll OPTIONS : -Wl,-v ;
_ = " " ;
# set up the -F option to include the paths to any frameworks used.
local rule prepare-framework-path ( target + )
{
# The -framework option only takes basename of the framework.
# The -F option specifies the directories where a framework
# is searched for. So, if we find <framework> feature
# with some path, we need to generate property -F option.
local framework-path = [ on $(target) return $(FRAMEWORK:D) ] ;
# Be sure to generate no -F if there's no path.
if $(framework-path) != ""
{
FRAMEWORK_PATH on $(target) += -F$(framework-path) ;
}
}
rule link
{
prepare-framework-path $(<) ;
}
# Note that using strip without any options was reported to result in broken
# binaries, at least on OS X 10.5.5, see:
# http://svn.boost.org/trac/boost/ticket/2347
# So we pass -S -x.
actions link bind LIBRARIES
{
"$(CONFIG_COMMAND)" -L"$(LINKPATH)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(FRAMEWORK_PATH) -framework$(_)$(FRAMEWORK:D=:S=) $(OPTIONS) $(USER_OPTIONS)
$(NEED_STRIP)"$(.STRIP)" $(NEED_STRIP)-S $(NEED_STRIP)-x $(NEED_STRIP)"$(<)"
}
rule link.dll
{
prepare-framework-path $(<) ;
}
actions link.dll bind LIBRARIES
{
"$(CONFIG_COMMAND)" -dynamiclib -Wl,-single_module -install_name "$(<:B)$(<:S)" -L"$(LINKPATH)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(FRAMEWORK_PATH) -framework$(_)$(FRAMEWORK:D=:S=) $(OPTIONS) $(USER_OPTIONS)
}
# We use libtool instead of ar to support universal binary linking
# TODO: Find a way to use the underlying tools, i.e. lipo, to do this.
actions piecemeal archive
{
"$(.LIBTOOL)" -static -o "$(<:T)" $(ARFLAGS) "$(>:T)"
}