1# Overridden to allow spaces in file names. 2actions Chmod1 3{ 4 $(CHMOD) "$(MODE)" "$(1)" 5} 6 7# Overridden to allow spaces in file names. 8actions piecemeal together existing Clean 9{ 10 $(RM) "$(>)" 11} 12 13#------------------------------------------------------------------------------- 14# Link rule/action are overwritten as they don't handle linking files who's name 15# contain spaces very well. Also adds resources and version to executable. 16#------------------------------------------------------------------------------- 17rule Link 18{ 19 # Note: RESFILES must be set before invocation. 20 21 if [ on $(1) return $(PLATFORM) ] = host { 22 LINK on $(1) = $(HOST_LINK) ; 23 LINKFLAGS on $(1) = $(HOST_LINKFLAGS) [ on $(1) return $(LINKFLAGS) ] ; 24 } else { 25 LINK on $(1) = $(TARGET_LINK) ; 26 LINKFLAGS on $(1) = $(TARGET_LINKFLAGS) 27 [ on $(1) return $(LINKFLAGS) ] ; 28 } 29 30 NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] ; 31 LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] ; 32 33 MODE on $(<) = $(EXEMODE) ; 34 on $(1) XRes $(1) : $(RESFILES) ; 35 Chmod $(<) ; 36 if ! [ on $(1) return $(DONT_USE_BEOS_RULES) ] { 37 SetType $(1) ; 38 MimeSet $(1) ; 39 SetVersion $(1) ; 40 } 41} 42 43actions Link bind NEEDLIBS LINK_BEGIN_GLUE LINK_END_GLUE 44{ 45 $(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(LINK_BEGIN_GLUE)" "$(2)" "$(NEEDLIBS)" $(LINKLIBS) "$(LINK_END_GLUE)" ; 46} 47 48rule Object 49{ 50 # find out which headers and defines to use 51 local headers ; 52 local sysHeaders ; 53 local defines ; 54 55 on $(1) { # use on $(1) variable values 56 if ! $(PLATFORM) in $(SUPPORTED_PLATFORMS) { 57 return ; 58 } 59 60 # Save HDRS for -I$(HDRS) on compile. 61 # We shouldn't need -I$(SEARCH_SOURCE) as cc can find headers 62 # in the .c file's directory, but generated .c files (from 63 # yacc, lex, etc) are located in $(LOCATE_TARGET), possibly 64 # different from $(SEARCH_SOURCE). 65 66 headers = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ; 67 sysHeaders = $(SUBDIRSYSHDRS) $(SYSHDRS) ; 68 defines = $(DEFINES) ; 69 70 if $(PLATFORM) = host { 71 sysHeaders += $(HOST_HDRS) ; 72 defines += $(HOST_DEFINES) ; 73 74 if $(USES_BE_API) { 75 sysHeaders += $(HOST_BE_API_HEADERS) ; 76 } 77 78 } else { 79 sysHeaders += $(TARGET_HDRS) ; 80 defines += $(TARGET_DEFINES) ; 81 } 82 } 83 84 # locate object and search for source 85 86 LocalClean clean : $(<) ; 87 88 MakeLocateDebug $(<) ; 89 SEARCH on $(>) = $(SEARCH_SOURCE) ; 90 91 HDRS on $(<) = $(headers) ; 92 SYSHDRS on $(<) = $(sysHeaders) ; 93 94 # handle #includes for source: Jam scans for headers with 95 # the regexp pattern $(HDRSCAN) and then invokes $(HDRRULE) 96 # with the scanned file as the target and the found headers 97 # as the sources. HDRSEARCH is the value of SEARCH used for 98 # the found header files. Finally, if jam must deal with 99 # header files of the same name in different directories, 100 # they can be distinguished with HDRGRIST. 101 102 # $(SEARCH_SOURCE:E) is where cc first looks for #include 103 # "foo.h" files. If the source file is in a distant directory, 104 # look there. Else, look in "" (the current directory). 105 106 HDRRULE on $(>) = HdrRule ; 107 HDRSCAN on $(>) = $(HDRPATTERN) ; 108 HDRSEARCH on $(>) = $(headers) $(sysHeaders) $(STDHDRS) ; 109 HDRGRIST on $(>) = $(HDRGRIST) ; 110 111 # propagate target specific-defines 112 113 DEFINES on $(1) = $(defines) ; 114 115 # if source is not .c, generate .c with specific rule 116 117 switch $(>:S) 118 { 119 case .asm : As $(<) : $(>) ; 120 case .c : Cc $(<) : $(>) ; 121 case .C : C++ $(<) : $(>) ; 122 case .cc : C++ $(<) : $(>) ; 123 case .cpp : C++ $(<) : $(>) ; 124 case .f : Fortran $(<) : $(>) ; 125 case .l : if [ on $(2) return $(GENERATE_C++) ] { 126 InheritPlatform $(<:S=.cpp) : $(1) ; 127 C++ $(<) : $(<:S=.cpp) ; 128 Lex $(<:S=.cpp) : $(>) ; 129 } else { 130 InheritPlatform $(<:S=.c) : $(1) ; 131 Cc $(<) : $(<:S=.c) ; 132 Lex $(<:S=.c) : $(>) ; 133 } 134 case *.o : return ; 135 case .s : As $(<) : $(>) ; 136 case .S : As $(<) : $(>) ; 137 case .y : if [ on $(2) return $(GENERATE_C++) ] { 138 InheritPlatform $(1:S=.cpp) $(1:S=.hpp) : $(1) ; 139 C++ $(1) : $(1:S=.cpp) ; 140 Yacc $(1:S=.cpp) $(1:S=.hpp) : $(2) ; 141 } else { 142 InheritPlatform $(1:S=.c) $(1:S=.h) : $(1) ; 143 Cc $(1) : $(1:S=.c) ; 144 Yacc $(1:S=.c) $(1:S=.h) : $(2) ; 145 } 146 case * : UserObject $(<) : $(>) ; 147 } 148} 149 150rule As 151{ 152 local flags ; 153 local includesSeparator ; 154 local localIncludesOption ; 155 local systemIncludesOption ; 156 if [ on $(1) return $(PLATFORM) ] = host { 157 flags = [ on $(1) return $(HOST_ASFLAGS) $(ASFLAGS) ] ; 158 159 CC on $(1) = $(HOST_CC) ; 160 161 includesSeparator = $(HOST_INCLUDES_SEPARATOR) ; 162 localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ; 163 systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ; 164 165 } else { 166 flags = [ on $(1) return $(TARGET_ASFLAGS) $(ASFLAGS) ] ; 167 168 CC on $(1) = $(TARGET_CC) ; 169 170 includesSeparator = $(TARGET_INCLUDES_SEPARATOR) ; 171 localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ; 172 systemIncludesOption = $(TARGET_SYSTEM_INCLUDES_OPTION) ; 173 } 174 175 Depends $(<) : $(>) ; 176 ASFLAGS on $(<) += $(flags) $(SUBDIRASFLAGS) ; 177 ASHDRS on $(<) = [ on $(<) FIncludes $(HDRS) : $(localIncludesOption) ] 178 $(includesSeparator) 179 [ on $(<) FSysIncludes $(SYSHDRS) : $(systemIncludesOption) ] ; 180 ASDEFS on $(<) = [ on $(<) FDefines $(DEFINES) ] ; 181} 182 183# TODO: The KERNEL_CCFLAGS were used here before. Check whether we need any 184# flags we don't have now. 185actions As 186{ 187 $(CC) -c "$(2)" -O2 $(ASFLAGS) -D_ASSEMBLER $(ASDEFS) $(ASHDRS) -o "$(1)" ; 188} 189 190rule Lex 191{ 192 Depends $(1) : $(2) ; 193 MakeLocateArch $(1) ; 194 LocalClean clean : $(1) ; 195} 196 197actions Lex 198{ 199 $(LEX) -o$(1) $(2) 200} 201 202rule Yacc 203{ 204 local source = $(1[1]) ; 205 local header = $(1[2]) ; 206 local yaccSource = $(2) ; 207 208 MakeLocateArch $(source) $(header) ; 209 210 Depends $(source) $(header) : $(yaccSource) ; 211 Yacc1 $(source) $(header) : $(yaccSource) ; 212 LocalClean clean : $(source) $(header) ; 213 214 # make sure someone includes $(header) else it will be 215 # a deadly independent target 216 217 Includes $(source) : $(header) ; 218} 219 220actions Yacc1 221{ 222 bison $(YACCFLAGS) -o $(1[1]) $(2) 223 [ -f $(1[1]).h ] && mv $(1[1]).h $(1[2]) || true 224} 225 226rule Cc 227{ 228 Depends $(<) : $(>) ; 229 230 on $(1) { 231 local flags ; 232 local includesSeparator ; 233 local localIncludesOption ; 234 local systemIncludesOption ; 235 236 # optimization flags 237 if $(DEBUG) = 0 { 238 flags += $(OPTIM) ; 239 } else { 240 flags += -O0 ; 241 } 242 243 if $(PLATFORM) = host { 244 # warning flags 245 if $(WARNINGS) != 0 { 246 flags += $(HOST_WARNING_CCFLAGS) ; 247 } 248 249 # debug and other flags 250 flags += $(HOST_CCFLAGS) $(HOST_DEBUG_$(DEBUG)_CCFLAGS) 251 $(SUBDIRCCFLAGS) $(CCFLAGS) ; 252 253 if $(USES_BE_API) { 254 flags += $(HOST_BE_API_CCFLAGS) ; 255 } 256 257 CC on $(1) = $(HOST_CC) ; 258 259 includesSeparator = $(HOST_INCLUDES_SEPARATOR) ; 260 localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ; 261 systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ; 262 263 } else { 264 # warning flags 265 if $(WARNINGS) != 0 { 266 flags += $(TARGET_WARNING_CCFLAGS) ; 267 } 268 269 # debug and other flags 270 flags += $(TARGET_CCFLAGS) $(TARGET_DEBUG_$(DEBUG)_CCFLAGS) 271 $(SUBDIRCCFLAGS) $(CCFLAGS) ; 272 273 CC on $(1) = $(TARGET_CC) ; 274 275 includesSeparator = $(TARGET_INCLUDES_SEPARATOR) ; 276 localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ; 277 systemIncludesOption = $(TARGET_SYSTEM_INCLUDES_OPTION) ; 278 } 279 280 CCFLAGS on $(<) = $(flags) ; 281 CCHDRS on $(<) = [ FIncludes $(HDRS) : $(localIncludesOption) ] 282 $(includesSeparator) 283 [ FSysIncludes $(SYSHDRS) : $(systemIncludesOption) ] ; 284 CCDEFS on $(<) = [ FDefines $(DEFINES) ] ; 285 } 286} 287 288actions Cc 289{ 290 $(CC) $(CCFLAGS) -c "$(2)" $(CCDEFS) $(CCHDRS) -o "$(1)" ; 291} 292 293rule C++ 294{ 295 Depends $(<) : $(>) ; 296 297 on $(1) { 298 local flags ; 299 local includesSeparator ; 300 local localIncludesOption ; 301 local systemIncludesOption ; 302 303 # optimization flags 304 if $(DEBUG) = 0 { 305 flags += $(OPTIM) ; 306 } else { 307 flags += -O0 ; 308 } 309 310 if $(PLATFORM) = host { 311 # warning flags 312 if $(WARNINGS) != 0 { 313 flags += $(HOST_WARNING_C++FLAGS) ; 314 } 315 316 # debug and other flags 317 flags += $(HOST_C++FLAGS) $(HOST_DEBUG_$(DEBUG)_C++FLAGS) 318 $(SUBDIRC++FLAGS) $(C++FLAGS) ; 319 320 if $(USES_BE_API) { 321 flags += $(HOST_BE_API_C++FLAGS) ; 322 } 323 324 C++ on $(1) = $(HOST_C++) ; 325 326 includesSeparator = $(HOST_INCLUDES_SEPARATOR) ; 327 localIncludesOption = $(HOST_LOCAL_INCLUDES_OPTION) ; 328 systemIncludesOption = $(HOST_SYSTEM_INCLUDES_OPTION) ; 329 330 } else { 331 # warning flags 332 if $(WARNINGS) != 0 { 333 flags += $(TARGET_WARNING_C++FLAGS) ; 334 } 335 336 # debug and other flags 337 flags += $(TARGET_C++FLAGS) $(TARGET_DEBUG_$(DEBUG)_C++FLAGS) 338 $(SUBDIRC++FLAGS) $(C++FLAGS) ; 339 340 C++ on $(1) = $(TARGET_C++) ; 341 342 includesSeparator = $(TARGET_INCLUDES_SEPARATOR) ; 343 localIncludesOption = $(TARGET_LOCAL_INCLUDES_OPTION) ; 344 systemIncludesOption = $(TARGET_SYSTEM_INCLUDES_OPTION) ; 345 } 346 347 C++FLAGS on $(<) = $(flags) ; 348 CCHDRS on $(<) = [ FIncludes $(HDRS) : $(localIncludesOption) ] 349 $(includesSeparator) 350 [ FSysIncludes $(SYSHDRS) : $(systemIncludesOption) ] ; 351 CCDEFS on $(<) = [ FDefines $(DEFINES) ] ; 352 } 353} 354 355actions C++ 356{ 357 $(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ; 358} 359 360rule Library 361{ 362 local lib = $(1) ; 363 local sources = [ FGristFiles $(2) ] ; 364 local objects = $(sources:S=$(SUFOBJ)) ; 365 366 InheritPlatform $(objects) : $(lib) ; 367 LibraryFromObjects $(lib) : $(objects) ; 368 Objects $(sources) ; 369} 370 371rule LibraryFromObjects 372{ 373 local _i _l _s ; 374 375 # Add grist to file names 376 # bonefish: No, don't. The Library rule does that anyway, and when we 377 # have an object from another dir, we certainly don't want that. 378 379 _s = $(>) ; 380 _l = $(<:S=$(SUFLIB)) ; 381 382 on $(_l) { 383 # set the tools according to the platform 384 if $(PLATFORM) = host { 385 AR on $(_l) = $(HOST_AR) $(HOST_ARFLAGS) ; 386 RANLIB on $(_l) = $(HOST_RANLIB) ; 387 } else { 388 AR on $(_l) = $(TARGET_AR) $(TARGET_ARFLAGS) ; 389 RANLIB on $(_l) = $(TARGET_RANLIB) ; 390 } 391 392 # library depends on its member objects 393 394 if $(KEEPOBJS) 395 { 396 LocalDepends obj : $(_s) ; 397 } 398 399 LocalDepends lib : $(_l) ; 400 401 # Set LOCATE for the library and its contents. The bound 402 # value shows up as $(NEEDLIBS) on the Link actions. 403 # For compatibility, we only do this if the library doesn't 404 # already have a path. 405 406 if ! $(_l:D) 407 { 408 # locate the library only, if it hasn't been located yet 409 local dir = $(LOCATE[1]) ; 410 if ! $(dir) { 411 MakeLocateDebug $(_l) ; 412 dir = [ on $(_l) return $(LOCATE[1]) ] ; 413 # Note: The "on ..." is necessary, since our environment 414 # isn't changed by MakeLocateDebug. 415 } 416 MakeLocate $(_l)($(_s:BS)) : $(dir) ; 417 } 418 419 if $(NOARSCAN) 420 { 421 # If we can't scan the library to timestamp its contents, 422 # we have to just make the library depend directly on the 423 # on-disk object files. 424 425 Depends $(_l) : $(_s) ; 426 } 427 else 428 { 429 # If we can scan the library, we make the library depend 430 # on its members and each member depend on the on-disk 431 # object file. 432 433 Depends $(_l) : $(_l)($(_s:BS)) ; 434 435 for _i in $(_s) 436 { 437 Depends $(_l)($(_i:BS)) : $(_i) ; 438 } 439 } 440 441 LocalClean clean : $(_l) ; 442 443 # bonefish: Not needed on the supported platforms. Maybe later... 444 # if $(CRELIB) { CreLib $(_l) : $(_s[1]) ; } 445 446 Archive $(_l) : $(_s) ; 447 448 if $(RANLIB) { Ranlib $(_l) ; } 449 450 # If we can't scan the library, we have to leave the .o's around. 451 452 if ! ( $(KEEPOBJS) || $(NOARSCAN) || $(NOARUPDATE) ) { 453 RmTemps $(_l) : $(_s) ; 454 } 455 } 456} 457 458rule Main 459{ 460 local target = $(1) ; 461 local sources = [ FGristFiles $(2) ] ; 462 local objects = $(sources:S=$(SUFOBJ)) ; 463 464 InheritPlatform $(objects) : $(target) ; 465 MainFromObjects $(target) : $(objects) ; 466 Objects $(sources) ; 467} 468 469rule MainFromObjects 470{ 471 local _s _t ; 472 473 # Add grist to file names 474 # Add suffix to exe 475 476 _s = [ FGristFiles $(>) ] ; 477 _t = [ FAppendSuffix $(<) : $(SUFEXE) ] ; 478 479 # so 'jam foo' works when it's really foo.exe 480 481 if $(_t) != $(<) 482 { 483 Depends $(<) : $(_t) ; 484 NotFile $(<) ; 485 } 486 487 # make compiled sources a dependency of target 488 489 LocalDepends exe : $(_t) ; 490 Depends $(_t) : $(_s) ; 491 MakeLocateDebug $(_t) ; 492 493 LocalClean clean : $(_t) ; 494 495 Link $(_t) : $(_s) ; 496} 497 498# Override Jam 2.5rc3 MakeLocate and MkDir to deal more intelligently 499# with grist set on the supplied directory name. 500rule MakeLocate 501{ 502 local dir = $(2[1]) ; 503 504 if $(dir) 505 { 506 if ! $(dir:G) { 507 dir = $(dir:G=dir) ; 508 } 509 LOCATE on $(1) += $(dir:G=) ; # don't relocate once located 510 Depends $(1) : $(dir) ; 511 MkDir $(dir) ; 512 } 513} 514 515rule MkDir 516{ 517 local dir = $(<) ; 518 if ! $(dir:G) { 519 dir = $(dir:G=dir) ; 520 } 521 522 # make this and all super directories 523 while true { 524 # If dir exists, don't update it 525 # Do this even for $(DOT). 526 NoUpdate $(dir) ; 527 528 # Bail out when reaching the CWD (".") or a directory we've already 529 # made. 530 if $(dir:G=) = $(DOT) || $($(dir:G=)-mkdir) { 531 return ; 532 } 533 534 local s ; 535 536 # Cheesy gate to prevent multiple invocations on same dir 537 # MkDir1 has the actions 538 # Arrange for jam dirs 539 540 $(dir:G=)-mkdir = true ; 541 MkDir1 $(dir) ; 542 LocalDepends dirs : $(dir) ; 543 544 # Recursively make parent directories. 545 # $(dir:P) = $(dir)'s parent, & we recurse until root 546 547 s = $(dir:P) ; # parent keeps grist 548 549 if $(s:G=) && $(s) != $(dir) { 550 Depends $(dir) : $(s) ; 551 dir = $(s) ; 552 } else if $(s) { 553 NotFile $(s) ; 554 break ; 555 } 556 } 557} 558 559rule ObjectCcFlags 560{ 561 # supports inheriting the global variable value 562 563 local file ; 564 for file in [ FGristFiles $(1:S=$(SUFOBJ)) ] { 565 CCFLAGS on $(file) = [ on $(file) return $(CCFLAGS) ] $(2) ; 566 } 567} 568 569rule ObjectC++Flags 570{ 571 # supports inheriting the global variable value 572 573 local file ; 574 for file in [ FGristFiles $(1:S=$(SUFOBJ)) ] { 575 C++FLAGS on $(file) = [ on $(file) return $(C++FLAGS) ] $(2) ; 576 } 577} 578 579rule ObjectDefines 580{ 581 # supports inheriting the global variable value and multiple files 582 583 if $(2) { 584 local file ; 585 for file in [ FGristFiles $(1:S=$(SUFOBJ)) ] { 586 DEFINES on $(file) = [ on $(file) return $(DEFINES) ] $(2) ; 587 CCDEFS on $(file) = [ on $(file) FDefines $(DEFINES) ] ; 588 } 589 } 590} 591 592rule ObjectHdrs 593{ 594 # ObjectHdrs <sources or objects> : <headers> : <gristed objects> 595 # Note: Parameter 3 <gristed objects> is an extension. 596 597 local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] $(3) ; 598 local headers = $(2) ; 599 600 local file ; 601 for file in $(objects) { 602 on $(file) { 603 local localHeaders = $(HDRS) $(headers) ; 604 SYSHDRS on $(file) = $(localHeaders) ; 605 606 # reformat ASHDRS and CCHDRS 607 local fileHeaders ; 608 609 if $(PLATFORM) = host { 610 fileHeaders = 611 [ FIncludes $(localHeaders) : $(HOST_LOCAL_INCLUDES_OPTION) ] 612 $(HOST_INCLUDES_SEPARATOR) 613 [ FSysIncludes $(SYSHDRS) 614 : $(HOST_SYSTEM_INCLUDES_OPTION) ] ; 615 } else { 616 fileHeaders = 617 [ FIncludes $(localHeaders) : $(TARGET_LOCAL_INCLUDES_OPTION) ] 618 $(TARGET_INCLUDES_SEPARATOR) 619 [ FSysIncludes $(SYSHDRS) 620 : $(TARGET_SYSTEM_INCLUDES_OPTION) ] ; 621 } 622 623 ASHDRS on $(file) = $(fileHeaders) ; 624 CCHDRS on $(file) = $(fileHeaders) ; 625 } 626 } 627} 628 629# Overridden to avoid calling SubDir for a directory twice (in SubInclude 630# and from the Jamfile in the directory). 631rule SubInclude 632{ 633 # SubInclude TOP d1 ... ; 634 # 635 # Include a subdirectory's Jamfile. 636 637 if ! $($(<[1])) 638 { 639 Exit SubInclude $(<[1]) without prior SubDir $(<[1]) ; 640 } 641 642 # Set up the config variables for the subdirectory. 643 local config = [ ConfigObject $(1) ] ; 644 645 __configured = ; 646 if ! [ on $(config) return $(__configured) ] { 647 # No custom configuration defined for the subdir. We use the variable 648 # values inherited by the closest ancestor. 649 config = $(HAIKU_INHERITED_SUBDIR_CONFIG) ; 650 } 651 652 on $(config) { 653 include [ FDirName $($(1[1])) $(1[2-) $(JAMFILE) ] ; 654 } 655} 656