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} 583 584actions SymLink1 585{ 586 $(RM) $(1) && $(LN) -s $(LINKCONTENTS) $(1) 587} 588 589#------------------------------------------------------------------------------- 590# Low-level OBOS utility rules 591#------------------------------------------------------------------------------- 592rule SetupObjectsDir 593{ 594 local rel_objectsdir; 595 596 # Copy subdir tokens except the first, as that will be "sources", and we 597 # do not want to include that :) 598 rel_objectsdir = [ FDirName $(SUBDIR_TOKENS[2-]) ] ; 599 LOCATE_TARGET = [ FDirName $(OBOS_OBJECT_TARGET) $(rel_objectsdir) ] ; 600} 601 602#------------------------------------------------------------------------------- 603# Link rule/action are overwritten as they don't handle linking files who's name 604# contain spaces very well. Also adds resources and version to executable. 605#------------------------------------------------------------------------------- 606rule Link 607{ 608 # Note: RESFILES must be set before invocation. 609 MODE on $(<) = $(EXEMODE) ; 610 on $(1) XRes $(1) : $(RESFILES) ; 611 SetVersion $(1) ; 612 Chmod $(<) ; 613 SetType $(1) ; 614 MimeSet $(1) ; 615} 616 617actions Link bind NEEDLIBS 618{ 619 $(LINK) $(LINKFLAGS) -o "$(1)" $(UNDEFS) $(2) $(NEEDLIBS) $(LINKLIBS) ; 620} 621 622# BeOS specific rules 623 624rule XRes 625{ 626 # XRes <target> : <resource files> 627 if $(2) 628 { 629 DEPENDS $(1) : $(2) ; 630 XRes1 $(1) : $(2) ; 631 } 632} 633 634rule XRes1 { } 635 636rule SetVersion 637{ 638 # SetVersion <target> 639} 640 641rule SetType 642{ 643 # SetType <target> 644} 645 646rule MimeSet 647{ 648 # SetType <target> 649} 650 651 652if $(OS) = BEOS 653{ 654 655actions XRes1 656{ 657 xres -o "$(1)" $(2) ; 658} 659 660actions SetVersion 661{ 662 setversion "$(1)" -system $(OBOS_BUILD_VERSION) -short "$(OBOS_BUILD_DESCRIPTION)" ; 663} 664 665actions SetType 666{ 667 settype -t $(OBOS_TARGET_TYPE) "$(1)" ; 668} 669 670actions MimeSet 671{ 672 mimeset -f "$(1)" ; 673} 674 675} # if BEOS 676 677 678rule assemble 679{ 680 DEPENDS $(1) : $(2) ; 681 Clean clean : $(1) ; 682} 683 684actions assemble 685{ 686$(CC) -c $(2) -O2 $(KERNEL_CCFLAGS) -o $(1) ; 687} 688 689## Kernel stuff! 690 691rule SetupKernel 692{ 693 # Usage SetupKernel <sources_or_objects> : <extra_cc_flags>; 694 695 local _objs = $(1:S=$(SUFOBJ)) ; 696 697 UsePublicHeaders kernel support ; 698 UsePublicHeaders [ FDirName os kernel ] ; 699 UsePrivateHeaders kernel ; 700 UsePosixHeaders ; 701 UseArchHeaders $(OBOS_ARCH) ; 702 703 SetupObjectsDir ; 704 705 CCFLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ; 706 C++FLAGS on $(_objs) = $(KERNEL_CCFLAGS) $(2) ; 707} 708 709rule KernelObjects 710{ 711 SetupKernel $(1) : $(2) ; 712 713 Objects $(1) ; 714} 715 716rule KernelLd 717{ 718 # KernelLd <name> : <objs> : <linkerscript> : <args> : <gcc_off> ; 719 720 SetupKernel $(2) ; 721 LINK on $(1) = ld ; 722 723 LINKFLAGS on $(1) = $(4) ; 724 if $(3) { LINKFLAGS on $(1) += --script=$(3) ; } 725 726 # Remove any preset LINKLIBS 727 LINKLIBS on $(1) = ; 728 729 # Show that we depend on the libraries we need 730 Clean clean : $(1) ; 731 Depends all : $(1) ; 732 Depends $(1) : $(2) ; 733 734 if $(6) { 735 Depends $(OBOS_KERNEL_CONFIG) : $(1) ; 736 for i in $(6) { 737 SECTIONS on $(OBOS_KERNEL_CONFIG) += ":" $(i) elf32 [ FDirName $(LOCATE_TARGET) $(1) ] ; 738 } 739 } 740 741 MakeLocate $(1) : $(LOCATE_TARGET) ; 742 743 # Add libgcc.a - NB this should be detected not hard coded! 744 if ! $(5) { 745 LINKLIBS on $(1) += "-L $(GCC_PATH) -lgcc" ; 746 } 747} 748 749actions KernelLd 750{ 751$(LINK) $(LINKFLAGS) -o $(1) $(2) $(LINKLIBS) ; 752} 753 754rule KernelStaticLibrary 755{ 756 # Usage KernelStaticLibrary <name> : <sources> : <extra cc flags> ; 757 # This is designed to take a set of sources and libraries and create 758 # a file called lib<name>.a 759 760 SetupKernel $(2) : $(3) ; 761 762 MakeLocateObjects $(2) ; 763 Library $(1) : $(2) ; 764} 765 766rule KernelStaticLibraryObjects 767{ 768 # Usage KernelStaticLibrary <name> : <sources> ; 769 # This is designed to take a set of sources and libraries and create 770 # a file called <name> 771 772 SetupKernel $(2) ; 773 774 # Show that we depend on the libraries we need 775 Clean clean : $(1) ; 776 Depends all : $(1) ; 777 Depends $(1) : $(2) ; 778 779 MakeLocate $(1) : $(LOCATE_TARGET) ; 780} 781 782actions KernelStaticLibraryObjects 783{ 784ar -r $(1) $(2) ; 785} 786 787rule SystemMain 788{ 789 # Usage SystemMain <target> : <sources> : <rqd_by> ; 790 SetupObjectsDir ; 791 792 LINKLIBS = ; 793 794 # This allows us to preset certain commands we use 795 # for building. 796 if $(3) { 797 for obj in $(3) { 798 BUILD_CMD on $(obj) = [ FDirName $(LOCATE_TARGET) $(1) ] ; 799 } 800 } 801 802 Main $(1) : $(2) ; 803} 804 805rule KernelConfigSection 806{ 807 # KernelConfigSection <section> : <type> : <file> ; 808 SECTIONS on $(OBOS_KERNEL_CONFIG) += ":" $(1) $(2) $(3) ; 809} 810 811rule WriteKernelConfig 812{ 813 # usage: WriteKernelConfig <target> ; 814 815 Depends files : $(1) ; 816 817 LOCATE on $(1) = $(LOCATE_TARGET) ; 818 819 MakeLocate $(1) : $(LOCATE_TARGET) ; 820 821 Clean clean : $(1) ; 822} 823 824actions WriteKernelConfig 825{ 826 target=$(1) 827 echo "# OpenBeOS Kernel Config File" > $target 828 echo "# Automatically generated - do not edit!" >> $target 829 issection="0" 830 section= 831 for i in "$(SECTIONS)" ; do 832 if [ $issection == 1 ]; then 833 section=$i 834 issection=2 835 echo "["$section"]" >> $target 836 elif [ $issection == 2 ]; then 837 type=$i 838 issection=3 839 echo "type="$type >> $target 840 else 841 if [ $i == ":" ]; then 842 issection=1 843 echo "" >> $target 844 else 845 file=$i 846 case $file in 847 /*) ;; 848 *) file=`pwd`/$file;; 849 esac 850 echo "file="$file >> $target 851 fi 852 fi 853 done 854} 855 856rule BuildKernel 857{ 858 # Usage BuildKernel <target> : <config_file> ; 859 860 Depends all : $(1) ; 861 Depends $(1) : $(2) ; 862 Clean clean : $(1) ; 863 864 MakeLocate $(1) : $(LOCATE_TARGET) ; 865} 866 867actions BuildKernel 868{ 869 $(BUILD_CMD) --strip-debug --strip-binary strip $(2) -o $(1) ; 870 echo "" 871 echo "Kernel linked!" 872 echo "" 873} 874 875# At present I don't bother moving the final location for 876# the floppy image as it makes copying it onto a floppy easier if it's 877# where you did the build. This is easy enough changed. 878rule KernelFloppyImage 879{ 880 # Usage KernelFloppyImage <target> : <kernel> : <bootblock> ; 881 882 Depends all : $(1) ; 883 Depends $(1) : $(2) ; 884 Clean clean : $(1) ; 885 886 BOOT_BLOCK on $(1) = $(3) ; 887} 888 889# This may be a bit verbose, but I think it's useful to show what's 890# going on, at least in this early stage of development. 891actions KernelFloppyImage 892{ 893 $(BUILD_CMD) $(BOOT_BLOCK) $(2) $(1) ; 894 echo "" 895 echo "*************************************************" 896 echo "* Kernel build completed! *" 897 echo "* Boot image for a 1.44M floppy created *" 898 echo "*************************************************" 899 echo "" 900 echo "Floppy image is $(OBOS_FLOPPY)" 901 echo "The following command will write it to a floppy on BeOS" 902 echo " dd if=$(OBOS_FLOPPY) of=/dev/disk/floppy/raw bs=18k" 903 echo "" 904} 905 906 907