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