-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
56 lines (42 loc) · 1.21 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
# CROSS_PREFIX:=~/riscv/bin/riscv64-unknown-linux-gnu
CROSS_PREFIX:=~/riscv/bin/riscv64-unknown-elf
CC=cc
LD=gcc
CFLAGS:=-I./include -Wall -Werror -g -O0 -std=c99
LDFLAGS:=-static
TESTS_CFLAGS:=-Wall -Werror -g -O0 -std=c99
TESTS_LDFLAGS:=-static
RVCC=$(CROSS_PREFIX)-gcc
DIRS:=. arch
DIRS+=arch/riscv
SRCS:=$(addsuffix /*.c,$(DIRS))
OBJDIR:=build
OBJS:=$(addprefix $(OBJDIR)/,$(patsubst %.c,%.o,$(wildcard $(SRCS))))
PROG:=rvvk
TESTS:=test_hello
.PHONY: all rvkk
all: $(PROG) $(TESTS)
rvvk: $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^
$(OBJDIR)/%.o: %.c | $(OBJDIR)
$(CC) $(CFLAGS) -c -o $@ $<
$(OBJDIR):
mkdir -p $(addprefix $(OBJDIR)/, $(DIRS))
%: tests/%.c
$(RVCC) $(TESTS_LDFLAGS) $(TESTS_CFLAGS) -z separate-code -o $@ $<
debug:
@echo "CC = $(CC)"
@echo "LD = $(LD)"
@echo "CFLAGS = $(CFLAGS)"
@echo "LDFLAGS = $(LDFLAGS)"
@echo "RVCC = $(RVCC)"
@echo "DIRS = $(DIRS)"
@echo "SRCS = $(SRCS)"
@echo "OBJDIR = $(OBJDIR)"
@echo "OBJS = $(OBJS)"
@echo "PROG = $(PROG)"
@echo "TESTS_CFLAGS = $(TESTS_CFLAGS)"
@echo "TESTS_LDFLAGS = $(TESTS_LDFLAGS)"
@echo "TESTS = $(TESTS)"
clean:
rm -rf $(OBJDIR) $(PROG) $(TESTS)