86 lines
2.0 KiB
Makefile
86 lines
2.0 KiB
Makefile
ifndef _MK_COMMON
|
|
_MK_COMMON := # defined
|
|
|
|
TL_TARGET?=all
|
|
BOARD?=iss
|
|
|
|
.PHONY: $(TL_TARGET)
|
|
$(TL_TARGET): $(TARGET).elf
|
|
|
|
ENV_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
|
|
BSP_BASE=$(ENV_DIR)/..
|
|
PLATFORM_DIR = $(ENV_DIR)/$(BOARD)
|
|
|
|
include $(BSP_BASE)/libwrap/libwrap.mk
|
|
|
|
|
|
ASM_SRCS += $(ENV_DIR)/start.S $(ENV_DIR)/entry.S
|
|
C_SRCS += $(PLATFORM_DIR)/init.c
|
|
|
|
LINKER_SCRIPT ?= $(PLATFORM_DIR)/$(LINK_TARGET).lds
|
|
|
|
INCLUDES += -I$(BSP_BASE)/include
|
|
INCLUDES += -I$(BSP_BASE)/drivers/
|
|
INCLUDES += -I$(ENV_DIR)
|
|
INCLUDES += -I$(PLATFORM_DIR)
|
|
|
|
LDFLAGS += -march=$(RISCV_ARCH) -mabi=$(RISCV_ABI)
|
|
LDFLAGS += -L$(ENV_DIR)
|
|
LD_SCRIPT += -T $(LINKER_SCRIPT) -Wl,--no-warn-rwx-segments -Wl,-Map=$(TARGET).map -nostartfiles
|
|
|
|
ifneq (,$(findstring specs=nano.specs,$(LDFLAGS), LD_SCRIPT))
|
|
# Found
|
|
else
|
|
# Not found
|
|
endif
|
|
|
|
|
|
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).elf $(LINK_OBJS)
|
|
|
|
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
|
|
CFLAGS += -mabi=$(RISCV_ABI)
|
|
CFLAGS += -mcmodel=medany
|
|
CFLAGS += -DBOARD_$(BOARD)
|
|
|
|
TRIPLET?=riscv64-unknown-elf
|
|
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
|
|
OBJCOPY := $(TOOL_DIR)$(TRIPLET)-objcopy
|
|
|
|
ifndef NO_DEFAULT_LINK
|
|
$(TARGET).elf: $(LINK_OBJS) $(LINK_DEPS)
|
|
echo LINK_OBJS: $(LINK_OBJS)
|
|
$(LD) $(LINK_OBJS) $(LDFLAGS) $(LIBWRAP_LDFLAGS) $(LIBWRAP) $(LD_SCRIPT) -o $@
|
|
$(OBJDUMP) -d -S $@ > $(TARGET).dis
|
|
endif
|
|
|
|
$(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:
|
|
rm -f $(CLEAN_OBJS) $(LIBWRAP)
|
|
|
|
endif
|