-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
73 lines (55 loc) · 1.65 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
CXX = clang++
CXX_FLAGS = -std=c++14
CXX_FLAGS += -Wall
CXX_FLAGS += -Wextra
CXX_FLAGS += -MMD
CXX_FLAGS += -MP
CXX_FLAGS += -Ofast
CXX_FLAGS += -march=native
CXX_FLAGS += -Wno-unknown-warning-option # ignore unknown warnings (as '-Wno-maybe-uninitialized' resulting from internal bugs)
CXX_FLAGS += -Qunused-arguments
CXX_FLAGS += -pipe
#CXX_FLAGS += -g
# Define useful make functions
recwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call recwildcard,$d/,$2))
# Name of the executable
EXE = main
# Basic project directories
BIN = bin/
OBJDIR = obj/
SRC = src/
ALL_SRC = $(sort $(dir $(call recwildcard,$(SRC)**/*/)))
# Set the virtual (search) path
VPATH = $(SRC):$(ALL_SRC)
# Determine all object files that we need in order to produce an executable
OBJ = $(addprefix $(OBJDIR),$(notdir $(patsubst %.cpp,%.o,$(call recwildcard,src/,*.cpp))))
# To determine source (.cpp) and header (.hh) dependencies
DEP = $(OBJ:.o=.d)
# Thread model to use
THREAD_MODEL := -pthread
# Libraries to link against
MATH_LIBS := -lm
.PHONY: clean
all: $(OBJDIR) $(BIN) $(BIN)$(EXE)
# To resolve header dependencies
-include $(DEP)
# Create object directory
$(OBJDIR):
mkdir $@
# Create binary directory
$(BIN):
mkdir $@
# Link all object code (against additional libraries) to produce the machine code
$(BIN)$(EXE): $(OBJ)
$(CXX) $(CXX_FLAGS) $^ $(MATH_LIBS) -o $@ $(THREAD_MODEL)
@echo "done ;-)"
# Compile source code to object code
$(OBJDIR)%.o: %.cpp
$(CXX) $(CXX_FLAGS) $(CXX_INCL) $(LLVM_FLAGS) -c $< -o $@
# Obivously a hell world program must be in here
hello_world:
@echo "Hello, World!"
# Clean all auto-generated stuff
clean:
rm -rf $(BIN)
rm -rf $(OBJDIR)