1# Vanilla Jam compatibility 2if ! $(INVOCATION_SUBDIR_SET) { 3 4 rule FIsPrefix 5 { 6 # FIsPrefix <a> : <b> ; 7 # Returns true, if list <a> is a prefix (a proper one or equal) of 8 # list <b>, an empty list otherwise. 9 local a = $(1) ; 10 local b = $(2) ; 11 while $(a) && $(a[1]) = $(b[1]) { 12 a = $(a[2-]) ; 13 b = $(b[2-]) ; 14 } 15 16 if $(a) { 17 return ; 18 } else { 19 return true ; 20 } 21 } 22 23 rule LocalClean { Clean $(1) : $(2) ; } 24 25 rule LocalDepends { Depends $(1) : $(2) ; } 26 27} # vanilla Jam compatibility 28 29# The directory for build system specific files 30OBOS_BUILD_DIR = [ FDirName $(OBOS_TOP) build ] ; 31 32# Cache files for header scanning and jamfile caching 33HCACHEFILE = header_cache ; 34JCACHEFILE = jamfile_cache ; 35LOCATE on $(HCACHEFILE) $(JCACHEFILE) = $(OBOS_BUILD_DIR) ; 36 37# Include BuildConfig 38{ 39 local buildConfig = [ GLOB $(OBOS_BUILD_DIR) : BuildConfig ] ; 40 if ! $(buildConfig) 41 { 42 ECHO "No BuildConfig found in $(OBOS_BUILD_DIR)!" ; 43 EXIT "Run ./configure in the source tree's root directory first!" ; 44 } 45 LOCATE on BuildConfig = $(OBOS_BUILD_DIR) ; 46 include BuildConfig ; 47} 48 49# Save the platform default headers. 50PLATFORM_DEFAULT_HEADERS = $(HDRS) ; 51 52# We do not include any local BeOS system headers by default 53CCFLAGS += -nostdinc ; 54C++FLAGS += -nostdinc ; 55 56# Determine if we're building on PPC or x86 57# Determine mimetype of executable 58# Cross compiling can come later 59 60TARGET_CPU ?= $(OSPLAT:L) ; 61OBOS_VERSION ?= R1 ; 62 63switch $(TARGET_CPU) { 64 case ppc : 65 { 66 if $(METROWERKS) { 67 # at least parts of OpenBeOS still can be compiled with 68 # the Metrowerks compiler on BeOS/PPC 69 OBOS_TARGET_TYPE ?= "application/x-be-executable" ; 70 } else { 71 OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ; 72 } 73 DEFINES += __POWERPC__ ; 74 OBOS_BOOT_PLATFORM = openfirmware ; 75 } 76 case x86 : 77 { 78 # nothing special to do here... 79 OBOS_BOOT_PLATFORM = bios_ia32 ; 80 } 81 case * : 82 Exit "Currently unsupported build platform:" $(TARGET_CPU) ; 83} 84 85# set target specific variables 86{ 87 #Echo "Building for" $(TARGET_CPU) ; 88 89 OBOS_TARGET ?= $(TARGET_CPU).$(OBOS_VERSION) ; 90 OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ; 91 OBOS_ARCH ?= $(TARGET_CPU) ; 92 OBOS_TARGET_DEFINE ?= "ARCH_"$(TARGET_CPU) ; 93} 94 95# Disable warnings only if WARNINGS is set to 0 96# Should be enabled by default later 97# 98WARNINGS ?= 1 ; 99if $(WARNINGS) = 1 { 100 # For an explanation of the different warning options, see: 101 # http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html 102 # to get even more warnings, add: 103 # -Wwrite-strings (doesn't work well with some Be headers) 104 # -Wundef (dito) 105 # -Wconversion (gets you many warnings about implicit conversions) 106 # -W (gets you even more warnigs) 107 CCFLAGS += -Wall -Wno-multichar -Wmissing-prototypes ; 108 CCFLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ; 109 C++FLAGS += -Wall -Wno-multichar -Wmissing-prototypes -Wno-ctor-dtor-privacy -Woverloaded-virtual ; 110 C++FLAGS += -Wpointer-arith -Wcast-align -Wsign-compare ; 111} else { 112 CCFLAGS += -Wno-multichar ; 113 C++FLAGS += -Wno-multichar ; 114} 115 116# standard kernel C/C++ flags 117KERNEL_CCFLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ; 118KERNEL_CCFLAGS += -fno-builtin -D$(OBOS_TARGET_DEFINE) ; 119KERNEL_CCFLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) ; 120KERNEL_C++FLAGS ?= -Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc ; 121KERNEL_C++FLAGS += -fno-builtin -fno-exceptions -fno-rtti -D$(OBOS_TARGET_DEFINE) ; 122KERNEL_C++FLAGS += -DBOCHS_DEBUG_HACK=$(BOCHS_DEBUG_HACK) ; 123 124# We might later want to introduce debug levels or handle the whole issue 125# differently. For now there's only on or off. 126# 127DEBUG ?= 0 ; 128if $(DEBUG) != 0 { 129 OPTIM ?= -O0 ; 130 CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ; 131 C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ; 132 KERNEL_CCFLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ; 133 KERNEL_C++FLAGS += -g [ FDefines DEBUG=$(DEBUG) ] ; 134 LINKFLAGS += -g ; 135} else { 136 OPTIM ?= -O2 ; 137} 138# 139# To disable for the tests OPTIM and DEBUG are overridden, set the environment 140# variable NO_TEST_DEBUG. 141 142# Instructs the Library rule to not make its object files temporary. 143# This is needed as some objects are used in a static library and for an 144# executable. 145KEEPOBJS = true ; 146 147# under BeOS use copyattr instead of cp 148if $(OS) = BEOS 149{ 150 CP = copyattr --data ; 151} 152 153# If no OBOS_OBJECT_TARGET is not defined yet, use our default directory and 154# include our "OBOS_TARGET" as subdirectory in there (to prevent different 155# builds mixing objects from different targets). 156if ! $(OBOS_OBJECT_TARGET) { 157 OBOS_OBJECT_TARGET ?= [ FDirName $(OBOS_TOP) objects $(OBOS_TARGET) ] ; 158} 159 160# If no OBOS_DISTRO_TARGET is not defined yet, use our default directory and 161# include our "OBOS_TARGET" as subdirectory in there (to prevent different 162# builds mixing executables from different targets). 163if ! $(OBOS_DISTRO_TARGET) { 164 OBOS_DISTRO_TARGET ?= [ FDirName $(OBOS_TOP) distro $(OBOS_TARGET) ] ; 165} 166 167# Set our version number if not already set and mark it as a developer build 168if ! $(OBOS_BUILD_VERSION) { 169 OBOS_BUILD_VERSION ?= "1 0 0 a 1" ; 170 OBOS_BUILD_DESCRIPTION ?= "Developer Build" ; 171} 172 173# If OBOS_BUILD_VERSION is set, but OBOS_BUILD_DESCRIPTION isn't, mark it as 174# an unknown build. 175if ! $(OBOS_BUILD_DESCRIPTION) { 176 OBOS_BUILD_DESCRIPTION ?= "Unknown Build" ; 177} 178 179# Relative subdirs for distro dir 180OBOS_ADDON_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system add-ons ] ; 181OBOS_APPS_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos apps ] ; 182OBOS_BIN_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos bin ] ; 183OBOS_ETC_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos etc ] ; 184OBOS_FONTS_DIR ?= [ FDirName $(OBOS_ETC_DIR) fonts ] ; 185OBOS_KERNEL_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system ] ; 186OBOS_PREFS_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos preferences ] ; 187OBOS_SERVER_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system servers ] ; 188OBOS_SHLIB_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ; 189OBOS_STLIB_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) develop lib 190 $(OBOS_ARCH) ] ; 191OBOS_TEST_DIR ?= [ FDirName $(OBOS_TOP) tests ] ; 192 193OBOS_KERNEL_CONFIG = config.$(OBOS_ARCH).ini ; 194OBOS_KERNEL = kernel.$(OBOS_ARCH) ; 195OBOS_FLOPPY = floppy.$(OBOS_ARCH) ; 196 197rule SetupIncludes 198{ 199 # XXX add "opengl" later 200 local os_includes = add-ons add-ons/file_system add-ons/graphics add-ons/input_server add-ons/screen_saver add-ons/tracker app device drivers game interface kernel media mail midi midi2 net storage support translation ; 201 202 # Overwrite any exiting content when changing HDRS. This rule may be invoked multiple times. 203 204 # Use headers directory, to allow to do things like include <posix/string.h> 205 HDRS = [ FDirName $(OBOS_TOP) headers ] ; 206 207 # Use posix headers directory 208 HDRS += [ FDirName $(OBOS_TOP) headers posix ] ; 209 210 # Use public OS header directories 211 HDRS += [ PublicHeaders $(os_includes) ] ; 212 213 # Used as a fallback, the R5 header directories (we should remove this as soon as possible) 214 HDRS += /boot/develop/headers/posix /boot/develop/headers/cpp ; 215 216 # The platform dependent headers. 217 HDRS += $(PLATFORM_HEADERS) ; 218} 219 220rule SetupR5Includes 221{ 222 # Unsets HDRS, so that the OBOS headers do not `shadow' the system headers. 223 HDRS = ; 224} 225 226rule SetupDefaultIncludes 227{ 228 # Resets HDRS to the default headers for the build platform. 229 HDRS = $(PLATFORM_DEFAULT_HEADERS) ; 230} 231 232#------------------------------------------------------------------------------- 233# Things Jam needs in order to work :) 234#------------------------------------------------------------------------------- 235 236rule Object 237{ 238 # This is basically the original Jambase 2.4 Object rule stripped by 239 # comments. Only the final switch statement has been changed to allow 240 # intermediate C++ files for Yacc and Lex. 241 242 LocalClean clean : $(<) ; 243 244 MakeLocate $(<) : $(LOCATE_TARGET) ; 245 SEARCH on $(>) = $(SEARCH_SOURCE) ; 246 247 HDRS on $(<) = $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ; 248 249 HDRRULE on $(>) = HdrRule ; 250 HDRSCAN on $(>) = $(HDRPATTERN) ; 251 HDRSEARCH on $(>) = 252 $(SEARCH_SOURCE:E) $(SUBDIRHDRS) $(HDRS) $(STDHDRS) ; 253 254 HDRGRIST on $(>) = $(HDRGRIST) ; 255 256 DEFINES on $(<) += $(DEFINES) ; 257 258 # if source is not .c, generate .c with specific rule 259 260 switch $(>:S) 261 { 262 case .asm : As $(<) : $(>) ; 263 case .c : Cc $(<) : $(>) ; 264 case .C : C++ $(<) : $(>) ; 265 case .cc : C++ $(<) : $(>) ; 266 case .cpp : C++ $(<) : $(>) ; 267 case .f : Fortran $(<) : $(>) ; 268 case .l : if [ on $(2) return $(GENERATE_C++) ] { 269 C++ $(<) : $(<:S=.cpp) ; 270 LexC++ $(<:S=.cpp) : $(>) ; 271 } else { 272 Cc $(<) : $(<:S=.c) ; 273 Lex $(<:S=.c) : $(>) ; 274 } 275 case .s : As $(<) : $(>) ; 276 case .y : if [ on $(2) return $(GENERATE_C++) ] { 277 C++ $(<) : $(<:S=.cpp) ; 278 Bison $(<:S=.cpp) : $(>) ; 279 } else { 280 Cc $(<) : $(<:S=$(YACCGEN)) ; 281 Yacc $(<:S=$(YACCGEN)) : $(>) ; 282 } 283 case * : UserObject $(<) : $(>) ; 284 } 285} 286 287rule UserObject 288{ 289 switch $(2) 290 { 291 case *.S : assemble $(1) : $(2) ; 292 case *.o : return ; 293 case * : ECHO "unknown suffix on" $(2) ; 294 } 295} 296 297# Override the default to give "prettier" command lines. 298actions Cc 299{ 300 $(CC) -c "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ; 301} 302 303actions C++ 304{ 305 $(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ; 306} 307 308 309#------------------------------------------------------------------------------- 310# General High-level OBOS target rules 311#------------------------------------------------------------------------------- 312 313rule App 314{ 315 # App <name> : <sources> : <libraries> ; 316 SetupIncludes ; 317 SetupObjectsDir ; 318 Main $(1) : $(2) ; 319 MakeLocate $(1) : $(OBOS_APPS_DIR) ; 320 LinkSharedOSLibs $(1) : $(3) ; 321 LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] 322 -Xlinker -soname=_APP_ ; 323} 324 325rule BinCommand 326{ 327 # BinCommand <name> : <sources> : <libraries> ; 328 SetupIncludes ; 329 SetupObjectsDir ; 330 Main $(1) : $(2) ; 331 MakeLocate $(1) : $(OBOS_BIN_DIR) ; 332 LinkSharedOSLibs $(1) : $(3) ; 333 LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] 334 -Xlinker -soname=_APP_ ; 335} 336 337rule StdBinCommands 338{ 339 # StdBinCommands <sources> : <libs> ; 340 SetupIncludes ; 341 SetupObjectsDir ; 342 local libs = $(2) ; 343 local source ; 344 for source in $(1) 345 { 346 local target = $(source:S=) ; 347 target = [ FGristFiles $(target) ] ; 348 349 BinCommand $(target) : $(source) : $(libs) ; 350 } 351} 352 353rule Preference 354{ 355 # Preference <name> : <sources> : <libraries> ; 356 SetupIncludes ; 357 SetupObjectsDir ; 358 Main $(1) : $(2) ; 359 MakeLocate $(1) : $(OBOS_PREFS_DIR) ; 360 LinkSharedOSLibs $(1) : $(3) ; 361 LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] 362 -Xlinker -soname=_APP_ ; 363} 364 365rule Server 366{ 367 # Server <name> : <sources> : <libraries> ; 368 369 SetupIncludes ; 370 SetupObjectsDir ; 371 Main $(1) : $(2) ; 372 MakeLocate $(1) : $(OBOS_SERVER_DIR) ; 373 LinkSharedOSLibs $(1) : $(3) ; 374 LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] 375 -Xlinker -soname=_APP_ ; 376} 377 378# test pseudo targets 379NOTFILE obostests ; 380NOTFILE r5tests ; 381 382rule CommonTestLib 383{ 384 # CommonTestLib <target> : <sources> : <obos libraries> 385 # : <r5 libraries> : <test libraries> : <public headers>; 386 # Builds a unit test for both OBOS and R5 modules. 387 # <target> The name of the target. 388 # <sources> The list of sources. 389 # <obos libraries> A list of link libraries for the OBOS tests (as passed 390 # to LinkSharedOSLibs). 391 # <r5 libraries> A list of link libraries for the R5 tests (as passed 392 # to LinkSharedOSLibs). 393 # <test libraries> A list of link libraries for both OBOS tests and R5 tests 394 # that have a common name (i.e. specify libx.so and the OBOS tests will link 395 # to libx.so and the R5 tests will link to libx_r5.so). 396 # <public headers> A list of public header dirs (as passed to 397 # UsePublicHeaders). 398 399 TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester lib ] : $(3) $(5) : $(6) ; 400 R5TestLib $(1) : $(2) : [ FDirName $(OBOS_TEST_DIR) unittester_r5 lib ] : $(4) [ R5SharedLibraryNames $(5) ] ; 401} 402 403rule TestLib 404{ 405 # TestLib <target> : <sources> : <dest> : <libraries> : <public headers> 406 # Builds a unit test library for an OBOS module. 407 # <target> The name of the target. 408 # <sources> The list of sources. 409 # <dest> The directory for the target (as passed to FDirName). 410 # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 411 # <public headers> A list of public header dirs (as passed to 412 # UsePublicHeaders). 413 414 local target = $(1) ; 415 local sources = $(2) ; 416 local dest = $(3) ; 417 local libraries = $(4) ; 418 local headerDirs = $(5) ; 419 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 420 421 # Our Main replacement. 422 MainFromObjects $(target) : $(objects) ; 423 TestObjects $(sources) : $(headerDirs) ; 424 425 MakeLocate $(target) : $(dest) ; 426 Depends $(target) : libcppunit.so ; 427 Depends obostests : $(target) ; 428 LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ; 429 LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ; 430} 431 432rule R5TestLib 433{ 434 # R5TestLib <target> : <sources> : <dest> : <libraries> 435 # Builds a unit test for an R5 module. "_r5" is appended to the object 436 # and the target name. 437 # <target> The name of the target. 438 # <sources> The list of sources. 439 # <dest> The directory for the target (as passed to FDirName). 440 # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 441 442 local target = $(1:B)_r5$(1:S) ; 443 local sources = $(2) ; 444 local dest = $(3) ; 445 local libraries = $(4) ; 446 local objects = [ R5ObjectNames $(sources) ] ; 447 448 # Our Main replacement. 449 MainFromObjects $(target) : $(objects) ; 450 TestObjects $(sources) : : true ; 451 452 MakeLocate $(target) : $(dest) ; 453 Depends $(target) : libcppunit.so ; 454 Depends r5tests : $(target) ; 455 LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ; 456 LINKFLAGS on $(target) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(target)\" ; 457} 458 459rule CommonUnitTest 460{ 461 # CommonUnitTest <target> : <sources> : <dest> : <obos libraries> 462 # : <r5 libraries> : <public headers>; 463 # Builds a unit test for both OBOS and R5 modules. 464 # <target> The name of the target. 465 # <sources> The list of sources. 466 # <dest> The directory for the target (as passed to FDirName). 467 # <obos libraries> A list of link libraries for the OBOS tests (as passed 468 # to LinkSharedOSLibs). 469 # <r5 libraries> A list of link libraries for the R5 tests (as passed 470 # to LinkSharedOSLibs). 471 # <public headers> A list of public header dirs (as passed to 472 # UsePublicHeaders). 473 474 UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ; 475 R5UnitTest $(1) : $(2) : $(3) : $(5) ; 476} 477 478rule UnitTest 479{ 480 # UnitTest <target> : <sources> : <dest> : <libraries> : <public headers> 481 # Builds a unit test for an OBOS module. 482 # <target> The name of the target. 483 # <sources> The list of sources. 484 # <dest> The directory for the target (as passed to FDirName). 485 # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 486 # <public headers> A list of public header dirs (as passed to 487 # UsePublicHeaders). 488 489 local target = $(1) ; 490 local sources = $(2) ; 491 local dest = $(3) ; 492 local libraries = $(4) ; 493 local headerDirs = $(5) ; 494 local objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 495 496 # Our Main replacement. 497 MainFromObjects $(target) : $(objects) ; 498 TestObjects $(sources) : $(headerDirs) ; 499 500 MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ; 501 Depends $(target) : libcppunit.so ; 502 Depends obostests : $(target) ; 503 LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ; 504} 505 506rule R5UnitTest 507{ 508 # R5UnitTest <target> : <sources> : <dest> : <libraries> 509 # Builds a unit test for an R5 module. "_r5" is appended to the object 510 # and the target name. 511 # <target> The name of the target. 512 # <sources> The list of sources. 513 # <dest> The directory for the target (as passed to FDirName). 514 # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 515 516 local target = $(1)_r5 ; 517 local sources = $(2) ; 518 local dest = $(3) ; 519 local libraries = $(4) ; 520 local objects = [ R5ObjectNames $(sources) ] ; 521 522 # Our Main replacement. 523 MainFromObjects $(target) : $(objects) ; 524 TestObjects $(sources) : : true ; 525 526 MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ; 527 Depends $(target) : libcppunit.so ; 528 Depends r5tests : $(target) ; 529 LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ; 530} 531 532rule R5ObjectNames 533{ 534 # R5ObjectNames <sources> ; 535 # Returns a list of gristed object names given a list of source file names. 536 # Moreover each object names gets "_r5" inserted before the object suffix. 537 local objects = $(1:S=)_r5 ; 538 return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ; 539} 540 541rule R5Objects 542{ 543 # R5Objects <sources> 544 # Similar to Objects, but appends "_r5" to the object file names and 545 # removes `-nostdinc' from the CC and C++ flags to enable system headers. 546 # <sources> The source files. 547 548 # Remove `-nostdinc' from CCFLAGS and C++FLAGS. 549 local oldCCFLAGS = $(CCFLAGS) ; 550 local oldC++FLAGS = $(C++FLAGS) ; 551 CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ; 552 C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ; 553 554 local sources = $(1) ; 555 local source ; 556 for source in [ FGristFiles $(sources) ] 557 { 558 local object = [ R5ObjectNames $(source) ] ; 559 Object $(object) : $(source) ; 560 LocalDepends obj : $(object) ; 561 } 562 563 # Reset CCFLAGS and C++FLAGS to original values. 564 CCFLAGS = $(oldCCFLAGS) ; 565 C++FLAGS = $(oldC++FLAGS) ; 566} 567 568rule TestObjects 569{ 570 # TestLib <sources> : <public headers> : <r5> 571 # Compiles objects for tests. 572 # <sources> The list of sources. 573 # <public headers> A list of public header dirs (as passed to 574 # UsePublicHeaders). 575 # <r5> If set, "_r5" is appended to the object file names and 576 # <public headers> is ignored. Furthermore the pre-processor macro 577 # TEST_R5 is defined, TEST_OBOS otherwise. 578 579 local sources = $(1) ; 580 local headerDirs = $(2) ; 581 local r5 = $(3) ; 582 local objects ; 583 584 # Turn optimization off. 585 if ! $(NO_TEST_DEBUG) { 586 local optim = $(OPTIM) ; 587 OPTIM = ; 588 } 589 590 SetupObjectsDir ; 591 592 # compile 593 if $(r5) { 594 SetupR5Includes ; 595 objects = [ R5ObjectNames $(sources) ] ; 596 R5Objects $(sources) ; 597 } else { 598 SetupIncludes ; 599 objects = [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 600 Objects $(sources) ; 601 } 602 603 # set headers/defines 604 UseCppUnitObjectHeaders $(sources) : $(objects) ; 605 if $(r5) { 606 ObjectsDefines $(objects) : TEST_R5 ; 607 } else { 608 UsePublicObjectHeaders $(sources) : $(headerDirs) : $(objects) ; 609 ObjectsDefines $(objects) : TEST_OBOS ; 610 } 611 612 if ! $(NO_TEST_DEBUG) { 613 # Turn debugging on. That is usually desired for test code. 614 ObjectCcFlags $(objects) : "-g" ; 615 ObjectC++Flags $(objects) : "-g" ; 616 617 # Turn optimization on again. 618 OPTIM = $(optim) ; 619 } 620} 621 622rule R5SharedLibraryNames 623{ 624 # R5SharedLibraryNames <sources> ; 625 # Returns a list of shared library names given a list of file names. NO 626 # GRISTING IS PERFORMED :-) However, each library names gets "_r5" inserted 627 # before the shared lib suffix. 628 return $(1:S=)_r5.so ; 629} 630 631rule SimpleTest 632{ 633 # UnitTest <target> : <sources> : <libraries> 634 # Builds a unit test for an OBOS module. 635 # <target> The name of the target. 636 # <sources> The list of sources. 637 # <dest> The directory for the target (as passed to FDirName). 638 # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 639 # <public headers> A list of public header dirs (as passed to 640 # UsePublicHeaders). 641 642 local target = $(1) ; 643 local sources = $(2) ; 644 local libraries = $(3) ; 645 local relPath = [ FRelPath src tests : $(SUBDIR_TOKENS) ] ; 646 647 # Turn optimization off. 648 if ! $(NO_TEST_DEBUG) { 649 local optim = $(OPTIM) ; 650 OPTIM = ; 651 } 652 653 SetupIncludes ; 654 SetupObjectsDir ; 655 MakeLocateObjects $(sources) ; 656 Main $(target) : $(sources) ; 657 MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ; 658 Depends obostests : $(target) ; 659 LinkSharedOSLibs $(target) : $(libraries) ; 660 ObjectsDefines $(sources) : TEST_OBOS ; 661 if ! $(NO_TEST_DEBUG) { 662 # Turn debugging on. That is usually desired for test code. 663 ObjectCcFlags $(sources) : "-g" ; 664 ObjectC++Flags $(sources) : "-g" ; 665 666 # Turn optimization on again. 667 OPTIM = $(optim) ; 668 } 669} 670 671rule Addon 672{ 673 # Addon <name> : <relpath> : <sources> : <is executable> : <libraries> ; 674 # <name>: Name of the add-on. 675 # <relpath>: Path where the add-on shall live relative to the add-on dir. 676 # <sources>: Source files. 677 # <is executable>: true, if the target shall be executable as well. 678 # <libraries>: Libraries to be linked against. 679 680 local isExecutable = $(4) ; 681 682 SetupIncludes ; 683 SetupObjectsDir ; 684 Main $(1) : $(3) ; 685 686 # Create output dir path for addon 687 local targetdir; 688 targetdir = [ FDirName $(OBOS_ADDON_DIR) $(2) ] ; 689 690 MakeLocate $(1) : $(targetdir) ; 691 692 local linkFlags = -Xlinker -soname=\"$(1)\" ; 693 if $(isExecutable) != true { 694 linkFlags = -nostart $(linkFlags) ; 695 } 696 LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] $(linkFlags) ; 697 LinkSharedOSLibs $(1) : $(5) ; 698} 699 700rule R5KernelAddon 701{ 702 # R5KernelAddon <name> : <relpath> : <sources> ; 703 704 local sources = $(3) ; 705 706 Addon $(1) : $(2) : $(3) ; 707 ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ; 708 ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic 709 -fno-exceptions -fno-rtti ; 710 LINKFLAGS on $(1) = [ on $(1) return $(LINKFLAGS) ] -nostdlib ; 711 LinkSharedOSLibs $(1) : /boot/develop/lib/x86/_KERNEL_ ; 712} 713 714rule Translator 715{ 716 # Translator <name> : <sources> : <libraries> ; 717 SetupIncludes ; 718 SetupObjectsDir ; 719 Main $(1) : $(2) ; 720 LinkSharedOSLibs $(1) : $(3) ; 721 722 # Create output dir path for translator 723 local targetdir; 724 targetdir = [ FDirName $(OBOS_ADDON_DIR) Translators ] ; 725 MakeLocate $(1) : $(targetdir) ; 726} 727 728rule MakeLocateObjects 729{ 730 # MakeLocateObjects <sources_or_objects> ; 731 732 local _objs = [ FGristFiles $(1:S=$(SUFOBJ)) ] ; 733 734 for o in $(_objs) 735 { 736 local dir = $(o:D) ; 737 if $(dir) { 738 MakeLocate $(o) : [ FDirName $(LOCATE_TARGET) $(dir) ] ; 739 } else { 740 MakeLocate $(o) : $(LOCATE_TARGET) ; 741 } 742 } 743} 744 745rule StaticLibrary 746{ 747 # StaticLibrary <name> : <sources> [ : <target dir> ] ; 748 # Creates a static library from sources. 749 # <name>: Basename of the library, without leading "lib" and trailing ".a". 750 # <source>: List of source files. 751 # <target dir>: Directory into which the library shall be placed. Defaults 752 # to the standard directory for static libs. 753 # 754 local lib = lib$(1)$(SUFLIB) ; 755 SetupIncludes ; 756 SetupObjectsDir ; 757 MakeLocateObjects $(2) ; 758 Library $(lib) : $(2) ; 759 local targetDir = $(3) ; 760 if ! $(targetDir) { 761 targetDir = $(OBOS_STLIB_DIR) ; 762 } 763 MakeLocate $(lib) : $(targetDir) ; 764 765 # If KEEPOBJS is set, Library doesn't make the library depend on 766 # `lib'. 767 if $(KEEPOBJS) { 768 LocalDepends lib : $(lib) ; 769 } 770} 771 772rule R5KernelStaticLibrary 773{ 774 # R5KernelStaticLibrary <name> : <sources> ; 775 776 local lib = lib$(1)$(SUFLIB) ; 777 local sources = $(2) ; 778 779 SetupIncludes ; 780 SetupObjectsDir ; 781 MakeLocateObjects $(sources) ; 782 Library $(lib) : $(sources) ; 783 ObjectCcFlags $(sources) : -D_KERNEL_MODE=1 -no-fpic ; 784 ObjectC++Flags $(sources) : -D_KERNEL_MODE=1 -no-fpic 785 -fno-exceptions -fno-rtti ; 786} 787 788rule MergeObjectFromObjects 789{ 790 # MergeObjectFromObjects <name> : <objects> ; 791 local objects = [ FGristFiles $(2) ] ; 792 MakeLocate $(1) : $(LOCATE_TARGET) ; 793 Depends $(1) : $(objects) ; 794 LINK on $(1) = ld ; 795 MergeObjectFromObjects1 $(1) : $(objects) ; 796} 797 798actions MergeObjectFromObjects1 799{ 800 $(LINK) -r $(2) -o $(1) ; 801} 802 803rule MergeObject 804{ 805 # MergeObject <name> : <sources> ; 806 SetupIncludes ; 807 SetupObjectsDir ; 808 MakeLocateObjects $(2) ; 809 Objects $(2) ; 810 MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) ; 811} 812 813rule SharedLibraryFromObjects 814{ 815 # SharedLibraryFromObjects <name> : <objects> : <libraries> ; 816 local _lib = lib$(1).so ; 817 MainFromObjects $(_lib) : $(2) ; 818 MakeLocate $(_lib) : $(OBOS_SHLIB_DIR) ; 819 LINKFLAGS on $(_lib) = [ on $(_lib) return $(LINKFLAGS) ] 820 -nostart -Xlinker -soname=\"$(_lib)\" ; 821 LinkSharedOSLibs $(_lib) : $(3) ; 822} 823 824rule SharedLibrary 825{ 826 # SharedLibrary <name> : <sources> : <libraries> ; 827 SetupIncludes ; 828 SetupObjectsDir ; 829 MakeLocateObjects $(2) ; 830 Objects $(2) ; 831 SharedLibraryFromObjects $(1) : $(2:S=$(SUFOBJ)) : $(3) ; 832} 833 834rule LinkSharedOSLibs 835{ 836 # LinkSharedOSLibs <name> : <libs> ; 837 # Valid elements for <libs> are e.g. "be" or "libopenbeos.so" or 838 # "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy 839 # has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the 840 # file will be bound!), otherwise it is prefixed "-l" and added to 841 # LINKLIBS. If you want to specify a target that isn't a library and 842 # also has neither grist nor a dirname, you can prepend "<nogrist>" as 843 # grist; it will be stripped by this rule. 844 845 for i in $(>) 846 { 847 local isfile = ; 848 if $(i:D) || $(i:G) { 849 isfile = true ; 850 if $(i:G) = <nogrist> { 851 i = $(i:G=) ; 852 } 853 } else { 854 switch $(i:B) 855 { 856 # XXX: _APP_ and _KERNEL_ should not be needed for ELF. 857 case _APP_ : isfile = true ; 858 case _KERNEL_ : isfile = true ; 859 case *.so : isfile = true ; 860 case *.a : isfile = true ; 861 case lib* : isfile = true ; 862 case * : isfile = ; 863 } 864 } 865 if $(isfile) { 866 NEEDLIBS on $(1) = [ on $(1) return $(NEEDLIBS) ] $(i) ; 867 Depends $(1) : $(i) ; 868 } else { 869 LINKLIBS on $(1) = [ on $(1) return $(LINKLIBS) ] -l$(i) ; 870 } 871 } 872} 873 874rule LinkStaticOSLibs 875{ 876 # LinkStaticOSLibs <name> : <libs> ; 877 878 for i in $(>) 879 { 880 LINKLIBS on $(<) = $(LINKLIBS) -l $(i) ; 881 } 882} 883 884rule AddResources 885{ 886 # AddResources <name> : <resourcefiles> ; 887 888 local resfiles = [ FGristFiles $(2) ] ; 889 SEARCH on $(resfiles) += $(SEARCH_SOURCE) ; 890 891 for file in $(resfiles) { 892 if $(file:S) = .rdef { 893 local rdef = $(file) ; 894 file = $(rdef:S=.rsrc) ; 895 ResComp $(file) : $(rdef) ; 896 } 897 RESFILES on $(1) += $(file) ; 898 } 899} 900 901rule ResComp 902{ 903 # ResComp <resource file> : <rdef file> ; 904 # 905 # <resource file> and <rdef file> must be gristed. 906 907 SetupObjectsDir ; 908 909 SEARCH on $(2) += $(SEARCH_SOURCE) ; 910 MakeLocate $(1) : $(LOCATE_TARGET) ; 911 Depends $(1) : $(2) rc ; 912 LocalClean clean : $(1) ; 913 ResComp1 $(1) : rc $(2) ; 914} 915 916actions ResComp1 917{ 918 $(2[1]) -o $(1) $(2[2-]) 919} 920 921rule ObjectsDefines 922{ 923 # Like ObjectDefines, but allows multiple files to be supplied 924 local file ; 925 for file in $(1) { 926 ObjectDefines $(file) : $(2) ; 927 } 928} 929 930rule SourceHdrs 931{ 932 # SourceHdrs <sources> : <headers> [ : <gristed objects> ] ; 933 # 934 # Is a wrapper for ObjectHdrs, that passes <sources> and <headers> or, 935 # if supplied <objects> and <headers>, and also adjusts HDRSEARCH (not 936 # done by ObjectHdrs). 937 938 local sources = [ FGristFiles $(1) ] ; 939 local headers = $(2) ; 940 local objects = $(3) ; 941 942 local file ; 943 if $(objects) { 944 for file in $(objects) { 945 ObjectHdrs $(file) : $(headers) ; 946 } 947 } else { 948 for file in $(sources) { 949 ObjectHdrs $(file) : $(headers) ; 950 } 951 } 952 953 # Also add the header search dirs to HDRSEARCH. Note, that these dirs 954 # will be listed after the STDHDRS (if any), but that's better than not 955 # being listed at all. 956 HDRSEARCH on $(sources) += $(headers) ; 957} 958 959rule PublicHeaders 960{ 961 # PublicHeaders <group list> 962 # 963 # Returns the directory names for the public header dirs identified by 964 # <group list>. 965 966 local list = $(1) ; 967 local dirs = [ FDirName $(OBOS_TOP) headers os ] ; 968 969 for i in $(list) { 970 dirs += [ FDirName $(OBOS_TOP) headers os $(i) ] ; 971 } 972 return $(dirs) ; 973} 974 975rule PrivateHeaders 976{ 977 # PrivateHeaders <group list> 978 # 979 # Returns the directory names for the private header dirs identified by 980 # <group list>. 981 982 local list = $(1) ; 983 local dirs ; 984 for i in $(list) { 985 dirs += [ FDirName $(OBOS_TOP) headers private $(i) ] ; 986 } 987 return $(dirs) ; 988} 989 990rule LibraryHeaders 991{ 992 # LibraryHeaders <group list> 993 # 994 # Returns the directory names for the library header dirs identified by 995 # <group list>. 996 997 local list = $(1) ; 998 local dirs ; 999 for i in $(list) { 1000 dirs += [ FDirName $(OBOS_TOP) headers libs $(i) ] ; 1001 } 1002 return $(dirs) ; 1003} 1004 1005rule ArchHeaders 1006{ 1007 # usage: ArchHeaders <arch> ; 1008 # 1009 # <arch> specifies the architecture (e.g. x86). 1010 1011 return [ FDirName $(OBOS_TOP) headers private kernel arch $(1) ] ; 1012} 1013 1014rule UsePublicHeaders 1015{ 1016 # UsePublicHeaders <group list> ; 1017 # 1018 # Adds the public C header dirs given by <group list> to the header search 1019 # dirs of the subdirectory. 1020 # NOTE: This rule must be invoked *before* the rule that builds the 1021 # objects. 1022 1023 UseHeaders [ PublicHeaders $(1) ] ; 1024} 1025 1026rule UsePublicObjectHeaders 1027{ 1028 # UsePublicObjectHeaders <sources> : <group list> [ : <objects> ] ; 1029 # 1030 # Adds the public C header dirs given by <group list> to the header search 1031 # dirs of either the object targets of <sources> or if supplied to 1032 # <objects>. Also adjusts HDRSEARCH of <sources>. 1033 # NOTE: This rule must be invoked *after* the rule that builds the objects. 1034 1035 SourceHdrs $(1) : [ PublicHeaders $(2) ] : $(3) ; 1036} 1037 1038rule UsePrivateHeaders 1039{ 1040 # UsePrivateHeaders <group list> ; 1041 # 1042 # Adds the private C header dirs given by <group list> to the header search 1043 # dirs of the subdirectory. 1044 # NOTE: This rule must be invoked *before* the rule that builds the objects. 1045 1046 UseHeaders [ PrivateHeaders $(1) ] ; 1047} 1048 1049rule UsePrivateObjectHeaders 1050{ 1051 # UsePrivateObjectHeaders <sources> : <group list> [ : <objects> ] ; 1052 # 1053 # Adds the private C header dirs given by <group list> to the header search 1054 # dirs of either the object targets of <sources> or if supplied to 1055 # <objects>. Also adjusts HDRSEARCH of <sources>. 1056 # NOTE: This rule must be invoked *after* the rule that builds the objects. 1057 1058 SourceHdrs $(1) : [ PrivateHeaders $(2) ] : $(3) ; 1059} 1060 1061rule UseHeaders 1062{ 1063 # UseHeaders <headers> ; 1064 # 1065 # Adds the C header dirs <headers> to the header search 1066 # dirs of the subdirectory. 1067 # NOTE: This rule must be invoked *before* the rule that builds the objects. 1068 1069 local header ; 1070 for header in $(1) { 1071 SubDirHdrs $(header) ; 1072 } 1073} 1074 1075rule UseCppUnitHeaders 1076{ 1077 SubDirHdrs [ FDirName $(OBOS_TOP) headers tools cppunit ] ; 1078} 1079 1080rule UseCppUnitObjectHeaders 1081{ 1082 # UseCppUnitObjectHeaders <sources> [ : <objects> ] ; 1083 SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers tools cppunit ] : $(2) ; 1084} 1085 1086rule UseArchHeaders 1087{ 1088 # usage: UseArchHeaders <arch> ; 1089 # 1090 # <arch> specifies the architecture (e.g. x86). 1091 # NOTE: This rule must be invoked *before* the rule that builds the objects. 1092 1093 local headers = [ ArchHeaders $(1) ] ; 1094 local opt = -D$(OBOS_TARGET_DEFINE) ; 1095 1096 SubDirCcFlags $(opt) ; 1097 SubDirC++Flags $(opt) ; 1098 HDRS += $(headers) ; 1099} 1100 1101rule UseArchObjectHeaders 1102{ 1103 # usage: UseArchObjectHeaders <sources> : <arch> : [ <objects> ] ; 1104 # 1105 # <arch> specifies the architecture (e.g. x86). 1106 # <sources_or_objects> Source or object files. 1107 # NOTE: This rule must be invoked *after* the rule that builds the objects. 1108 1109 local sources = $(1) ; 1110 local headers = [ ArchHeaders $(2) ] ; 1111 local objects = $(3) ; 1112 local targets ; 1113 if $(objects) { 1114 targets = $(objects) ; 1115 } else { 1116 targets = $(sources) ; 1117 } 1118 local opt = -D$(OBOS_TARGET_DEFINE) ; 1119 1120 ObjectCcFlags $(targets) : $(opt) ; 1121 ObjectC++Flags $(targets) : $(opt) ; 1122 SourceHdrs $(sources) : $(headers) : $(objects) ; 1123} 1124 1125rule UsePosixHeaders 1126{ 1127 # XXX changed to do nothing 1128} 1129 1130rule UsePosixObjectHeaders 1131{ 1132 # UsePosixObjectHeaders <sources> [ : <objects> ] ; 1133 # 1134 # Adds the POSIX header dir to the header search 1135 # dirs of either the object targets of <sources> or if supplied to 1136 # <objects>. Also adjusts HDRSEARCH of <sources>. 1137 # NOTE: This rule must be invoked *after* the rule that builds the objects. 1138 1139 SourceHdrs $(1) : [ FDirName $(OBOS_TOP) headers posix ] : $(2) ; 1140} 1141 1142rule UseLibraryHeaders 1143{ 1144 # UseLibraryHeaders <group list> ; 1145 # 1146 # Adds the library header dirs given by <group list> to the header search 1147 # dirs of the subdirectory. 1148 # NOTE: This rule must be invoked *before* the rule that builds the objects. 1149 1150 UseHeaders [ LibraryHeaders $(1) ] ; 1151} 1152 1153rule SplitPath 1154{ 1155 # SplitPath <path> ; 1156 # Decomposes a path into its components. 1157 local path = $(1:G=) ; 1158 local components ; 1159 # $(path:D) for "/" is "/". Therefore the second condition. 1160 while $(path:D) && $(path:D) != $(path) 1161 { 1162 # Note: $(path:B) returns "." for "..", but $(path:D=) is fine. 1163 components = $(path:D=) $(components) ; 1164 path = $(path:D) ; 1165 } 1166 components = $(path) $(components) ; 1167 return $(components) ; 1168} 1169 1170rule PrependObjectHdrs 1171{ 1172 # PrependObjectHdrs <objects_or_sources> : <dirs> ; 1173 # Prepends <dirs> to the list of header search dirs of the objects 1174 # specified by <objects_or_sources>. The HDRS variable will not be 1175 # changed, only CCHDRS. 1176 # Note: A subsequent ObjectHdrs invocation will therefore undo the 1177 # effect of this rule. 1178 # NOTE: This is a hack. 1179 1180 local objects = [ FGristFiles $(1:S=$(SUFOBJ)) ] ; 1181 local dirs = $(2) ; 1182 for object in $(objects) { 1183 # Don't change HDRS to avoid screwing up the header scanning. 1184 PREPENDED_HDRS on $(object) 1185 = $(dirs) [ on $(object) return $(PREPENDED_HDRS) ] ; 1186 CCHDRS on $(object) 1187 = [ FIncludes [ on $(object) return $(PREPENDED_HDRS) $(HDRS) ] ] ; 1188 } 1189} 1190 1191rule SymLink 1192{ 1193 # SymLink <target> : <source> ; 1194 # Links <target> to <source>. 1195 # <source> is the exact link contents. No binding is done. 1196 LINKCONTENTS on $(1) = $(2) ; 1197 SymLink1 $(1) ; 1198 LocalDepends all : $(target) ; 1199} 1200 1201actions SymLink1 1202{ 1203 $(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)" 1204} 1205 1206rule RelSymLink 1207{ 1208 # RelSymLink <link> : <link target> 1209 # Creates a relative symbolic link from <link> to <link target>. 1210 # <link> and <link target> can be usual targets. They may have a grist 1211 # and don't need to have any dirname. Their LOCATE variables are used to 1212 # find their locations. 1213 1214 local target = $(1) ; 1215 local source = $(2) ; 1216 local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ; 1217 local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ; 1218 local sourcePath = $(source:G=) ; 1219 sourcePath = $(sourcePath:D=$(sourceDir)) ; 1220 local targetDirComponents = [ SplitPath $(targetDir) ] ; 1221 local sourceComponents = [ SplitPath $(sourcePath) ] ; 1222 1223 SymLink $(target) 1224 : [ FRelPath $(targetDirComponents) : $(sourceComponents) ] ; 1225 NOUPDATE $(target) ; 1226 Depends $(target) : $(source) ; 1227 LocalClean clean : $(target) ; 1228} 1229 1230rule AbsSymLink 1231{ 1232 # AbsSymLink <link> : <link target> : <link dir> 1233 # Creates an absolute symbolic link from <link> to <link target>. 1234 # <link> and <link target> must be usual targets. If <link dir> is 1235 # given, then it is set as LOCATE directory on <link>. 1236 1237 LocalDepends files : $(1) ; 1238 Depends $(1) : $(2) ; 1239 if $(3) { 1240 MakeLocate $(1) : $(3) ; 1241 } 1242 SEARCH on $(2) += $(SEARCH_SOURCE) ; 1243 LocalClean clean : $(1) ; 1244} 1245 1246actions AbsSymLink 1247{ 1248 target="$(2)" 1249 case "$target" in 1250 /*) ;; 1251 *) target=`pwd`/"$target";; 1252 esac 1253 $(RM) "$(1)" && $(LN) -s "$target" "$(1)" 1254} 1255 1256rule OBOSInstall 1257{ 1258 # Usage: OBOSInstall <[ install [ and uninstall ] pseudotarget ]> 1259 # : <directory> : <sources to install> 1260 # : [ <installgrist> ] : [ <install rule> ] ; 1261 local install = $(1[1]) ; 1262 install ?= install ; 1263 local uninstall = $(1[2]) ; 1264 uninstall ?= un$(install) ; 1265 local dir = $(2) ; 1266 local sources = $(3) ; 1267 local installgrist = $(4) ; 1268 installgrist ?= $(INSTALLGRIST) ; 1269 local installRule = $(5) ; 1270 installRule ?= Install ; 1271 local targets = $(sources:G=$(installgrist)) ; 1272 1273 Depends $(install) : $(targets) ; 1274 Clean $(uninstall) : $(targets) ; 1275 1276 SEARCH on $(sources) += $(SEARCH_SOURCE) ; 1277 MakeLocate $(targets) : $(dir) ; 1278 1279 local source ; 1280 for source in $(sources) { 1281 local target = $(source:G=$(installgrist)) ; 1282 1283 Depends $(target) : $(source) ; 1284 $(installRule) $(target) : $(source) ; 1285 1286 if [ on $(target) return $(MODE) ] { 1287 Chmod $(target) ; 1288 } 1289 1290 if $(OWNER) && $(CHOWN) { 1291 Chown $(target) ; 1292 OWNER on $(target) = $(OWNER) ; 1293 } 1294 1295 if $(GROUP) && $(CHGRP) { 1296 Chgrp $(target) ; 1297 GROUP on $(target) = $(GROUP) ; 1298 } 1299 } 1300} 1301 1302rule OBOSInstallAbsSymLink 1303{ 1304 # Usage: OBOSInstallAbsSymLink <[ install [ and uninstall ] pseudotarget ]> 1305 # : <directory> : <sources to install> 1306 # : [ <installgrist> ] ; 1307 OBOSInstall $(1) : $(2) : $(3) : $(4) : AbsSymLink ; 1308} 1309 1310rule InstallRelSymLinkAdapter 1311{ 1312 # InstallRelSymLinkAdapter <link> : <link target> 1313 if ! [ on $(2) return $(TARGET) ] { 1314 TARGET on $(2) = [ on $(2) return $(SEARCH) ] ; 1315 } 1316 RelSymLink $(1) : $(2) ; 1317} 1318 1319rule OBOSInstallRelSymLink 1320{ 1321 # Usage: OBOSInstallRelSymLink <[ install [ and uninstall ] pseudotarget ]> 1322 # : <directory> : <sources to install> 1323 # : [ <installgrist> ] ; 1324 OBOSInstall $(1) : $(2) : $(3) : $(4) : InstallRelSymLinkAdapter ; 1325} 1326 1327 1328#------------------------------------------------------------------------------- 1329# Low-level OBOS utility rules 1330#------------------------------------------------------------------------------- 1331rule SetupObjectsDir 1332{ 1333 local rel_objectsdir; 1334 1335 # Copy subdir tokens except the first, as that will be "sources", and we 1336 # do not want to include that :) 1337 rel_objectsdir = [ FDirName $(SUBDIR_TOKENS[2-]) ] ; 1338 LOCATE_TARGET = [ FDirName $(OBOS_OBJECT_TARGET) $(rel_objectsdir) ] ; 1339 LOCATE_SOURCE = $(LOCATE_TARGET) ; 1340 SEARCH_SOURCE = [ Filter $(SEARCH_SOURCE) : $(LOCATE_TARGET) ] 1341 $(LOCATE_TARGET) ; 1342} 1343 1344#------------------------------------------------------------------------------- 1345# Link rule/action are overwritten as they don't handle linking files who's name 1346# contain spaces very well. Also adds resources and version to executable. 1347#------------------------------------------------------------------------------- 1348rule Link 1349{ 1350 # Note: RESFILES must be set before invocation. 1351 MODE on $(<) = $(EXEMODE) ; 1352 on $(1) XRes $(1) : $(RESFILES) ; 1353 Chmod $(<) ; 1354 SetType $(1) ; 1355 MimeSet $(1) ; 1356 SetVersion $(1) ; 1357} 1358 1359actions Link bind NEEDLIBS 1360{ 1361 $(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(2)" "$(NEEDLIBS)" $(LINKLIBS) ; 1362} 1363 1364rule LexC++ 1365{ 1366 Depends $(1) : $(2) ; 1367 MakeLocate $(1) : $(LOCATE_SOURCE) ; 1368 LocalClean clean : $(1) ; 1369} 1370 1371actions LexC++ 1372{ 1373 $(LEX) -o$(1) $(2) 1374} 1375 1376rule Bison 1377{ 1378 local _h ; 1379 1380 _h = $(1).h ; 1381 1382 MakeLocate $(<) $(_h) : $(LOCATE_SOURCE) ; 1383 1384 Depends $(<) $(_h) : $(>) ; 1385 Bison1 $(<) $(_h) : $(>) ; 1386 LocalClean clean : $(<) $(_h) ; 1387 1388 # make sure someone includes $(_h) else it will be 1389 # a deadly independent target 1390 1391 Includes $(<) : $(_h) ; 1392} 1393 1394actions Bison1 1395{ 1396 bison $(YACCFLAGS) -o $(1[1]) $(2) 1397} 1398 1399# BeOS specific rules 1400 1401rule XRes 1402{ 1403 # XRes <target> : <resource files> 1404 if $(2) 1405 { 1406 Depends $(1) : $(2) ; 1407 XRes1 $(1) : $(2) ; 1408 } 1409} 1410 1411rule XRes1 { } 1412 1413rule SetVersion 1414{ 1415 # SetVersion <target> 1416} 1417 1418rule SetType 1419{ 1420 # SetType <target> 1421} 1422 1423rule MimeSet 1424{ 1425 # SetType <target> 1426} 1427 1428 1429if $(OS) = BEOS 1430{ 1431 1432actions XRes1 1433{ 1434 xres -o "$(1)" "$(2)" ; 1435} 1436 1437actions SetVersion 1438{ 1439 setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ; 1440} 1441 1442actions SetType 1443{ 1444 settype -t $(OBOS_TARGET_TYPE) "$(1)" ; 1445} 1446 1447actions MimeSet 1448{ 1449 mimeset -f "$(1)" ; 1450} 1451 1452} # if BEOS 1453 1454 1455rule assemble 1456{ 1457 Depends $(<) : $(>) ; 1458 ASFLAGS on $(<) += $(ASFLAGS) $(SUBDIRASFLAGS) ; 1459 ASHDRS on $(<) = [ FIncludes $(SEARCH_SOURCE) $(SUBDIRHDRS) $(HDRS) ] ; 1460} 1461 1462actions assemble 1463{ 1464 $(CC) -c "$(2)" -O2 $(ASFLAGS) -D_ASSEMBLER $(KERNEL_CCFLAGS) $(ASHDRS) -o "$(1)" ; 1465} 1466 1467# Overridden to allow spaces in file names. 1468actions Chmod1 1469{ 1470 $(CHMOD) "$(MODE)" "$(1)" 1471} 1472 1473# Overridden to allow spaces in file names. 1474actions piecemeal together existing Clean 1475{ 1476 $(RM) "$(>)" 1477} 1478 1479rule ObjectReference 1480{ 1481 # ObjectReference <reference object> : <source object> 1482 # Makes <reference object> refer to the same file as <source object>. 1483 # The filenames must of course be identical. 1484 # <source object> must have already been LOCATEd. 1485 1486 local ref = $(1) ; 1487 local source = $(2) ; 1488 if $(ref) != $(source) { 1489 Depends $(ref) : $(source) ; 1490 LOCATE on $(ref) = [ on $(source) return $(LOCATE) ] ; 1491 } 1492} 1493 1494rule ObjectReferences 1495{ 1496 # ObjectReferences <source objects> 1497 # Creates local references to <source objects>, i.e. identifiers with the 1498 # current grist referring to the same files. <source objects> must have 1499 # already been LOCATEd. 1500 1501 local source ; 1502 for source in $(1) { 1503 ObjectReference [ FGristFiles $(source) ] : $(source) ; 1504 } 1505} 1506 1507rule Filter 1508{ 1509 # Filter <list> : <excludes> ; 1510 # Removes all occurrences of <excludes> in <list>. 1511 1512 local list = $(1) ; 1513 local excludes = $(2) ; 1514 local newList ; 1515 local item ; 1516 for item in $(list) { 1517 local skip ; 1518 local exclude ; 1519 for exclude in $(excludes) { 1520 if $(item) = $(exclude) { 1521 skip = true ; 1522 } 1523 } 1524 if ! $(skip) { 1525 newList += $(item) ; 1526 } 1527 } 1528 return $(newList) ; 1529} 1530 1531 1532## Kernel stuff! 1533 1534rule SetupKernel 1535{ 1536 # Usage SetupKernel <sources_or_objects> : <extra_cc_flags>; 1537 1538 local _objs = [ FGristFiles $(1:S=$(SUFOBJ)) ] ; 1539 1540 #Setup Kernel header directories 1541 local public_kernel_includes = add-ons/file_system add-ons/graphics device drivers kernel storage support ; 1542 local private_kernel_includes = kernel libroot ; 1543 # Use posix headers directory 1544 HDRS = [ FDirName $(OBOS_TOP) headers posix ] ; 1545 # Use public OS header directories 1546 HDRS += [ PublicHeaders $(public_kernel_includes) ] ; 1547 # Use private directories 1548 HDRS += [ PrivateHeaders $(private_kernel_includes) ] ; 1549 # The platform dependent headers. 1550 HDRS += $(PLATFORM_HEADERS) ; 1551 1552 UseArchHeaders $(OBOS_ARCH) ; 1553 1554 SetupObjectsDir ; 1555 1556 CCFLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ; 1557 C++FLAGS on $(_objs) = $(KERNEL_C++FLAGS) $(2) ; 1558} 1559 1560rule KernelObjects 1561{ 1562 SetupKernel $(1) : $(2) ; 1563 1564 Objects $(1) ; 1565} 1566 1567rule KernelLd 1568{ 1569 # KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> : <config_section> ; 1570 1571 SetupKernel $(2) ; 1572 LINK on $(1) = ld ; 1573 1574 LINKFLAGS on $(1) = $(4) ; 1575 if $(3) { LINKFLAGS on $(1) += --script=$(3) ; } 1576 1577 # Remove any preset LINKLIBS 1578 LINKLIBS on $(1) = ; 1579 1580 # Show that we depend on the libraries we need 1581 LocalClean clean : $(1) ; 1582 LocalDepends all : $(1) ; 1583 Depends $(1) : $(2) ; 1584 1585 if $(6) { 1586 for i in $(6) { 1587 KernelConfigSection $(i) : elf32 : $(1) ; 1588 } 1589 } 1590 1591 MakeLocate $(1) : $(LOCATE_TARGET) ; 1592 1593 # Add the platform specific static libs (libgcc.a). 1594 if ! $(5) { 1595 LINKLIBS on $(1) += $(PLATFORM_LINKLIBS) ; 1596 } 1597} 1598 1599actions KernelLd 1600{ 1601 $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ; 1602} 1603 1604rule KernelMergeObject 1605{ 1606 # KernelMergeObject <name> : <sources> : <extra CFLAGS> ; 1607 1608 SetupKernel $(2) : $(3) ; 1609 1610 MakeLocateObjects $(2) ; 1611 Objects $(2) ; 1612 MergeObjectFromObjects $(1) : $(2:S=$(SUFOBJ)) ; 1613} 1614 1615rule KernelStaticLibrary 1616{ 1617 # Usage KernelStaticLibrary <name> : <sources> : <extra cc flags> ; 1618 # This is designed to take a set of sources and libraries and create 1619 # a file called lib<name>.a 1620 1621 SetupKernel $(2) : $(3) ; 1622 1623 MakeLocateObjects $(2) ; 1624 Library $(1) : $(2) ; 1625} 1626 1627rule KernelStaticLibraryObjects 1628{ 1629 # Usage KernelStaticLibrary <name> : <sources> ; 1630 # This is designed to take a set of sources and libraries and create 1631 # a file called <name> 1632 1633 SetupKernel $(2) ; 1634 1635 # Show that we depend on the libraries we need 1636 LocalClean clean : $(1) ; 1637 LocalDepends all : $(1) ; 1638 Depends $(1) : $(2) ; 1639 1640 MakeLocate $(1) : $(LOCATE_TARGET) ; 1641} 1642 1643actions KernelStaticLibraryObjects 1644{ 1645 ar -r "$(1)" "$(2)" ; 1646} 1647 1648rule BuildPlatformMain 1649{ 1650 # Usage BuildPlatformMain <target> : <sources> ; 1651 SetupObjectsDir ; 1652 SetupDefaultIncludes ; 1653 1654 # Remove `-nostdinc' from CCFLAGS and C++FLAGS. 1655 local oldCCFLAGS = $(CCFLAGS) ; 1656 local oldC++FLAGS = $(C++FLAGS) ; 1657 CCFLAGS = [ Filter $(CCFLAGS) : -nostdinc ] ; 1658 C++FLAGS = [ Filter $(C++FLAGS) : -nostdinc ] ; 1659 1660 Main $(1) : $(2) ; 1661 1662 # Reset CCFLAGS and C++FLAGS to original values. 1663 CCFLAGS = $(oldCCFLAGS) ; 1664 C++FLAGS = $(oldC++FLAGS) ; 1665} 1666 1667rule BuildPlatformTest 1668{ 1669 # Usage BuildPlatformTest <target> : <sources> ; 1670 1671 local target = $(1) ; 1672 local sources = $(2) ; 1673 1674 BuildPlatformMain $(target) : $(sources) ; 1675 local relPath ; 1676 if [ FIsPrefix src tests : $(SUBDIR_TOKENS) ] { 1677 relPath = $(SUBDIR_TOKENS[3-]) ; 1678 } else { 1679 relPath = $(SUBDIR_TOKENS[2-]) ; 1680 } 1681 MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(relPath) ] ; 1682} 1683 1684rule KernelConfigSection 1685{ 1686 # KernelConfigSection <section> : <type> : <file> ; 1687 1688 SECTION_NAMES on $(OBOS_KERNEL_CONFIG) += $(1) ; 1689 SECTION_TYPES on $(OBOS_KERNEL_CONFIG) += $(2) ; 1690 SECTION_FILES on $(OBOS_KERNEL_CONFIG) += $(3) ; 1691 1692 Depends $(OBOS_KERNEL_CONFIG) : $(3) ; 1693} 1694 1695rule WriteKernelConfig 1696{ 1697 # usage: WriteKernelConfig <target> ; 1698 1699 LocalDepends files : $(1) ; 1700 1701 MakeLocate $(1) : $(OBOS_OBJECT_TARGET) ; 1702 1703 LocalClean clean : $(1) ; 1704} 1705 1706actions WriteKernelConfig bind SECTION_FILES 1707{ 1708 target="$(1)" 1709 echo "# OpenBeOS Kernel Config File" > "$target" 1710 echo "# Automatically generated - do not edit!" >> "$target" 1711 count=0 1712 for section in "$(SECTION_NAMES)" ; do 1713 count=`expr $count + 1` 1714 eval section$count="$section" 1715 done 1716 i=1 1717 for type in "$(SECTION_TYPES)" ; do 1718 eval type$i="$type" 1719 i=`expr $i + 1` 1720 done 1721 i=1 1722 for file in "$(SECTION_FILES)" ; do 1723 eval file$i="$file" 1724 i=`expr $i + 1` 1725 done 1726 for i in `seq $count` ; do 1727 eval section="\$section$i" 1728 eval type="\$type$i" 1729 eval file="\$file$i" 1730 echo "" >> "$target" 1731 echo "["$section"]" >> "$target" 1732 echo "type="$type >> "$target" 1733 case "$file" in 1734 /*) ;; 1735 *) file=`pwd`/"$file";; 1736 esac 1737 echo "file="$file >> "$target" 1738 done 1739} 1740 1741rule BuildKernel 1742{ 1743 # Usage BuildKernel <target> : <config_file> ; 1744 local kernel = $(1) ; 1745 local configFile = $(2) ; 1746 local bootmaker = bootmaker ; 1747 1748 LocalDepends all : $(kernel) ; 1749 Depends $(kernel) : $(configFile) $(bootmaker) ; 1750 LocalClean clean : $(kernel) ; 1751 MakeLocate $(kernel) : $(LOCATE_TARGET) ; 1752 1753 BOOT_MAKER on $(kernel) = $(bootmaker) ; 1754} 1755 1756actions BuildKernel bind BOOT_MAKER 1757{ 1758 "$(BOOT_MAKER)" --strip-debug --strip-binary strip "$(2)" -o "$(1)" ; 1759 echo "" 1760 echo "Kernel linked!" 1761 echo "" 1762} 1763 1764rule KernelFloppyImage 1765{ 1766 # Usage KernelFloppyImage <target> : <kernel> : <bootblock> ; 1767 local floppy = $(1) ; 1768 local kernel = $(2) ; 1769 local bootblock = $(3) ; 1770 local makeflop = makeflop ; 1771 1772 LocalDepends all : $(floppy) ; 1773 Depends $(floppy) : $(kernel) $(bootblock) $(makeflop) ; 1774 LocalClean clean : $(floppy) ; 1775 MakeLocate $(floppy) : $(OBOS_OBJECT_TARGET) ; 1776 1777 BOOT_BLOCK on $(floppy) = $(bootblock) ; 1778 MAKE_FLOP on $(floppy) = $(makeflop) ; 1779} 1780 1781# This may be a bit verbose, but I think it's useful to show what's 1782# going on, at least in this early stage of development. 1783actions KernelFloppyImage bind BOOT_BLOCK bind MAKE_FLOP 1784{ 1785 "$(MAKE_FLOP)" "-p $(shell expr 18 \* 2 \* 512)" "$(BOOT_BLOCK)" "$(2)" "$(1)" ; 1786 1787 echo "" 1788 echo "*************************************************" 1789 echo "* Kernel build completed! *" 1790 echo "* Boot image for a 1.44M floppy created *" 1791 echo "*************************************************" 1792 echo "" 1793 echo "Floppy image is $(1)" 1794 echo "The following command will write it to a floppy on BeOS" 1795 echo " dd if=$(1) of=/dev/disk/floppy/raw bs=18k" 1796 echo "Alternatively you can run" 1797 echo " ./configure --floppy /dev/disk/floppy/raw" 1798 echo "once and build + write the image subsequently via" 1799 echo " jam installfloppy" 1800 echo "" 1801} 1802 1803rule InstallFloppy 1804{ 1805 # InstallFloppy <target> : <floppy> 1806 # "dd"s <floppy> to $(FLOPPY_PATH). 1807 1808 local target = $(1) ; 1809 local floppy = $(2) ; 1810 1811 NotFile $(target) ; 1812 Always $(target) ; 1813 Depends $(target) : $(floppy) ; 1814} 1815 1816actions InstallFloppy 1817{ 1818 if [ -z $(FLOPPY_PATH) ] ; then 1819 echo "Can't install floppy: FLOPPY_PATH not set." 1820 echo "run: ./configure --floppy <floppy path>" 1821 echo 1822 exit 0 1823 fi 1824 dd if=$(2) of=$(FLOPPY_PATH) bs=18k 1825} 1826 1827#------------------------------------------------------------------------------- 1828# FreeType 2 specific rules and variables 1829#------------------------------------------------------------------------------- 1830 1831FT2_INCLUDE = [ FDirName $(OBOS_TOP) headers libs freetype2 ] ; 1832FT2_SRC = [ FDirName $(OBOS_TOP) src libs freetype2 ] ; 1833 1834FT2_LIB = freetype ; 1835 1836FT2_COMPONENTS ?= gzip # support for gzip-compressed files. 1837 autohint # auto-hinter 1838 base # base component (public APIs) 1839 bdf # BDF font driver 1840 cache # cache sub-system 1841 cff # CFF/CEF font driver 1842 cid # Postscript CID-keyed font driver 1843 pcf # PCF font driver 1844 pfr # PFR/TrueDoc font driver 1845 psaux # Common Postscript routines module 1846 pshinter # Postscript hinter module 1847 psnames # Postscript names handling 1848 raster # Monochrome rasterizer 1849 smooth # Anti-aliased rasterizer 1850 sfnt # SFNT-based format support routines 1851 truetype # TrueType font driver 1852 type1 # Postscript Type 1 font driver 1853 type42 # Postscript Type 42 (embedded TrueType) driver 1854 winfonts # Windows FON/FNT font driver 1855 ; 1856 1857rule UseFreeTypeHeaders 1858{ 1859 SubDirHdrs $(FT2_INCLUDE) ; 1860} 1861 1862rule UseFreeTypeObjectHeaders 1863{ 1864 # UseFreeTypeObjectHeaders <sources> [ : <objects> ] ; 1865 SourceHdrs $(1) : $(FT2_INCLUDE) : $(2) ; 1866} 1867 1868rule FT2_SubDir 1869{ 1870 # FT2_SubDir <dir> 1871 # <dir>: Components of a directory in the original hierarchy. 1872 local dir = $(1) ; 1873 local topDir ; 1874 switch $(dir[1]) 1875 { 1876 case "include" : topDir = $(FT2_INCLUDE) ; 1877 case src : topDir = $(FT2_SRC) ; 1878 case * : ECHO "Unknown FreeType2 directory: " $(dir) ; 1879 } 1880 return [ FDirName $(topDir) $(dir[2-]) ] ; 1881} 1882 1883rule FT2_Library 1884{ 1885 # FT2_Library <libname> : <sources> 1886 # Builds objects from sources and adds the objects to the list of objects 1887 # to be linked into the library. 1888 # <libname> The name of the library. 1889 # <sources> The sources. 1890 1891 local library = lib$(1).so ; 1892 local sources = $(2) ; 1893 SetupIncludes ; 1894 SetupObjectsDir ; 1895 MakeLocateObjects $(sources) ; 1896 Objects $(sources) ; 1897 LIBRARY_OBJECTS on $(library) += [ FGristFiles $(sources:S=$(SUFOBJ)) ] ; 1898} 1899 1900rule FT2_LinkLibrary 1901{ 1902 # FT2_LinkLibrary <libname> 1903 # Links the library from the objects build with FT2_LIBRARY before. 1904 1905 local library = lib$(1).so ; 1906 local objects = [ on $(library) return $(LIBRARY_OBJECTS) ] ; 1907 ObjectReferences $(objects) ; 1908 objects = [ FGristFiles $(objects) ] ; 1909 SharedLibraryFromObjects $(1) : $(objects) ; 1910} 1911 1912