-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
54 lines (40 loc) · 999 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
54
NAME = nemu
INC_DIR += ./include
BUILD_DIR ?= ./build
OBJ_DIR ?= $(BUILD_DIR)/obj
BINARY ?= $(BUILD_DIR)/$(NAME)
include Makefile.git
.DEFAULT_GOAL = app
# Compilation flags
CC = gcc
LD = gcc
INCLUDES = $(addprefix -I, $(INC_DIR))
CFLAGS += -O2 -MMD -Wall -Werror -ggdb3 $(INCLUDES) -fomit-frame-pointer
# Files to be compiled
SRCS = $(shell find src/ -name "*.c")
OBJS = $(SRCS:src/%.c=$(OBJ_DIR)/%.o)
# Compilation patterns
$(OBJ_DIR)/%.o: src/%.c
@echo + CC $<
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c -o $@ $<
# Depencies
-include $(OBJS:.o=.d)
# Some convinient rules
.PHONY: app run submit clean
app: $(BINARY)
ARGS ?= -l $(BUILD_DIR)/nemu-log.txt
# Command to execute NEMU
NEMU_EXEC := $(BINARY) $(ARGS)
$(BINARY): $(OBJS)
$(call git_commit, "compile")
@echo + LD $@
@$(LD) -O2 -o $@ $^ -lSDL2 -lreadline
run: $(BINARY)
$(call git_commit, "run")
$(NEMU_EXEC)
gdb: $(BINARY)
$(call git_commit, "gdb")
gdb -s $(BINARY) --args $(NEMU_EXEC)
clean:
rm -rf $(BUILD_DIR)