-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
83 lines (66 loc) · 1.91 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Compiler and flags
CXX := g++
CXXFLAGS := -Wall -Werror -Wextra -pedantic
CXXFLAGS += -std=c++20 -ggdb
CXXFLAGS += -pipe -O2
CXXFLAGS += -MMD -MP
# Directories
SRC_DIR := src
BUILD_DIR := build
INCLUDE_DIR := include
PROTOBUF_DIR := protobuf
# Create necessary directories
$(shell mkdir -p $(BUILD_DIR) $(BUILD_DIR)/protobuf)
# Source files
SRCS := $(wildcard $(SRC_DIR)/*.cc)
OBJS := $(SRCS:$(SRC_DIR)/%.cc=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
# Protobuf files
PROTO_SRC := $(PROTOBUF_DIR)/chord.proto
PROTO_CC := $(BUILD_DIR)/protobuf/chord.pb.cc
PROTO_H := $(BUILD_DIR)/protobuf/chord.pb.h
PROTO_OBJ := $(PROTO_CC:.cc=.o)
# Include directories and libraries
INCLUDES := -I$(INCLUDE_DIR) -I$(BUILD_DIR)
INCLUDES += $(shell pkg-config --cflags protobuf)
LDFLAGS := $(shell pkg-config --libs protobuf)
LDLIBS := -lprotobuf -lcrypto
# Target executable
TARGET := chord
# Default target
all: $(TARGET)
# Link the final executable
$(TARGET): $(PROTO_OBJ) $(OBJS)
@echo "Linking $@..."
@$(CXX) $(OBJS) $(PROTO_OBJ) $(LDFLAGS) $(LDLIBS) -o $@
# Compile source files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cc
@echo "Compiling $<..."
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
# Generate and compile protobuf files
$(PROTO_CC) $(PROTO_H): $(PROTO_SRC)
@echo "Generating protobuf files..."
@protoc --cpp_out=$(BUILD_DIR)/protobuf -I$(PROTOBUF_DIR) $<
$(PROTO_OBJ): $(PROTO_CC)
@echo "Compiling protobuf..."
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
# Clean build artifacts
clean:
@echo "Cleaning..."
@rm -rf $(BUILD_DIR) $(TARGET)
# Deep clean (including generated protobuf files)
distclean: clean
@echo "Deep cleaning..."
@rm -rf $(PROTOBUF_DIR)/*.pb.*
# Include dependency files
-include $(DEPS)
# Phony targets
.PHONY: all clean distclean
# Build info target
info:
@echo "Compiler: $(CXX)"
@echo "Flags: $(CXXFLAGS)"
@echo "Include dirs: $(INCLUDES)"
@echo "Libraries: $(LDLIBS)"
@echo "Source files: $(SRCS)"
.PHONY: info