-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
53 lines (37 loc) · 1.16 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
.PHONY: clean
TARGET=invaders
TEST_TARGET=test
CC=cc
CFLAGS=-std=c17 -Wall -Wextra -pedantic -g -O0 $(shell sdl2-config --cflags)
LN_FLAGS=$(shell sdl2-config --libs)
BUILD_DIR=./build
SRC_DIR=./src
SOURCE = $(wildcard $(SRC_DIR)/*.c)
OBJECTS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SOURCE))
TEST_OBJECTS = build/8080.o build/disassembler_8080.o build/test.o
# Gcc/Clang will create these .d files containing dependencies.
DEP = $(OBJECTS:%.o=%.d)
default: $(TARGET)
$(TARGET): $(BUILD_DIR)/$(TARGET)
$(BUILD_DIR)/$(TARGET): $(OBJECTS)
$(CC) $(CFLAGS) $(LN_FLAGS) $^ -o $@
$(TEST_TARGET): $(BUILD_DIR)/$(TEST_TARGET)
$(BUILD_DIR)/$(TEST_TARGET): $(TEST_OBJECTS)
$(CC) $(CFLAGS) $^ -o $@
-include $(DEP)
# The potential dependency on header files is covered
# by calling `-include $(DEP)`.
# The -MMD flags additionaly creates a .d file with
# the same name as the .o file.
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -MMD -c $< -o $@
build/test.o: test/test.c
@mkdir -p $(@D)
$(CC) $(CFLAGS) -MMD -c $< -o $@
clean:
-rm -rf $(BUILD_DIR)
run: $(TARGET)
$(BUILD_DIR)/$(TARGET)
run_tests: $(TEST_TARGET)
$(BUILD_DIR)/$(TEST_TARGET)