terapines.mk 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # Required Version: ZCC Toolchain Version >= 4.1.2
  2. # If the zcc toolchain version is less than 4.1.2, use nuclei-sdk v0.8.0
  3. CC := zcc
  4. CXX := z++
  5. OBJDUMP := llvm-objdump
  6. OBJCOPY := llvm-objcopy
  7. # use gnu gdb to debug or upload
  8. GDB := riscv64-unknown-elf-gdb
  9. AR := llvm-ar
  10. SIZE := llvm-size
  11. OPENOCD := openocd
  12. ifneq ($(findstring libncrt,$(STDCLIB)),)
  13. $(error Terapines toolchain dont provide libncrt library support)
  14. endif
  15. # Handle standard c library selection variable STDCLIB
  16. ifneq ($(findstring newlib,$(STDCLIB)),)
  17. ### Handle cases when STDCLIB variable has newlib in it
  18. ifeq ($(STDCLIB),newlib_full)
  19. LDLIBS += -lc -lclang_rt.builtins
  20. else ifeq ($(STDCLIB),newlib_fast)
  21. LDLIBS += -lc_small -lclang_rt.builtins_small
  22. STDCLIB_LDFLAGS += -u _printf_float -u _scanf_float
  23. else ifeq ($(STDCLIB),newlib_small)
  24. LDLIBS += -lc_small -lclang_rt.builtins_small
  25. STDCLIB_LDFLAGS += -u _printf_float
  26. else ifeq ($(STDCLIB),newlib_nano)
  27. LDLIBS += -lc_nano -lclang_rt.builtins_nano
  28. # work around for relocation R_RISCV_PCREL_HI20 out of range: -524289 is not in [-524288, 524287]; references _printf_float when compile with rv64
  29. # If it report above error, you can add -u _printf_float
  30. STDCLIB_LDFLAGS += #-u _printf_float
  31. else
  32. LDLIBS += -lc_small -lclang_rt.builtins_small
  33. STDCLIB_LDFLAGS += #-u _printf_float
  34. endif
  35. ###
  36. else ifneq ($(findstring libncrt,$(STDCLIB)),)
  37. ### Handle cases when STDCLIB variable has libncrt in it
  38. LDLIBS += -l$(patsubst lib%,%,$(STDCLIB)) -lheapops_$(NCRTHEAP)
  39. COMMON_FLAGS += -isystem=/include/libncrt
  40. ###
  41. else ifeq ($(STDCLIB),nostd)
  42. ### Handle cases when no standard system directories for header files
  43. COMMON_FLAGS += -nostdinc
  44. ###
  45. else ifeq ($(STDCLIB),nospec)
  46. ### Handle cases no specs configs are passed
  47. COMMON_FLAGS +=
  48. ###
  49. else
  50. LDLIBS += -lc_small -lclang_rt.builtins_small
  51. STDCLIB_LDFLAGS += -u _printf_float
  52. ###
  53. endif
  54. ifneq ($(SEMIHOST),)
  55. ifneq ($(findstring libncrt,$(STDCLIB)),)
  56. LDLIBS += -lfileops_semi
  57. else
  58. LDLIBS += -lsemihost
  59. endif
  60. else
  61. ifneq ($(findstring libncrt,$(STDCLIB)),)
  62. LDLIBS += -lfileops_$(NCRTIO)
  63. endif
  64. endif
  65. ## Link with standard c++ library
  66. LDLIBS += -lc++ -lunwind
  67. ## Heap and stack size settings
  68. ## It will define symbols only used in linker script
  69. ## __STACK_SIZE and __HEAP_SIZE are not a c marco
  70. ## they are ld symbols used by linker
  71. ifneq ($(STACKSZ),)
  72. LDFLAGS += -Wl,--defsym=__STACK_SIZE=$(STACKSZ)
  73. endif
  74. ifneq ($(HEAPSZ),)
  75. LDFLAGS += -Wl,--defsym=__HEAP_SIZE=$(HEAPSZ)
  76. endif
  77. ## SIMU=xlspike/qemu
  78. ### enable run on xlspike and qemu auto-exit if return from main
  79. ifneq ($(SIMU),)
  80. SIMULATION_MODE=SIMULATION_MODE_$(call uc, $(SIMU))
  81. COMMON_FLAGS += -DSIMULATION_MODE=$(SIMULATION_MODE)
  82. endif
  83. COMMON_FLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI) -mcmodel=$(RISCV_CMODEL)
  84. # Enable some experimental extension for llvm clang
  85. COMMON_FLAGS += -menable-experimental-extensions
  86. ## Append mtune options when RISCV_TUNE is defined
  87. ## It might be defined in SoC/<SOC>/build.mk, and can be overwritten by make
  88. ifneq ($(RISCV_TUNE),)
  89. COMMON_FLAGS += -mtune=$(RISCV_TUNE)
  90. endif
  91. # Disable auto vectorization when AUTOVEC=0
  92. # see https://llvm.org/docs/Vectorizers.html
  93. ifeq ($(AUTOVEC),0)
  94. COMMON_FLAGS += -fno-vectorize -fno-slp-vectorize
  95. endif
  96. ifneq ($(findstring newlib,$(STDCLIB)),)
  97. LDFLAGS += -u __on_exit_args
  98. endif
  99. LDFLAGS += -nodefaultlibs