This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
68 lines (58 loc) · 2 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
#====================================================
# Variables
#====================================================
TARGET_EXEC := main
TEST_EXEC := tests
CC := g++
BUILD_DIR := bin
SRC_DIR := src
TEST_DIR := test
OBJ_DIR := obj
#====================================================
# Source files
#====================================================
SRC := $(shell find $(SRC_DIR) -name '*.cpp')
TEST := $(shell find $(SRC_DIR) -type f | grep -v 'main.cpp') $(shell find $(TEST_DIR) -name '*.cpp')
OBJ := $(SRC:%=$(OBJ_DIR)/%.o)
TEST_OBJ := $(TEST:%=$(OBJ_DIR)/%.o)
#====================================================
# Dependencies and flags
#====================================================
DEPS := $(OBJ:.o=.d)
INC_DIR := $(shell find $(SRC_DIR) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIR))
WFLAGS := -Wall -Wextra -Wno-unused
CPPFLAGS := -std=c++17 -g $(LDFLAGS) $(INC_FLAGS) -MMD -MP $(WFLAGS)
LDFLAGS := -losmanip -larsenalgear
#====================================================
# Aliases
#====================================================
.PHONY: clean all
#====================================================
# Building
#====================================================
#Building all:
all: $(BUILD_DIR)/$(TARGET_EXEC) $(BUILD_DIR)/$(TEST_EXEC)
main: $(BUILD_DIR)/$(TARGET_EXEC)
tests: $(BUILD_DIR)/$(TEST_EXEC)
#Building main executable:
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJ)
@ mkdir -p $(dir $@)
$(CC) $(OBJ) -o $@ $(LDFLAGS)
#Building test executable:
$(BUILD_DIR)/$(TEST_EXEC): $(TEST_OBJ)
@ mkdir -p $(dir $@)
$(CC) $(TEST_OBJ) -o $@ $(LDFLAGS)
#Put object files into the object dir:
$(OBJ_DIR)/%.cpp.o: %.cpp
@ mkdir -p $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
#====================================================
# Clean
#====================================================
clean:
rm -r $(OBJ_DIR) $(BUILD_DIR)
#====================================================
# Include
#====================================================
-include $(DEPS)