-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
79 lines (66 loc) · 2.97 KB
/
Makefile
File metadata and controls
79 lines (66 loc) · 2.97 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
CXX := clang++
# NOTE: -MMD and -MP are used to generate a list of (header and source)
# dependencies for each object file and header file. These have the `.d`
# extension.
CXXFLAGS := -std=c++20 -Wall -Wextra -Wimplicit-fallthrough -MMD -MP -Isrc -Wsign-conversion -DNAN_BOXING
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
CXXFLAGS += -I$(shell brew --prefix boost)/include
endif
BUILD ?= debug
# -g is used to include debug information in the compiled binaries, useful for
# LLDB or else you just get a sea of assembly code!
ifeq ($(BUILD),debug)
CXXFLAGS += -g -O0 -DLOX_DEBUG -DLOX_GC_DEBUG
else ifeq ($(BUILD),release)
CXXFLAGS += -O3
else
$(error Unknown build type: $(BUILD). Valid options are "debug" and "release".)
endif
# NOTE: Phony targets are targets that aren't actual files. If you don't
# declare this, and there's a file named "clean" in your directory, then
# running `make clean` will cause Make to try to build that file, instead
# of the `clean` target.
.PHONY: clean all test
# NOTE: The first target is always the default target, i.e., the target that
# is built when you just run `make` without any arguments.
APP := loxc
all: $(APP)
try: $(APP)
./$(APP) test.lox
bench: $(APP)
hyperfine --warmup 2 './$(APP) bench.lox'
SRCS := $(wildcard src/*.cpp)
OBJS := $(SRCS:.cpp=.o)
DEPS := $(SRCS:.cpp=.d)
# NOTE: This line will include the dependency files generated by the -MMD flag.
# That means that we don't need to manually specify dependencies here: we let
# Clang figure it out, and include the generated files.
-include $(DEPS)
# NOTE: The dependency files only tell Make which files depend on which files. It
# doesn't include instructions for actually building the object files. In fact,
# Make has a built-in rule for building `.o` files from `.cpp` files, so we could
# get away without specifying it; but it's probably better to be explicit.
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
APP_OBJS := app/main.o
$(APP): $(OBJS) $(APP_OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^
TEST_SRCS := $(wildcard tests/*.cpp)
TEST_OBJS := $(TEST_SRCS:.cpp=.o)
TEST_DEPS := $(TEST_SRCS:.cpp=.d)
-include $(TEST_DEPS)
TEST_RUNNER_EXECUTABLE := tests/test_runner
# NOTE: I had to find the name `catch2-with-main` by inspecting the contents of
# $(brew --prefix catch2)/share/pkgconfig. Homebrew doesn't really expose this to
# you (even though it does install catch2-with-main when you install catch 2).
CATCH2_FLAGS := $(shell pkg-config --cflags --libs catch2-with-main)
# NOTE: $(CATCH2_FLAGS) MUST come after the object files, because the linker
# needs to see the object files first to know what symbols are needed from the
# Catch2 library. It can't 'revisit' older object files to resolve symbols.
$(TEST_RUNNER_EXECUTABLE): $(OBJS) $(TEST_OBJS)
$(CXX) $(TEST_CXXFLAGS) -o $(TEST_RUNNER_EXECUTABLE) $^ $(CATCH2_FLAGS)
test: $(APP) $(TEST_RUNNER_EXECUTABLE)
./$(TEST_RUNNER_EXECUTABLE) && ./tests/e2e.sh
clean:
rm -f $(APP_OBJS) $(OBJS) $(TEST_OBJS) $(DEPS) $(TEST_DEPS) $(APP) $(TEST_RUNNER_EXECUTABLE)