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