2023-08-20 15:00:51 +02:00
|
|
|
ifndef _MK_COMMON
|
|
|
|
_MK_COMMON := # defined
|
2018-09-25 18:31:29 +02:00
|
|
|
|
2024-01-13 23:06:01 +01:00
|
|
|
TL_TARGET?=all
|
|
|
|
|
|
|
|
.PHONY: $(TL_TARGET)
|
2024-06-10 10:13:07 +02:00
|
|
|
$(TL_TARGET): $(TARGET).elf
|
2018-09-25 18:31:29 +02:00
|
|
|
|
2024-01-27 16:54:25 +01:00
|
|
|
ENV_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
|
|
|
|
BSP_BASE=$(ENV_DIR)/..
|
|
|
|
PLATFORM_DIR = $(ENV_DIR)/$(BOARD)
|
|
|
|
|
2018-09-25 18:31:29 +02:00
|
|
|
include $(BSP_BASE)/libwrap/libwrap.mk
|
|
|
|
|
2023-08-20 15:00:51 +02:00
|
|
|
BOARD?=iss
|
2018-09-25 18:31:29 +02:00
|
|
|
|
2024-01-27 16:54:25 +01:00
|
|
|
ASM_SRCS += $(ENV_DIR)/start.S $(ENV_DIR)/entry.S
|
|
|
|
C_SRCS += $(PLATFORM_DIR)/init.c
|
2024-12-17 12:32:21 +01:00
|
|
|
C_SRCS += $(PLATFORM_DIR)/write.c
|
2018-09-25 18:31:29 +02:00
|
|
|
|
2024-01-13 23:06:01 +01:00
|
|
|
LINKER_SCRIPT ?= $(PLATFORM_DIR)/$(LINK_TARGET).lds
|
2018-09-25 18:31:29 +02:00
|
|
|
|
|
|
|
INCLUDES += -I$(BSP_BASE)/include
|
|
|
|
INCLUDES += -I$(BSP_BASE)/drivers/
|
|
|
|
INCLUDES += -I$(ENV_DIR)
|
|
|
|
INCLUDES += -I$(PLATFORM_DIR)
|
2024-12-17 12:32:21 +01:00
|
|
|
INCLUDES += -I$(BSP_BASE)/libwrap/sys/
|
2018-09-25 18:31:29 +02:00
|
|
|
|
2023-08-20 15:00:51 +02:00
|
|
|
LDFLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI)
|
|
|
|
LDFLAGS += -L$(ENV_DIR)
|
2024-01-13 23:24:39 +01:00
|
|
|
LD_SCRIPT += -T $(LINKER_SCRIPT) -Wl,--no-warn-rwx-segments -Wl,-Map=$(TARGET).map -nostartfiles
|
2024-01-27 16:54:25 +01:00
|
|
|
|
|
|
|
ifneq (,$(findstring specs=nano.specs,$(LDFLAGS), LD_SCRIPT))
|
|
|
|
# Found
|
|
|
|
else
|
|
|
|
# Not found
|
|
|
|
endif
|
|
|
|
|
2018-09-25 18:31:29 +02:00
|
|
|
|
|
|
|
ASM_OBJS := $(ASM_SRCS:.S=.o)
|
|
|
|
C_OBJS := $(C_SRCS:.c=.o)
|
|
|
|
CXX_OBJS := $(CXX_SRCS:.cpp=.o)
|
|
|
|
|
|
|
|
LINK_OBJS += $(ASM_OBJS) $(C_OBJS) $(CXX_OBJS)
|
|
|
|
LINK_DEPS += $(LINKER_SCRIPT)
|
|
|
|
|
|
|
|
CLEAN_OBJS += $(TARGET) $(LINK_OBJS)
|
|
|
|
|
2023-08-20 15:00:51 +02:00
|
|
|
GCCVERSION = $(shell $(CC) --version | grep gcc | awk '{print($NF);}')
|
|
|
|
ifeq ($(GCCVERSION),9.2)
|
|
|
|
CFLAGS += -march=$(RISCV_ARCH)
|
|
|
|
else
|
|
|
|
CFLAGS += -march=$(RISCV_ARCH)_zicsr_zifencei
|
|
|
|
endif
|
2018-09-25 18:31:29 +02:00
|
|
|
CFLAGS += -mabi=$(RISCV_ABI)
|
|
|
|
CFLAGS += -mcmodel=medany
|
2023-11-24 11:39:23 +01:00
|
|
|
CFLAGS += -DBOARD_$(BOARD)
|
2018-09-25 18:31:29 +02:00
|
|
|
|
|
|
|
TRIPLET?=riscv64-unknown-elf
|
2023-08-20 15:00:51 +02:00
|
|
|
CXX=$(TOOL_DIR)$(TRIPLET)-c++
|
|
|
|
CC=$(TOOL_DIR)$(TRIPLET)-gcc
|
|
|
|
LD=$(TOOL_DIR)$(TRIPLET)-gcc
|
|
|
|
AR=$(TOOL_DIR)$(TRIPLET)-ar
|
|
|
|
OBJDUMP := $(TOOL_DIR)$(TRIPLET)-objdump
|
2024-01-13 23:06:01 +01:00
|
|
|
OBJCOPY := $(TOOL_DIR)$(TRIPLET)-objcopy
|
2018-09-25 18:31:29 +02:00
|
|
|
|
2024-01-13 23:06:01 +01:00
|
|
|
ifndef NO_DEFAULT_LINK
|
2024-06-10 10:13:07 +02:00
|
|
|
$(TARGET).elf: $(LINK_OBJS) $(LINK_DEPS)
|
2024-01-27 16:54:25 +01:00
|
|
|
$(LD) $(LINK_OBJS) $(LDFLAGS) $(LIBWRAP_LDFLAGS) $(LIBWRAP) $(LD_SCRIPT) -o $@
|
2024-01-13 23:06:01 +01:00
|
|
|
$(OBJDUMP) -d -S $@ > $(TARGET).dis
|
|
|
|
endif
|
|
|
|
|
2018-09-25 18:31:29 +02:00
|
|
|
$(ASM_OBJS): %.o: %.S $(HEADERS)
|
|
|
|
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
|
|
|
|
|
|
|
|
$(C_OBJS): %.o: %.c $(HEADERS)
|
|
|
|
$(CC) $(CFLAGS) $(INCLUDES) -include sys/cdefs.h -c -o $@ $<
|
|
|
|
|
|
|
|
$(CXX_OBJS): %.o: %.cpp $(HEADERS)
|
|
|
|
$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) -include sys/cdefs.h -c -o $@ $<
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2024-07-16 16:22:42 +02:00
|
|
|
rm -f $(CLEAN_OBJS) $(LIBWRAP) *.a *.hex *.map *.dis *.elf
|
2018-09-25 18:31:29 +02:00
|
|
|
|
2023-08-20 15:00:51 +02:00
|
|
|
endif
|