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 277 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB 278 # offset in floppy image (>= sizeof(haiku_loader)) 279 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 384 ; # in kB 280 281 # nasm is required for target arch x86 282 if ! $(HAIKU_NASM) { 283 Exit "HAIKU_NASM not set. Please re-run configure." ; 284 } 285 286 case riscv64 : 287 HAIKU_KERNEL_PLATFORM ?= efi ; 288 HAIKU_BOOT_TARGETS += efi riscv ; 289 290 HAIKU_BOOT_SDIMAGE_BEGIN = 2 ; # KiB 291 292 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; 293 # offset in floppy image (>= sizeof(haiku_loader)) 294 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 192 ; # in kB - unused yet 295 HAIKU_BOOT_LOADER_BASE ?= 0x1000000 ; 296 297 case x86_64 : 298 # x86_64 completely shares the x86 bootloader for MBR. 299 HAIKU_KERNEL_PLATFORM ?= bios_ia32 ; 300 HAIKU_BOOT_TARGETS += bios_ia32 efi pxe_ia32 ; 301 302 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 2880 ; # in kB 303 # offset in floppy image (>= sizeof(haiku_loader)) 304 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 384 ; # in kB 305 306 # x86_64 kernel source is under arch/x86. 307 HAIKU_KERNEL_ARCH_DIR = x86 ; 308 309 # nasm is required for target arch x86_64 310 if ! $(HAIKU_NASM) { 311 Exit "HAIKU_NASM not set. Please re-run configure." ; 312 } 313 314 case m68k : 315 HAIKU_KERNEL_PLATFORM ?= atari_m68k ; 316 HAIKU_BOOT_TARGETS += amiga_m68k atari_m68k next_m68k ; 317 switch $(HAIKU_KERNEL_PLATFORM) { 318 case atari_m68k : 319 { 320 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB 321 } 322 case amiga_m68k : 323 { 324 # for now we have trouble reading from double-sided images 325 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 880 ; # in kB 326 } 327 case next_m68k : 328 { 329 HAIKU_BOOT_FLOPPY_IMAGE_SIZE = 1440 ; # in kB 330 } 331 } 332 # offset in floppy image (>= sizeof(haiku_loader)) 333 HAIKU_BOOT_ARCHIVE_IMAGE_OFFSET = 260 ; # in kB 334 HAIKU_CONTAINER_STRIP_EXECUTABLES on 335 $(HAIKU_FLOPPY_BOOT_IMAGE_CONTAINER_NAME) = 1 ; 336 337 case * : 338 Exit "Currently unsupported target CPU:" $(cpu) ; 339 } 340 341 # private kernel headers to be used when compiling kernel code 342 HAIKU_PRIVATE_KERNEL_HEADERS = 343 [ PrivateHeaders $(DOT) kernel libroot shared 344 kernel/boot/platform/$(HAIKU_KERNEL_PLATFORM) ] 345 [ ArchHeaders $(HAIKU_KERNEL_ARCH_DIR) ] 346 [ FDirName $(HAIKU_COMMON_DEBUG_OBJECT_DIR_$(architecture)) system 347 kernel ] 348 $(HAIKU_PRIVATE_SYSTEM_HEADERS_$(architecture)) 349 ; 350 351 # C/C++ flags 352 local ccBaseFlags = -finline -fno-builtin -Wno-main ; 353 354 if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 { 355 if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 { 356 # Clang does not yet understand this flag. 357 ccBaseFlags += -fno-semantic-interposition ; 358 } 359 360 ccBaseFlags += -ffreestanding ; 361 } 362 363 local c++BaseFlags = $(ccBaseFlags) -fno-exceptions ; 364 365 if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) != 1 366 && $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 { 367 c++BaseFlags += -fno-use-cxa-atexit ; 368 } 369 370 HAIKU_KERNEL_CCFLAGS = $(HAIKU_CCFLAGS_$(architecture)) $(ccBaseFlags) ; 371 HAIKU_KERNEL_C++FLAGS = $(HAIKU_C++FLAGS_$(architecture)) $(c++BaseFlags) ; 372 HAIKU_KERNEL_PIC_CCFLAGS = ; 373 HAIKU_KERNEL_PIC_LINKFLAGS = ; 374 HAIKU_KERNEL_ADDON_LINKFLAGS = ; 375 376 # Common boot-related cflags which apply to all loaders 377 HAIKU_BOOT_CCFLAGS = $(HAIKU_CCFLAGS_$(architecture)) $(ccBaseFlags) ; 378 HAIKU_BOOT_C++FLAGS = $(HAIKU_C++FLAGS_$(architecture)) $(c++BaseFlags) ; 379 HAIKU_BOOT_OPTIM = -Os ; 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 HAIKU_BOOT_DEFINES += _BOOT_MODE ; 598 599 # kernel add-on glue code 600 HAIKU_KERNEL_ADDON_BEGIN_GLUE_CODE = <$(architecture)>crtbeginS.o 601 <src!system!glue!$(architecture)>haiku_version_glue.o ; 602 HAIKU_KERNEL_ADDON_END_GLUE_CODE = <$(architecture)>crtendS.o ; 603} 604 605 606rule ArchitectureSetupWarnings architecture 607{ 608 # ArchitectureSetupWarnings <architecture> ; 609 # 610 # Sets up compiler warnings and error flags for various subdirectories for 611 # the given packaging architecture. 612 613 if $(HAIKU_CC_IS_CLANG_$(architecture)) = 1 { 614 AppendToConfigVar CCFLAGS : 615 HAIKU_TOP src system libroot posix glibc : 616 -fgnu89-inline -fheinous-gnu-extensions : global ; 617 } 618 619 local cpu = $(HAIKU_CPU_$(architecture)) ; 620 switch $(cpu) { 621 case arm : 622 return ; 623 # we use #warning as placeholders for things to write... 624 case m68k : 625 return ; 626 # we use #warning as placeholders for things to write... 627 case ppc : 628 return ; 629 # we use #warning as placeholders for things to write... 630 } 631 632 # enable -Werror for certain parts of the source tree 633 HAIKU_WERROR_ARCH = $(architecture) ; 634 635 rule EnableWerror dirTokens : scope { 636 # Clang gives way more warnings than GCC, so that code won't compile 637 # with -Werror when using Clang. 638 if $(HAIKU_CC_IS_CLANG_$(architecture)) != 1 { 639 SetConfigVar WARNINGS : HAIKU_TOP $(dirTokens) : treatAsErrors 640 : $(scope) ; 641 } 642 } 643 644 rule EnableStackProtector dirTokens : scope { 645 # enable stack protector, if requested 646 if $(HAIKU_USE_STACK_PROTECTOR) = 1 { 647 AppendToConfigVar CCFLAGS : HAIKU_TOP $(dirTokens) : 648 -fstack-protector : $(scope) ; 649 AppendToConfigVar C++FLAGS : HAIKU_TOP $(dirTokens) : 650 -fstack-protector : $(scope) ; 651 } 652 } 653 654 # Work-around for GCC 2 problem -- despite -Wno-multichar it reports 655 # multichar warnings in headers/private/kernel/debugger_keymaps.h included 656 # by src/system/kernel/arch/x86/arch_debug_console.cpp. 657 if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) = 1 { 658 local file = <src!system!kernel!arch!x86>arch_debug_console.o ; 659 WARNINGS on $(file) = $(WARNINGS) ; 660 } 661 662 EnableWerror src add-ons accelerants ; 663 EnableWerror src add-ons bluetooth ; 664 EnableWerror src add-ons decorators ; 665 EnableWerror src add-ons disk_systems ; 666 EnableWerror src add-ons input_server ; 667 EnableWerror src add-ons kernel bluetooth ; 668 EnableWerror src add-ons kernel bus_managers ; 669 EnableWerror src add-ons kernel busses ; 670 EnableWerror src add-ons kernel console ; 671 EnableWerror src add-ons kernel cpu ; 672 EnableWerror src add-ons kernel debugger ; 673# EnableWerror src add-ons kernel drivers audio ; 674 EnableWerror src add-ons kernel drivers bluetooth ; 675 EnableWerror src add-ons kernel drivers bus ; 676 EnableWerror src add-ons kernel drivers common ; 677 EnableWerror src add-ons kernel drivers disk ; 678 EnableWerror src add-ons kernel drivers dvb ; 679# EnableWerror src add-ons kernel drivers graphics ; 680 EnableWerror src add-ons kernel drivers graphics intel_extreme ; 681 EnableWerror src add-ons kernel drivers input ; 682 EnableWerror src add-ons kernel drivers joystick ; 683 EnableWerror src add-ons kernel drivers midi ; 684 EnableWerror src add-ons kernel drivers misc ; 685 EnableWerror src add-ons kernel drivers network ether 3com ; 686# EnableWerror src add-ons kernel drivers network ether atheros813x ; 687# EnableWerror src add-ons kernel drivers network ether atheros81xx ; 688# EnableWerror src add-ons kernel drivers network ether attansic_l1 ; 689# EnableWerror src add-ons kernel drivers network ether attansic_l2 ; 690# EnableWerror src add-ons kernel drivers network ether broadcom440x ; 691# EnableWerror src add-ons kernel drivers network ether broadcom570x ; 692# EnableWerror src add-ons kernel drivers network ether dec21xxx ; 693 EnableWerror src add-ons kernel drivers network ether etherpci ; 694# EnableWerror src add-ons kernel drivers network ether intel22x ; 695# EnableWerror src add-ons kernel drivers network ether ipro100 ; 696# EnableWerror src add-ons kernel drivers network ether ipro1000 ; 697# EnableWerror src add-ons kernel drivers network ether jmicron2x0 ; 698# EnableWerror src add-ons kernel drivers network ether marvell_yukon ; 699# EnableWerror src add-ons kernel drivers network ether nforce ; 700# EnableWerror src add-ons kernel drivers network ether pcnet ; 701 EnableWerror src add-ons kernel drivers network ether pegasus ; 702 EnableWerror src add-ons kernel drivers network ether rdc ; 703# EnableWerror src add-ons kernel drivers network ether rtl8139 ; 704# EnableWerror src add-ons kernel drivers network ether rtl81xx ; 705 EnableWerror src add-ons kernel drivers network ether sis19x ; 706# EnableWerror src add-ons kernel drivers network ether sis900 ; 707# EnableWerror src add-ons kernel drivers network ether syskonnect ; 708 EnableWerror src add-ons kernel drivers network ether usb_asix ; 709 EnableWerror src add-ons kernel drivers network ether usb_davicom ; 710 EnableWerror src add-ons kernel drivers network ether usb_ecm ; 711 EnableWerror src add-ons kernel drivers network ether usb_rndis ; 712 EnableWerror src add-ons kernel drivers network ether via_rhine ; 713 EnableWerror src add-ons kernel drivers network ether virtio ; 714# EnableWerror src add-ons kernel drivers network ether vt612x ; 715 EnableWerror src add-ons kernel drivers network ether wb840 ; 716 EnableWerror src add-ons kernel drivers network tun ; 717# EnableWerror src add-ons kernel drivers network wlan ; 718 EnableWerror src add-ons kernel drivers network wwan ; 719 EnableWerror src add-ons kernel drivers ports ; 720 EnableWerror src add-ons kernel drivers power ; 721 EnableWerror src add-ons kernel drivers printer ; 722 EnableWerror src add-ons kernel drivers random ; 723 EnableWerror src add-ons kernel drivers tty ; 724 EnableWerror src add-ons kernel drivers video ; 725 EnableWerror src add-ons kernel file_systems bfs ; 726 EnableWerror src add-ons kernel file_systems cdda ; 727 EnableWerror src add-ons kernel file_systems ext2 ; 728 EnableWerror src add-ons kernel file_systems fat ; 729 EnableWerror src add-ons kernel file_systems googlefs ; 730 EnableWerror src add-ons kernel file_systems iso9660 ; 731 EnableWerror src add-ons kernel file_systems layers ; 732# EnableWerror src add-ons kernel file_systems netfs ; 733 EnableWerror src add-ons kernel file_systems nfs ; 734 EnableWerror src add-ons kernel file_systems nfs4 ; 735# EnableWerror src add-ons kernel file_systems ntfs ; 736 EnableWerror src add-ons kernel file_systems packagefs ; 737 EnableWerror src add-ons kernel file_systems ramfs ; 738 EnableWerror src add-ons kernel file_systems reiserfs ; 739 EnableWerror src add-ons kernel file_systems udf ; 740 EnableWerror src add-ons kernel file_systems userlandfs ; 741# EnableWerror src add-ons kernel file_systems xfs ; 742 EnableWerror src add-ons kernel generic ; 743 EnableWerror src add-ons kernel network ; 744 EnableWerror src add-ons kernel partitioning_systems ; 745 EnableWerror src add-ons kernel power ; 746 EnableWerror src add-ons locale ; 747 EnableWerror src add-ons mail_daemon ; 748 EnableWerror src add-ons media media-add-ons ; 749 EnableWerror src add-ons media plugins ape_reader ; 750 EnableWerror src add-ons media plugins au_reader ; 751 EnableWerror src add-ons media plugins ffmpeg ; 752 EnableWerror src add-ons media plugins raw_decoder ; 753 EnableWerror src add-ons print ; 754 EnableWerror src add-ons screen_savers ; 755 EnableWerror src add-ons tracker ; 756 EnableWerror src add-ons translators bmp ; 757 EnableWerror src add-ons translators exr ; 758 EnableWerror src add-ons translators gif ; 759 EnableWerror src add-ons translators hvif ; 760 EnableWerror src add-ons translators ico ; 761 EnableWerror src add-ons translators jpeg ; 762# EnableWerror src add-ons translators jpeg2000 ; 763 EnableWerror src add-ons translators pcx ; 764 EnableWerror src add-ons translators png ; 765 EnableWerror src add-ons translators ppm ; 766 EnableWerror src add-ons translators raw ; 767 EnableWerror src add-ons translators rtf ; 768 EnableWerror src add-ons translators sgi ; 769 EnableWerror src add-ons translators shared ; 770 EnableWerror src add-ons translators stxt ; 771 EnableWerror src add-ons translators tga ; 772 EnableWerror src add-ons translators tiff ; 773 EnableWerror src add-ons translators wonderbrush ; 774 EnableWerror src add-ons print ; 775 EnableWerror src bin debug strace ; 776 EnableWerror src bin desklink ; 777 EnableWerror src bin listusb ; 778 EnableWerror src bin multiuser ; 779 EnableWerror src bin package ; 780 EnableWerror src bin package_repo ; 781 EnableWerror src bin pkgman ; 782 EnableWerror src bin writembr ; 783 EnableWerror src libs bsd ; 784 EnableWerror src apps ; 785 EnableWerror src kits ; 786 EnableWerror src preferences ; 787 EnableWerror src servers ; 788 EnableWerror src system boot ; 789 EnableWerror src system kernel ; 790 EnableWerror src system libroot add-ons ; 791 EnableWerror src system libroot os ; 792 EnableWerror src system libroot posix locale ; 793 EnableWerror src system libroot posix wchar ; 794 EnableWerror src system runtime_loader ; 795 796 EnableStackProtector src apps ; 797 EnableStackProtector src kits ; 798 EnableStackProtector src preferences ; 799 EnableStackProtector src servers ; 800 EnableStackProtector src system kernel ; 801} 802 803 804rule MultiArchIfPrimary ifValue : elseValue : architecture 805{ 806 # MultiArchIfPrimary <ifValue> : <elseValue> 807 # [ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ; 808 # 809 # Returns one of the two given values depending on whether 810 # <architecture> is the primary packaging architecture. 811 812 architecture ?= $(TARGET_PACKAGING_ARCH) ; 813 814 if $(architecture) = $(TARGET_PACKAGING_ARCHS[1]) { 815 return $(ifValue) ; 816 } 817 return $(elseValue) ; 818} 819 820 821rule MultiArchConditionalGristFiles files : primaryGrist : secondaryGrist 822 : architecture 823{ 824 # MultiArchConditionalGristFiles <files> : <primaryGrist> 825 # : <secondaryGrist> [ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ; 826 # 827 # Returns <files> with their grist set to either <primaryGrist> or 828 # <secondaryGrist> depending on whether <architecture> is the primary 829 # packaging architecture. 830 831 architecture ?= $(TARGET_PACKAGING_ARCH) ; 832 833 local grist = [ MultiArchIfPrimary $(primaryGrist) : $(secondaryGrist) 834 : $(architecture) ] ; 835 return $(files:G=$(grist:E=)) ; 836} 837 838 839rule MultiArchDefaultGristFiles files : gristPrefix : architecture 840{ 841 # MultiArchDefaultGristFiles <files> : <gristPrefix> 842 # [ : <architecture> = $(TARGET_PACKAGING_ARCH) ] ; 843 # 844 # Convenient shorthand for MultiArchConditionalGristFiles for the common 845 # case that for a secondary packaging architecture the packaging 846 # architecture name shall be appended to the grist while it shall be omitted 847 # for the primary packaging architecture. IOW, if architecture is the 848 # primary packaging architecture, <files> are returned with their grist set 849 # to <gristPrefix>, otherwise <files> are returned with their grist set to 850 # <gristPrefix>!<architecture> respectively <architecture> (if <gristPrefix> 851 # is empty). 852 853 architecture ?= $(TARGET_PACKAGING_ARCH) ; 854 855 local secondaryGrist = $(gristPrefix)!$(architecture) ; 856 secondaryGrist ?= $(architecture) ; 857 858 return [ MultiArchConditionalGristFiles $(files) : $(gristPrefix) : 859 $(secondaryGrist) : $(architecture) ] ; 860} 861 862 863rule MultiArchSubDirSetup architectures 864{ 865 # MultiArchSubDirSetup <architectures> ; 866 # 867 # For each of the given packaging architectures <architectures> that are 868 # in the packaging architectures configured for the build (or all configured 869 # packaging architectures, if <architectures> is empty) an object is 870 # prepared that can be used for an "on ... { ... }" block to set up subdir 871 # variables for the respective packaging architecture. Most notably 872 # TARGET_PACKAGING_ARCH, TARGET_ARCH are set to the values for the 873 # respective packaging architecture. The per-subdir variables SOURCE_GRIST, 874 # LOCATE_TARGET, LOCATE_SOURCE, SEARCH_SOURCE, *_LOCATE_TARGET, are reset. 875 # All SUBDIR* and config variables are set to the values they had when this 876 # rule was invoked. 877 878 local result ; 879 architectures ?= $(TARGET_PACKAGING_ARCHS) ; 880 local architecture ; 881 for architecture in $(architectures) { 882 if ! $(architecture) in $(TARGET_PACKAGING_ARCHS) { 883 continue ; 884 } 885 886 local architectureObject = $(architecture:G=<arch-object>) ; 887 result += $(architectureObject) ; 888 889 # Set the variables that default to the values of the respective 890 # variables for the primary architecture. 891 TARGET_PACKAGING_ARCH on $(architectureObject) = $(architecture) ; 892 893 local var ; 894 for var in TARGET_ARCH { 895 $(var) on $(architectureObject) = $($(var)_$(architecture)) ; 896 } 897 898 # Clone the current config variable values and the variables SubDir 899 # resets. 900 for var in $(AUTO_SET_UP_CONFIG_VARIABLES) SUBDIR$(SUBDIRRESET) { 901 $(var) on $(architectureObject) = $($(var)) ; 902 } 903 904 # adjust SOURCE_GRIST and HDRGRIST 905 SOURCE_GRIST on $(architectureObject) 906 = $(SOURCE_GRIST:E=)!$(architecture) ; 907 908 HDRGRIST on $(architectureObject) 909 = $(HDRGRIST:E=)!$(architecture) ; 910 911 # Adjust the subdir's object dirs that are architecture dependent. To 912 # avoid duplicating the code from SetupObjectsDir, we call it. Since it 913 # sets global variables, we set these variables on our object, call 914 # SetupObjectsDir in an "on" block, and grab the new variable values. 915 local hostTarget = HOST TARGET ; 916 local objectDirVars = 917 COMMON_ARCH COMMON_DEBUG DEBUG_$(HAIKU_DEBUG_LEVELS) 918 ; 919 objectDirVars = 920 COMMON_PLATFORM_LOCATE_TARGET 921 $(hostTarget)_$(objectDirVars)_LOCATE_TARGET 922 LOCATE_TARGET 923 LOCATE_SOURCE 924 SEARCH_SOURCE 925 ; 926 927 for var in $(objectDirVars) { 928 $(var) on $(architectureObject) = ; 929 } 930 931 on $(architectureObject) { 932 SetupObjectsDir ; 933 934 for var in $(objectDirVars) { 935 $(var) on $(architectureObject) = $($(var)) ; 936 } 937 } 938 } 939 940 return $(result) ; 941} 942