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 StaticLibraryFromObjects $(lib) : $(objects) $(otherObjects) ; 158 Objects $(2) ; 159} 160 161rule StaticLibraryFromObjects 162{ 163 if ! [ IsPlatformSupportedForTarget $(1) ] { 164 return ; 165 } 166 167 LibraryFromObjects $(1) : $(2) ; 168} 169 170rule AssembleNasm 171{ 172 if ! [ on $(1) return $(NASMFLAGS) ] { 173 NASMFLAGS on $(1) = -f elf32 ; 174 } 175 176 Depends $(1) : $(2) [ on $(2) return $(PLATFORM) ] ; 177} 178 179actions AssembleNasm 180{ 181 if test $(ASFLAGS) ; then 182 $(HAIKU_NASM) -d $(ASFLAGS) $(NASMFLAGS) -I$(2:D)/ -o $(1) $(2) ; 183 else 184 $(HAIKU_NASM) $(NASMFLAGS) -I$(2:D)/ -o $(1) $(2) ; 185 fi 186} 187 188rule CompileDTS 189{ 190 MakeLocate $(<) : $(HAIKU_OUTPUT_DIR) ; 191 Depends $(<) : $(>) ; 192} 193 194actions CompileDTS 195{ 196 cpp -P -xassembler-with-cpp \ 197 -I$(HAIKU_TOP)/src/data/dts/arch/$(TARGET_ARCH) \ 198 -I$(HAIKU_TOP)/src/data/dts $(2) \ 199 | dtc -O dtb -o $(1) \ 200 -i $(HAIKU_TOP)/src/data/dts/arch/$(TARGET_ARCH) \ 201 -i $(HAIKU_TOP)/src/data/dts ; 202} 203 204rule Ld 205{ 206 # Ld <name> : <objs> : <linkerscript> : <flags> ; 207 # 208 local target = $(1) ; 209 local objects = $(2) ; 210 local linkerScript = $(3) ; 211 local linkerFlags = $(4) ; 212 213 if $(linkerScript) { 214 linkerFlags += --script=$(linkerScript) ; 215 } 216 217 on $(target) { 218 if $(PLATFORM) = host { 219 LINK on $(target) = $(HOST_LD) ; 220 LINKFLAGS on $(target) = $(HOST_LDFLAGS) $(LINKFLAGS) $(linkerFlags) ; 221 } else { 222 LINK on $(target) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ; 223 LINKFLAGS on $(target) = $(TARGET_LDFLAGS_$(TARGET_PACKAGING_ARCH)) 224 $(LINKFLAGS) $(linkerFlags) ; 225 } 226 227 NEEDLIBS on $(target) = $(NEEDLIBS) ; 228 LINKLIBS on $(target) = $(LINKLIBS) ; 229 } 230 231 LocalClean clean : $(target) ; 232 LocalDepends all : $(target) ; 233 Depends $(target) : $(objects) ; 234 235 MakeLocateDebug $(target) ; 236 237 on $(1) XRes $(1) : $(RESFILES) ; 238 if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] { 239 SetType $(1) ; 240 MimeSet $(1) ; 241 SetVersion $(1) ; 242 } 243} 244 245actions Ld 246{ 247 $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" "$(NEEDLIBS)" $(LINKLIBS) 248} 249 250rule CreateAsmStructOffsetsHeader header : source 251{ 252 # CreateAsmStructOffsetsHeader header : source 253 # 254 # Grist will be added to both header and source. 255 256 header = [ FGristFiles $(header) ] ; 257 source = [ FGristFiles $(source) ] ; 258 259 # find out which headers, defines, etc. to use 260 local headers ; 261 local sysHeaders ; 262 local defines ; 263 local flags ; 264 local includesSeparator ; 265 local localIncludesOption ; 266 local systemIncludesOption ; 267 268 on $(header) { # use on $(1) variable values 269 if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) { 270 return ; 271 } 272 273 # headers and defines 274 headers = $(HAIKU_CONFIG_HEADERS) $(SEARCH_SOURCE) $(SUBDIRHDRS) 275 $(HDRS) ; 276 sysHeaders = $(SUBDIRSYSHDRS) $(SYSHDRS) ; 277 defines = $(DEFINES) ; 278 279 if $(PLATFORM) = host { 280 sysHeaders += $(HOST_HDRS) ; 281 defines += $(HOST_DEFINES) ; 282 283 if $(USES_BE_API) { 284 sysHeaders += $(HOST_BE_API_HEADERS) ; 285 } 286 287 } else { 288 sysHeaders += [ FStandardHeaders $(TARGET_PACKAGING_ARCH) ] 289 $(TARGET_HDRS_$(TARGET_PACKAGING_ARCH)) ; 290 defines += $(TARGET_DEFINES_$(TARGET_PACKAGING_ARCH)) 291 $(TARGET_DEFINES) ; 292 } 293 294 # optimization flags 295 if $(DEBUG) = 0 { 296 flags += $(OPTIM) ; 297 } else { 298 flags += -O0 ; 299 } 300 301 if $(PLATFORM) = host { 302 # warning flags 303 if $(WARNINGS) != 0 { 304 flags += $(HOST_WARNING_C++FLAGS) ; 305 if $(WARNINGS) = treatAsErrors { 306 flags += -Werror $(HOST_WERROR_FLAGS) ; 307 } 308 } 309 310 # debug and other flags 311 flags += $(HOST_C++FLAGS) $(HOST_DEBUG_$(DEBUG)_C++FLAGS) 312 $(SUBDIRC++FLAGS) $(C++FLAGS) ; 313 314 if $(USES_BE_API) { 315 flags += $(HOST_BE_API_C++FLAGS) ; 316 } 317 318 C++ on $(header) = $(HOST_C++) ; 319 320 includesSeparator = $(HOST_INCLUDES_SEPARATOR) ; 321 localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ; 322 systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ; 323 324 } else { 325 # warning flags 326 if $(WARNINGS) != 0 { 327 flags += $(TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH)) ; 328 if $(WARNINGS) = treatAsErrors { 329 flags += -Werror 330 $(TARGET_WERROR_FLAGS_$(TARGET_PACKAGING_ARCH)) ; 331 } 332 } 333 334 # debug and other flags 335 flags += $(TARGET_C++FLAGS_$(TARGET_PACKAGING_ARCH)) 336 $(TARGET_DEBUG_$(DEBUG)_C++FLAGS_$(TARGET_PACKAGING_ARCH)) 337 $(SUBDIRC++FLAGS) $(C++FLAGS) ; 338 339 C++ on $(header) = $(TARGET_C++_$(TARGET_PACKAGING_ARCH)) ; 340 341 includesSeparator 342 = $(TARGET_INCLUDES_SEPARATOR_$(TARGET_PACKAGING_ARCH)) ; 343 localIncludesOption 344 = $(TARGET_LOCAL_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ; 345 systemIncludesOption 346 = $(TARGET_SYSTEM_INCLUDES_OPTION_$(TARGET_PACKAGING_ARCH)) ; 347 } 348 } 349 350 # Turn off "invalid use of offsetof()" macro warning. We use offsetof() also 351 # for non-PODs. Since we're using the same compiler for the whole kernel and 352 # don't do virtual inheritence, that works well enough. 353 flags += -Wno-invalid-offsetof ; 354 # TODO: Rather get rid of the respective offsetof() instances. 355 356 # locate object, search for source, and set on target variables 357 358 Depends $(header) : $(source) $(PLATFORM) ; 359 SEARCH on $(source) += $(SEARCH_SOURCE) ; 360 MakeLocateArch $(header) ; 361 LocalClean clean : $(header) ; 362 363 HDRRULE on $(source) = HdrRule ; 364 HDRSCAN on $(source) = $(HDRPATTERN) ; 365 HDRSEARCH on $(source) = $(headers) $(sysHeaders) $(STDHDRS) ; 366 HDRGRIST on $(source) = $(HDRGRIST) ; 367 368 C++FLAGS on $(header) = $(flags) ; 369 CCHDRS on $(header) = [ FIncludes $(headers) : $(localIncludesOption) ] 370 $(includesSeparator) 371 [ FSysIncludes $(sysHeaders) : $(systemIncludesOption) ] ; 372 CCDEFS on $(header) = [ FDefines $(defines) ] ; 373 374 CreateAsmStructOffsetsHeader1 $(header) : $(source) ; 375} 376 377actions CreateAsmStructOffsetsHeader1 378{ 379 $(C++) -S "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o - \ 380 | grep "#define" | sed -e 's/[\$\#]\([0-9]\)/\1/' > "$(1)" 381} 382 383rule MergeObjectFromObjects 384{ 385 # MergeObjectFromObjects <name> : <objects> : <other objects> ; 386 # Merges object files to an object file. 387 # <name>: Name of the object file to create. No grist will be added. 388 # <objects>: Object files to be merged. Grist will be added. 389 # <other objects>: Object files or static libraries to be merged. No grist 390 # will be added. 391 # 392 local objects = [ FGristFiles $(2) ] ; 393 394 on $(1) { 395 if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) { 396 return ; 397 } 398 399 if $(PLATFORM) = host { 400 LINK on $(1) = $(HOST_LD) ; 401 LINKFLAGS on $(target) = $(HOST_LDFLAGS) ; 402 } else { 403 LINK on $(1) = $(TARGET_LD_$(TARGET_PACKAGING_ARCH)) ; 404 LINKFLAGS on $(target) 405 = $(TARGET_LDFLAGS_$(TARGET_PACKAGING_ARCH)) ; 406 } 407 } 408 409 MakeLocateDebug $(1) ; 410 Depends $(1) : $(objects) ; 411 Depends $(1) : $(3) ; 412 LocalDepends obj : $(1) ; 413 MergeObjectFromObjects1 $(1) : $(objects) $(3) ; 414} 415 416actions MergeObjectFromObjects1 417{ 418 $(LINK) $(LINKFLAGS) -r $(2) -o $(1) ; 419} 420 421rule MergeObject 422{ 423 # MergeObject <name> : <sources> : <other objects> ; 424 # Compiles source files and merges the object files to an object file. 425 # <name>: Name of the object file to create. No grist will be added. 426 # <sources>: Sources to be compiled. Grist will be added. 427 # <other objects>: Object files or static libraries to be merged. No grist 428 # will be added. 429 # 430 local target = $(1) ; 431 local sources = [ FGristFiles $(2) ] ; 432 local otherObjects = $(3) ; 433 local objects = $(sources:S=$(SUFOBJ)) ; 434 435 if ! [ IsPlatformSupportedForTarget $(1) ] { 436 return ; 437 } 438 439 InheritPlatform $(objects) : $(target) ; 440 Objects $(sources) ; 441 MergeObjectFromObjects $(target) : $(objects) : $(otherObjects) ; 442} 443 444rule SharedLibraryFromObjects 445{ 446 # SharedLibraryFromObjects <lib> : <objects> : <libraries> ; 447 # 448 local _lib = $(1) ; 449 450 if ! [ IsPlatformSupportedForTarget $(1) ] { 451 return ; 452 } 453 454 local soname = [ on $(_lib) return $(HAIKU_SONAME) ] ; 455 soname ?= $(_lib:BS) ; 456 457 MainFromObjects $(_lib) : $(2) ; 458 LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ] 459 -shared -Xlinker -soname=\"$(soname)\" ; 460 LinkAgainst $(_lib) : $(3) ; 461 462 AddSharedObjectGlueCode $(_lib) : false ; 463} 464 465rule SharedLibrary 466{ 467 # SharedLibrary <lib> : <sources> : <libraries> : <abiVersion> ; 468 local lib = $(1) ; 469 local sources = [ FGristFiles $(2) ] ; 470 local objects = $(sources:S=$(SUFOBJ)) ; 471 local libs = $(3) ; 472 local abiVersion = $(4) ; # major ABI (soname) version for lib (if any) 473 474 if ! [ IsPlatformSupportedForTarget $(1) ] { 475 return ; 476 } 477 478 if $(abiVersion) { 479 HAIKU_SONAME on $(lib) = $(lib:BS).$(abiVersion) ; 480 HAIKU_LIB_ABI_VERSION on $(lib) = $(abiVersion) ; 481 } 482 483 InheritPlatform $(objects) : $(lib) ; 484 Objects $(sources) ; 485 SharedLibraryFromObjects $(lib) : $(objects) : $(libs) ; 486} 487 488rule LinkAgainst 489{ 490 # LinkAgainst <name> : <libs> [ : <mapLibs> ] ; 491 # Valid elements for <libs> are e.g. "be" or "libtranslation.so" or 492 # "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy 493 # has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the 494 # file will be bound!), otherwise it is prefixed "-l" and added to 495 # LINKLIBS. If you want to specify a target that isn't a library and 496 # also has neither grist nor a dirname, you can prepend "<nogrist>" as 497 # grist; it will be stripped by this rule. 498 # <mapLibs> specifies whether the to translate library names (e.g. "be" 499 # to "libbe.so" in case of target platform "haiku"). Defaults to "true". 500 # 501 local target = $(1) ; 502 local libs = $(2) ; 503 local mapLibs = $(3:E=true) ; 504 505 on $(target) { 506 local i ; 507 508 # map libraries, if desired and target platform is Haiku 509 local map = $(TARGET_LIBRARY_NAME_MAP_$(TARGET_PACKAGING_ARCH)) ; 510 if $(PLATFORM) != host && $(mapLibs) = true && $(map) { 511 local mappedLibs ; 512 513 for i in $(libs) { 514 local mapped = $($(map)_$(i)) ; 515 mapped ?= $(i) ; 516 mappedLibs += $(mapped) ; 517 } 518 519 libs = $(mappedLibs) ; 520 } 521 522 local linkLibs ; 523 local needLibs ; 524 525 for i in $(libs) 526 { 527 local isfile = ; 528 if $(i:D) || $(i:G) { 529 isfile = true ; 530 if $(i:G) = <nogrist> { 531 i = $(i:G=) ; 532 } 533 } else { 534 switch $(i:B) 535 { 536 # XXX: _APP_ and _KERNEL_ should not be needed for ELF. 537 case _APP_ : isfile = true ; 538 case _KERNEL_ : isfile = true ; 539 case lib* : isfile = true ; 540 case * : isfile = ; 541 } 542 if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) { 543 isfile = true ; 544 } 545 } 546 547 if $(isfile) { 548 needLibs += $(i) ; 549 } else { 550 linkLibs += $(i) ; 551 } 552 } 553 554 NEEDLIBS on $(1) = $(NEEDLIBS) $(needLibs) ; 555 LINKLIBS on $(1) = $(LINKLIBS) -l$(linkLibs) ; 556 557 if $(needLibs) && ! $(NO_LIBRARY_DEPENDENCIES) { 558 Depends $(1) : $(needLibs) ; 559 } 560 } 561} 562 563rule AddResources 564{ 565 # AddResources <name> : <resourcefiles> ; 566 567 # add grist to the resource files which don't have any yet 568 local resfiles ; 569 local file ; 570 for file in $(2) { 571 if ! $(file:G) { 572 file = [ FGristFiles $(file) ] ; 573 } 574 resfiles += $(file) ; 575 } 576 577 SEARCH on $(resfiles) += $(SEARCH_SOURCE) ; 578 579 for file in $(resfiles) { 580 if $(file:S) = .rdef { 581 local rdef = $(file) ; 582 file = $(rdef:S=.rsrc) ; 583 ResComp $(file) : $(rdef) ; 584 } 585 InheritPlatform $(file) : $(1) ; 586 RESFILES on $(1) += $(file) ; 587 } 588} 589 590rule SetVersionScript target : versionScript 591{ 592 # SetVersionScript <target> : <versionScript> 593 # 594 # Sets the version script for <target>. Grist will be added to 595 # <versionScript> and SEARCH will be set on it. 596 597 versionScript = [ FGristFiles $(versionScript) ] ; 598 599 SEARCH on $(versionScript) += $(SEARCH_SOURCE) ; 600 601 VERSION_SCRIPT on $(target) = $(versionScript) ; 602 Depends $(target) : $(versionScript) ; 603} 604 605rule BuildPlatformObjects 606{ 607 # Usage BuildPlatformObjects <sources> ; 608 # <sources> The sources. 609 # 610 local sources = [ FGristFiles $(1) ] ; 611 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 612 613 PLATFORM on $(objects) = host ; 614 SUPPORTED_PLATFORMS on $(objects) = host ; 615 616 Objects $(sources) ; 617} 618 619actions CygwinExtensionFix 620{ 621 if test -f $(1).exe ; then 622 rm -f $(1) 623 mv $(1).exe $(1) 624 fi 625} 626 627rule BuildPlatformMain 628{ 629 # Usage BuildPlatformMain <target> : <sources> : <libraries> ; 630 # <target> The executable/library. 631 # <sources> The sources. 632 # <libraries> Libraries to link against. 633 # 634 local target = $(1) ; 635 local sources = $(2) ; 636 local libs = $(3) ; 637 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 638 639 PLATFORM on $(target) = host ; 640 SUPPORTED_PLATFORMS on $(target) = host ; 641 DONT_USE_BEOS_RULES on $(target) = true ; 642 643 local usesBeAPI = [ on $(target) return $(USES_BE_API) ] ; 644 if $(usesBeAPI) { 645 # propagate the flag to the objects 646 USES_BE_API on $(objects) = $(usesBeAPI) ; 647 648 # add the build libroot 649 if ! $(HOST_PLATFORM_BEOS_COMPATIBLE) { 650 local libroot = [ on $(target) return $(HOST_LIBROOT) ] ; 651 Depends $(target) : $(libroot) ; 652 NEEDLIBS on $(target) += $(libroot) ; 653 } 654 } 655 656 Main $(target) : $(sources) ; 657 LinkAgainst $(target) : $(libs) ; 658 if $(HOST_PLATFORM) = cygwin { 659 # Cygwin gcc adds the ".exe" extension. We cannot force 660 # jam to use SUFEXE as haiku target executables are not 661 # supposed to have this extension, thus finding 662 # dependencies will fail for these. 663 # The hack is to remove the extension after a successful 664 # build of the Target. 665 CygwinExtensionFix $(target) ; 666 } 667} 668 669rule BuildPlatformSharedLibrary 670{ 671 # Usage BuildPlatformSharedLibrary <target> : <sources> : <libraries> ; 672 # <target> The library. 673 # <sources> The sources. 674 # <libraries> Libraries to link against. 675 # 676 local target = $(1) ; 677 local sources = $(2) ; 678 local libs = $(3) ; 679 680 BuildPlatformMain $(target) : $(sources) : $(libs) ; 681 682 if $(HOST_PLATFORM) = darwin { 683 LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] 684 -dynamic -dynamiclib -Xlinker -flat_namespace ; 685 } else if $(HOST_PLATFORM) = cygwin { 686 LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] 687 -shared -Xlinker --allow-multiple-definition ; 688 } else { 689 LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] 690 -shared -Xlinker -soname=\"$(target:G=)\" ; 691 } 692 693 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 694 CCFLAGS on $(objects) += $(HOST_PIC_CCFLAGS) ; 695 C++FLAGS on $(objects) += $(HOST_PIC_C++FLAGS) ; 696} 697 698rule BuildPlatformMergeObject 699{ 700 # BuildPlatformMergeObject <name> : <sources> : <other objects> ; 701 # Compiles source files and merges the object files to an object file. 702 # <name>: Name of the object file to create. No grist will be added. 703 # <sources>: Sources to be compiled. Grist will be added. 704 # <other objects>: Object files or static libraries to be merged. No grist 705 # will be added. 706 # 707 local target = $(1) ; 708 local sources = $(2) ; 709 local otherObjects = $(3) ; 710 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 711 712 PLATFORM on $(target) = host ; 713 SUPPORTED_PLATFORMS on $(target) = host ; 714 715 local usesBeAPI = [ on $(target[1]) return $(USES_BE_API) ] ; 716 if $(usesBeAPI) { 717 # propagate the flag to the objects 718 USES_BE_API on $(objects) = $(usesBeAPI) ; 719 } 720 721 MergeObject $(target) : $(sources) : $(otherObjects) ; 722} 723 724rule BuildPlatformMergeObjectPIC target : sources : otherObjects 725{ 726 # BuildPlatformMergeObjectPIC <name> : <sources> : <other objects> ; 727 # Compiles source files and merges the object files to an object file. 728 # Same as BuildPlatformMergeObject rule but adds position-independent 729 # flags to the compiler (if any). 730 # <name>: Name of the object file to create. No grist will be added. 731 # <sources>: Sources to be compiled. Grist will be added. 732 # <other objects>: Object files or static libraries to be merged. No grist 733 # will be added. 734 # 735 ObjectCcFlags $(sources) : $(HOST_PIC_CCFLAGS) ; 736 ObjectC++Flags $(sources) : $(HOST_PIC_C++FLAGS) ; 737 738 BuildPlatformMergeObject $(target) : $(sources) : $(otherObjects) ; 739} 740 741rule BuildPlatformStaticLibrary lib : sources : otherObjects 742{ 743 # BuildPlatformStaticLibrary <lib> : <sources> ; 744 # Creates a static library from sources. 745 # <lib>: The static library to be built. 746 # <sources>: List of source files. 747 # <otherObjects>: List of additional object files. 748 # 749 750 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 751 752 PLATFORM on $(lib) = host ; 753 SUPPORTED_PLATFORMS on $(lib) = host ; 754 755 local usesBeAPI = [ on $(lib) return $(USES_BE_API) ] ; 756 if $(usesBeAPI) { 757 # propagate the flag to the objects 758 USES_BE_API on $(objects) = $(usesBeAPI) ; 759 } 760 761 StaticLibrary $(lib) : $(sources) : $(otherObjects) ; 762} 763 764rule BuildPlatformStaticLibraryPIC target : sources : otherObjects 765{ 766 # Like BuildPlatformStaticLibrary, but producing position independent code. 767 768 ObjectCcFlags $(sources) : $(HOST_PIC_CCFLAGS) ; 769 ObjectC++Flags $(sources) : $(HOST_PIC_C++FLAGS) ; 770 771 BuildPlatformStaticLibrary $(target) : $(sources) : $(otherObjects) ; 772} 773 774rule BootstrapStage0PlatformObjects sources : separateFromStandardSiblings 775{ 776 # BootstrapStage0PlatformObjects <sources> : <separateFromStandardSiblings> 777 # Builds objects from the given sources for stage0 of the bootstrap process. 778 # <sources> The sources from which objects should be created. 779 # <separateFromStandardSiblings> Pass 'true' if the same objects are built 780 # in a different context, too, so that a separate grist and target location 781 # is required. This defaults to ''. 782 local source ; 783 for source in $(sources) { 784 local objectGrist ; 785 if $(separateFromStandardSiblings) = true { 786 objectGrist = "bootstrap!$(SOURCE_GRIST)" ; 787 } else { 788 objectGrist = $(SOURCE_GRIST) ; 789 } 790 local object = $(source:S=$(SUFOBJ):G=$(objectGrist)) ; 791 PLATFORM on $(object) = bootstrap_stage0 ; 792 SUPPORTED_PLATFORMS on $(object) = bootstrap_stage0 ; 793 if $(separateFromStandardSiblings) = true { 794 MakeLocate $(object) : [ 795 FDirName $(TARGET_DEBUG_$(DEBUG)_LOCATE_TARGET) bootstrap 796 ] ; 797 } 798 Object $(object) : $(source) ; 799 } 800} 801