-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (94 loc) · 3.03 KB
/
Makefile
File metadata and controls
116 lines (94 loc) · 3.03 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Makefile for C++ Thread Pool Library
# Compiler and flags
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -pthread -O2
DEBUG_FLAGS = -g -DDEBUG
RELEASE_FLAGS = -O3 -DNDEBUG
# Directories
SRC_DIR = src
INCLUDE_DIR = include
EXAMPLES_DIR = examples
TESTS_DIR = tests
BUILD_DIR = build
# Source files
SOURCES = $(wildcard $(SRC_DIR)/*.cpp)
OBJECTS = $(SOURCES:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
# Example files
EXAMPLES = $(wildcard $(EXAMPLES_DIR)/*.cpp)
EXAMPLE_BINS = $(EXAMPLES:$(EXAMPLES_DIR)/%.cpp=$(BUILD_DIR)/%)
# Test files
TESTS = $(wildcard $(TESTS_DIR)/*.cpp)
TEST_BINS = $(TESTS:$(TESTS_DIR)/%.cpp=$(BUILD_DIR)/%)
# Library name
LIBRARY = $(BUILD_DIR)/libthreadpool.a
# Default target
all: $(BUILD_DIR) $(LIBRARY) $(EXAMPLE_BINS) $(TEST_BINS)
# Create build directory
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Build library
$(LIBRARY): $(OBJECTS)
ar rcs $@ $^
# Build object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -I$(INCLUDE_DIR) -c $< -o $@
# Build examples
examples: $(BUILD_DIR)/basic_usage $(BUILD_DIR)/exception_test $(BUILD_DIR)/performance_test $(BUILD_DIR)/priority_dependency_demo
$(BUILD_DIR)/%: $(EXAMPLES_DIR)/%.cpp $(LIBRARY)
$(CXX) $(CXXFLAGS) -I$(INCLUDE_DIR) $< -L$(BUILD_DIR) -lthreadpool -o $@
# Build tests
$(BUILD_DIR)/test_%: $(TESTS_DIR)/test_%.cpp $(LIBRARY)
$(CXX) $(CXXFLAGS) -I$(INCLUDE_DIR) $< -L$(BUILD_DIR) -lthreadpool -o $@
# Debug build
debug: CXXFLAGS += $(DEBUG_FLAGS)
debug: all
# Release build
release: CXXFLAGS += $(RELEASE_FLAGS)
release: all
# Run examples
run-examples: $(EXAMPLE_BINS)
@echo "Running examples..."
@for example in $(EXAMPLE_BINS); do \
echo "Running $$(basename $$example)..."; \
$$example; \
echo ""; \
done
# Run tests
run-tests: $(TEST_BINS)
@echo "Running tests..."
@for test in $(TEST_BINS); do \
echo "Running $$(basename $$test)..."; \
$$test; \
echo ""; \
done
# Clean build files
clean:
rm -rf $(BUILD_DIR)
# Install (copy headers to system include)
install: $(LIBRARY)
@echo "Installing headers to /usr/local/include..."
sudo cp -r $(INCLUDE_DIR)/* /usr/local/include/
@echo "Installing library to /usr/local/lib..."
sudo cp $(LIBRARY) /usr/local/lib/
@echo "Installation complete!"
# Uninstall
uninstall:
@echo "Removing installed files..."
sudo rm -rf /usr/local/include/thread_pool.hpp
sudo rm -rf /usr/local/include/task_queue.hpp
sudo rm -rf /usr/local/include/worker_thread.hpp
sudo rm -f /usr/local/lib/libthreadpool.a
@echo "Uninstallation complete!"
# Show help
help:
@echo "Available targets:"
@echo " all - Build library, examples, and tests"
@echo " debug - Build with debug flags"
@echo " release - Build with release flags"
@echo " run-examples - Build and run all examples"
@echo " run-tests - Build and run all tests"
@echo " clean - Remove build files"
@echo " install - Install to system directories"
@echo " uninstall - Remove from system directories"
@echo " help - Show this help message"
.PHONY: all debug release run-examples run-tests clean install uninstall help