-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
82 lines (61 loc) · 2.35 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
# TODO: check unsupported extensions
RV32_EXT ?= rv32gc
OPT_LEVEL ?= 0 1 2
CFLAGS := -std=c99
LDFLAGS := -lsemihost -lm
CURDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
SRC_DIR := $(CURDIR)/src
BUILD_DIR := $(CURDIR)/build
SRCS := \
captcha.c \
fcalc.c \
mandelbrot.c \
nqueens.c \
nyancat.c \
pi.c \
puzzle.c \
qrcode.c \
richards.c \
spirograph.c
ifneq ($(findstring f,$(RV32_EXT)),)
SRCS += \
ieee754.c
endif
EXECUTABLES := $(SRCS:%.c=%.elf)
SHELL_HACK := $(shell mkdir -p $(foreach LEVEL,$(OPT_LEVEL),$(BUILD_DIR)/$(RV32_EXT)/O$(LEVEL)))
.PHONY: all clean distclean build-O0 build-O1 build-O2
ifneq ($(filter $(OPT_LEVEL), 0),)
all: build-O0
endif
ifneq ($(filter $(OPT_LEVEL), 1),)
all: build-O1
endif
ifneq ($(filter $(OPT_LEVEL), 2),)
all: build-O2
endif
all:
$(Q)$(MAKE) -C src/asm-hello BUILD_DIR="$(BUILD_DIR)" RV32_EXT=$(RV32_EXT) OPT_LEVEL="$(OPT_LEVEL)" all
$(Q)$(MAKE) -C src/cc BUILD_DIR="$(BUILD_DIR)" RV32_EXT=$(RV32_EXT) OPT_LEVEL="$(OPT_LEVEL)" all
$(Q)$(MAKE) -C src/ansibench/nbench BUILD_DIR="$(BUILD_DIR)" RV32_EXT=$(RV32_EXT) OPT_LEVEL="$(OPT_LEVEL)" all
$(Q)$(MAKE) -C src/ansibench/coremark BUILD_DIR="$(BUILD_DIR)" RV32_EXT=$(RV32_EXT) OPT_LEVEL="$(OPT_LEVEL)" all
$(Q)$(MAKE) -C src/rv8-bench BUILD_DIR="$(BUILD_DIR)" RV32_EXT=$(RV32_EXT) OPT_LEVEL="$(OPT_LEVEL)" all
include mk/common.mk
include mk/toolchain.mk
build-O0: $(addprefix $(BUILD_DIR)/$(RV32_EXT)/O0/,$(EXECUTABLES))
$(BUILD_DIR)/$(RV32_EXT)/O0/%.elf: $(SRC_DIR)/%.c | build-toolchain
$(VECHO) " RISCVCC\t$(patsubst $(abspath $(BUILD_DIR)/..)/%,%,$@)\n"
$(Q)$(CROSS_COMPILE) -o $@ -O0 $(CFLAGS) $< $(LDFLAGS)
build-O1: $(addprefix $(BUILD_DIR)/$(RV32_EXT)/O1/,$(EXECUTABLES))
$(BUILD_DIR)/$(RV32_EXT)/O1/%.elf: $(SRC_DIR)/%.c | build-toolchain
$(VECHO) " RISCVCC\t$(patsubst $(abspath $(BUILD_DIR)/..)/%,%,$@)\n"
$(Q)$(CROSS_COMPILE) -o $@ -O1 $(CFLAGS) $< $(LDFLAGS)
build-O2: $(addprefix $(BUILD_DIR)/$(RV32_EXT)/O2/,$(EXECUTABLES))
$(BUILD_DIR)/$(RV32_EXT)/O2/%.elf: $(SRC_DIR)/%.c | build-toolchain
$(VECHO) " RISCVCC\t$(patsubst $(abspath $(BUILD_DIR)/..)/%,%,$@)\n"
$(Q)$(CROSS_COMPILE) -o $@ -O2 $(CFLAGS) $< $(LDFLAGS)
clean:
$(RM) -r $(foreach LEVEL,$(OPT_LEVEL),$(BUILD_DIR)/$(RV32_EXT)/O$(LEVEL)/*)
distclean: clean
$(RM) -r $(BUILD_DIR)/*
$(RM) -r $(RISCV_TOOLCHAIN_DIR)/build/*
$(Q)$(MAKE) -C $(RISCV_TOOLCHAIN_DIR) distclean