-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
94 lines (71 loc) · 2.53 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
include ./paths
#From file 'paths':
#TOOLS
#RISCV_LD_LIBRARY_PATH
#TARGET := Name of current directory:
TARGET := $(notdir $(CURDIR))
SRC_DIR := src
BUILD_DIR := Debug
SRC_CPP := $(foreach DIR, $(SRC_DIR), $(wildcard $(DIR)/*.cpp))
SRC_ASM := $(foreach DIR, $(SRC_DIR), $(wildcard $(DIR)/*.asm))
SRC_S := $(foreach DIR, $(SRC_DIR), $(wildcard $(DIR)/*.S))
OBJECTS := $(addprefix $(BUILD_DIR)/, $(SRC_CPP:.cpp=.o)) \
$(addprefix $(BUILD_DIR)/, $(SRC_ASM:.asm=.o)) \
$(addprefix $(BUILD_DIR)/, $(SRC_S:.S=.o))
CXX := $(TOOLS)riscv64-unknown-elf-g++
CXXFLAGS = -march=rv64g -msmall-data-limit=8 -O0 -fmessage-length=0 \
-fsigned-char -ffunction-sections -fdata-sections -g3 \
-std=gnu++11 -fabi-version=0 \
-fno-exceptions -fno-rtti -fno-use-cxa-atexit -fno-threadsafe-statics -fno-unwind-tables \
-MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
ASFLAGS = -march=rv64g -msmall-data-limit=8 -O0 -fmessage-length=0 \
-fsigned-char -ffunction-sections -fdata-sections -g3 \
-x assembler-with-cpp \
-MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"
LDFLAGS := -march=rv64g -msmall-data-limit=8 -O0 -fmessage-length=0 \
-fsigned-char -ffunction-sections -fdata-sections -g3 \
-T"src/link.ld" -nostartfiles -Xlinker --gc-sections \
-L"${RISCV_LD_LIBRARY_PATH}" \
-Wl,-Map,"$(BUILD_DIR)/$(TARGET).map" \
--specs=nosys.specs
LDLIBS := -lc
default: all
.PHONY: all
all: link
.PHONY: link
link: $(OBJECTS)
@echo Linking target: $(TARGET).elf
@mkdir -p $(dir $@)
$(CXX) $(LDFLAGS) -o $(BUILD_DIR)/$(TARGET).elf $(OBJECTS) $(LDLIBS)
@echo ""
@echo "Post-build:"
$(TOOLS)riscv64-unknown-elf-objdump -S "$(BUILD_DIR)/$(TARGET).elf" > "$(TARGET).txt"
$(TOOLS)riscv64-unknown-elf-objcopy -O verilog "$(BUILD_DIR)/$(TARGET).elf" "$(BUILD_DIR)/$(TARGET).hex"
@echo ""
@$(TOOLS)riscv64-unknown-elf-size --format=berkeley "$(BUILD_DIR)/$(TARGET).elf"
@echo ""
@echo "Done"
#Compile obj-files and generate dependency info
$(BUILD_DIR)/%.o: %.cpp
@echo Building file: "$@"
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS)
@echo ""
$(BUILD_DIR)/%.o: %.S
@echo Building file: "$@"
@mkdir -p $(dir $@)
$(CXX) $(ASFLAGS)
@echo ""
$(BUILD_DIR)/%.o: %.asm
@echo Building file: "$@"
@mkdir -p $(dir $@)
$(CXX) $(ASFLAGS)
@echo ""
#Include .d files for existing .o files
ifneq ($(strip $(OBJECTS:%.o=%.d)),)
-include $(OBJECTS:%.o=%.d)
endif
.PHONY: clean
clean:
@echo "Clean..."
@rm -rf $(BUILD_DIR)/*