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