ls1x-master-v0.4/build/Makefile
2024-11-27 15:39:05 +08:00

96 lines
2.9 KiB
Makefile
Executable File

# **********************************************
# ls1x project
# **********************************************
# Name of application
# **********************************************
# Tools
# **********************************************
CROSS_COMPILE = loongarch32-linux-gnu-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
STRIP = $(CROSS_COMPILE)strip
SIZE = $(CROSS_COMPILE)size
# **********************************************
# Directories
# **********************************************
BUILD_DIR = $(ROOT_DIR)/build
TARGET = $(ROOT_DIR)/target
PUBLIC = $(ROOT_DIR)/public
USER = $(ROOT_DIR)/user
ifeq ($(BOARD),1c102)
BOARDNAME = LS1C102
IMAGENAME = 1c102_demo
else ifeq ($(BOARD),1c103)
BOARDNAME = LS1C103
IMAGENAME = 1c103_demo
endif
PRIVATE = $(ROOT_DIR)/private/ls$(BOARD)
CASE = $(ROOT_DIR)/private/ls$(BOARD)/case
BCMDLINE = $(ROOT_DIR)/user/$(BOARD)_cmdline.o
BCOMMAND = $(ROOT_DIR)/user/$(BOARD)_cmd.o
BINT = $(ROOT_DIR)/user/$(BOARD)_Interrupt.o
SRCDIR = $(TARGET) $(PUBLIC) $(PRIVATE) $(CASE)
VPATH = $(SRCDIR) $(USER)
# **********************************************
# Image file names and map file
# **********************************************
IMAGE_ELF = $(IMAGENAME).elf
IMAGE_BIN = $(IMAGENAME).bin
IMAGE_MAP = $(IMAGENAME).map
# **********************************************
# Compiler and linker options
# **********************************************
INCLUDE += -I$(ROOT_DIR)/include -I$(ROOT_DIR)/public -I$(PRIVATE) -I$(TARGET)
FLAGS = -std=gnu99 -O2 -ffunction-sections -fdata-sections -msoft-float -fsched-pressure -fno-builtin -D $(BOARDNAME)
CC_OPTS = $(DEBUG) $(FLAGS) $(INCLUDE)
CC_COPTS = $(DEBUG) $(FLAGS) $(INCLUDE)
LD_SCRIPT = ld.script
LD_OPTS = -G 0 -static -T $(LD_SCRIPT) -Map $(IMAGE_MAP) --gc-sections
# **********************************************
# Files to be compiled
# **********************************************
SRC_C = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.c))
SRC_S = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.S))
SRC = $(SRC_C) $(SRC_S)
OBJ_C = $(notdir $(patsubst %.c, %.o, $(SRC_C)))
OBJ_C += $(notdir $(BCMDLINE))
OBJ_C += $(notdir $(BCOMMAND))
OBJ_C += $(notdir $(BINT))
OBJ_S = start.o $(filter-out start.o, $(notdir $(patsubst %.S, %.o, $(SRC_S))))
LS1C1X_OBJ = $(OBJ_S) $(OBJ_C)
# **********************************************
# Rules
# **********************************************
.PHONY : all
all : $(IMAGE_BIN)
$(IMAGE_BIN):$(LS1C1X_OBJ)
$(LD) $(LD_OPTS) -o $(IMAGE_ELF) $^ -Map $(IMAGE_MAP)
#$(STRIP) $(IMAGE_ELF)
$(OBJCOPY) -O binary $(IMAGE_ELF) $(IMAGE_BIN)
$(SIZE) $(IMAGE_ELF)
$(OBJDUMP) -alD $(IMAGE_ELF) > $(IMAGENAME).s
#cp -rf $(BUILD_DIR)/$(IMAGE_BIN) ..
$(OBJ_C) : %.o : %.c
$(CC) $(CC_COPTS) -c -o $@ $^
$(OBJ_S) : %.o : %.S
$(CC) $(CC_OPTS) -c -o $@ $^
.PHONY : clean
clean :
rm -rf *.o *.elf *.map *.bin *.s *.a