]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/tools/build/src/tools/darwin.jam
update sources to v12.2.3
[ceph.git] / ceph / src / boost / tools / build / src / tools / darwin.jam
CommitLineData
7c673cae
FG
1# Copyright 2003 Christopher Currie
2# Copyright 2006 Dave Abrahams
3# Copyright 2003, 2004, 2005, 2006 Vladimir Prus
4# Copyright 2005-2007 Mat Marcus
5# Copyright 2005-2007 Adobe Systems Incorporated
6# Copyright 2007-2010 Rene Rivera
7# Distributed under the Boost Software License, Version 1.0.
8# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
9
10# Please see http://article.gmane.org/gmane.comp.lib.boost.build/3389/
11# for explanation why it's a separate toolset.
12
13import feature : feature ;
14import toolset : flags ;
15import type ;
16import common ;
17import generators ;
18import path : basename ;
19import version ;
20import property-set ;
21import regex ;
22import errors ;
23
24## Use a framework.
25feature framework : : free ;
26
27## The MacOSX version to compile for, which maps to the SDK to use (sysroot).
28feature macosx-version : : propagated link-incompatible symmetric optional ;
29
30## The minimal MacOSX version to target.
31feature macosx-version-min : : propagated optional ;
32
33## A dependency, that is forced to be included in the link.
34feature force-load : : free dependency incidental ;
35
36#############################################################################
37
38_ = " " ;
39
40if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
41{
42 .debug-configuration = true ;
43}
44
45feature.extend toolset : darwin ;
46import gcc ;
47toolset.inherit-generators darwin : gcc : gcc.mingw.link gcc.mingw.link.dll ;
48
49generators.override darwin.prebuilt : builtin.prebuilt ;
50generators.override darwin.searched-lib-generator : searched-lib-generator ;
51
52# Override default do-nothing generators.
53generators.override darwin.compile.c.pch : pch.default-c-pch-generator ;
54generators.override darwin.compile.c++.pch : pch.default-cpp-pch-generator ;
55
56type.set-generated-target-suffix PCH : <toolset>darwin : gch ;
57
58toolset.inherit-rules darwin : gcc : localize ;
59toolset.inherit-flags darwin : gcc
60 : <runtime-link>static
61 <architecture>arm/<address-model>32
62 <architecture>arm/<address-model>64
63 <architecture>arm/<instruction-set>
64 <architecture>x86/<address-model>32
65 <architecture>x86/<address-model>64
66 <architecture>x86/<instruction-set>
67 <architecture>power/<address-model>32
68 <architecture>power/<address-model>64
69 <architecture>power/<instruction-set>
70 <inlining>full ;
71
72# Options:
73#
74# <root>PATH
75# Platform root path. The common autodetection will set this to
76# "/Developer". And when a command is given it will be set to
77# the corresponding "*.platform/Developer" directory.
78#
79rule init ( version ? : command * : options * : requirement * )
80{
81 # First time around, figure what is host OSX version
82 if ! $(.host-osx-version)
83 {
84 .host-osx-version = [ MATCH "^([0-9.]+)"
85 : [ SHELL "/usr/bin/sw_vers -productVersion" ] ] ;
86 if $(.debug-configuration)
87 {
88 ECHO notice: OSX version on this machine is $(.host-osx-version) ;
89 }
90 }
91
92 # - The root directory of the tool install.
93 local root = [ feature.get-values <root> : $(options) ] ;
94
95 # - The bin directory where to find the commands to execute.
96 local bin ;
97
98 # - The configured compile driver command.
99 local command = [ common.get-invocation-command darwin : g++ : $(command) ] ;
100
101 # The version as reported by the compiler
102 local real-version ;
103
104 # - Autodetect the root and bin dir if not given.
105 if $(command)
106 {
107 bin ?= [ common.get-absolute-tool-path $(command[1]) ] ;
108 if $(bin) = "/usr/bin"
109 {
110 root ?= /Developer ;
111 }
112 else
113 {
114 local r = $(bin:D) ;
115 r = $(r:D) ;
116 root ?= $(r) ;
117 }
118 }
119
120 # - Autodetect the version if not given.
121 if $(command)
122 {
123 # - The 'command' variable can have multiple elements. When calling
124 # the SHELL builtin we need a single string.
125 local command-string = $(command:J=" ") ;
126 real-version = [ MATCH "^([0-9.]+)"
127 : [ SHELL "$(command-string) -dumpversion" ] ] ;
128 version ?= $(real-version) ;
129 }
130
131 .real-version.$(version) = $(real-version) ;
132
133 # - Define the condition for this toolset instance.
134 local condition =
135 [ common.check-init-parameters darwin $(requirement) : version $(version) ] ;
136
137 # - Set the toolset generic common options.
138 common.handle-options darwin : $(condition) : $(command) : $(options) ;
139
140 # - GCC 4.0 and higher in Darwin does not have -fcoalesce-templates.
141 if $(real-version) < "4.0.0"
142 {
143 flags darwin.compile.c++ OPTIONS $(condition) : -fcoalesce-templates ;
144 }
145 # - GCC 4.2 and higher in Darwin does not have -Wno-long-double.
146 if $(real-version) < "4.2.0"
147 {
148 flags darwin.compile OPTIONS $(condition) : -Wno-long-double ;
149 }
150 # - GCC on Darwin with -pedantic, suppress unsupported long long warning
151 flags darwin.compile OPTIONS $(condition)/<warnings>all : -Wno-long-long ;
152
153 # - GCC on El Capitan (10.11) does not suport -finline-functions
154 if "10.11.0" <= $(.host-osx-version)
155 {
156 flags darwin.compile OPTIONS $(condition)/<inlining>full : -Wno-inline ;
157 }
158
159 # - Set the link flags common with the GCC toolset.
160 gcc.init-link-flags darwin darwin $(condition) ;
161
162 # - The symbol strip program.
163 local strip ;
164 if <striper> in $(options)
165 {
166 # We can turn off strip by specifying it as empty. In which
167 # case we switch to using the linker to do the strip.
168 flags darwin.link.dll OPTIONS
169 $(condition)/<main-target-type>LIB/<link>shared/<address-model>32/<strip>on : -Wl,-x ;
170 flags darwin.link.dll OPTIONS
171 $(condition)/<main-target-type>LIB/<link>shared/<address-model>/<strip>on : -Wl,-x ;
172 flags darwin.link OPTIONS
173 $(condition)/<main-target-type>EXE/<address-model>32/<strip>on : -s ;
174 flags darwin.link OPTIONS
175 $(condition)/<main-target-type>EXE/<address-model>/<strip>on : -s ;
176 }
177 else
178 {
179 # Otherwise we need to find a strip program to use. And hence
180 # also tell the link action that we need to use a strip
181 # post-process.
182 flags darwin.link NEED_STRIP $(condition)/<strip>on : "" ;
183 strip =
184 [ common.get-invocation-command darwin
185 : strip : [ feature.get-values <striper> : $(options) ] : $(bin) : search-path ] ;
186 flags darwin.link .STRIP $(condition) : $(strip[1]) ;
187 if $(.debug-configuration)
188 {
189 ECHO notice: using strip for $(condition) at $(strip[1]) ;
190 }
191 }
192
193 # - The archive builder (libtool is the default as creating
194 # archives in darwin is complicated.
195 local archiver =
196 [ common.get-invocation-command darwin
197 : libtool : [ feature.get-values <archiver> : $(options) ] : $(bin) : search-path ] ;
198 flags darwin.archive .LIBTOOL $(condition) : $(archiver[1]) ;
199 if $(.debug-configuration)
200 {
201 ECHO notice: using archiver for $(condition) at $(archiver[1]) ;
202 }
203
204 # - Initialize the SDKs available in the root for this tool.
205 local sdks = [ init-available-sdk-versions $(condition) : $(root) ] ;
206
207 #~ ECHO --- ;
208 #~ ECHO --- bin :: $(bin) ;
209 #~ ECHO --- root :: $(root) ;
210 #~ ECHO --- version :: $(version) ;
211 #~ ECHO --- condition :: $(condition) ;
212 #~ ECHO --- strip :: $(strip) ;
213 #~ ECHO --- archiver :: $(archiver) ;
214 #~ ECHO --- sdks :: $(sdks) ;
215 #~ ECHO --- ;
216 #~ EXIT ;
217}
218
219# Add and set options for a discovered SDK version.
220local rule init-sdk ( condition * : root ? : version + : version-feature ? )
221{
222 local rule version-to-feature ( version + )
223 {
224 switch $(version[1])
225 {
226 case appletv* :
227 {
228 return $(version[1])-$(version[2-]:J=.) ;
229 }
230 case iphone* :
231 {
232 return $(version[1])-$(version[2-]:J=.) ;
233 }
234 case mac* :
235 {
236 return $(version[2-]:J=.) ;
237 }
238 case * :
239 {
240 return $(version:J=.) ;
241 }
242 }
243 }
244
245 if $(version-feature)
246 {
247 if $(.debug-configuration)
248 {
249 ECHO notice: available sdk for $(condition)/<macosx-version>$(version-feature) at $(root) ;
250 }
251
252 # Add the version to the features for specifying them.
253 if ! $(version-feature) in [ feature.values macosx-version ]
254 {
255 feature.extend macosx-version : $(version-feature) ;
256 }
257 if ! $(version-feature) in [ feature.values macosx-version-min ]
258 {
259 feature.extend macosx-version-min : $(version-feature) ;
260 }
261
262 # Set the flags the version needs to compile with, first
263 # generic options.
264 flags darwin.compile OPTIONS $(condition)/<macosx-version>$(version-feature)
265 : -isysroot $(root) ;
266 flags darwin.link OPTIONS $(condition)/<macosx-version>$(version-feature)
267 : -isysroot $(root) ;
268
269 # Then device variation options.
270 switch $(version[1])
271 {
272 case appletvsim* :
273 {
274 local N = $(version[2]) ;
275 if ! $(version[3]) { N += 00 ; }
276 else if [ regex.match (..) : $(version[3]) ] { N += $(version[3]) ; }
277 else { N += 0$(version[3]) ; }
278 if ! $(version[4]) { N += 00 ; }
279 else if [ regex.match (..) : $(version[4]) ] { N += $(version[4]) ; }
280 else { N += 0$(version[4]) ; }
281 N = $(N:J=) ;
282 flags darwin.compile OPTIONS <macosx-version-min>$(version-feature)
283 : -D__IPHONE_OS_VERSION_MIN_REQUIRED=$(N) ;
284 flags darwin.link OPTIONS <macosx-version-min>$(version-feature)
285 : -D__IPHONE_OS_VERSION_MIN_REQUIRED=$(N) ;
286 }
287
288 case appletv* :
289 {
290 flags darwin.compile OPTIONS <macosx-version-min>$(version-feature)
291 : -mtvos-version-min=$(version[2-]:J=.) ;
292 flags darwin.link OPTIONS <macosx-version-min>$(version-feature)
293 : -mtvos-version-min=$(version[2-]:J=.) ;
294 }
295
296 case iphonesim* :
297 {
298 local N = $(version[2]) ;
299 if ! $(version[3]) { N += 00 ; }
300 else if [ regex.match (..) : $(version[3]) ] { N += $(version[3]) ; }
301 else { N += 0$(version[3]) ; }
302 if ! $(version[4]) { N += 00 ; }
303 else if [ regex.match (..) : $(version[4]) ] { N += $(version[4]) ; }
304 else { N += 0$(version[4]) ; }
305 N = $(N:J=) ;
306 flags darwin.compile OPTIONS <macosx-version-min>$(version-feature)
307 : -D__IPHONE_OS_VERSION_MIN_REQUIRED=$(N) ;
308 flags darwin.link OPTIONS <macosx-version-min>$(version-feature)
309 : -D__IPHONE_OS_VERSION_MIN_REQUIRED=$(N) ;
310 }
311
312 case iphone* :
313 {
314 flags darwin.compile OPTIONS <macosx-version-min>$(version-feature)
315 : -miphoneos-version-min=$(version[2-]:J=.) ;
316 flags darwin.link OPTIONS <macosx-version-min>$(version-feature)
317 : -miphoneos-version-min=$(version[2-]:J=.) ;
318 }
319
320 case mac* :
321 {
322 flags darwin.compile OPTIONS <macosx-version-min>$(version-feature)
323 : -mmacosx-version-min=$(version[2-]:J=.) ;
324 flags darwin.link OPTIONS <macosx-version-min>$(version-feature)
325 : -mmacosx-version-min=$(version[2-]:J=.) ;
326 }
327 }
328
329 if $(version[3]) > 0
330 {
331 # We have a minor version of an SDK. We want to set up
332 # previous minor versions, plus the current minor version.
333 # So we recurse to set up the previous minor versions, up to
334 # the current version.
335 local minor-minus-1 = [ CALC $(version[3]) - 1 ] ;
336 return
337 [ init-sdk $(condition) : $(root)
338 : $(version[1-2]) $(minor-minus-1) : [ version-to-feature $(version[1-2]) $(minor-minus-1) ] ]
339 $(version-feature) ;
340 }
341 else
342 {
343 return $(version-feature) ;
344 }
345 }
346 else if $(version[4])
347 {
348 # We have a patch version of an SDK. We want to set up
349 # both the specific patch version, and the minor version.
350 # So we recurse to set up the patch version. Plus the minor version.
351 return
352 [ init-sdk $(condition) : $(root)
353 : $(version[1-3]) : [ version-to-feature $(version[1-3]) ] ]
354 [ init-sdk $(condition) : $(root)
355 : $(version) : [ version-to-feature $(version) ] ] ;
356 }
357 else
358 {
359 # Yes, this is intentionally recursive.
360 return
361 [ init-sdk $(condition) : $(root)
362 : $(version) : [ version-to-feature $(version) ] ] ;
363 }
364}
365
366# Determine the MacOSX SDK versions installed and their locations.
367local rule init-available-sdk-versions ( condition * : root ? )
368{
369 root ?= /Developer ;
370 local sdks-root = $(root)/SDKs ;
371 local sdks = [ GLOB $(sdks-root) : MacOSX*.sdk AppleTVOS*.sdk AppleTVSimulator*.sdk iPhoneOS*.sdk iPhoneSimulator*.sdk ] ;
372 local result ;
373 for local sdk in $(sdks)
374 {
375 local sdk-match = [ MATCH ([^0-9]+)([0-9]+)[.]([0-9x]+)[.]?([0-9x]+)? : $(sdk:D=) ] ;
376 local sdk-platform = $(sdk-match[1]:L) ;
377 local sdk-version = $(sdk-match[2-]) ;
378 if $(sdk-version)
379 {
380 switch $(sdk-platform)
381 {
382 case macosx :
383 {
384 sdk-version = mac $(sdk-version) ;
385 }
386 case appletvos :
387 {
388 sdk-version = appletv $(sdk-version) ;
389 }
390 case appletvsimulator :
391 {
392 sdk-version = appletvsim $(sdk-version) ;
393 }
394 case iphoneos :
395 {
396 sdk-version = iphone $(sdk-version) ;
397 }
398 case iphonesimulator :
399 {
400 sdk-version = iphonesim $(sdk-version) ;
401 }
402 case * :
403 {
404 sdk-version = $(sdk-version:J=-) ;
405 }
406 }
407 result += [ init-sdk $(condition) : $(sdk) : $(sdk-version) ] ;
408 }
409 }
410 return $(result) ;
411}
412
413# Generic options.
414flags darwin.compile OPTIONS <flags> ;
415
416# The following adds objective-c support to darwin.
417# Thanks to http://thread.gmane.org/gmane.comp.lib.boost.build/13759
418
419generators.register-c-compiler darwin.compile.m : OBJECTIVE_C : OBJ : <toolset>darwin ;
420generators.register-c-compiler darwin.compile.mm : OBJECTIVE_CPP : OBJ : <toolset>darwin ;
421
422rule setup-address-model ( targets * : sources * : properties * )
423{
424 local ps = [ property-set.create $(properties) ] ;
425 local arch = [ $(ps).get <architecture> ] ;
426 local instruction-set = [ $(ps).get <instruction-set> ] ;
427 local address-model = [ $(ps).get <address-model> ] ;
428 local osx-version = [ $(ps).get <macosx-version> ] ;
429 local gcc-version = [ $(ps).get <toolset-darwin:version> ] ;
430 gcc-version = $(.real-version.$(gcc-version)) ;
431 local options ;
432
433 local support-ppc64 = 1 ;
434
435 osx-version ?= $(.host-osx-version) ;
436
437 switch $(osx-version)
438 {
439 case iphone* :
440 {
441 support-ppc64 = ;
442 }
443
444 case * :
445 if $(osx-version) && ! [ version.version-less [ regex.split $(osx-version) \\. ] : 10 6 ]
446 {
447 # When targeting 10.6:
448 # - gcc 4.2 will give a compiler errir if ppc64 compilation is requested
449 # - gcc 4.0 will compile fine, somehow, but then fail at link time
450 support-ppc64 = ;
451 }
452 }
453 switch $(arch)
454 {
455 case combined :
456 {
457 if $(address-model) = 32_64 {
458 if $(support-ppc64) {
459 options = -arch i386 -arch ppc -arch x86_64 -arch ppc64 ;
460 } else {
461 # Build 3-way binary
462 options = -arch i386 -arch ppc -arch x86_64 ;
463 }
464 } else if $(address-model) = 64 {
465 if $(support-ppc64) {
466 options = -arch x86_64 -arch ppc64 ;
467 } else {
468 errors.user-error "64-bit PPC compilation is not supported when targeting OSX 10.6 or later" ;
469 }
470 } else {
471 options = -arch i386 -arch ppc ;
472 }
473 }
474
475 case x86 :
476 {
477 if $(address-model) = 32_64 {
478 options = -arch i386 -arch x86_64 ;
479 } else if $(address-model) = 64 {
480 options = -arch x86_64 ;
481 } else {
482 options = -arch i386 ;
483 }
484 }
485
486 case power :
487 {
488 if ! $(support-ppc64)
489 && ( $(address-model) = 32_64 || $(address-model) = 64 )
490 {
491 errors.user-error "64-bit PPC compilation is not supported when targeting OSX 10.6 or later" ;
492 }
493
494 if $(address-model) = 32_64 {
495 options = -arch ppc -arch ppc64 ;
496 } else if $(address-model) = 64 {
497 options = -arch ppc64 ;
498 } else {
499 options = -arch ppc ;
500 }
501 }
502
503 case arm :
504 {
505 if $(instruction-set) {
506 options = -arch$(_)$(instruction-set) ;
507 } else {
508 options = -arch arm ;
509 }
510 }
511 }
512
513 if $(options)
514 {
515 OPTIONS on $(targets) += $(options) ;
516 }
517}
518
7c673cae
FG
519rule compile.m ( targets * : sources * : properties * )
520{
521 LANG on $(<) = "-x objective-c" ;
b32b8144 522 gcc.set-fpic-options $(targets) : $(sources) : $(properties) ;
7c673cae
FG
523 setup-address-model $(targets) : $(sources) : $(properties) ;
524}
525
526actions compile.m
527{
528 "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
529}
530
531rule compile.mm ( targets * : sources * : properties * )
532{
533 LANG on $(<) = "-x objective-c++" ;
b32b8144 534 gcc.set-fpic-options $(targets) : $(sources) : $(properties) ;
7c673cae
FG
535 setup-address-model $(targets) : $(sources) : $(properties) ;
536}
537
538actions compile.mm
539{
540 "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
541}
542
543# Set the max header padding to allow renaming of libs for installation.
544flags darwin.link.dll OPTIONS : -headerpad_max_install_names ;
545
546# To link the static runtime we need to link to all the core runtime libraries.
547flags darwin.link OPTIONS <runtime-link>static
548 : -nodefaultlibs -shared-libgcc -lstdc++-static -lgcc_eh -lgcc -lSystem ;
549
550# Strip as much as possible when optimizing.
551flags darwin.link OPTIONS <optimization>speed : -Wl,-dead_strip -no_dead_strip_inits_and_terms ;
552flags darwin.link OPTIONS <optimization>space : -Wl,-dead_strip -no_dead_strip_inits_and_terms ;
553
554# Dynamic/shared linking.
555flags darwin.compile OPTIONS <link>shared : -dynamic ;
556
557# Misc options.
558flags darwin.compile OPTIONS : -gdwarf-2 -fexceptions ;
559#~ flags darwin.link OPTIONS : -fexceptions ;
560
561# Add the framework names to use.
562flags darwin.link FRAMEWORK <framework> ;
563
564#
565flags darwin.link FORCE_LOAD <force-load> ;
566
567# This is flag is useful for debugging the link step
568# uncomment to see what libtool is doing under the hood
569#~ flags darwin.link.dll OPTIONS : -Wl,-v ;
570
571# set up the -F option to include the paths to any frameworks used.
572local rule prepare-framework-path ( target + )
573{
574 # The -framework option only takes basename of the framework.
575 # The -F option specifies the directories where a framework
576 # is searched for. So, if we find <framework> feature
577 # with some path, we need to generate property -F option.
578 local framework-paths = [ on $(target) return $(FRAMEWORK:D) ] ;
579
580 # Be sure to generate no -F if there's no path.
581 for local framework-path in $(framework-paths)
582 {
583 if $(framework-path) != ""
584 {
585 FRAMEWORK_PATH on $(target) += -F$(framework-path) ;
586 }
587 }
588}
589
590rule link ( targets * : sources * : properties * )
591{
592 DEPENDS $(targets) : [ on $(targets) return $(FORCE_LOAD) ] ;
593 setup-address-model $(targets) : $(sources) : $(properties) ;
594 prepare-framework-path $(<) ;
595}
596
597# Note that using strip without any options was reported to result in broken
598# binaries, at least on OS X 10.5.5, see:
599# http://svn.boost.org/trac/boost/ticket/2347
600# So we pass -S -x.
601actions link bind LIBRARIES FORCE_LOAD
602{
603 "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -o "$(<)" "$(>)" -Wl,-force_load$(_)"$(FORCE_LOAD)" "$(LIBRARIES)" -l$(FINDLIBS-SA) -l$(FINDLIBS-ST) $(FRAMEWORK_PATH) -framework$(_)$(FRAMEWORK:D=:S=) $(OPTIONS) $(USER_OPTIONS)
604 $(NEED_STRIP)"$(.STRIP)" $(NEED_STRIP)-S $(NEED_STRIP)-x $(NEED_STRIP)"$(<)"
605}
606
607rule link.dll ( targets * : sources * : properties * )
608{
609 setup-address-model $(targets) : $(sources) : $(properties) ;
610 prepare-framework-path $(<) ;
611}
612
613actions link.dll bind LIBRARIES
614{
615 "$(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)
616}
617
618# We use libtool instead of ar to support universal binary linking
619# TODO: Find a way to use the underlying tools, i.e. lipo, to do this.
620actions piecemeal archive
621{
622 "$(.LIBTOOL)" -static -o "$(<:T)" $(ARFLAGS) "$(>:T)"
623}