-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
65 lines (48 loc) · 897 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
55
56
57
58
59
60
61
62
63
64
65
# Compiler
CC=gcc
LD=gcc
# Flags
CFLAGS=-O2 -Wall -Wno-tautological-compare
LDFLAGS=
# Tools
MKDIR=mkdir
RM=rm
RMDIR=rmdir
# Directories
OBJDIR=obj/
SRCDIR=src/
# Files
BIN=zzazz
HEADERS_RAW= \
instructions.h \
cpu.h \
memory.h \
syscall.h \
opcode_table.h \
SOURCES_RAW= \
main.c \
SOURCES=$(addprefix $(SRCDIR)/, $(SOURCES_RAW))
HEADERS=$(addprefix $(SRCDIR)/, $(HEADERS_RAW))
OBJECTS=$(addprefix $(OBJDIR)/, $(SOURCES:$(SRCDIR)/%.c=%.o))
# Rules
.DEFAULT_GOAL := all
all: $(OBJDIR) $(BIN)
run: all
./$(BIN)
clean:
$(RM) $(BIN) || true
$(RM) $(OBJECTS) || true
$(RMDIR) $(OBJDIR) || true
print_vars:
echo $(SOURCES)
echo $(HEADERS)
echo $(OBJECTS)
$(OBJDIR):
$(MKDIR) -p $(OBJDIR)
$(BINDIR):
$(MKDIR) -p $(BINDIR)
$(BIN): $(OBJECTS)
$(LD) $(LDFLAGS) -o $@ $(OBJECTS)
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(HEADERS)
$(CC) $(CFLAGS) -o $@ -c $<
$(SRCDIR)/%.c: $(HEADERS)