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