1rule ArchitectureSetup architecture 2{ 3 # ArchitectureSetup <architecture> ; 4 # 5 # Initializes all global packaging architecture dependent variables for the 6 # given packaging architecture. Also sets HAIKU_ARCH (to the primary 7 # architecture), if this is the first invocation of the rule, and adds 8 # the architecture to HAIKU_ARCHS, if not yet contained. 9 10 # enable GCC -pipe option, if requested 11 local ccBaseFlags ; 12 if $(HAIKU_USE_GCC_PIPE) = 1 { 13 ccBaseFlags = -pipe ; 14 } 15 16 if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 { 17 # disable strict aliasing on anything newer than gcc 2 as it may lead to 18 # unexpected results. 19 # TODO: remove the -fno-strict-aliasing option when all code has been 20 # analyzed/fixed with regard to aliasing. 21 ccBaseFlags += -fno-strict-aliasing ; 22 23 # Without this flag, GCC deletes many null-pointer checks that are 24 # technically undefined behavior (e.g. passing NULL to strdup, among 25 # others), which breaks both the kernel and various applications. See: 26 # - https://freelists.org/post/haiku-development/hrev45320-Yet-another-nonobvious-effect-of-ftreevrp-optimization 27 # - https://dev.haiku-os.org/ticket/13285#comment:8 (& subsequent comments) 28 # - https://dev.haiku-os.org/ticket/10803#comment:4 (& subsequent comments) 29 # Note that the Linux also does the same: 30 # - https://github.com/torvalds/linux/commit/a3ca86aea507904 31 ccBaseFlags += -fno-delete-null-pointer-checks ; 32 33 # disable some builtins that are incompatible with our definitions 34 ccBaseFlags += -fno-builtin-fork -fno-builtin-vfork ; 35 } 36 37 # default architecture tuning 38 local cpu = $(HAIKU_CPU_$(architecture)) ; 39 local archFlags ; 40 switch $(cpu) { 41 case ppc : archFlags += -mcpu=440fp ; 42 case arm : archFlags += -march=armv7-a -mfloat-abi=hard ; 43 case arm64 : archFlags += -march=armv8.2-a+fp16 ; 44 case x86 : archFlags += -march=pentium ; 45 case riscv64 : archFlags += -march=rv64gc ; 46 } 47 if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 { 48 # TODO: These should be included in Clang's compiler specs. 49 ccBaseFlags += -fPIC ; 50 HAIKU_LINKFLAGS_$(architecture) += -shared ; 51 52 # lld doesn't currently implement R_RISCV_ALIGN relaxation 53 if $(cpu) = riscv64 { 54 ccBaseFlags += -mno-relax ; 55 } 56 } 57 ccBaseFlags += $(archFlags) ; 58 59 # activating graphite optimizations 60 if $(HAIKU_USE_GCC_GRAPHITE_$(architecture)) = 1 { 61 ccBaseFlags += -floop-nest-optimize -fgraphite-identity ; 62 } 63 64 # initial state for flags etc. 65 HAIKU_C++_$(architecture) ?= $(HAIKU_CC_$(architecture)) ; 66 HAIKU_LINK_$(architecture) ?= $(HAIKU_CC_$(architecture)) ; 67 68 HAIKU_CCFLAGS_$(architecture) += $(ccBaseFlags) -nostdinc ; 69 HAIKU_C++FLAGS_$(architecture) += $(ccBaseFlags) -nostdinc ; 70 HAIKU_LINKFLAGS_$(architecture) += $(ccBaseFlags) ; 71 HAIKU_ASFLAGS_$(architecture) += $(archFlags) -nostdinc ; 72 73 # strip is required 74 if ! $(HAIKU_STRIP_$(architecture)) { 75 Exit "HAIKU_STRIP_$(architecture) not set. Please re-run configure." ; 76 } 77 78 HAIKU_ARCH_$(architecture) = $(cpu) ; 79 HAIKU_ARCH ?= $(cpu) ; 80 # Set only, if not set yet. This way HAIKU_ARCH is set to the primary 81 # architecture. 82 if ! $(cpu) in $(HAIKU_ARCHS) { 83 HAIKU_ARCHS += $(cpu) ; 84 } 85 HAIKU_DEFINES_$(architecture) += ARCH_$(cpu) ; 86 87 # directories 88 HAIKU_ARCH_OBJECT_DIR_$(architecture) 89 = [ FDirName $(HAIKU_OBJECT_BASE_DIR) $(architecture) ] ; 90 HAIKU_COMMON_DEBUG_OBJECT_DIR_$(architecture) 91 = [ FDirName $(HAIKU_ARCH_OBJECT_DIR_$(architecture)) common ] ; 92 HAIKU_DEBUG_0_OBJECT_DIR_$(architecture) 93 = [ FDirName $(HAIKU_ARCH_OBJECT_DIR_$(architecture)) release ] ; 94 95 local level ; 96 for level in $(HAIKU_DEBUG_LEVELS[2-]) { 97 HAIKU_DEBUG_$(level)_OBJECT_DIR_$(architecture) 98 = [ FDirName $(HAIKU_ARCH_OBJECT_DIR_$(architecture)) 99 debug_$(level) ] ; 100 } 101 102 # set variables for gcc header options 103 SetIncludePropertiesVariables HAIKU : _$(architecture) ; 104 105 # warning flags 106 HAIKU_WARNING_CCFLAGS_$(architecture) = -Wall 107 -Wno-multichar 108 -Wpointer-arith -Wsign-compare 109 -Wmissing-prototypes ; 110 HAIKU_WARNING_C++FLAGS_$(architecture) = -Wall 111 -Wno-multichar 112 -Wpointer-arith -Wsign-compare 113 -Wno-ctor-dtor-privacy -Woverloaded-virtual ; 114 115 # disable some Clang warnings that are not very useful 116 if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 { 117 HAIKU_WARNING_CCFLAGS_$(architecture) += 118 -Wno-unused-private-field -Wno-gnu-designator 119 -Wno-builtin-requires-header ; 120 HAIKU_WARNING_C++FLAGS_$(architecture) += 121 -Wno-unused-private-field -Wno-gnu-designator 122 -Wno-builtin-requires-header ; 123 } 124 125 HAIKU_WERROR_FLAGS_$(architecture) = ; 126 127 if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 { 128 # TODO: Remove all these. 129 HAIKU_WERROR_FLAGS_$(architecture) += -Wno-error=unused-but-set-variable 130 -Wno-error=deprecated -Wno-error=deprecated-declarations 131 -Wno-error=cpp -Wno-error=trigraphs -Wno-error=register ; 132 # These currently generate too many "false positives." 133 HAIKU_WERROR_FLAGS_$(architecture) += -Wno-error=address-of-packed-member 134 -Wno-error=stringop-overread -Wno-error=array-bounds ; 135 # But these can stay. 136 HAIKU_WERROR_FLAGS_$(architecture) += -Wno-error=cast-align 137 -Wno-error=format-truncation ; 138 } 139 140 # debug flags 141 local debugFlags = -ggdb ; 142 143 # debug 0: suppress asserts 144 HAIKU_DEBUG_0_CCFLAGS_$(architecture) = [ FDefines NDEBUG=$(NDEBUG) ] ; 145 HAIKU_DEBUG_0_C++FLAGS_$(architecture) = [ FDefines NDEBUG=$(NDEBUG) ] ; 146 147 local level ; 148 for level in $(HAIKU_DEBUG_LEVELS[2-]) { 149 local flags = $(debugFlags) [ FDefines DEBUG=$(level) ] ; 150 HAIKU_DEBUG_$(level)_CCFLAGS_$(architecture) = $(flags) ; 151 HAIKU_DEBUG_$(level)_C++FLAGS_$(architecture) = $(flags) ; 152 } 153 154 # TODO: Temporary work-around. Should be defined in the compiler specs 155 HAIKU_LINKFLAGS_$(architecture) += -Xlinker --no-undefined ; 156 157 if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) = 1 { 158 HAIKU_DEFINES_$(architecture) += _BEOS_R5_COMPATIBLE_ ; 159 } 160 161 # private shared kernel/libroot headers 162 HAIKU_PRIVATE_SYSTEM_HEADERS_$(architecture) 163 = [ PrivateHeaders $(DOT) system system/arch/$(cpu) ] ; 164 165 # library and executable glue code 166 local commonGlueCode = 167 <src!system!glue!$(architecture)>init_term_dyn.o 168 <src!system!glue!arch!$(cpu)!$(architecture)>crti.o 169 <src!system!glue!arch!$(cpu)!$(architecture)>crtn.o 170 ; 171 HAIKU_LIBRARY_BEGIN_GLUE_CODE_$(architecture) = 172 <src!system!glue!arch!$(cpu)!$(architecture)>crti.o 173 <$(architecture)>crtbeginS.o 174 <src!system!glue!$(architecture)>init_term_dyn.o 175 ; 176 HAIKU_LIBRARY_END_GLUE_CODE_$(architecture) = 177 <$(architecture)>crtendS.o 178 <src!system!glue!arch!$(cpu)!$(architecture)>crtn.o 179 ; 180 HAIKU_EXECUTABLE_BEGIN_GLUE_CODE_$(architecture) = 181 <src!system!glue!arch!$(cpu)!$(architecture)>crti.o 182 <$(architecture)>crtbeginS.o 183 <src!system!glue!$(architecture)>start_dyn.o 184 <src!system!glue!$(architecture)>init_term_dyn.o 185 ; 186 HAIKU_EXECUTABLE_END_GLUE_CODE_$(architecture) 187 = $(HAIKU_LIBRARY_END_GLUE_CODE_$(architecture)) ; 188 189 SEARCH on <$(architecture)>crtbeginS.o <$(architecture)>crtendS.o 190 = $(HAIKU_GCC_LIB_DIR_$(architecture)) ; 191 192 # init library name map 193 local libraryGrist = "" ; 194 if $(architecture) != $(HAIKU_PACKAGING_ARCHS[1]) { 195 libraryGrist = $(architecture) ; 196 } 197 local i ; 198 for i in be bnetapi debug device game locale mail media midi midi2 199 network package root screensaver textencoding tracker 200 translation z { 201 local library = lib$(i).so ; 202 HAIKU_LIBRARY_NAME_MAP_$(architecture)_$(i) 203 = $(library:G=$(libraryGrist)) ; 204 } 205 HAIKU_LIBRARY_NAME_MAP_$(architecture)_localestub 206 = <$(architecture)>liblocalestub.a ; 207 HAIKU_LIBRARY_NAME_MAP_$(architecture)_shared 208 = <$(architecture)>libshared.a ; 209 if $(architecture) = $(HAIKU_PACKAGING_ARCHS[1]) { 210 HAIKU_LIBRARY_NAME_MAP_$(architecture)_input_server 211 = <nogrist>input_server ; 212 } else { 213 HAIKU_LIBRARY_NAME_MAP_$(architecture)_input_server 214 = <$(architecture)>input_server ; 215 } 216} 217 218 219rule KernelArchitectureSetup architecture 220{ 221 # KernelArchitectureSetup <architecture> ; 222 # 223 # Initializes the global kernel and boot loader related variables. Those 224 # don't have a packaging architecture suffix, since they are only set for 225 # the primary packaging architecture. <architecture> is the primary 226 # packaging architecture (supplied for convenience). 227 228 HAIKU_KERNEL_ARCH = $(HAIKU_ARCH) ; 229 HAIKU_KERNEL_ARCH_DIR = $(HAIKU_KERNEL_ARCH) ; 230 231 local cpu = $(HAIKU_CPU_$(architecture)) ; 232 233 switch $(cpu) { 234 case ppc : 235 HAIKU_KERNEL_PLATFORM ?= openfirmware ; 236 HAIKU_BOOT_TARGETS += openfirmware ; 237 238 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB 239 # offset in floppy image (>= sizeof(haiku_loader)) 240 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 384 ; # in kB 241 242 case sparc : 243 HAIKU_KERNEL_PLATFORM ?= openfirmware ; 244 HAIKU_BOOT_TARGETS += openfirmware ; 245 246 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB 247 # offset in floppy image (>= sizeof(haiku_loader)) 248 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 384 ; # in kB 249 250 case arm : 251 HAIKU_KERNEL_PLATFORM ?= efi ; 252 HAIKU_BOOT_TARGETS += efi ; 253 254 # SOC's like allwinner need an offset to skip the hardcoded initial loader 255 HAIKU_BOOT_SDIMAGE_BEGIN = 20475 ; # in KiB 256 257 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; 258 # offset in floppy image (>= sizeof(haiku_loader)) 259 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - unused yet 260 HAIKU_BOOT_LOADER_BASE ?= 0x1000000 ; 261 262 case arm64 : 263 HAIKU_KERNEL_PLATFORM ?= efi ; 264 HAIKU_BOOT_TARGETS += efi ; 265 266 HAIKU_BOOT_SDIMAGE_BEGIN = 2 ; # in KiB 267 268 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; 269 # offset in floppy image (>= sizeof(haiku_loader)) 270 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - unused yet 271 HAIKU_BOOT_LOADER_BASE ?= 0x1000000 ; 272 273 case x86 : 274 HAIKU_KERNEL_PLATFORM ?= bios_ia32 ; 275 HAIKU_BOOT_TARGETS += bios_ia32 efi pxe_ia32 ; 276 HAIKU_ANYBOOT_LEGACY = 1 ; 277 278 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB 279 # offset in floppy image (>= sizeof(haiku_loader)) 280 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 384 ; # in kB 281 282 # nasm is required for target arch x86 283 if ! $(HAIKU_NASM) { 284 Exit "HAIKU_NASM not set. Please re-run configure." ; 285 } 286 287 case riscv64 : 288 HAIKU_KERNEL_PLATFORM ?= efi ; 289 HAIKU_BOOT_TARGETS += efi riscv ; 290 291 HAIKU_BOOT_SDIMAGE_BEGIN = 2 ; # KiB 292 293 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; 294 # offset in floppy image (>= sizeof(haiku_loader)) 295 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - unused yet 296 HAIKU_BOOT_LOADER_BASE ?= 0x1000000 ; 297 298 case x86_64 : 299 # x86_64 completely shares the x86 bootloader for MBR. 300 HAIKU_KERNEL_PLATFORM ?= bios_ia32 ; 301 HAIKU_BOOT_TARGETS += bios_ia32 efi pxe_ia32 ; 302 303 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB 304 # offset in floppy image (>= sizeof(haiku_loader)) 305 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 384 ; # in kB 306 307 # x86_64 kernel source is under arch/x86. 308 HAIKU_KERNEL_ARCH_DIR = x86 ; 309 310 # nasm is required for target arch x86_64 311 if ! $(HAIKU_NASM) { 312 Exit "HAIKU_NASM not set. Please re-run configure." ; 313 } 314 315 case m68k : 316 HAIKU_KERNEL_PLATFORM ?= atari_m68k ; 317 HAIKU_BOOT_TARGETS += amiga_m68k atari_m68k next_m68k ; 318 switch $(HAIKU_KERNEL_PLATFORM) { 319 case atari_m68k : 320 { 321 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB 322 } 323 case amiga_m68k : 324 { 325 # for now we have trouble reading from double-sided images 326 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 880 ; # in kB 327 } 328 case next_m68k : 329 { 330 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB 331 } 332 } 333 # offset in floppy image (>= sizeof(haiku_loader)) 334 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 260 ; # in kB 335 HAIKU_CONTAINER_STRIP_EXECUTABLES on 336 $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) = 1 ; 337 338 case * : 339 Exit "Currently unsupported target CPU:" $(cpu) ; 340 } 341 342 # private kernel headers to be used when compiling kernel code 343 HAIKU_PRIVATE_KERNEL_HEADERS = 344 [ PrivateHeaders $(DOT) kernel libroot shared 345 kernel/boot/platform/$(HAIKU_KERNEL_PLATFORM) ] 346 [ ArchHeaders $(HAIKU_KERNEL_ARCH_DIR) ] 347 [ FDirName $(HAIKU_COMMON_DEBUG_OBJECT_DIR_$(architecture)) system 348 kernel ] 349 $(HAIKU_PRIVATE_SYSTEM_HEADERS_$(architecture)) 350 ; 351 352 # C/C++ flags 353 local ccBaseFlags = -finline -fno-builtin -Wno-main ; 354 355 if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 { 356 if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 { 357 # Clang does not yet understand this flag. 358 ccBaseFlags += -fno-semantic-interposition ; 359 } 360 361 ccBaseFlags += -ffreestanding ; 362 } 363 364 local c++BaseFlags = $(ccBaseFlags) -fno-exceptions ; 365 366 if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 367 && $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 { 368 c++BaseFlags += -fno-use-cxa-atexit ; 369 } 370 371 HAIKU_KERNEL_CCFLAGS = $(HAIKU_CCFLAGS_$(architecture)) $(ccBaseFlags) ; 372 HAIKU_KERNEL_C++FLAGS = $(HAIKU_C++FLAGS_$(architecture)) $(c++BaseFlags) ; 373 HAIKU_KERNEL_PIC_CCFLAGS = ; 374 HAIKU_KERNEL_PIC_LINKFLAGS = ; 375 HAIKU_KERNEL_ADDON_LINKFLAGS = ; 376 377 # Common boot-related cflags which apply to all loaders 378 HAIKU_BOOT_CCFLAGS = $(HAIKU_CCFLAGS_$(architecture)) $(ccBaseFlags) ; 379 HAIKU_BOOT_C++FLAGS = $(HAIKU_C++FLAGS_$(architecture)) $(c++BaseFlags) ; 380 HAIKU_BOOT_LINKFLAGS = ; 381 HAIKU_BOOT_LDFLAGS = -Bstatic ; 382 383 # Remove -fPIC and other unwanted options from the BOOT flags (they are sometimes 384 # added to force PIC in general.) 385 local fixedBootCCFlags ; 386 local fixedBootC++Flags ; 387 for flag in $(HAIKU_BOOT_CCFLAGS) { 388 if $(flag) = "-fpic" || $(flag) = "-fPIC" { 389 continue ; 390 } 391 fixedBootCCFlags += $(flag) ; 392 } 393 for flag in $(HAIKU_BOOT_C++FLAGS) { 394 if $(flag) = "-fpic" || $(flag) = "-fPIC" { 395 continue ; 396 } 397 fixedBootC++Flags += $(flag) ; 398 } 399 HAIKU_BOOT_CCFLAGS = $(fixedBootCCFlags) ; 400 HAIKU_BOOT_C++FLAGS = $(fixedBootC++Flags) ; 401 402 # Any special kernel base addresses 403 if $(HAIKU_BOOT_LOADER_BASE) { 404 HAIKU_BOOT_LDFLAGS += 405 --defsym BOOT_LOADER_BASE=$(HAIKU_BOOT_LOADER_BASE) ; 406 } 407 408 switch $(cpu) { 409 case arm : 410 HAIKU_KERNEL_PIC_LINKFLAGS += -z max-page-size=0x1000 ; 411 HAIKU_KERNEL_ADDON_LINKFLAGS += -z max-page-size=0x1000 ; 412 HAIKU_KERNEL_PIC_CCFLAGS = -fpic ; 413 HAIKU_KERNEL_PIC_LINKFLAGS = -shared ; 414 415 case arm64 : 416 HAIKU_KERNEL_PIC_LINKFLAGS += -z max-page-size=0x1000 ; 417 HAIKU_KERNEL_ADDON_LINKFLAGS += -z max-page-size=0x1000 ; 418 HAIKU_KERNEL_PIC_CCFLAGS = -fpic ; 419 HAIKU_KERNEL_PIC_LINKFLAGS = -shared ; 420 421 case m68k : 422 # We don't want to have to handle emulating missing FPU opcodes for 423 # 040 and 060 in the kernel. 424 HAIKU_KERNEL_CCFLAGS += -m68020-60 ; 425 HAIKU_KERNEL_C++FLAGS += -m68020-60 ; 426 427 case ppc : 428 # Build a position independent PPC kernel. We need to be able to 429 # relocate the kernel, since the virtual address space layout at 430 # boot time is not fixed. 431 HAIKU_KERNEL_PIC_CCFLAGS = -fPIE ; 432 HAIKU_KERNEL_PIC_LINKFLAGS = -shared -fPIE ; 433 434 case riscv64 : 435 # Kernel lives within any single 2 GiB address space. 436 # Default is medlow (-2GiB / +2GiB) 437 HAIKU_KERNEL_CCFLAGS += -mcmodel=medany -fpic ; 438 HAIKU_KERNEL_C++FLAGS += -mcmodel=medany -fpic ; 439 HAIKU_KERNEL_PIC_LINKFLAGS = -shared ; 440 441 case sparc : 442 # The medlow code model is enough (64-bit addresses, programs must 443 # be linked in the low 32 bits of memory. Programs can be 444 # statically or dynamically linked.) 445 HAIKU_KERNEL_CCFLAGS += -mcmodel=medlow ; 446 HAIKU_KERNEL_C++FLAGS += -mcmodel=medlow ; 447 448 # Unfortunately it's not easy to make the kernel be 449 # position-independant, on sparc, that requires relocation support 450 # in the ELF loader to fill in the plt section. 451 HAIKU_KERNEL_PIC_CCFLAGS = -fPIE ; 452 HAIKU_KERNEL_PIC_LINKFLAGS = -shared -fPIE ; 453 454 case x86 : 455 HAIKU_KERNEL_PIC_CCFLAGS = -fno-pic ; 456 HAIKU_KERNEL_CCFLAGS += -march=pentium ; 457 HAIKU_KERNEL_C++FLAGS += -march=pentium ; 458 459 case x86_64 : 460 # Kernel lives in the top 2GB of the address space, use kernel code 461 # model. 462 HAIKU_KERNEL_PIC_CCFLAGS = -fno-pic -mcmodel=kernel ; 463 464 # Disable the red zone, which cannot be used in kernel code due to 465 # interrupts, and always enable the frame pointer so stack traces 466 # are correct. 467 HAIKU_KERNEL_CCFLAGS += -mno-red-zone -fno-omit-frame-pointer ; 468 HAIKU_KERNEL_C++FLAGS += -mno-red-zone -fno-omit-frame-pointer ; 469 HAIKU_KERNEL_PIC_LINKFLAGS += -z max-page-size=0x1000 ; 470 HAIKU_KERNEL_ADDON_LINKFLAGS += -z max-page-size=0x1000 ; 471 472 if x86 in $(HAIKU_ARCHS[2-]) || x86_gcc2 in $(HAIKU_ARCHS[2-]) { 473 Echo "Enable kernel ia32 compatibility" ; 474 HAIKU_KERNEL_DEFINES += _COMPAT_MODE ; 475 HAIKU_KERNEL_COMPAT_MODE = 1 ; 476 } 477 } 478 479 # bootloader-centric flags 480 HAIKU_BOOT_CCFLAGS 481 += -DBOOT_ARCHIVE_IMAGE_OFFSET=$(HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET) ; 482 HAIKU_BOOT_C++FLAGS 483 += -DBOOT_ARCHIVE_IMAGE_OFFSET=$(HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET) ; 484 485 local bootTarget ; 486 for bootTarget in $(HAIKU_BOOT_TARGETS) { 487 switch $(bootTarget) { 488 case efi : 489 # efi bootloader is PIC 490 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fpic -fno-stack-protector 491 -fPIC -fshort-wchar -Wno-error=unused-variable -Wno-error=main ; 492 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fpic -fno-stack-protector 493 -fPIC -fshort-wchar -Wno-error=unused-variable -Wno-error=main ; 494 switch $(cpu) { 495 case x86 : 496 if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 { 497 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -maccumulate-outgoing-args ; 498 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -maccumulate-outgoing-args ; 499 } 500 case x86_64 : 501 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -mno-red-zone ; 502 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -mno-red-zone ; 503 if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 { 504 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -maccumulate-outgoing-args ; 505 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -maccumulate-outgoing-args ; 506 } 507 case arm : 508 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -mfloat-abi=soft ; 509 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -mfloat-abi=soft ; 510 511 # Remove any previous -mfloat-abi=hard setting from compiler flags 512 local fixedBootCCFlags ; 513 local fixedBootC++Flags ; 514 for flag in $(HAIKU_BOOT_CCFLAGS) { 515 if $(flag) = "-mfloat-abi=hard" { 516 continue ; 517 } 518 fixedBootCCFlags += $(flag) ; 519 } 520 for flag in $(HAIKU_BOOT_C++FLAGS) { 521 if $(flag) = "-mfloat-abi=hard" { 522 continue ; 523 } 524 fixedBootC++Flags += $(flag) ; 525 } 526 HAIKU_BOOT_CCFLAGS = $(fixedBootCCFlags) ; 527 HAIKU_BOOT_C++FLAGS = $(fixedBootC++Flags) ; 528 } 529 HAIKU_BOOT_$(bootTarget:U)_LDFLAGS = -Bstatic -Bsymbolic 530 -nostdlib -znocombreloc -no-undefined ; 531 case bios_ia32 : 532 # bios_ia32 is non-PIC 533 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -march=pentium ; 534 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -march=pentium ; 535 if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 { 536 HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386 ; 537 } else { 538 HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386_haiku ; 539 } 540 if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 { 541 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -Wno-error=main -m32 ; 542 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -Wno-error=main -m32 ; 543 } 544 case pxe_ia32 : 545 # pxe_ia32 is non-PIC 546 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -march=pentium ; 547 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -march=pentium ; 548 if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 { 549 HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386 ; 550 } else { 551 HAIKU_BOOT_$(bootTarget:U)_LDFLAGS += -m elf_i386_haiku ; 552 } 553 if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 { 554 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -Wno-error=main -m32 ; 555 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -Wno-error=main -m32 ; 556 } 557 case *_m68k : 558 # TODO: make sure all m68k bootloaders are non-PIC 559 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -Wno-error=main ; 560 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -Wno-error=main ; 561 switch $(cpu) { 562 case m68k : 563 # use only common instructions by default 564 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -m68020-60 ; 565 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -m68020-60 ; 566 # TODO: coldfire (FireBee) 567 } 568 case riscv : 569 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -mcmodel=medany -fno-omit-frame-pointer -fno-plt -fno-pic -fno-semantic-interposition ; 570 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -mcmodel=medany -fno-omit-frame-pointer -fno-plt -fno-pic -fno-semantic-interposition ; 571 case openfirmware : 572 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -fno-semantic-interposition -Wno-error=main -Wstack-usage=1023 ; 573 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -fno-semantic-interposition -Wno-error=main -Wstack-usage=1023 ; 574 case * : 575 # all other bootloaders are non-PIC 576 HAIKU_BOOT_$(bootTarget:U)_CCFLAGS += -fno-pic -Wno-error=main ; 577 HAIKU_BOOT_$(bootTarget:U)_C++FLAGS += -fno-pic -Wno-error=main ; 578 } 579 } 580 581 # warning flags 582 HAIKU_KERNEL_WARNING_CCFLAGS = $(HAIKU_WARNING_CCFLAGS_$(architecture)) ; 583 HAIKU_KERNEL_WARNING_C++FLAGS = $(HAIKU_WARNING_C++FLAGS_$(architecture)) ; 584 585 # debug flags 586 local level ; 587 for level in $(HAIKU_DEBUG_LEVELS) { 588 local flags = $(HAIKU_DEBUG_FLAGS) [ FDefines DEBUG=$(level) ] ; 589 HAIKU_KERNEL_DEBUG_$(level)_CCFLAGS 590 = $(HAIKU_DEBUG_$(level)_CCFLAGS_$(architecture)) ; 591 HAIKU_KERNEL_DEBUG_$(level)_C++FLAGS 592 = $(HAIKU_DEBUG_$(level)_C++FLAGS_$(architecture)) ; 593 } 594 595 # defines 596 HAIKU_KERNEL_DEFINES += _KERNEL_MODE ; 597 598 # kernel add-on glue code 599 HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE = <$(architecture)>crtbeginS.o 600 <src!system!glue!$(architecture)>haiku_version_glue.o ; 601 HAIKU_KERNEL_ADDON_END_GLUE_CODE = <$(architecture)>crtendS.o ; 602} 603 604 605rule ArchitectureSetupWarnings architecture 606{ 607 # ArchitectureSetupWarnings <architecture> ; 608 # 609 # Sets up compiler warnings and error flags for various subdirectories for 610 # the given packaging architecture. 611 612 if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 { 613 AppendToConfigVar CCFLAGS : 614 HAIKU_TOP src system libroot posix glibc : 615 -fgnu89-inline -fheinous-gnu-extensions : global ; 616 } 617 618 local cpu = $(HAIKU_CPU_$(architecture)) ; 619 switch $(cpu) { 620 case arm : 621 return ; 622 # we use #warning as placeholders for things to write... 623 case m68k : 624 return ; 625 # we use #warning as placeholders for things to write... 626 case ppc : 627 return ; 628 # we use #warning as placeholders for things to write... 629 } 630 631 # enable -Werror for certain parts of the source tree 632 HAIKU_WERROR_ARCH = $(architecture) ; 633 634 rule EnableWerror dirTokens : scope { 635 # Clang gives way more warnings than GCC, so that code won't compile 636 # with -Werror when using Clang. 637 if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 { 638 SetConfigVar WARNINGS : HAIKU_TOP $(dirTokens) : treatAsErrors 639 : $(scope) ; 640 } 641 } 642 643 rule EnableStackProtector dirTokens : scope { 644 # enable stack protector, if requested 645 if $(HAIKU_USE_STACK_PROTECTOR) = 1 { 646 AppendToConfigVar CCFLAGS : HAIKU_TOP $(dirTokens) : 647 -fstack-protector : $(scope) ; 648 AppendToConfigVar C++FLAGS : HAIKU_TOP $(dirTokens) : 649 -fstack-protector : $(scope) ; 650 } 651 } 652 653 # Work-around for GCC 2 problem -- despite -Wno-multichar it reports 654 # multichar warnings in headers/private/kernel/debugger_keymaps.h included 655 # by src/system/kernel/arch/x86/arch_debug_console.cpp. 656 if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) = 1 { 657 local file = <src!system!kernel!arch!x86>arch_debug_console.o ; 658 WARNINGS on $(file) = $(WARNINGS) ; 659 } 660 661 EnableWerror src add-ons accelerants ; 662 EnableWerror src add-ons bluetooth ; 663 EnableWerror src add-ons decorators ; 664 EnableWerror src add-ons disk_systems ; 665 EnableWerror src add-ons input_server ; 666 EnableWerror src add-ons kernel bluetooth ; 667 EnableWerror src add-ons kernel bus_managers ; 668 EnableWerror src add-ons kernel busses ; 669 EnableWerror src add-ons kernel console ; 670 EnableWerror src add-ons kernel cpu ; 671 EnableWerror src add-ons kernel debugger ; 672# EnableWerror src add-ons kernel drivers audio ; 673 EnableWerror src add-ons kernel drivers bluetooth ; 674 EnableWerror src add-ons kernel drivers bus ; 675 EnableWerror src add-ons kernel drivers common ; 676 EnableWerror src add-ons kernel drivers disk ; 677 EnableWerror src add-ons kernel drivers dvb ; 678# EnableWerror src add-ons kernel drivers graphics ; 679 EnableWerror src add-ons kernel drivers graphics intel_extreme ; 680 EnableWerror src add-ons kernel drivers input ; 681 EnableWerror src add-ons kernel drivers joystick ; 682 EnableWerror src add-ons kernel drivers midi ; 683 EnableWerror src add-ons kernel drivers misc ; 684 EnableWerror src add-ons kernel drivers network ether 3com ; 685# EnableWerror src add-ons kernel drivers network ether atheros813x ; 686# EnableWerror src add-ons kernel drivers network ether atheros81xx ; 687# EnableWerror src add-ons kernel drivers network ether attansic_l1 ; 688# EnableWerror src add-ons kernel drivers network ether attansic_l2 ; 689# EnableWerror src add-ons kernel drivers network ether broadcom440x ; 690# EnableWerror src add-ons kernel drivers network ether broadcom570x ; 691# EnableWerror src add-ons kernel drivers network ether dec21xxx ; 692 EnableWerror src add-ons kernel drivers network ether etherpci ; 693# EnableWerror src add-ons kernel drivers network ether intel22x ; 694# EnableWerror src add-ons kernel drivers network ether ipro100 ; 695# EnableWerror src add-ons kernel drivers network ether ipro1000 ; 696# EnableWerror src add-ons kernel drivers network ether jmicron2x0 ; 697# EnableWerror src add-ons kernel drivers network ether marvell_yukon ; 698# EnableWerror src add-ons kernel drivers network ether nforce ; 699# EnableWerror src add-ons kernel drivers network ether pcnet ; 700 EnableWerror src add-ons kernel drivers network ether pegasus ; 701 EnableWerror src add-ons kernel drivers network ether rdc ; 702# EnableWerror src add-ons kernel drivers network ether rtl8139 ; 703# EnableWerror src add-ons kernel drivers network ether rtl81xx ; 704 EnableWerror src add-ons kernel drivers network ether sis19x ; 705# EnableWerror src add-ons kernel drivers network ether sis900 ; 706# EnableWerror src add-ons kernel drivers network ether syskonnect ; 707 EnableWerror src add-ons kernel drivers network ether usb_asix ; 708 EnableWerror src add-ons kernel drivers network ether usb_davicom ; 709 EnableWerror src add-ons kernel drivers network ether usb_ecm ; 710 EnableWerror src add-ons kernel drivers network ether usb_rndis ; 711 EnableWerror src add-ons kernel drivers network ether via_rhine ; 712 EnableWerror src add-ons kernel drivers network ether virtio ; 713# EnableWerror src add-ons kernel drivers network ether vt612x ; 714 EnableWerror src add-ons kernel drivers network ether wb840 ; 715 EnableWerror src add-ons kernel drivers network tun ; 716# EnableWerror src add-ons kernel drivers network wlan ; 717 EnableWerror src add-ons kernel drivers network wwan ; 718 EnableWerror src add-ons kernel drivers ports ; 719 EnableWerror src add-ons kernel drivers power ; 720 EnableWerror src add-ons kernel drivers printer ; 721 EnableWerror src add-ons kernel drivers random ; 722 EnableWerror src add-ons kernel drivers tty ; 723 EnableWerror src add-ons kernel drivers video ; 724 EnableWerror src add-ons kernel file_systems bfs ; 725 EnableWerror src add-ons kernel file_systems cdda ; 726 EnableWerror src add-ons kernel file_systems ext2 ; 727# EnableWerror src add-ons kernel file_systems fat ; 728 EnableWerror src add-ons kernel file_systems googlefs ; 729 EnableWerror src add-ons kernel file_systems iso9660 ; 730 EnableWerror src add-ons kernel file_systems layers ; 731# EnableWerror src add-ons kernel file_systems netfs ; 732# EnableWerror src add-ons kernel file_systems nfs ; 733 EnableWerror src add-ons kernel file_systems nfs4 ; 734# EnableWerror src add-ons kernel file_systems ntfs ; 735 EnableWerror src add-ons kernel file_systems packagefs ; 736# EnableWerror src add-ons kernel file_systems ramfs ; 737# EnableWerror src add-ons kernel file_systems reiserfs ; 738 EnableWerror src add-ons kernel file_systems udf ; 739 EnableWerror src add-ons kernel file_systems userlandfs ; 740 EnableWerror src add-ons kernel file_systems xfs ; 741 EnableWerror src add-ons kernel generic ; 742 EnableWerror src add-ons kernel network ; 743 EnableWerror src add-ons kernel partitioning_systems ; 744 EnableWerror src add-ons kernel power ; 745 EnableWerror src add-ons locale ; 746 EnableWerror src add-ons mail_daemon ; 747 EnableWerror src add-ons media media-add-ons ; 748 EnableWerror src add-ons media plugins ape_reader ; 749 EnableWerror src add-ons media plugins au_reader ; 750# EnableWerror src add-ons media plugins ffmpeg ; 751 EnableWerror src add-ons media plugins raw_decoder ; 752 EnableWerror src add-ons print ; 753 EnableWerror src add-ons screen_savers ; 754 EnableWerror src add-ons tracker ; 755 EnableWerror src add-ons translators bmp ; 756 EnableWerror src add-ons translators exr ; 757 EnableWerror src add-ons translators gif ; 758 EnableWerror src add-ons translators hvif ; 759 EnableWerror src add-ons translators ico ; 760 EnableWerror src add-ons translators jpeg ; 761# EnableWerror src add-ons translators jpeg2000 ; 762 EnableWerror src add-ons translators pcx ; 763 EnableWerror src add-ons translators png ; 764 EnableWerror src add-ons translators ppm ; 765 EnableWerror src add-ons translators raw ; 766 EnableWerror src add-ons translators rtf ; 767 EnableWerror src add-ons translators sgi ; 768 EnableWerror src add-ons translators shared ; 769 EnableWerror src add-ons translators stxt ; 770 EnableWerror src add-ons translators tga ; 771 EnableWerror src add-ons translators tiff ; 772 EnableWerror src add-ons translators wonderbrush ; 773 EnableWerror src add-ons print ; 774 EnableWerror src bin desklink ; 775 EnableWerror src bin listusb ; 776 EnableWerror src bin multiuser ; 777 EnableWerror src bin package ; 778 EnableWerror src bin package_repo ; 779 EnableWerror src bin pkgman ; 780 EnableWerror src bin writembr ; 781 EnableWerror src libs bsd ; 782 EnableWerror src apps ; 783 EnableWerror src kits ; 784 EnableWerror src preferences ; 785 EnableWerror src servers ; 786 EnableWerror src system boot ; 787 EnableWerror src system kernel ; 788 EnableWerror src system libroot add-ons ; 789 EnableWerror src system libroot os ; 790 EnableWerror src system libroot posix locale ; 791 EnableWerror src system libroot posix wchar ; 792 EnableWerror src system runtime_loader ; 793 794 EnableStackProtector src apps ; 795 EnableStackProtector src kits ; 796 EnableStackProtector src preferences ; 797 EnableStackProtector src servers ; 798 EnableStackProtector src system kernel ; 799} 800 801 802rule MultiArchIfPrimary ifValue : elseValue : architecture 803{ 804 # MultiArchIfPrimary <ifValue> : <elseValue> 805 # [ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ; 806 # 807 # Returns one of the two given values depending on whether 808 # <architecture> is the primary packaging architecture. 809 810 architecture ?= $(TARGET_PACKAGING_ARCH) ; 811 812 if $(architecture) = $(TARGET_PACKAGING_ARCHS[1]) { 813 return $(ifValue) ; 814 } 815 return $(elseValue) ; 816} 817 818 819rule MultiArchConditionalGristFiles files : primaryGrist : secondaryGrist 820 : architecture 821{ 822 # MultiArchConditionalGristFiles <files> : <primaryGrist> 823 # : <secondaryGrist> [ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ; 824 # 825 # Returns <files> with their grist set to either <primaryGrist> or 826 # <secondaryGrist> depending on whether <architecture> is the primary 827 # packaging architecture. 828 829 architecture ?= $(TARGET_PACKAGING_ARCH) ; 830 831 local grist = [ MultiArchIfPrimary $(primaryGrist) : $(secondaryGrist) 832 : $(architecture) ] ; 833 return $(files:G=$(grist:E=)) ; 834} 835 836 837rule MultiArchDefaultGristFiles files : gristPrefix : architecture 838{ 839 # MultiArchDefaultGristFiles <files> : <gristPrefix> 840 # [ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ; 841 # 842 # Convenient shorthand for MultiArchConditionalGristFiles for the common 843 # case that for a secondary packaging architecture the packaging 844 # architecture name shall be appended to the grist while it shall be omitted 845 # for the primary packaging architecture. IOW, if architecture is the 846 # primary packaging architecture, <files> are returned with their grist set 847 # to <gristPrefix>, otherwise <files> are returned with their grist set to 848 # <gristPrefix>!<architecture> respectively <architecture> (if <gristPrefix> 849 # is empty). 850 851 architecture ?= $(TARGET_PACKAGING_ARCH) ; 852 853 local secondaryGrist = $(gristPrefix)!$(architecture) ; 854 secondaryGrist ?= $(architecture) ; 855 856 return [ MultiArchConditionalGristFiles $(files) : $(gristPrefix) : 857 $(secondaryGrist) : $(architecture) ] ; 858} 859 860 861rule MultiArchSubDirSetup architectures 862{ 863 # MultiArchSubDirSetup <architectures> ; 864 # 865 # For each of the given packaging architectures <architectures> that are 866 # in the packaging architectures configured for the build (or all configured 867 # packaging architectures, if <architectures> is empty) an object is 868 # prepared that can be used for an "on ... { ... }" block to set up subdir 869 # variables for the respective packaging architecture. Most notably 870 # TARGET_PACKAGING_ARCH, TARGET_ARCH are set to the values for the 871 # respective packaging architecture. The per-subdir variables SOURCE_GRIST, 872 # LOCATE_TARGET, LOCATE_SOURCE, SEARCH_SOURCE, *_LOCATE_TARGET, are reset. 873 # All SUBDIR* and config variables are set to the values they had when this 874 # rule was invoked. 875 876 local result ; 877 architectures ?= $(TARGET_PACKAGING_ARCHS) ; 878 local architecture ; 879 for architecture in $(architectures) { 880 if ! $(architecture) in $(TARGET_PACKAGING_ARCHS) { 881 continue ; 882 } 883 884 local architectureObject = $(architecture:G=<arch-object>) ; 885 result += $(architectureObject) ; 886 887 # Set the variables that default to the values of the respective 888 # variables for the primary architecture. 889 TARGET_PACKAGING_ARCH on $(architectureObject) = $(architecture) ; 890 891 local var ; 892 for var in TARGET_ARCH { 893 $(var) on $(architectureObject) = $($(var)_$(architecture)) ; 894 } 895 896 # Clone the current config variable values and the variables SubDir 897 # resets. 898 for var in $(AUTO_SET_UP_CONFIG_VARIABLES) SUBDIR$(SUBDIRRESET) { 899 $(var) on $(architectureObject) = $($(var)) ; 900 } 901 902 # adjust SOURCE_GRIST and HDRGRIST 903 SOURCE_GRIST on $(architectureObject) 904 = $(SOURCE_GRIST:E=)!$(architecture) ; 905 906 HDRGRIST on $(architectureObject) 907 = $(HDRGRIST:E=)!$(architecture) ; 908 909 # Adjust the subdir's object dirs that are architecture dependent. To 910 # avoid duplicating the code from SetupObjectsDir, we call it. Since it 911 # sets global variables, we set these variables on our object, call 912 # SetupObjectsDir in an "on" block, and grab the new variable values. 913 local hostTarget = HOST TARGET ; 914 local objectDirVars = 915 COMMON_ARCH COMMON_DEBUG DEBUG_$(HAIKU_DEBUG_LEVELS) 916 ; 917 objectDirVars = 918 COMMON_PLATFORM_LOCATE_TARGET 919 $(hostTarget)_$(objectDirVars)_LOCATE_TARGET 920 LOCATE_TARGET 921 LOCATE_SOURCE 922 SEARCH_SOURCE 923 ; 924 925 for var in $(objectDirVars) { 926 $(var) on $(architectureObject) = ; 927 } 928 929 on $(architectureObject) { 930 SetupObjectsDir ; 931 932 for var in $(objectDirVars) { 933 $(var) on $(architectureObject) = $($(var)) ; 934 } 935 } 936 } 937 938 return $(result) ; 939} 940