1# Include BuildConfig 2{ 3 local buildConfig = [ GLOB $(OBOS_TOP) : BuildConfig ] ; 4 if ! $(buildConfig) 5 { 6 EXIT "No BuildConfig!" 7 "Run ./configure in the source tree's root directory first!" ; 8 } 9 include $(buildConfig) ; 10} 11 12# Determine if we're building on PPC or x86 13# Determine mimetype of executable 14# Cross compiling can come later 15 16if $(METROWERKS) { 17 OBOS_TARGET ?= "ppc.R1" ; 18 OBOS_TARGET_TYPE ?= "application/x-be-executable" ; 19 OBOS_ARCH ?= "ppc" ; 20 OBOS_TARGET_DEFINE ?= "ARCH_ppc" ; 21} else { 22 OBOS_TARGET ?= "x86.R1" ; 23 OBOS_TARGET_TYPE ?= "application/x-vnd.Be-elfexecutable" ; 24 OBOS_ARCH ?= "x86" ; 25 OBOS_TARGET_DEFINE ?= "ARCH_x86" ; 26 OBOS_TARGET_DIR ?= "x86" ; 27} 28 29# Enable warnings only if WARNINGS is defined 30# Should be enabled by default later 31 32if $(WARNINGS) { 33 # For an explanation of the different warning options, see: 34 # http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html 35 # to get even more warnings, add: 36 # -Wwrite-strings (doesn't work well with some Be headers) 37 # -Wundef (dito) 38 # -Wconversion (gets you many warnings about implicit conversions) 39 # -W (gets you even more warnigs) 40 CCFLAGS ?= "-Wall -Wno-multichar -Wmissing-prototypes" ; 41 CCFLAGS += "-Wpointer-arith -Wcast-align -Wsign-compare" ; 42 C++FLAGS ?= "-Wall -Wno-multichar -Wmissing-prototypes -Wno-ctor-dtor-privacy -Woverloaded-virtual" ; 43 C++FLAGS += "-Wpointer-arith -Wcast-align -Wsign-compare" ; 44} 45 46KERNEL_CCFLAGS ?= "-Wall -Wno-multichar -Wmissing-prototypes -finline -nostdinc" ; 47KERNEL_CCFLAGS += "-fno-builtin -D$(OBOS_TARGET_DEFINE) " ; 48 49AR = ar r ; 50OPTIM = -O2 ; 51 52# If no OBOS_OBJECT_TARGET is not defined yet, use our default directory and 53# include our "OBOS_TARGET" as subdirectory in there (to prevent different 54# builds mixing objects from different targets). 55if ! $(OBOS_OBJECT_TARGET) { 56 OBOS_OBJECT_TARGET ?= [ FDirName $(OBOS_TOP) objects $(OBOS_TARGET) ] ; 57} 58 59# If no OBOS_DISTRO_TARGET is not defined yet, use our default directory and 60# include our "OBOS_TARGET" as subdirectory in there (to prevent different 61# builds mixing executables from different targets). 62if ! $(OBOS_DISTRO_TARGET) { 63 OBOS_DISTRO_TARGET ?= [ FDirName $(OBOS_TOP) distro $(OBOS_TARGET) ] ; 64} 65 66# Set our version number if not already set and mark it as a developer build 67if ! $(OBOS_BUILD_VERSION) { 68 OBOS_BUILD_VERSION ?= "1 0 0 a 1" ; 69 OBOS_BUILD_DESCRIPTION ?= "Developer Build" ; 70} 71 72# If OBOS_BUILD_VERSION is set, but OBOS_BUILD_DESCRIPTION isn't, mark it as 73# an unknown build. 74if ! $(OBOS_BUILD_DESCRIPTION) { 75 OBOS_BUILD_DESCRIPTION ?= "Unknown Build" ; 76} 77 78# Relative subdirs for distro dir (these are for *INTERNAL* use by the following rules only!) 79OBOS_APPS_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos apps ] ; 80OBOS_BIN_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos bin ] ; 81OBOS_PREFS_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos preferences ] ; 82OBOS_SERVER_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system servers ] ; 83OBOS_ADDON_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system add-ons ] ; 84OBOS_SHLIB_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ; 85OBOS_STLIB_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system lib ] ; 86OBOS_KERNEL_DIR ?= [ FDirName $(OBOS_DISTRO_TARGET) beos system ] ; 87OBOS_TEST_DIR ?= [ FDirName $(OBOS_TOP) tests ] ; 88 89OBOS_KERNEL_CONFIG = config.$(OBOS_ARCH).ini ; 90OBOS_KERNEL = kernel.$(OBOS_ARCH) ; 91OBOS_FLOPPY = floppy.$(OBOS_ARCH) ; 92 93rule SetupIncludes 94{ 95 OBOS_INCLUDES ?= . add-ons app be_apps device drivers game interface kernel mail media midi midi2 net opengl storage support translation ; 96 UsePublicHeaders $(OBOS_INCLUDES) ; 97 UsePosixHeaders ; 98} 99 100#------------------------------------------------------------------------------- 101# Things Jam needs in order to work :) 102#------------------------------------------------------------------------------- 103 104rule UserObject 105{ 106 switch $(2) 107 { 108 case *.S : assemble $(1) : $(2) ; 109 case * : ECHO "unknown suffix on" $(2) ; 110 } 111} 112 113# Override the default to give "prettier" command lines. 114actions Cc 115{ 116 $(CC) -c "$(2)" $(CCFLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ; 117} 118 119actions C++ 120{ 121 $(C++) -c "$(2)" $(C++FLAGS) $(CCDEFS) $(CCHDRS) -o "$(1)" ; 122} 123 124 125#------------------------------------------------------------------------------- 126# General High-level OBOS target rules 127#------------------------------------------------------------------------------- 128 129rule App 130{ 131 # App <name> : <sources> ; 132 SetupObjectsDir ; 133 Main $(<) : $(>) ; 134 MakeLocate $(<) : $(OBOS_APPS_DIR) ; 135} 136 137rule BinCommand 138{ 139 # BinCommand <name> : <sources> : <libraries> ; 140 SetupObjectsDir ; 141 Main $(1) : $(2) ; 142 MakeLocate $(1) : $(OBOS_BIN_DIR) ; 143 LinkSharedOSLibs $(1) : $(3) ; 144} 145 146rule StdBinCommands 147{ 148 # StdBinCommands <sources> : <libs> ; 149 local libs = $(2) ; 150 for source in $(1) 151 { 152 local target = $(source:S=) ; 153 target = [ FGristFiles $(target) ] ; 154 BinCommand $(target) : $(source) : $(libs) ; 155 } 156} 157 158rule Preference 159{ 160 # Preference <name> : <sources> ; 161# SetupIncludes ; 162 SetupObjectsDir ; 163 Main $(<) : $(>) ; 164 MakeLocate $(<) : $(OBOS_PREFS_DIR) ; 165} 166 167rule Server 168{ 169 # Server <name> : <sources> ; 170 171# SetupIncludes ; 172 SetupObjectsDir ; 173 Main $(<) : $(>) ; 174 MakeLocate $(<) : $(OBOS_SERVER_DIR) ; 175} 176 177# test pseudo targets 178NOTFILE obostests ; 179NOTFILE r5tests ; 180 181rule CommonUnitTest 182{ 183 # CommonUnitTest <target> : <sources> : <dest> : <obos libraries> 184 # : <r5 libraries> : <public headers>; 185 # Builds a unit test for both OBOS and R5 modules. 186 # <target> The name of the target. 187 # <sources> The list of sources. 188 # <dest> The directory for the target (as passed to FDirName). 189 # <obos libraries> A list of link libraries for the OBOS tests (as passed 190 # to LinkSharedOSLibs). 191 # <r5 libraries> A list of link libraries for the R5 tests (as passed 192 # to LinkSharedOSLibs). 193 # <public headers> A list of public header dirs (as passed to 194 # UsePublicHeaders). 195 196 UnitTest $(1) : $(2) : $(3) : $(4) : $(6) ; 197 R5UnitTest $(1) : $(2) : $(3) : $(5) ; 198} 199 200rule UnitTest 201{ 202 # UnitTest <target> : <sources> : <dest> : <libraries> : <public headers> 203 # Builds a unit test for an OBOS module. 204 # <target> The name of the target. 205 # <sources> The list of sources. 206 # <dest> The directory for the target (as passed to FDirName). 207 # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 208 # <public headers> A list of public header dirs (as passed to 209 # UsePublicHeaders). 210 211 local target = $(1) ; 212 local sources = $(2) ; 213 local dest = $(3) ; 214 local libraries = $(4) ; 215 local headerDirs = $(5) ; 216 217 # Turn optimization off. 218 local optim = $(OPTIM) ; 219 OPTIM = ; 220 221# SetupIncludes ; 222 UseCppUnitHeaders ; 223 SetupObjectsDir ; 224 MakeLocateObjects $(sources) ; 225 Main $(target) : $(sources) ; 226 MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ; 227 DEPENDS $(target) : libcppunit.so ; 228 DEPENDS obostests : $(target) ; 229 LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ; 230 UsePublicObjectHeaders $(sources) : $(headerDirs) ; 231 ObjectDefines $(sources) : TEST_OBOS ; 232 233 # Turn debugging on. That is usually desired for test code. 234 ObjectCcFlags $(sources) : "-g" ; 235 ObjectC++Flags $(sources) : "-g" ; 236 237 # Turn optimization on again. 238 OPTIM = $(optim) ; 239} 240 241rule R5UnitTest 242{ 243 # R5UnitTest <target> : <sources> : <dest> : <libraries> 244 # Builds a unit test for an R5 module. "_r5" is appended to the object 245 # and the target name. 246 # <target> The name of the target. 247 # <sources> The list of sources. 248 # <dest> The directory for the target (as passed to FDirName). 249 # <libraries> A list of link libraries (as passed to LinkSharedOSLibs). 250 251 local target = $(1)_r5 ; 252 local sources = $(2) ; 253 local dest = $(3) ; 254 local libraries = $(4) ; 255 local objects = [ R5ObjectNames $(sources) ] ; 256 257 # Turn optimization off. 258 local optim = $(OPTIM) ; 259 OPTIM = ; 260 261 UseCppUnitHeaders ; 262 SetupObjectsDir ; 263 MakeLocateObjects $(objects) ; 264 265 # Our Main replacement. 266 MainFromObjects $(target) : $(objects) ; 267 local source ; 268 for source in [ FGristFiles $(sources) ] 269 { 270 local object = [ R5ObjectNames $(source) ] ; 271 Object $(object) : $(source) ; 272 Depends obj : $(object) ; 273 } 274 275 MakeLocate $(target) : [ FDirName $(OBOS_TEST_DIR) $(dest) ] ; 276 DEPENDS $(target) : libcppunit.so ; 277 DEPENDS r5tests : $(target) ; 278 LinkSharedOSLibs $(target) : libcppunit.so $(libraries) ; 279 ObjectDefines $(objects) : TEST_R5 ; 280 281 # Turn debugging on. That is usually desired for test code. 282 ObjectCcFlags $(objects) : "-g" ; 283 ObjectC++Flags $(objects) : "-g" ; 284 285 # Turn optimization on again. 286 OPTIM = $(optim) ; 287} 288 289rule R5ObjectNames 290{ 291 # R5ObjectNames <sources> ; 292 # Returns a list of gristed object names given a list of source file names. 293 # Moreover each object names gets "_r5" inserted before the object suffix. 294 local objects = $(1:S=)_r5 ; 295 return [ FGristFiles $(objects:S=$(SUFOBJ)) ] ; 296} 297 298rule Addon 299{ 300 # Addon <name> : <relpath> : <sources> ; 301 302# SetupIncludes ; 303 SetupObjectsDir ; 304 Main $(1) : $(3) ; 305 306 # Create output dir path for addon 307 local targetdir; 308 targetdir = [ FDirName $(OBOS_ADDON_DIR) $(2) ] ; 309 310 MakeLocate $(1) : $(targetdir) ; 311 LINKFLAGS on $(1) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(1)\" ; 312} 313 314rule MakeLocateObjects 315{ 316 # MakeLocateObjects <gristed_sources_or_objects> ; 317 318 local _objs = $(1:S=$(SUFOBJ)) ; 319 320 for o in $(_objs) 321 { 322 local dir = $(o:D) ; 323 if $(dir) { 324 MakeLocate $(o) : [ FDirName $(LOCATE_TARGET) $(dir) ] ; 325 } else { 326 MakeLocate $(o) : $(LOCATE_TARGET) ; 327 } 328 } 329} 330 331rule StaticLibrary 332{ 333 # StaticLibrary <name> : <sources> ; 334 335 SetupIncludes ; 336 SetupObjectsDir ; 337 MakeLocateObjects $(2) ; 338 Library lib$(<).a : $(>) ; 339 MakeLocate lib$(<).a : $(OBOS_STLIB_DIR) ; 340} 341 342rule SharedLibrary 343{ 344 # SharedLibrary <name> : <sources> ; 345 local _lib = lib$(1).so ; 346 347# SetupIncludes ; 348 SetupObjectsDir ; 349 MakeLocateObjects $(2) ; 350 Main $(_lib) : $(2) ; 351 MakeLocate $(_lib) : $(OBOS_SHLIB_DIR) ; 352 LINKFLAGS on $(_lib) = $(LINKFLAGS) -nostart -Xlinker -soname=\"$(_lib)\" ; 353} 354 355rule LinkSharedOSLibs 356{ 357 # LinkSharedOSLibs <name> : <libs> ; 358 # Valid elements for <libs> are e.g. "be" or "libopenbeos.so" or 359 # "/boot/.../libfoo.so". If the basename starts with "lib" or the thingy 360 # has a dirname or grist, it is added to the NEEDLIBS variable (i.e. the 361 # file will be bound!), otherwise it is prefixed "-l" and added to 362 # LINKLIBS. 363 364 for i in $(>) 365 { 366 local isfile = ; 367 if $(i:D) || $(i:G) { 368 isfile = true ; 369 } else { 370 switch $(i:B) 371 { 372 case lib* : isfile = true ; 373 case * : isfile = ; 374 } 375 } 376 if $(isfile) { 377 NEEDLIBS on $(1) += $(i) ; 378 DEPENDS $(1) : $(i) ; 379 } else { 380 LINKLIBS on $(1) += -l$(i) ; 381 } 382 } 383} 384 385rule LinkStaticOSLibs 386{ 387 # LinkStaticOSLibs <name> : <libs> ; 388 389 for i in $(>) 390 { 391 LINKLIBS on $(<) = $(LINKLIBS) -l $(i) ; 392 } 393} 394 395rule AddResources 396{ 397 # AddResources <name> : <resourcefiles> ; 398 399 SEARCH on $(2) = $(SEARCH_SOURCE) ; 400 RESFILES on $(1) += $(2) ; 401} 402 403rule PublicHeaders 404{ 405 # PublicHeaders <group list> 406 # 407 # Returns the directory names for the public header dirs identified by 408 # <group list>. 409 410 local list = $(1) ; 411 local dirs ; 412 for i in $(list) { 413 dirs += [ FDirName $(OBOS_TOP) headers os $(i) ] ; 414 } 415 return $(dirs) ; 416} 417 418rule PrivateHeaders 419{ 420 # PrivateHeaders <group list> 421 # 422 # Returns the directory names for the private header dirs identified by 423 # <group list>. 424 425 local list = $(1) ; 426 local dirs ; 427 for i in $(list) { 428 dirs += [ FDirName $(OBOS_TOP) headers private $(i) ] ; 429 } 430 return $(dirs) ; 431} 432 433rule ArchHeaders 434{ 435 # usage: ArchHeaders <arch> ; 436 # 437 # <arch> specifies the architecture (e.g. x86). 438 439 return [ FDirName $(OBOS_TOP) headers private kernel arch $(1) ] ; 440} 441 442rule UsePublicHeaders 443{ 444 # UsePublicHeaders <group list> ; 445 # 446 # Adds the public C header dirs given by <group list> to the header search 447 # dirs of the subdirectory. 448 # NOTE: This rule must be invoked *before* the rule that builds the objects. 449 450 UseHeaders [ PublicHeaders $(1) ] ; 451} 452 453rule UsePublicObjectHeaders 454{ 455 # UsePublicObjectHeaders <sources_or_objects> : <group list> ; 456 # 457 # Adds the public C header dirs given by <group list> to the header search 458 # dirs of <sources_or_objects>. 459 # NOTE: This rule must be invoked *after* the rule that builds the objects. 460 461 ObjectHdrs $(1) : [ PublicHeaders $(2) ] ; 462} 463 464rule UsePrivateHeaders 465{ 466 # UsePrivateHeaders <group list> ; 467 # 468 # Adds the private C header dirs given by <group list> to the header search 469 # dirs of the subdirectory. 470 # NOTE: This rule must be invoked *before* the rule that builds the objects. 471 472 UseHeaders [ PrivateHeaders $(1) ] ; 473} 474 475rule UsePrivateObjectHeaders 476{ 477 # UsePrivateObjectHeaders <sources_or_objects> : <group list> ; 478 # 479 # Adds the private C header dirs given by <group list> to the header search 480 # dirs of <sources_or_objects>. 481 # NOTE: This rule must be invoked *after* the rule that builds the objects. 482 483 ObjectHdrs $(1) : [ PrivateHeaders $(2) ] ; 484} 485 486rule UseHeaders 487{ 488 # UseHeaders <headers> ; 489 # 490 # Adds the C header dirs <headers> to the header search 491 # dirs of the subdirectory. 492 # NOTE: This rule must be invoked *before* the rule that builds the objects. 493 494 local header ; 495 for header in $(1) { 496 SubDirHdrs $(header) ; 497 } 498} 499 500rule UseCppUnitHeaders 501{ 502 SubDirHdrs [ FDirName $(OBOS_TOP) headers tools cppunit ] ; 503} 504 505rule UseArchHeaders 506{ 507 # usage: UseArchHeaders <arch> ; 508 # 509 # <arch> specifies the architecture (e.g. x86). 510 # NOTE: This rule must be invoked *before* the rule that builds the objects. 511 512 local headers = [ ArchHeaders $(1) ] ; 513 local opt = -D$(OBOS_TARGET_DEFINE) ; 514 515 SubDirCcFlags $(opt) ; 516 SubDirC++Flags $(opt) ; 517 SubDirHdrs $(headers) ; 518} 519 520rule UseArchObjectHeaders 521{ 522 # usage: UseArchObjectHeaders <sources_or_objects> : <arch> ; 523 # 524 # <arch> specifies the architecture (e.g. x86). 525 # <sources_or_objects> Source or object files. 526 # NOTE: This rule must be invoked *after* the rule that builds the objects. 527 528 local targets = $(1) ; 529 local headers = [ ArchHeaders $(2) ] ; 530 local opt = -D$(OBOS_TARGET_DEFINE) ; 531 532 ObjectCcFlags $(targets) : $(opt) ; 533 ObjectC++Flags $(targets) : $(opt) ; 534 ObjectHdrs $(targets) : $(headers) ; 535} 536 537rule UsePosixHeaders 538{ 539 # UsePrivateHeaders <group list> ; 540 # 541 # Adds the POSIX header dir to the header search 542 # dirs of the subdirectory. 543 # NOTE: This rule must be invoked *before* the rule that builds the objects. 544 545 SubDirHdrs [ FDirName $(OBOS_TOP) headers posix ] ; 546} 547 548rule UsePosixObjectHeaders 549{ 550 # UsePosixObjectHeaders <sources_or_objects> ; 551 # 552 # Adds the POSIX header dir to the header search 553 # dirs of <sources_or_objects>. 554 # NOTE: This rule must be invoked *after* the rule that builds the objects. 555 556 ObjectHdrs $(1) : [ FDirName $(OBOS_TOP) headers posix ] ; 557} 558 559rule SplitPath 560{ 561 # SplitPath <path> ; 562 # Decomposes a path into its components. 563 local path = $(1:G=) ; 564 local components ; 565 while $(path:D) 566 { 567 # Note: $(path:B) returns "." for "..", but $(path:D=) is fine. 568 components = $(path:D=) $(components) ; 569 path = $(path:D) ; 570 } 571 components = $(path) $(components) ; 572 return $(components) ; 573} 574 575rule SymLink 576{ 577 # SymLink <target> : <source> ; 578 # Links <target> to <source>. 579 # <source> is the exact link contents. No binding is done. 580 LINKCONTENTS on $(1) = $(2) ; 581 SymLink1 $(1) ; 582 DEPENDS all : $(target) ; 583} 584 585actions SymLink1 586{ 587 $(RM) "$(1)" && $(LN) -s "$(LINKCONTENTS)" "$(1)" 588} 589 590rule RelSymLink 591{ 592 # RelSymLink <link> : <link target> 593 # Creates a relative symbolic link from <link> to <link target>. 594 # <link> and <link target> can be usual targets. They may have a grist 595 # and don't need to have any dirname. Their LOCATE variables are used to 596 # find their locations. 597 598 local target = $(1) ; 599 local source = $(2) ; 600 local targetDir = [ on $(target) FDirName $(LOCATE[1]) $(target:D) ] ; 601 local sourceDir = [ on $(source) FDirName $(LOCATE[1]) $(source:D) ] ; 602 local sourcePath = $(source:G=) ; 603 sourcePath = $(sourcePath:D=$(sourceDir)) ; 604 local targetDirComponents = [ SplitPath $(targetDir) ] ; 605 local sourceComponents = [ SplitPath $(sourcePath) ] ; 606 607 SymLink $(target) 608 : [ FRelPath $(targetDirComponents) : $(sourceComponents) ] ; 609 NOUPDATE $(target); 610 DEPENDS $(target) : $(source) ; 611} 612 613#------------------------------------------------------------------------------- 614# Low-level OBOS utility rules 615#------------------------------------------------------------------------------- 616rule SetupObjectsDir 617{ 618 local rel_objectsdir; 619 620 # Copy subdir tokens except the first, as that will be "sources", and we 621 # do not want to include that :) 622 rel_objectsdir = [ FDirName $(SUBDIR_TOKENS[2-]) ] ; 623 LOCATE_TARGET = [ FDirName $(OBOS_OBJECT_TARGET) $(rel_objectsdir) ] ; 624} 625 626#------------------------------------------------------------------------------- 627# Link rule/action are overwritten as they don't handle linking files who's name 628# contain spaces very well. Also adds resources and version to executable. 629#------------------------------------------------------------------------------- 630rule Link 631{ 632 # Note: RESFILES must be set before invocation. 633 MODE on $(<) = $(EXEMODE) ; 634 on $(1) XRes $(1) : $(RESFILES) ; 635 SetVersion $(1) ; 636 Chmod $(<) ; 637 SetType $(1) ; 638 MimeSet $(1) ; 639} 640 641actions Link bind NEEDLIBS 642{ 643 $(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) "$(2)" "$(NEEDLIBS)" $(LINKLIBS) ; 644} 645 646# BeOS specific rules 647 648rule XRes 649{ 650 # XRes <target> : <resource files> 651 if $(2) 652 { 653 DEPENDS $(1) : $(2) ; 654 XRes1 $(1) : $(2) ; 655 } 656} 657 658rule XRes1 { } 659 660rule SetVersion 661{ 662 # SetVersion <target> 663} 664 665rule SetType 666{ 667 # SetType <target> 668} 669 670rule MimeSet 671{ 672 # SetType <target> 673} 674 675 676if $(OS) = BEOS 677{ 678 679actions XRes1 680{ 681 xres -o "$(1)" "$(2)" ; 682} 683 684actions SetVersion 685{ 686 setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ; 687} 688 689actions SetType 690{ 691 settype -t $(OBOS_TARGET_TYPE) "$(1)" ; 692} 693 694actions MimeSet 695{ 696 mimeset -f "$(1)" ; 697} 698 699} # if BEOS 700 701 702rule assemble 703{ 704 DEPENDS $(1) : $(2) ; 705 Clean clean : $(1) ; 706} 707 708actions assemble 709{ 710 $(CC) -c "$(2)" -O2 $(KERNEL_CCFLAGS) -o "$(1)" ; 711} 712 713# Overridden to allow spaces in file names. 714actions Chmod1 715{ 716 $(CHMOD) "$(MODE)" "$(1)" 717} 718 719 720## Kernel stuff! 721 722rule SetupKernel 723{ 724 # Usage SetupKernel <sources_or_objects> : <extra_cc_flags>; 725 726 local _objs = $(1:S=$(SUFOBJ)) ; 727 728 UsePublicHeaders kernel support ; 729 UsePublicHeaders [ FDirName os kernel ] ; 730 UsePrivateHeaders kernel ; 731 UsePosixHeaders ; 732 UseArchHeaders $(OBOS_ARCH) ; 733 734 SetupObjectsDir ; 735 736 CCFLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ; 737 C++FLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ; 738} 739 740rule KernelObjects 741{ 742 SetupKernel $(1) : $(2) ; 743 744 Objects $(1) ; 745} 746 747rule KernelLd 748{ 749 # KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> ; 750 751 SetupKernel $(2) ; 752 LINK on $(1) = ld ; 753 754 LINKFLAGS on $(1) = $(4) ; 755 if $(3) { LINKFLAGS on $(1) += --script=$(3) ; } 756 757 # Remove any preset LINKLIBS 758 LINKLIBS on $(1) = ; 759 760 # Show that we depend on the libraries we need 761 Clean clean : $(1) ; 762 Depends all : $(1) ; 763 Depends $(1) : $(2) ; 764 765 if $(6) { 766 Depends $(OBOS_KERNEL_CONFIG) : $(1) ; 767 for i in $(6) { 768 SECTIONS on $(OBOS_KERNEL_CONFIG) += ":" $(i) elf32 [ FDirName $(LOCATE_TARGET) $(1) ] ; 769 } 770 } 771 772 MakeLocate $(1) : $(LOCATE_TARGET) ; 773 774 # Add libgcc.a - NB this should be detected not hard coded! 775 if ! $(5) { 776 LINKLIBS on $(1) += -L $(GCC_PATH) -lgcc ; 777 } 778} 779 780actions KernelLd 781{ 782 $(LINK) $(LINKFLAGS) -o "$(1)" "$(2)" $(LINKLIBS) ; 783} 784 785rule KernelStaticLibrary 786{ 787 # Usage KernelStaticLibrary <name> : <sources> : <extra cc flags> ; 788 # This is designed to take a set of sources and libraries and create 789 # a file called lib<name>.a 790 791 SetupKernel $(2) : $(3) ; 792 793 MakeLocateObjects $(2) ; 794 Library $(1) : $(2) ; 795} 796 797rule KernelStaticLibraryObjects 798{ 799 # Usage KernelStaticLibrary <name> : <sources> ; 800 # This is designed to take a set of sources and libraries and create 801 # a file called <name> 802 803 SetupKernel $(2) ; 804 805 # Show that we depend on the libraries we need 806 Clean clean : $(1) ; 807 Depends all : $(1) ; 808 Depends $(1) : $(2) ; 809 810 MakeLocate $(1) : $(LOCATE_TARGET) ; 811} 812 813actions KernelStaticLibraryObjects 814{ 815 ar -r "$(1)" "$(2)" ; 816} 817 818rule SystemMain 819{ 820 # Usage SystemMain <target> : <sources> : <rqd_by> ; 821 SetupObjectsDir ; 822 823 LINKLIBS = ; 824 825 # This allows us to preset certain commands we use 826 # for building. 827 if $(3) { 828 for obj in $(3) { 829 BUILD_CMD on $(obj) = [ FDirName $(LOCATE_TARGET) $(1) ] ; 830 } 831 } 832 833 Main $(1) : $(2) ; 834} 835 836rule KernelConfigSection 837{ 838 # KernelConfigSection <section> : <type> : <file> ; 839 SECTIONS on $(OBOS_KERNEL_CONFIG) += ":" $(1) $(2) $(3) ; 840} 841 842rule WriteKernelConfig 843{ 844 # usage: WriteKernelConfig <target> ; 845 846 Depends files : $(1) ; 847 848 LOCATE on $(1) = $(LOCATE_TARGET) ; 849 850 MakeLocate $(1) : $(LOCATE_TARGET) ; 851 852 Clean clean : $(1) ; 853} 854 855actions WriteKernelConfig 856{ 857 target="$(1)" 858 echo "# OpenBeOS Kernel Config File" > "$target" 859 echo "# Automatically generated - do not edit!" >> "$target" 860 issection="0" 861 section= 862 for i in "$(SECTIONS)" ; do 863 if [ $issection == 1 ]; then 864 section="$i" 865 issection=2 866 echo "["$section"]" >> "$target" 867 elif [ $issection == 2 ]; then 868 type=$i 869 issection=3 870 echo "type="$type >> "$target" 871 else 872 if [ "$i" == ":" ]; then 873 issection=1 874 echo "" >> "$target" 875 else 876 file="$i" 877 case "$file" in 878 /*) ;; 879 *) file=`pwd`/"$file";; 880 esac 881 echo "file="$file >> $target 882 fi 883 fi 884 done 885} 886 887rule BuildKernel 888{ 889 # Usage BuildKernel <target> : <config_file> ; 890 891 Depends all : $(1) ; 892 Depends $(1) : $(2) ; 893 Clean clean : $(1) ; 894 895 MakeLocate $(1) : $(LOCATE_TARGET) ; 896} 897 898actions BuildKernel 899{ 900 "$(BUILD_CMD)" --strip-debug --strip-binary strip "$(2)" -o "$(1)" ; 901 echo "" 902 echo "Kernel linked!" 903 echo "" 904} 905 906# At present I don't bother moving the final location for 907# the floppy image as it makes copying it onto a floppy easier if it's 908# where you did the build. This is easy enough changed. 909rule KernelFloppyImage 910{ 911 # Usage KernelFloppyImage <target> : <kernel> : <bootblock> ; 912 913 Depends all : $(1) ; 914 Depends $(1) : $(2) ; 915 Clean clean : $(1) ; 916 917 BOOT_BLOCK on $(1) = $(3) ; 918} 919 920# This may be a bit verbose, but I think it's useful to show what's 921# going on, at least in this early stage of development. 922actions KernelFloppyImage 923{ 924 "$(BUILD_CMD)" "$(BOOT_BLOCK)" "$(2)" "$(1)" ; 925 echo "" 926 echo "*************************************************" 927 echo "* Kernel build completed! *" 928 echo "* Boot image for a 1.44M floppy created *" 929 echo "*************************************************" 930 echo "" 931 echo "Floppy image is $(OBOS_FLOPPY)" 932 echo "The following command will write it to a floppy on BeOS" 933 echo " dd if=$(OBOS_FLOPPY) of=/dev/disk/floppy/raw bs=18k" 934 echo "" 935} 936 937 938