-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
44 lines (33 loc) · 936 Bytes
/
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
# source: https://stackanswers.net/questions/how-to-make-makefile-recompile-when-a-header-file-is-changed
# Compiler and flags
CXX = g++
CXXFLAGS = -Wall -Wextra -std=c++11
LDFLAGS =
# Source and build-output locations
SRC_DIR = ./src
BUILD_DIR = ./build
OUTPUT_EXEC = ./a.out
$(shell mkdir -p $(BUILD_DIR))
# Source and object files
SOURCES := $(wildcard $(SRC_DIR)/*.cpp)
OBJECTS := $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SOURCES))
DEPENDS := $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.d,$(SOURCES))
#$(info $$SOURCES = [$(SOURCES)])
#$(info $$OBJECTS = [$(OBJECTS)])
#$(info $$DEPENDS = [$(DEPENDS)])
# Recipes
.PHONY: all
all: run
.PHONY: clean
clean:
rm -r $(BUILD_DIR)
rm $(OUTPUT_EXEC)
.PHONY: build
build: $(OBJECTS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(OUTPUT_EXEC) $^
-include $(DEPENDS)
$(BUILD_DIR)/%.o: src/%.cpp Makefile
$(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
.PHONY: run
run: build
$(OUTPUT_EXEC)