1 2rule AddSharedObjectGlueCode 3{ 4 # AddSharedObjectGlueCode <target> : <isExecutable> ; 5 6 # we link with -nostdlib and add the required libs manually, when building 7 # for Haiku 8 local platform ; 9 on $(1) { 10 platform = $(PLATFORM) ; 11 if $(platform) = haiku { 12 local stdLibs = libroot.so ; 13 local beginGlue ; 14 local endGlue ; 15 if $(2) = true { 16 beginGlue += $(HAIKU_EXECUTABLE_BEGIN_GLUE_CODE) ; 17 endGlue += $(HAIKU_EXECUTABLE_END_GLUE_CODE) ; 18 } else { 19 beginGlue += $(HAIKU_LIBRARY_BEGIN_GLUE_CODE) ; 20 endGlue += $(HAIKU_LIBRARY_END_GLUE_CODE) ; 21 22 # special case for libroot: don't link it against itself 23 if $(DONT_LINK_AGAINST_LIBROOT) { 24 stdLibs = ; 25 } 26 } 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 = -nostart $(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 Ld 171{ 172 # Ld <name> : <objs> : <linkerscript> : <flags> ; 173 # 174 local target = $(1) ; 175 local objects = $(2) ; 176 local linkerScript = $(3) ; 177 local linkerFlags = $(4) ; 178 179 if $(linkerScript) { 180 linkerFlags += --script=$(linkerScript) ; 181 } 182 183 on $(target) { 184 if $(PLATFORM) = host { 185 LINK on $(target) = $(HOST_LD) ; 186 LINKFLAGS on $(target) = $(HOST_LDFLAGS) $(LINKFLAGS) $(linkerFlags) ; 187 } else { 188 LINK on $(target) = $(TARGET_LD) ; 189 LINKFLAGS on $(target) = $(TARGET_LDFLAGS) $(LINKFLAGS) 190 $(linkerFlags) ; 191 } 192 193 NEEDLIBS on $(target) = $(NEEDLIBS) ; 194 LINKLIBS on $(target) = $(LINKLIBS) ; 195 } 196 197 LocalClean clean : $(target) ; 198 LocalDepends all : $(target) ; 199 Depends $(target) : $(objects) ; 200 201 MakeLocateDebug $(target) ; 202 203 on $(1) XRes $(1) : $(RESFILES) ; 204 if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] { 205 SetType $(1) ; 206 MimeSet $(1) ; 207 SetVersion $(1) ; 208 } 209} 210 211actions Ld 212{ 213 $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" "$(NEEDLIBS)" $(LINKLIBS) 214} 215 216rule CreateAsmStructOffsetsHeader header : source 217{ 218 # CreateAsmStructOffsetsHeader header : source 219 # 220 # Grist will be added to both header and source. 221 222 header = [ FGristFiles $(header) ] ; 223 source = [ FGristFiles $(source) ] ; 224 225 # find out which headers, defines, etc. to use 226 local headers ; 227 local sysHeaders ; 228 local defines ; 229 local flags ; 230 local includesSeparator ; 231 local localIncludesOption ; 232 local systemIncludesOption ; 233 234 on $(header) { # use on $(1) variable values 235 if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) { 236 return ; 237 } 238 239 # headers and defines 240 headers = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ; 241 sysHeaders = $(SUBDIRSYSHDRS) $(SYSHDRS) ; 242 defines = $(DEFINES) ; 243 244 if $(PLATFORM) = host { 245 sysHeaders += $(HOST_HDRS) ; 246 defines += $(HOST_DEFINES) ; 247 248 if $(USES_BE_API) { 249 sysHeaders += $(HOST_BE_API_HEADERS) ; 250 } 251 252 } else { 253 sysHeaders += $(TARGET_HDRS) ; 254 defines += $(TARGET_DEFINES) ; 255 } 256 257 # optimization flags 258 if $(DEBUG) = 0 { 259 flags += $(OPTIM) ; 260 } else { 261 flags += -O0 ; 262 } 263 264 if $(PLATFORM) = host { 265 # warning flags 266 if $(WARNINGS) != 0 { 267 flags += $(HOST_WARNING_C++FLAGS) ; 268 } 269 270 # debug and other flags 271 flags += $(HOST_C++FLAGS) $(HOST_DEBUG_$(DEBUG)_C++FLAGS) 272 $(SUBDIRC++FLAGS) $(C++FLAGS) ; 273 274 if $(USES_BE_API) { 275 flags += $(HOST_BE_API_C++FLAGS) ; 276 } 277 278 C++ on $(header) = $(HOST_C++) ; 279 280 includesSeparator = $(HOST_INCLUDES_SEPARATOR) ; 281 localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ; 282 systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ; 283 284 } else { 285 # warning flags 286 if $(WARNINGS) != 0 { 287 flags += $(TARGET_WARNING_C++FLAGS) ; 288 } 289 290 # debug and other flags 291 flags += $(TARGET_C++FLAGS) $(TARGET_DEBUG_$(DEBUG)_C++FLAGS) 292 $(SUBDIRC++FLAGS) $(C++FLAGS) ; 293 294 C++ on $(header) = $(TARGET_C++) ; 295 296 includesSeparator = $(TARGET_INCLUDES_SEPARATOR) ; 297 localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ; 298 systemIncludesOption = $(TARGET_SYSTEM_INCLUDES_OPTION) ; 299 } 300 } 301 302 # locate object, search for source, and set on target variables 303 304 Depends $(header) : $(source) ; 305 SEARCH on $(source) += $(SEARCH_SOURCE) ; 306 MakeLocateArch $(header) ; 307 LocalClean clean : $(header) ; 308 309 HDRRULE on $(source) = HdrRule ; 310 HDRSCAN on $(source) = $(HDRPATTERN) ; 311 HDRSEARCH on $(source) = $(headers) $(sysHeaders) $(STDHDRS) ; 312 HDRGRIST on $(source) = $(HDRGRIST) ; 313 314 C++FLAGS on $(header) = $(flags) ; 315 CCHDRS on $(header) = [ FIncludes $(headers) : $(localIncludesOption) ] 316 $(includesSeparator) 317 [ FSysIncludes $(sysHeaders) : $(systemIncludesOption) ] ; 318 CCDEFS on $(header) = [ FDefines $(defines) ] ; 319 320 CreateAsmStructOffsetsHeader1 $(header) : $(source) ; 321} 322 323actions CreateAsmStructOffsetsHeader1 324{ 325 $(C++) -S "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o - \ 326 | grep "#define" | sed -e 's/[\$\#]\([0-9]\)/\1/' > "$(1)" 327} 328 329rule MergeObjectFromObjects 330{ 331 # MergeObjectFromObjects <name> : <objects> : <other objects> ; 332 # Merges object files to an object file. 333 # <name>: Name of the object file to create. No grist will be added. 334 # <objects>: Object files to be merged. Grist will be added. 335 # <other objects>: Object files or static libraries to be merged. No grist 336 # will be added. 337 # 338 local objects = [ FGristFiles $(2) ] ; 339 340 on $(1) { 341 if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) { 342 return ; 343 } 344 345 if $(PLATFORM) = host { 346 LINK on $(1) = $(HOST_LD) ; 347 LINKFLAGS on $(target) = $(HOST_LDFLAGS) ; 348 } else { 349 LINK on $(1) = $(TARGET_LD) ; 350 LINKFLAGS on $(target) = $(TARGET_LDFLAGS) ; 351 } 352 } 353 354 MakeLocateDebug $(1) ; 355 Depends $(1) : $(objects) ; 356 Depends $(1) : $(3) ; 357 LocalDepends obj : $(1) ; 358 MergeObjectFromObjects1 $(1) : $(objects) $(3) ; 359} 360 361actions MergeObjectFromObjects1 362{ 363 $(LINK) $(LINKFLAGS) -r $(2) -o $(1) ; 364} 365 366rule MergeObject 367{ 368 # MergeObject <name> : <sources> : <other objects> ; 369 # Compiles source files and merges the object files to an object file. 370 # <name>: Name of the object file to create. No grist will be added. 371 # <sources>: Sources to be compiled. Grist will be added. 372 # <other objects>: Object files or static libraries to be merged. No grist 373 # will be added. 374 # 375 local target = $(1) ; 376 local sources = [ FGristFiles $(2) ] ; 377 local otherObjects = $(3) ; 378 local objects = $(sources:S=$(SUFOBJ)) ; 379 380 if ! [ IsPlatformSupportedForTarget $(1) ] { 381 return ; 382 } 383 384 InheritPlatform $(objects) : $(target) ; 385 Objects $(sources) ; 386 MergeObjectFromObjects $(target) : $(objects) : $(otherObjects) ; 387} 388 389rule SharedLibraryFromObjects 390{ 391 # SharedLibraryFromObjects <lib> : <objects> : <libraries> ; 392 # 393 local _lib = $(1) ; 394 395 if ! [ IsPlatformSupportedForTarget $(1) ] { 396 return ; 397 } 398 399 MainFromObjects $(_lib) : $(2) ; 400 LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ] 401 -nostart -Xlinker -soname=\"$(_lib:G=)\" ; 402 LinkAgainst $(_lib) : $(3) ; 403 404 AddSharedObjectGlueCode $(_lib) : false ; 405} 406 407rule SharedLibrary 408{ 409 # SharedLibrary <lib> : <sources> : <libraries> ; 410 local lib = $(1) ; 411 local sources = [ FGristFiles $(2) ] ; 412 local objects = $(sources:S=$(SUFOBJ)) ; 413 local libs = $(3) ; 414 415 if ! [ IsPlatformSupportedForTarget $(1) ] { 416 return ; 417 } 418 419 InheritPlatform $(objects) : $(lib) ; 420 Objects $(sources) ; 421 SharedLibraryFromObjects $(lib) : $(objects) : $(libs) ; 422} 423 424rule LinkAgainst 425{ 426 # LinkAgainst <name> : <libs> [ : <mapLibs> ] ; 427 # Valid elements for <libs> are e.g. "be" or "libtranslation.so" or 428 # "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy 429 # has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the 430 # file will be bound!), otherwise it is prefixed "-l" and added to 431 # LINKLIBS. If you want to specify a target that isn't a library and 432 # also has neither grist nor a dirname, you can prepend "<nogrist>" as 433 # grist; it will be stripped by this rule. 434 # <mapLibs> specifies whether the to translate library names (e.g. "be" 435 # to "libbe.so" in case of target platform "haiku"). Defaults to "true". 436 # 437 local target = $(1) ; 438 local libs = $(2) ; 439 local mapLibs = $(3:E=true) ; 440 441 on $(target) { 442 # map libraries, if desired and target platform is Haiku 443 if $(PLATFORM) != host && $(mapLibs) = true 444 && $(TARGET_LIBRARY_NAME_MAP) { 445 local mappedLibs ; 446 447 for i in $(libs) { 448 local mapped = $($(TARGET_LIBRARY_NAME_MAP)_$(i)) ; 449 mapped ?= $(i) ; 450 mappedLibs += $(mapped) ; 451 } 452 453 libs = $(mappedLibs) ; 454 } 455 456 local linkLibs ; 457 local needLibs ; 458 459 for i in $(libs) 460 { 461 local isfile = ; 462 if $(i:D) || $(i:G) { 463 isfile = true ; 464 if $(i:G) = <nogrist> { 465 i = $(i:G=) ; 466 } 467 } else { 468 switch $(i:B) 469 { 470 # XXX: _APP_ and _KERNEL_ should not be needed for ELF. 471 case _APP_ : isfile = true ; 472 case _KERNEL_ : isfile = true ; 473 case lib* : isfile = true ; 474 case * : isfile = ; 475 } 476 if ! $(isfile) && ( $(i:S) = .so || $(i:S) = .a ) { 477 isfile = true ; 478 } 479 } 480 481 if $(isfile) { 482 needLibs += $(i) ; 483 } else { 484 linkLibs += $(i) ; 485 } 486 } 487 488 NEEDLIBS on $(1) = $(NEEDLIBS) $(needLibs) ; 489 LINKLIBS on $(1) = $(LINKLIBS) -l$(linkLibs) ; 490 491 if $(needLibs) && ! $(NO_LIBRARY_DEPENDENCIES) { 492 Depends $(1) : $(needLibs) ; 493 } 494 } 495} 496 497rule AddResources 498{ 499 # AddResources <name> : <resourcefiles> ; 500 501 # add grist to the resource files which don't have any yet 502 local resfiles ; 503 local file ; 504 for file in $(2) { 505 if ! $(file:G) { 506 file = [ FGristFiles $(file) ] ; 507 } 508 resfiles += $(file) ; 509 } 510 511 SEARCH on $(resfiles) += $(SEARCH_SOURCE) ; 512 513 for file in $(resfiles) { 514 if $(file:S) = .rdef { 515 local rdef = $(file) ; 516 file = $(rdef:S=.rsrc) ; 517 ResComp $(file) : $(rdef) ; 518 } 519 InheritPlatform $(file) : $(1) ; 520 RESFILES on $(1) += $(file) ; 521 } 522} 523 524rule BuildPlatformObjects 525{ 526 # Usage BuildPlatformObjects <sources> ; 527 # <sources> The sources. 528 # 529 local sources = [ FGristFiles $(1) ] ; 530 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 531 532 PLATFORM on $(objects) = host ; 533 SUPPORTED_PLATFORMS on $(objects) = host ; 534 535 Objects $(sources) ; 536} 537 538actions CygwinExtensionFix 539{ 540 if test -f $(1).exe ; then 541 rm -f $(1) 542 mv $(1).exe $(1) 543 fi 544} 545 546rule BuildPlatformMain 547{ 548 # Usage BuildPlatformMain <target> : <sources> : <libraries> ; 549 # <target> The executable/library. 550 # <sources> The sources. 551 # <libraries> Libraries to link against. 552 # 553 local target = $(1) ; 554 local sources = $(2) ; 555 local libs = $(3) ; 556 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 557 558 PLATFORM on $(target) = host ; 559 SUPPORTED_PLATFORMS on $(target) = host ; 560 DONT_USE_BEOS_RULES on $(target) = true ; 561 562 local usesBeAPI = [ on $(target) return $(USES_BE_API) ] ; 563 if $(usesBeAPI) { 564 # propagate the flag to the objects 565 USES_BE_API on $(objects) = $(usesBeAPI) ; 566 567 # add the build libroot 568 if ! $(HOST_PLATFORM_BEOS_COMPATIBLE) { 569 local libroot = [ on $(target) return $(HOST_LIBROOT) ] ; 570 Depends $(target) : $(libroot) ; 571 NEEDLIBS on $(target) += $(libroot) ; 572 } 573 } 574 575 Main $(target) : $(sources) ; 576 LinkAgainst $(target) : $(libs) ; 577 if $(HOST_PLATFORM) = cygwin { 578 # Cygwin gcc adds the ".exe" extension. We cannot force 579 # jam to use SUFEXE as haiku target executables are not 580 # supposed to have this extension, thus finding 581 # dependencies will fail for these. 582 # The hack is to remove the extension after a successful 583 # build of the Target. 584 CygwinExtensionFix $(target) ; 585 } 586} 587 588rule BuildPlatformSharedLibrary 589{ 590 # Usage BuildPlatformSharedLibrary <target> : <sources> : <libraries> ; 591 # <target> The library. 592 # <sources> The sources. 593 # <libraries> Libraries to link against. 594 # 595 local target = $(1) ; 596 local sources = $(2) ; 597 local libs = $(3) ; 598 599 BuildPlatformMain $(target) : $(sources) : $(libs) ; 600 601 if $(HOST_PLATFORM) = darwin { 602 LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] 603 -dynamic -dynamiclib -Xlinker -flat_namespace ; 604 } else if $(HOST_PLATFORM) = cygwin { 605 LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] 606 -shared -Xlinker --allow-multiple-definition ; 607 } else { 608 LINKFLAGS on $(target) = [ on $(target) return $(LINKFLAGS) ] 609 -shared -Xlinker -soname=\"$(target:G=)\" ; 610 } 611 612 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 613 CCFLAGS on $(objects) += $(HOST_PIC_CCFLAGS) ; 614 C++FLAGS on $(objects) += $(HOST_PIC_C++FLAGS) ; 615} 616 617rule BuildPlatformMergeObject 618{ 619 # BuildPlatformMergeObject <name> : <sources> : <other objects> ; 620 # Compiles source files and merges the object files to an object file. 621 # <name>: Name of the object file to create. No grist will be added. 622 # <sources>: Sources to be compiled. Grist will be added. 623 # <other objects>: Object files or static libraries to be merged. No grist 624 # will be added. 625 # 626 local target = $(1) ; 627 local sources = $(2) ; 628 local otherObjects = $(3) ; 629 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 630 631 PLATFORM on $(target) = host ; 632 SUPPORTED_PLATFORMS on $(target) = host ; 633 634 local usesBeAPI = [ on $(target[1]) return $(USES_BE_API) ] ; 635 if $(usesBeAPI) { 636 # propagate the flag to the objects 637 USES_BE_API on $(objects) = $(usesBeAPI) ; 638 } 639 640 MergeObject $(target) : $(sources) : $(otherObjects) ; 641} 642 643rule BuildPlatformMergeObjectPIC target : sources : otherObjects 644{ 645 # BuildPlatformMergeObjectPIC <name> : <sources> : <other objects> ; 646 # Compiles source files and merges the object files to an object file. 647 # Same as BuildPlatformMergeObject rule but adds position-independent 648 # flags to the compiler (if any). 649 # <name>: Name of the object file to create. No grist will be added. 650 # <sources>: Sources to be compiled. Grist will be added. 651 # <other objects>: Object files or static libraries to be merged. No grist 652 # will be added. 653 # 654 ObjectCcFlags $(sources) : $(HOST_PIC_CCFLAGS) ; 655 ObjectC++Flags $(sources) : $(HOST_PIC_C++FLAGS) ; 656 657 BuildPlatformMergeObject $(target) : $(sources) : $(otherObjects) ; 658} 659 660rule BuildPlatformStaticLibrary lib : sources : otherObjects 661{ 662 # BuildPlatformStaticLibrary <lib> : <sources> ; 663 # Creates a static library from sources. 664 # <lib>: The static library to be built. 665 # <sources>: List of source files. 666 # <otherObjects>: List of additional object files. 667 # 668 669 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 670 671 PLATFORM on $(lib) = host ; 672 SUPPORTED_PLATFORMS on $(lib) = host ; 673 674 local usesBeAPI = [ on $(lib) return $(USES_BE_API) ] ; 675 if $(usesBeAPI) { 676 # propagate the flag to the objects 677 USES_BE_API on $(objects) = $(usesBeAPI) ; 678 } 679 680 StaticLibrary $(lib) : $(sources) : $(otherObjects) ; 681} 682 683