-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
66 lines (50 loc) · 1.25 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
# Compiler
CXX := clang++
# Compiler flags
CXXFLAGS := -std=c++17 -Wall -Wextra -pedantic
DBGFLAGS := -g $(CXXFLAGS)
# Directories
SRC_DIR := src
INCLUDE_DIR := include
BUILD_DIR := build
OBJ_DIR := $(BUILD_DIR)/obj
INSTALL_DIR := $(HOME)/.local/bin
# Source files
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
# Object files
OBJS := $(SRCS:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
# Executable name
TARGET := $(BUILD_DIR)/terminder
DEBUG_TARGET := $(BUILD_DIR)/terminder_debug
# Default target
all: $(TARGET)
# Compile source files into object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -I$(INCLUDE_DIR) -c $< -o $@
# Link object files into executable
$(TARGET): $(OBJS)
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $^ -o $@
# Debug build
debug: $(DEBUG_TARGET)
$(DEBUG_TARGET): $(SRCS)
@mkdir -p $(@D)
$(CXX) $(DBGFLAGS) -I$(INCLUDE_DIR) $^ -o $@
# Run the program
run: $(TARGET)
./$(TARGET) $(ARGS)
# Debug with with LLDB
debug-lldb: $(DEBUG_TARGET)
lldb $(DEBUG_TARGET)
# Installation
install: $(TARGET)
install -d $(INSTALL_DIR)
install -m 755 $(TARGET) $(INSTALL_DIR)
uninstall:
rm -f $(INSTALL_DIR)$(notdir $(TARGET))
# Clean build files
clean:
rm -rf $(BUILD_DIR)
# Phony targets
.PHONY: all run clean debug debug-lldb install uninstall