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