-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
54 lines (42 loc) · 1.42 KB
/
Copy pathMakefile
File metadata and controls
54 lines (42 loc) · 1.42 KB
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
# Compiler
CXX := g++
# Directories
BUILD_DIR := build
SRC_DIR := src
LIB_DIR := lib
OBJ_DIR := $(BUILD_DIR)/obj
THIRD_PARTY_DIR := third-party
# Static library
LIB_NAME := launchpad
STATIC_LIB := $(LIB_DIR)/lib$(LIB_NAME).a
THIRD_PARTY_LIB_PATHS := $(shell find $(THIRD_PARTY_DIR) -name 'lib')/$(shell uname -m)
THIRD_PARTY_PATHS := $(patsubst %/lib,%,$(shell find $(THIRD_PARTY_DIR) -name 'lib'))
THIRD_PARTY_LIBS := $(patsubst $(THIRD_PARTY_DIR)/%,%,$(THIRD_PARTY_PATHS))
# Source & Headers
SRC := $(wildcard $(SRC_DIR)/*.cpp)
INCLUDE_PATHS := $(addsuffix /include, $(THIRD_PARTY_PATHS)) include $(SRC_DIR)
OBJ := $(patsubst $(SRC_DIR)/%.cpp,$(OBJ_DIR)/%.o,$(SRC))
# Compiler & Linker Flags
CXXFLAGS := -std=c++20 -Wall -Wextra $(addprefix -I, $(INCLUDE_PATHS))
LDFLAGS := $(addprefix -L, $(THIRD_PARTY_LIBS)) $(addprefix -l, $(THIRD_PARTY_LIBS))
# Dependency files
DEPS := $(OBJ:.o=.d)
# Default target
static: $(STATIC_LIB)
# Create lib archive
$(STATIC_LIB): $(OBJ) | $(LIB_DIR)
@echo "[archive] lib$(LIB_NAME).a"
@ar rcs "$@" $(OBJ)
# Compile object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
@echo "[compile] $(patsubst $(SRC_DIR)/%.cpp,%.cpp,$<)"
@"$(CXX)" $(CXXFLAGS) -MMD -MF "$(OBJ_DIR)/$*.d" -c "$<" -o "$@"
# Create necessary directories
$(BUILD_DIR) $(OBJ_DIR) $(LIB_DIR):
@mkdir -p "$@"
# Clean rule
clean:
@rm -rf "$(BUILD_DIR)" "$(LIB_DIR)"
# Include dependency files
-include $(DEPS)
.PHONY: static clean