terapines.mk 2.9 KB

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