-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
48 lines (34 loc) · 1.13 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
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
CPPFLAGS += -Wall -Werror -MMD -MP -Isrc -g -std=c++17
NAME = cpu-sim
# All the .cpp source files
SRCS = $(shell find src -name '*.cpp')
# The implementation source files
IMPL_SRCS = $(shell find src -name '*.cpp' -not -name '*_tests.cpp' -not -name 'main.cpp' -not -name 'test_main.cpp')
# The unit test source files
TEST_SRCS = $(shell find src -name '*_tests.cpp')
TEST_SRCS += $(shell find src -name 'test_main.cpp')
IMPL_OBJS = $(IMPL_SRCS:src/%.cpp=bin/%.o)
TEST_OBJS = $(TEST_SRCS:src/%.cpp=bin/%.o)
DEPS = $(SRCS:src/%.cpp=bin/%.d)
# make syntax:
# <target>: <prerequisite 1> <prerequisite 2> ... <prerequisite n>
# > <recipe>
# Build the program
$(NAME): bin/main.o $(IMPL_OBJS)
g++ $(CPPFLAGS) $^ -o $(NAME)
clean:
rm -rf $(NAME) bin/ tests/output/{*,*/*}/*.{actual,diff}
$(SRCS): | bin
bin:
mkdir -p $(shell find src -type d | sed "s/src/bin/")
# Build objects (non-testing)
bin/%.o: src/%.cpp
g++ $(CPPFLAGS) -Isrc $< -c -o $@
# Auto dependency management.
-include $(DEPS)