-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
88 lines (71 loc) · 2.8 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#
# This is a generic Makefile designed to compile a sample directory of code.
# This file depends on variables having been set before calling:
# EXE: The name of the result file
# OBJS: Array of objects files (.o) to be generated
# CLEAN_RM: Optional list of additional files to delete on `make clean`
#
# @author Wade Fagen-Ulmschneider, <waf@illinois.edu>
# @author Jeffrey Tolar
# @author Eric Huber (edits made for CS Fundamentals MOOC)
#
EXE = mars
OBJS = main.o
CLEAN_RM =
# include ../../_make/generic.mk
# Compiler/linker config and object/depfile directory:
CXX = g++
LD = g++
OBJS_DIR = .objs
SRC_DIR = src
# -MMD and -MP asks clang++ to generate a .d file listing the headers used in the source code for use in the Make process.
# -MMD: "Write a depfile containing user headers"
# -MP : "Create phony target for each dependency (other than main file)"
# (https://clang.llvm.org/docs/ClangCommandLineReference.html)
DEPFILE_FLAGS = -MMD -MP
# Provide lots of helpful warning/errors:
# (Switching from clang++ to g++ caused some trouble here. Not all flags are identically between the compilers.)
#WARNINGS_AS_ERRORS = -Werror # Un-commenting this line makes compilation much more strict.
GCC_EXCLUSIVE_WARNING_OPTIONS = # -Wno-unused-but-set-variable
CLANG_EXCLUSIVE_WARNING_OPTIONS = # -Wno-unused-parameter -Wno-unused-variable
ifeq ($(CXX),g++)
EXCLUSIVE_WARNING_OPTIONS = $(GCC_EXCLUSIVE_WARNING_OPTIONS)
else
EXCLUSIVE_WARNING_OPTIONS = $(CLANG_EXCLUSIVE_WARNING_OPTIONS)
endif
# ASANFLAGS = -fsanitize=address -fno-omit-frame-pointer # for debugging, if supported on the OS
WARNINGS = -pedantic -Wall $(WARNINGS_AS_ERRORS) -Wfatal-errors -Wextra $(EXCLUSIVE_WARNING_OPTIONS)
# Flags for compile:
CXXFLAGS += -std=c++17 -O0 $(WARNINGS) $(DEPFILE_FLAGS) -g -c $(ASANFLAGS)
# Flags for linking:
LDFLAGS += -std=c++17 $(ASANFLAGS)
# Rule for `all` (first/default rule):
all: $(EXE)
# Rule for linking the final executable:
# - $(EXE) depends on all object files in $(OBJS)
# - `patsubst` function adds the directory name $(OBJS_DIR) before every object file
$(EXE): $(patsubst %.o, $(OBJS_DIR)/%.o, $(OBJS))
$(LD) $^ $(LDFLAGS) -o $@
# Ensure .objs/ exists:
$(OBJS_DIR):
@mkdir -p $(OBJS_DIR)
# @mkdir -p $(OBJS_DIR)/uiuc
# Rules for compiling source code.
# - Every object file is required by $(EXE)
# - Generates the rule requiring the .cpp file of the same name
$(OBJS_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJS_DIR)
$(CXX) $(CXXFLAGS) $< -o $@
# Additional dependencies for object files are included in the clang++
# generated .d files (from $(DEPFILE_FLAGS)):
-include $(OBJS_DIR)/*.d
# -include $(OBJS_DIR)/uiuc/*.d
##### Custom rule run and display
run: all
$(EXE)
py visual.py
# Standard C++ Makefile rules:
clean:
rm -rf $(EXE) $(TEST) $(OBJS_DIR) $(CLEAN_RM) *.o *.d
tidy: clean
rm -rf doc
.PHONY: all tidy clean