1rule AddSharedObjectGlueCode 2{ 3 # AddSharedObjectGlueCode <target> : <isExecutable> ; 4 5 # we link with -nostdlib and add the required libs manually, when building 6 # for Haiku 7 local platform ; 8 on $(1) { 9 platform = $(PLATFORM) ; 10 if $(platform) = haiku { 11 local stdLibs = [ MultiArchDefaultGristFiles libroot.so ] 12 [ TargetLibgcc ] ; 13 local type = EXECUTABLE ; 14 if $(2) != true { 15 type = LIBRARY ; 16 17 # special case for libroot: don't link it against itself 18 if $(DONT_LINK_AGAINST_LIBROOT) { 19 stdLibs = ; 20 } 21 } 22 23 local beginGlue 24 = $(HAIKU_$(type)_BEGIN_GLUE_CODE_$(TARGET_PACKAGING_ARCH)) ; 25 local endGlue 26 = $(HAIKU_$(type)_END_GLUE_CODE_$(TARGET_PACKAGING_ARCH)) ; 27 28 LINK_BEGIN_GLUE on $(1) = $(beginGlue) ; 29 LINK_END_GLUE on $(1) = $(endGlue) ; 30 31 NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(stdLibs) ; 32 Depends $(1) : $(stdLibs) $(beginGlue) $(endGlue) ; 33 LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib 34 -Xlinker --no-undefined ; 35 } 36 } 37 38 # link against the compatibility libraries needed for the target 39 if $(platform) != host && $(TARGET_HAIKU_COMPATIBILITY_LIBS) { 40 LinkAgainst $(1) : $(TARGET_HAIKU_COMPATIBILITY_LIBS) ; 41 } 42} 43 44rule Executable 45{ 46 # Executable <name> : <sources> : <libraries> : <res> ; 47 # 48 if ! [ IsPlatformSupportedForTarget $(1) ] { 49 return ; 50 } 51 52 AddResources $(1) : $(4) ; 53 Main $(1) : $(2) ; 54 LinkAgainst $(1) : $(3) ; 55 LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] 56 -Xlinker -soname=_APP_ ; 57 58 # we link with -nostdlib and add the required libs manually, when building 59 # for Haiku 60 AddSharedObjectGlueCode $(1) : true ; 61} 62 63rule Application 64{ 65 # Application <name> : <sources> : <libraries> : <res> ; 66 Executable $(1) : $(2) : $(3) : $(4) ; 67} 68 69rule BinCommand 70{ 71 # BinCommand <name> : <sources> : <libraries> : <res> ; 72 Executable $(1) : $(2) : $(3) : $(4) ; 73} 74 75rule StdBinCommands 76{ 77 # StdBinCommands <sources> : <libs> : <res> ; 78 local libs = $(2) ; 79 local ress = $(3) ; 80 local source ; 81 for source in $(1) 82 { 83 local target = $(source:S=) ; 84 85 BinCommand $(target) : $(source) : $(libs) : $(ress) ; 86 } 87} 88 89rule Preference 90{ 91 # Preference <name> : <sources> : <libraries> : <res> ; 92 Executable $(1) : $(2) : $(3) : $(4) ; 93} 94 95rule Server 96{ 97 # Server <name> : <sources> : <libraries> : <res> ; 98 99 Executable $(1) : $(2) : $(3) : $(4) ; 100} 101 102rule Addon target : sources : libraries : isExecutable 103{ 104 # Addon <target> : <sources> : <is executable> : <libraries> ; 105 # <target>: The add-on. 106 # <sources>: Source files. 107 # <libraries>: Libraries to be linked against. 108 # <isExecutable>: true, if the target shall be executable as well. 109 110 if ! [ IsPlatformSupportedForTarget $(target) ] { 111 return ; 112 } 113 114 Main $(target) : $(sources) ; 115 116 local linkFlags = -Xlinker -soname=\"$(target:G=)\" ; 117 if $(isExecutable) != true { 118 linkFlags = -shared $(linkFlags) ; 119 } 120 LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] $(linkFlags) ; 121 LinkAgainst $(target) : $(libraries) ; 122 123 AddSharedObjectGlueCode $(target) : $(isExecutable) ; 124} 125 126rule Translator target : sources : libraries : isExecutable 127{ 128 # Translator <target> : <sources> : <libraries> : <isExecutable> ; 129 Addon $(target) : $(sources) : $(libraries) : $(isExecutable) ; 130} 131 132rule ScreenSaver target : sources : libraries 133{ 134 # ScreenSaver <target> : <sources> : <libraries> ; 135 Addon $(target) : $(sources) : $(libraries) : false ; 136} 137 138rule StaticLibrary 139{ 140 # StaticLibrary <lib> : <sources> : <otherObjects> ; 141 # Creates a static library from sources. 142 # <lib>: The static library to be built. 143 # <sources>: List of source files. 144 # <otherObjects>: List of additional object files. 145 # 146 local lib = $(1) ; 147 local sources = [ FGristFiles $(2) ] ; 148 local otherObjects = $(3) ; 149 local objects = $(sources:S=$(SUFOBJ)) ; 150 151 if ! [ IsPlatformSupportedForTarget $(1) ] { 152 return ; 153 } 154 155 InheritPlatform $(objects) : $(lib) ; 156 157 if $(TARGET_CC_IS_LEGACY_GCC_$(TARGET_PACKAGING_ARCH)) = 0 158 && [ on $(lib) return $(NO_HIDDEN_VISIBILITY) ] != 1 { 159 CCFLAGS on $(objects) += -fvisibility=hidden ; 160 C++FLAGS on $(objects) += -fvisibility=hidden ; 161 } 162 163 StaticLibraryFromObjects $(lib) : $(objects) $(otherObjects) ; 164 Objects $(2) ; 165} 166 167rule StaticLibraryFromObjects 168{ 169 if ! [ IsPlatformSupportedForTarget $(1) ] { 170 return ; 171 } 172 173 LibraryFromObjects $(1) : $(2) ; 174} 175 176rule AssembleNasm 177{ 178 if ! [ on $(1) return $(NASMFLAGS) ] { 179 NASMFLAGS on $(1) = -f elf32 ; 180 } 181 182 Depends $(1) : $(2) [ on $(2) return $(PLATFORM) ] ; 183} 184 185actions AssembleNasm 186{ 187 if test $(ASFLAGS) ; then 188 $(HAIKU_NASM) -d $(ASFLAGS) $(NASMFLAGS) -I$(2:D)/ -o $(1) $(2) ; 189 else 190 $(HAIKU_NASM) $(NASMFLAGS) -I$(2:D)/ -o $(1) $(2) ; 191 fi 192} 193 194rule Ld 195{ 196 # Ld <name> : <objs> : <linkerscript> : <flags> ; 197 # 198 local target = $(1) ; 199 local objects = $(2) ; 200 local linkerScript = $(3) ; 201 local linkerFlags = $(4) ; 202 203 if $(linkerScript) { 204 linkerFlags += --script=$(linkerScript) ; 205 } 206 207 on $(target) { 208 if $(PLATFORM) = host { 209 LINK on $(target) = $(HOST_LD) ; 210 LINKFLAGS on $(target) = $(HOST_LDFLAGS) $(LINKFLAGS) $(linkerFlags) ; 211 } else { 212 LINK on $(target) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ; 213 LINKFLAGS on $(target) = $(TARGET_LDFLAGS_$(TARGET_PACKAGING_ARCH)) 214 $(LINKFLAGS) $(linkerFlags) ; 215 } 216 217 NEEDLIBS on $(target) = $(NEEDLIBS) ; 218 LINKLIBS on $(target) = $(LINKLIBS) ; 219 } 220 221 LocalClean clean : $(target) ; 222 LocalDepends all : $(target) ; 223 Depends $(target) : $(objects) ; 224 225 MakeLocateDebug $(target) ; 226 227 on $(1) XRes $(1) : $(RESFILES) ; 228 if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] { 229 SetType $(1) ; 230 MimeSet $(1) ; 231 SetVersion $(1) ; 232 } 233} 234 235actions Ld 236{ 237 $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" "$(NEEDLIBS)" $(LINKLIBS) 238} 239 240rule CreateAsmStructOffsetsHeader header : source : architecture 241{ 242 # CreateAsmStructOffsetsHeader header : source : architecture 243 # 244 # Grist will be added to both header and source. 245 246 header = [ FGristFiles $(header) ] ; 247 source = [ FGristFiles $(source) ] ; 248 249 TARGET_PACKAGING_ARCH on $(header) = $(architecture) ; 250 251 # find out which headers, defines, etc. to use 252 local headers ; 253 local sysHeaders ; 254 local defines ; 255 local flags ; 256 local includesSeparator ; 257 local localIncludesOption ; 258 local systemIncludesOption ; 259 260 on $(header) { # use on $(1) variable values 261 if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) { 262 Echo $(PLATFORM) is not in SUPPORTED_PLATFORMS, cannot make struct-offsets header! ; 263 return ; 264 } 265 266 # headers and defines 267 headers = $(HAIKU_CONFIG_HEADERS) $(SEARCH_SOURCE) $(SUBDIRHDRS) 268 $(HDRS) ; 269 sysHeaders = $(SUBDIRSYSHDRS) $(SYSHDRS) ; 270 defines = $(DEFINES) ; 271 272 if $(PLATFORM) = host { 273 sysHeaders += $(HOST_HDRS) ; 274 defines += $(HOST_DEFINES) ; 275 276 if $(USES_BE_API) { 277 sysHeaders += $(HOST_BE_API_HEADERS) ; 278 } 279 } else { 280 sysHeaders += [ FStandardHeaders $(TARGET_PACKAGING_ARCH) : C++ ] 281 $(TARGET_HDRS_$(TARGET_PACKAGING_ARCH)) ; 282 defines += $(TARGET_DEFINES_$(TARGET_PACKAGING_ARCH)) 283 $(TARGET_DEFINES) ; 284 } 285 286 # optimization flags 287 if $(DEBUG) = 0 { 288 flags += $(OPTIM) ; 289 } else { 290 flags += -O0 ; 291 } 292 293 if $(PLATFORM) = host { 294 # warning flags 295 if $(WARNINGS) != 0 { 296 flags += $(HOST_WARNING_C++FLAGS) ; 297 if $(WARNINGS) = treatAsErrors { 298 flags += -Werror $(HOST_WERROR_FLAGS) ; 299 } 300 } 301 302 # debug and other flags 303 flags += $(HOST_C++FLAGS) $(HOST_DEBUG_$(DEBUG)_C++FLAGS) 304 $(SUBDIRC++FLAGS) $(C++FLAGS) ; 305 306 if $(USES_BE_API) { 307 flags += $(HOST_BE_API_C++FLAGS) ; 308 } 309 310 C++ on $(header) = $(HOST_C++) ; 311 312 includesSeparator = $(HOST_INCLUDES_SEPARATOR) ; 313 localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ; 314 systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ; 315 } else { 316 # warning flags 317 if $(WARNINGS) != 0 { 318 flags += $(TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH)) ; 319 if $(WARNINGS) = treatAsErrors { 320 flags += -Werror 321 $(TARGET_WERROR_FLAGS_$(TARGET_PACKAGING_ARCH)) ; 322 } 323 } 324 325 # debug and other flags 326 flags += $(TARGET_C++FLAGS_$(TARGET_PACKAGING_ARCH)) 327 $(TARGET_DEBUG_$(DEBUG)_C++FLAGS_$(TARGET_PACKAGING_ARCH)) 328 $(SUBDIRC++FLAGS) $(C++FLAGS) ; 329 330 C++ on $(header) = $(TARGET_C++_$(TARGET_PACKAGING_ARCH)) ; 331 332 includesSeparator 333 = $(TARGET_INCLUDES_SEPARATOR_$(TARGET_PACKAGING_ARCH)) ; 334 localIncludesOption 335 = $(TARGET_LOCAL_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ; 336 systemIncludesOption 337 = $(TARGET_SYSTEM_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ; 338 } 339 } 340 341 # Turn off "invalid use of offsetof()" macro warning. We use offsetof() also 342 # for non-PODs. Since we're using the same compiler for the whole kernel and 343 # don't do virtual inheritence, that works well enough. 344 flags += -Wno-invalid-offsetof ; 345 # TODO: Rather get rid of the respective offsetof() instances. 346 347 # locate object, search for source, and set on target variables 348 349 Depends $(header) : $(source) $(PLATFORM) ; 350 SEARCH on $(source) += $(SEARCH_SOURCE) ; 351 MakeLocate $(header) : [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR_$(architecture)) 352 system kernel ] ; 353 LocalClean clean : $(header) ; 354 355 HDRRULE on $(source) = HdrRule ; 356 HDRSCAN on $(source) = $(HDRPATTERN) ; 357 HDRSEARCH on $(source) = $(headers) $(sysHeaders) $(STDHDRS) ; 358 HDRGRIST on $(source) = $(HDRGRIST) ; 359 360 C++FLAGS on $(header) = $(flags) ; 361 CCHDRS on $(header) = [ FIncludes $(headers) : $(localIncludesOption) ] 362 $(includesSeparator) 363 [ FSysIncludes $(sysHeaders) : $(systemIncludesOption) ] ; 364 CCDEFS on $(header) = [ FDefines $(defines) ] ; 365 366 CreateAsmStructOffsetsHeader1 $(header) : $(source) ; 367} 368 369actions CreateAsmStructOffsetsHeader1 370{ 371 $(C++) -S "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o - \ 372 | $(SED) 's/@define/#define/g' | grep "#define" \ 373 | $(SED) -e 's/[\$\#]\([0-9]\)/\1/' > "$(1)" 374 grep -q "#define" "$(1)" 375} 376 377rule MergeObjectFromObjects 378{ 379 # MergeObjectFromObjects <name> : <objects> : <other objects> ; 380 # Merges object files to an object file. 381 # <name>: Name of the object file to create. No grist will be added. 382 # <objects>: Object files to be merged. Grist will be added. 383 # <other objects>: Object files or static libraries to be merged. No grist 384 # will be added. 385 # 386 local objects = [ FGristFiles $(2) ] ; 387 388 on $(1) { 389 if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) { 390 return ; 391 } 392 393 if $(PLATFORM) = host { 394 LINK on $(1) = $(HOST_LD) ; 395 LINKFLAGS on $(target) = $(HOST_LDFLAGS) ; 396 } else { 397 LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ; 398 LINKFLAGS on $(target) 399 = $(TARGET_LDFLAGS_$(TARGET_PACKAGING_ARCH)) ; 400 } 401 } 402 403 MakeLocateDebug $(1) ; 404 Depends $(1) : $(objects) ; 405 Depends $(1) : $(3) ; 406 LocalDepends obj : $(1) ; 407 MergeObjectFromObjects1 $(1) : $(objects) $(3) ; 408} 409 410actions MergeObjectFromObjects1 411{ 412 $(LINK) $(LINKFLAGS) -r $(2) -o $(1) 413} 414 415rule MergeObject 416{ 417 # MergeObject <name> : <sources> : <other objects> ; 418 # Compiles source files and merges the object files to an object file. 419 # <name>: Name of the object file to create. No grist will be added. 420 # <sources>: Sources to be compiled. Grist will be added. 421 # <other objects>: Object files or static libraries to be merged. No grist 422 # will be added. 423 # 424 local target = $(1) ; 425 local sources = [ FGristFiles $(2) ] ; 426 local otherObjects = $(3) ; 427 local objects = $(sources:S=$(SUFOBJ)) ; 428 429 if ! [ IsPlatformSupportedForTarget $(1) ] { 430 return ; 431 } 432 433 InheritPlatform $(objects) : $(target) ; 434 Objects $(sources) ; 435 MergeObjectFromObjects $(target) : $(objects) : $(otherObjects) ; 436} 437 438rule SharedLibraryFromObjects 439{ 440 # SharedLibraryFromObjects <lib> : <objects> : <libraries> ; 441 # 442 local _lib = $(1) ; 443 444 if ! [ IsPlatformSupportedForTarget $(1) ] { 445 return ; 446 } 447 448 local soname = [ on $(_lib) return $(HAIKU_SONAME) ] ; 449 soname ?= $(_lib:BS) ; 450 451 MainFromObjects $(_lib) : $(2) ; 452 LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ] 453 -shared -Xlinker -soname=\"$(soname)\" ; 454 LinkAgainst $(_lib) : $(3) ; 455 456 AddSharedObjectGlueCode $(_lib) : false ; 457} 458 459rule SharedLibrary 460{ 461 # SharedLibrary <lib> : <sources> : <libraries> : <abiVersion> ; 462 local lib = $(1) ; 463 local sources = [ FGristFiles $(2) ] ; 464 local objects = $(sources:S=$(SUFOBJ)) ; 465 local libs = $(3) ; 466 local abiVersion = $(4) ; # major ABI (soname) version for lib (if any) 467 468 if ! [ IsPlatformSupportedForTarget $(1) ] { 469 return ; 470 } 471 472 if $(abiVersion) { 473 HAIKU_SONAME on $(lib) = $(lib:BS).$(abiVersion) ; 474 HAIKU_LIB_ABI_VERSION on $(lib) = $(abiVersion) ; 475 } 476 477 InheritPlatform $(objects) : $(lib) ; 478 Objects $(sources) ; 479 SharedLibraryFromObjects $(lib) : $(objects) : $(libs) ; 480} 481 482rule LinkAgainst 483{ 484 # LinkAgainst <name> : <libs> [ : <mapLibs> ] ; 485 # Valid elements for <libs> are e.g. "be" or "libtranslation.so" or 486 # "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy 487 # has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the 488 # file will be bound!), otherwise it is prefixed "-l" and added to 489 # LINKLIBS. If you want to specify a target that isn't a library and 490 # also has neither grist nor a dirname, you can prepend "<nogrist>" as 491 # grist; it will be stripped by this rule. 492 # <mapLibs> specifies whether the to translate library names (e.g. "be" 493 # to "libbe.so" in case of target platform "haiku"). Defaults to "true". 494 # 495 local target = $(1) ; 496 local libs = $(2) ; 497 local mapLibs = $(3:E=true) ; 498 499 local linkLibs ; 500 local needLibs ; 501 502 on $(target) { 503 local i ; 504 505 # map libraries, if desired and target platform is Haiku 506 local map = $(TARGET_LIBRARY_NAME_MAP_$(TARGET_PACKAGING_ARCH)) ; 507 if $(PLATFORM) != host && $(mapLibs) = true && $(map) { 508 local mappedLibs ; 509 510 for i in $(libs) { 511 local mapped = $($(map)_$(i)) ; 512 mapped ?= $(i) ; 513 mappedLibs += $(mapped) ; 514 } 515 516 libs = $(mappedLibs) ; 517 } 518 519 for i in $(libs) { 520 local isfile = ; 521 if $(i:D) || $(i:G) { 522 isfile = true ; 523 if $(i:G) = <nogrist> { 524 i = $(i:G=) ; 525 } 526 } else { 527 switch $(i:B) 528 { 529 # XXX: _APP_ and _KERNEL_ should not be needed for ELF. 530 case _APP_ : isfile = true ; 531 case _KERNEL_ : isfile = true ; 532 case lib* : isfile = true ; 533 case * : isfile = ; 534 } 535 if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) { 536 isfile = true ; 537 } 538 } 539 540 if $(isfile) { 541 needLibs += $(i) ; 542 } else { 543 linkLibs += $(i) ; 544 } 545 } 546 } 547 548 # Copy in the library dependencies from any static libraries first. 549 # (We have to do the [ on ... ] outside the on { } block. ) 550 for i in $(needLibs) { 551 if $(i:S) = .a { 552 needLibs += [ on $(i) return $(NEEDLIBS) ] ; 553 linkLibs += [ on $(i) return $(LINKLIBS) ] ; 554 } 555 } 556 557 on $(target) { 558 NEEDLIBS on $(1) = $(NEEDLIBS) $(needLibs) ; 559 LINKLIBS on $(1) = $(LINKLIBS) -l$(linkLibs) ; 560 561 if $(needLibs) && ! $(NO_LIBRARY_DEPENDENCIES) { 562 Depends $(1) : $(needLibs) ; 563 } 564 } 565} 566 567rule AddResources 568{ 569 # AddResources <name> : <resourcefiles> ; 570 571 # add grist to the resource files which don't have any yet 572 local resfiles ; 573 local file ; 574 for file in $(2) { 575 if ! $(file:G) { 576 file = [ FGristFiles $(file) ] ; 577 } 578 resfiles += $(file) ; 579 } 580 581 SEARCH on $(resfiles) += $(SEARCH_SOURCE) ; 582 583 for file in $(resfiles) { 584 if $(file:S) = .rdef { 585 local rdef = $(file) ; 586 file = $(rdef:S=.rsrc) ; 587 ResComp $(file) : $(rdef) ; 588 } 589 InheritPlatform $(file) : $(1) ; 590 RESFILES on $(1) += $(file) ; 591 } 592} 593 594rule SetVersionScript target : versionScript 595{ 596 # SetVersionScript <target> : <versionScript> 597 # 598 # Sets the version script for <target>. Grist will be added to 599 # <versionScript> and SEARCH will be set on it. 600 601 versionScript = [ FGristFiles $(versionScript) ] ; 602 603 SEARCH on $(versionScript) += $(SEARCH_SOURCE) ; 604 605 VERSION_SCRIPT on $(target) = $(versionScript) ; 606 Depends $(target) : $(versionScript) ; 607} 608 609rule BuildPlatformObjects 610{ 611 # Usage BuildPlatformObjects <sources> ; 612 # <sources> The sources. 613 # 614 local sources = [ FGristFiles $(1) ] ; 615 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 616 617 PLATFORM on $(objects) = host ; 618 SUPPORTED_PLATFORMS on $(objects) = host ; 619 620 Objects $(sources) ; 621} 622 623rule BuildPlatformMain 624{ 625 # Usage BuildPlatformMain <target> : <sources> : <libraries> ; 626 # <target> The executable/library. 627 # <sources> The sources. 628 # <libraries> Libraries to link against. 629 # 630 local target = $(1) ; 631 local sources = $(2) ; 632 local libs = $(3) ; 633 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 634 635 PLATFORM on $(target) = host ; 636 SUPPORTED_PLATFORMS on $(target) = host ; 637 DONT_USE_BEOS_RULES on $(target) = true ; 638 639 local usesBeAPI = [ on $(target) return $(USES_BE_API) ] ; 640 if $(usesBeAPI) { 641 # propagate the flag to the objects 642 USES_BE_API on $(objects) = $(usesBeAPI) ; 643 644 # add the build libroot 645 local libroot = [ on $(target) return $(HOST_LIBROOT) ] ; 646 Depends $(target) : $(libroot) ; 647 NEEDLIBS on $(target) += $(libroot) ; 648 } 649 650 Main $(target) : $(sources) ; 651 LinkAgainst $(target) : $(libs) ; 652} 653 654rule BuildPlatformSharedLibrary 655{ 656 # Usage BuildPlatformSharedLibrary <target> : <sources> : <libraries> ; 657 # <target> The library. 658 # <sources> The sources. 659 # <libraries> Libraries to link against. 660 # 661 local target = $(1) ; 662 local sources = $(2) ; 663 local libs = $(3) ; 664 665 BuildPlatformMain $(target) : $(sources) : $(libs) ; 666 667 if $(HOST_PLATFORM) = darwin { 668 LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] 669 -dynamic -dynamiclib -Xlinker -flat_namespace ; 670 } else { 671 LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] 672 -shared -Xlinker -soname=\"$(target:G=)\" ; 673 } 674 675 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 676 CCFLAGS on $(objects) += $(HOST_PIC_CCFLAGS) ; 677 C++FLAGS on $(objects) += $(HOST_PIC_C++FLAGS) ; 678} 679 680rule BuildPlatformMergeObject 681{ 682 # BuildPlatformMergeObject <name> : <sources> : <other objects> ; 683 # Compiles source files and merges the object files to an object file. 684 # <name>: Name of the object file to create. No grist will be added. 685 # <sources>: Sources to be compiled. Grist will be added. 686 # <other objects>: Object files or static libraries to be merged. No grist 687 # will be added. 688 # 689 local target = $(1) ; 690 local sources = $(2) ; 691 local otherObjects = $(3) ; 692 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 693 694 PLATFORM on $(target) = host ; 695 SUPPORTED_PLATFORMS on $(target) = host ; 696 697 local usesBeAPI = [ on $(target[1]) return $(USES_BE_API) ] ; 698 if $(usesBeAPI) { 699 # propagate the flag to the objects 700 USES_BE_API on $(objects) = $(usesBeAPI) ; 701 } 702 703 MergeObject $(target) : $(sources) : $(otherObjects) ; 704} 705 706rule BuildPlatformMergeObjectPIC target : sources : otherObjects 707{ 708 # BuildPlatformMergeObjectPIC <name> : <sources> : <other objects> ; 709 # Compiles source files and merges the object files to an object file. 710 # Same as BuildPlatformMergeObject rule but adds position-independent 711 # flags to the compiler (if any). 712 # <name>: Name of the object file to create. No grist will be added. 713 # <sources>: Sources to be compiled. Grist will be added. 714 # <other objects>: Object files or static libraries to be merged. No grist 715 # will be added. 716 # 717 ObjectCcFlags $(sources) : $(HOST_PIC_CCFLAGS) ; 718 ObjectC++Flags $(sources) : $(HOST_PIC_C++FLAGS) ; 719 720 BuildPlatformMergeObject $(target) : $(sources) : $(otherObjects) ; 721} 722 723rule BuildPlatformStaticLibrary lib : sources : otherObjects 724{ 725 # BuildPlatformStaticLibrary <lib> : <sources> ; 726 # Creates a static library from sources. 727 # <lib>: The static library to be built. 728 # <sources>: List of source files. 729 # <otherObjects>: List of additional object files. 730 # 731 732 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 733 734 PLATFORM on $(lib) = host ; 735 SUPPORTED_PLATFORMS on $(lib) = host ; 736 737 local usesBeAPI = [ on $(lib) return $(USES_BE_API) ] ; 738 if $(usesBeAPI) { 739 # propagate the flag to the objects 740 USES_BE_API on $(objects) = $(usesBeAPI) ; 741 } 742 743 StaticLibrary $(lib) : $(sources) : $(otherObjects) ; 744} 745 746rule BuildPlatformStaticLibraryPIC target : sources : otherObjects 747{ 748 # Like BuildPlatformStaticLibrary, but producing position independent code. 749 750 ObjectCcFlags $(sources) : $(HOST_PIC_CCFLAGS) ; 751 ObjectC++Flags $(sources) : $(HOST_PIC_C++FLAGS) ; 752 753 BuildPlatformStaticLibrary $(target) : $(sources) : $(otherObjects) ; 754} 755 756rule BootstrapStage0PlatformObjects sources : separateFromStandardSiblings 757{ 758 # BootstrapStage0PlatformObjects <sources> : <separateFromStandardSiblings> 759 # Builds objects from the given sources for stage0 of the bootstrap process. 760 # <sources> The sources from which objects should be created. 761 # <separateFromStandardSiblings> Pass 'true' if the same objects are built 762 # in a different context, too, so that a separate grist and target location 763 # is required. This defaults to ''. 764 local source ; 765 for source in $(sources) { 766 local objectGrist ; 767 if $(separateFromStandardSiblings) = true { 768 objectGrist = "bootstrap!$(SOURCE_GRIST)" ; 769 } else { 770 objectGrist = $(SOURCE_GRIST) ; 771 } 772 local object = $(source:S=$(SUFOBJ):G=$(objectGrist)) ; 773 PLATFORM on $(object) = bootstrap_stage0 ; 774 SUPPORTED_PLATFORMS on $(object) = bootstrap_stage0 ; 775 if $(separateFromStandardSiblings) = true { 776 MakeLocate $(object) : [ 777 FDirName $(TARGET_DEBUG_$(DEBUG)_LOCATE_TARGET) bootstrap 778 ] ; 779 } 780 Object $(object) : $(source) ; 781 } 782} 783