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