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