-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
61 lines (47 loc) · 1.73 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
57
58
59
60
CC := gcc
CFLAGS := -Wall -g -Werror=missing-declarations -Werror=redundant-decls
LFLAGS := -framework OpenGL -lglew -lGLFW
# Include directory
IDIR := include
# Source directory
SDIR = src
# Object directory
ODIR := obj
INCLUDES = -I$(IDIR)
# $(wildcard pattern…) - this string is replaced by a space-separated list
# of names of existing files that match one of the given file name patterns.
#
# List of header (dependencies) files in $(IDIR) (include directory)
DEPENDENCIES = $(wildcard $(IDIR)/*.h)
# $(patsubst pattern,replacement,text) - finds whitespace-separated words in text
# that match pattern and replaces them with replacement.
#
# List of object files needed to produce the executable - this is will be
# used to say all .c files must be compiled into .o objects
OBJECTS = $(patsubst $(SDIR)/%.c,$(ODIR)/%.o,$(wildcard $(SDIR)/*.c))
# Specifying objects as a dependency makes the compiler first compile the individual c files into objects, and only then build the executable
# ($<) is the first item in the dependencies list, ($@) is the left side of the rule's "":""
#
# Rule to describe how all .c files must be compiled into .o files with the needed dependencies
$(ODIR)/%.o: $(SDIR)/%.c $(DEPENDENCIES)
$(CC) $(INCLUDES) -c $< -o $@ $(CFLAGS)
# ($^) is the right side of the rule's "":""
# So this rule will put all .o files together to output the executable named "emulator"
#
# Rule to build the executable named "emulator"
emulator: $(OBJECTS)
$(CC) $(INCLUDES) $^ -o $@ $(CFLAGS) $(LFLAGS)
@echo All complete!
DEBUG=0
DEBUGT=256
debug: emulator
./emulator -d $(DEBUG)
test: emulator
./emulator -t $(TESTPATH)
dt: emulator
./emulator -t $(TESTPATH) -d $(DEBUGT)
clean:
rm $(ODIR)/*.o
rm emulator
run: emulator
./emulator