-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
53 lines (40 loc) · 977 Bytes
/
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
CC:=gcc
TARGET:=linux
SRC_DIR=src
OBJ_DIR=obj
BIN_DIR=bin
CFLAGS=--std=c99
CFLAGS+=-Iinclude/ -Iinclude/hw/$(TARGET)
CFLAGS+=-MMD
ifdef RELEASE
CFLAGS+=-s
else
CFLAGS+=-fsanitize=address -ggdb
endif
LDFLAGS=-lc -lreadline
ifndef RELEASE
LDFLAGS+=-fsanitize=address
endif
OBJS=$(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(wildcard $(SRC_DIR)/*.c))
HWOBJS=$(patsubst $(SRC_DIR)/hw/$(TARGET)/%.c,$(OBJ_DIR)/hw/$(TARGET)/%.o,$(wildcard $(SRC_DIR)/hw/$(TARGET)/*.c))
.PHONY: all run clean clean-all
all: $(BIN_DIR)/$(TARGET)
run: $(BIN_DIR)/$(TARGET)
./$^
$(BIN_DIR)/$(TARGET): $(HWOBJS) $(BIN_DIR)/afi.a
@mkdir -p bin
$(CC) $^ -o $@ $(LDFLAGS)
$(BIN_DIR)/afi.a: $(OBJS)
@mkdir -p bin
$(AR) rcs $@ $^
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p obj/
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/hw/$(TARGET)/%.o: $(SRC_DIR)/hw/$(TARGET)/%.c
@mkdir -p obj/hw/$(TARGET)
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -rf obj/
clean-all: clean
rm -rf bin/
-include $(OBJS:.o=.d)