-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
69 lines (52 loc) · 2.63 KB
/
Copy pathMakefile
File metadata and controls
69 lines (52 loc) · 2.63 KB
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
RISCV_ISA ?= "rv32i_zicsr"
RISCV_ABI ?= "ilp32"
OPTIMIZATION_FLAGS ?= "-O0"
program ?= $(program)
CC ?= ggcc
LD ?= gcc
SRCDIR := ./Software
HEADERDIR := ./Software
BUILDDIR := ./build
TARGET := $(program).elf
SOURCES := $(shell find $(SRCDIR) -type f -name *.c* )
ASSEMBLY := $(shell find $(SRCDIR) -type f -name *.s -or -name *.S)
HEDEARS := $(shell find $(HEADERDIR) -type f -name *.h*)
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(addsuffix .o,$(basename $(SOURCES))))
DEPS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(addsuffix .d,$(basename $(SOURCES))))
CFLAGS := $(OPTIMIZATION_FLAGS) -mcmodel=medlow -march=$(RISCV_ISA) -mabi=$(RISCV_ABI) -static -lc -Wall -Wextra -L$$CC_INSTALLATION_PATH/lib -nostartfiles --entry=_start --static -fno-exceptions -fPIC -falign-functions=16
LDFLAG := $(OPTIMIZATION_FLAGS) -Wl,-Map=./$(program).map,--cref,--no-warn-mismatch -lc -T ./Software/generic/RISCV-platform/linker.ld -nostartfiles -Xlinker --defsym=__stack_size=0xA00 -Wl,--entry=_start --static -fno-exceptions -fPIC
CXXFLAGS := $(OPTIMIZATION_FLAGS) -Wall -Wextra
COBJFLAGS := $(CFLAGS) -c
## verbsely add includes
INC := -I$(SRCDIR)/generic/CSP/Comet/ -I$(SRCDIR)/uC-CPU/ -I$(SRCDIR)/uC-CPU/RISC-V/GCC/ -I$(SRCDIR)/generic/generic/riscv32/micrium_meets_riscv/application/ -I$(SRCDIR)/generic/generic/riscv32/micrium_meets_riscv/Cfg/ -I$(SRCDIR)/generic/generic/riscv32/micrium_meets_riscv/ -I$(SRCDIR)/uC-Clk/Cfg/ -I$(SRCDIR)/uC-Clk/Source/ -I$(SRCDIR)/uC-CPU/Cfg/ -I$(SRCDIR)/uC-LIB/Cfg/ -I$(SRCDIR)/uC-LIB/ -I$(SRCDIR)/uC-OS3/Cfg/ -I$(SRCDIR)/uC-OS3/Ports/RISC-V/RV32/GCC/ -I$(SRCDIR)/uC-OS3/Source/ -I./Software/generic/RISCV-platform/
all: debug
debug: CFLAGS += -g
debug: $(TARGET)
release: $(TARGET)
release: CFLAGS += -O3
GREEN=`tput setaf 2`
RESET=`tput sgr0`
define print_green
@echo "$(GREEN)$(1)$(RESET)"
endef
all: $(TARGET)
clean:
rm -rf $(BUILDDIR)
rm -f $(TARGET)
$(TARGET): $(BUILDDIR) $(OBJECTS) $(HEDEARS)
$(call print_green,"Linking object files...")
@ echo $(CC) $(LDFLAG) $(CFLAGS) $(INC) $(OBJECTS) $(ASSEMBLY) -o $(TARGET)
$(CC) $(LDFLAG) $(CFLAGS) $(INC) $(OBJECTS) $(ASSEMBLY) -o $(TARGET)
$(call print_green,"$(TARGET) has been created!")
$(BUILDDIR) :
mkdir $(BUILDDIR)
$(BUILDDIR)/%.o: $(SRCDIR)/%.c*
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(INC) -c -o $@ $<
@$(CC) $(CFLAGS) $(INC) -M $< -MT $@ > $(@:.o=.td)
@cp $(@:.o=.td) $(@:.o=.d);
@sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.td) >> $(@:.o=.d);
@rm -f $(@:.o=.td)
-include $(DEPS)
.PHONY: clean all