-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
63 lines (48 loc) · 1.21 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
CXX := g++
ifeq ($(OS),Windows_NT)
detected_OS := Windows
RM := rmdir /Q /S
UN := del
FixPath = $(subst /,\,$1)
ext := .exe
else
detected_OS := $(shell uname)
RM := rm -f -r
UN := $(RM)
FLAGS := -p
FixPath = $1
endif
MD := mkdir $(FLAGS)
# Dependency flags
CXXFLAGS += -MMD -MP
# Compiler flags
CXXFLAGS += -std=c++17 -pedantic-errors
CXXFLAGS += -Wall -Wextra
CXXFLAGS += -g3 -O3
# Linker flags
CPPFLAGS += -Iinclude
DIRS := $(patsubst src/%, %, $(wildcard src/*))
PROG_SOURCES := $(wildcard src/*/*.cpp)
OBJECTS := $(patsubst src/%.cpp, build/%.o, $(PROG_SOURCES))
DEPENDENCIES := $(patsubst src/%.cpp, build/%.d, $(PROG_SOURCES))
all: clean prepare dirs main run
-include $(call FixPath,$(DEPENDENCIES))
prepare:
@echo Preparing build directories
-@$(RM) build
dirs:
@$(MD) $(call FixPath,$(patsubst %, build/%, $(DIRS)))
@echo Created directories: $(DIRS)
build/%.o: src/%.cpp
@echo Compiling: $< : $@
@$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $(call FixPath,$<) -o $(call FixPath,$@)
main: $(OBJECTS)
@echo Linking $@
@$(CXX) $(CXXFLAGS) -o $@ $(call FixPath,$^) $(LDFLAGS)
run: main$(ext)
@echo Running main
@./main
clean:
@echo Cleaning up executable
-@$(UN) $(call FixPath,./main$(ext))
.PHONY: show dirs