-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
121 lines (104 loc) · 3.16 KB
/
Copy pathMakefile
File metadata and controls
121 lines (104 loc) · 3.16 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
117
118
119
120
121
# PrometheusClient Makefile
# Tested on Linux only
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -O2
CXXFLAGS_DEBUG = -std=c++17 -Wall -Wextra -g -O0
# Directories
SRC_DIR = src
INC_DIR = include
BUILD_DIR = build
# Source files
SOURCES = $(wildcard $(SRC_DIR)/*.cpp)
OBJECTS = $(SOURCES:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
# Library names
LIB_SHARED = libprom.so
LIB_STATIC = libprom.a
# Installation paths
PREFIX = /usr/local
INSTALL_LIB = $(PREFIX)/lib
INSTALL_INC = $(PREFIX)/include/prom
# Default target
.PHONY: all
all: shared static
# Create build directory
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Compile object files (Position Independent Code for shared library)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp | $(BUILD_DIR)
$(CXX) $(CXXFLAGS) -fPIC -c $< -o $@ -I$(INC_DIR)
# Build shared library
.PHONY: shared
shared: $(BUILD_DIR)/$(LIB_SHARED)
$(BUILD_DIR)/$(LIB_SHARED): $(OBJECTS)
$(CXX) -shared -o $@ $^
@echo ""
@echo "==> Built shared library: $(BUILD_DIR)/$(LIB_SHARED)"
@echo ""
# Build static library
.PHONY: static
static: $(BUILD_DIR)/$(LIB_STATIC)
$(BUILD_DIR)/$(LIB_STATIC): $(OBJECTS)
ar rcs $@ $^
@echo ""
@echo "==> Built static library: $(BUILD_DIR)/$(LIB_STATIC)"
@echo ""
# Debug build
.PHONY: debug
debug: CXXFLAGS = $(CXXFLAGS_DEBUG)
debug: clean shared static
@echo "==> Debug build complete"
# Install to system
.PHONY: install
install: shared static
@echo "Installing to $(PREFIX)..."
install -d $(INSTALL_LIB)
install -d $(INSTALL_INC)
install -m 644 $(BUILD_DIR)/$(LIB_SHARED) $(INSTALL_LIB)/
install -m 644 $(BUILD_DIR)/$(LIB_STATIC) $(INSTALL_LIB)/
install -m 644 $(INC_DIR)/*.hpp $(INSTALL_INC)/
ldconfig
@echo ""
@echo "==> Installation complete!"
@echo " Libraries: $(INSTALL_LIB)"
@echo " Headers: $(INSTALL_INC)"
@echo ""
# Uninstall from system
.PHONY: uninstall
uninstall:
@echo "Uninstalling from $(PREFIX)..."
rm -f $(INSTALL_LIB)/$(LIB_SHARED)
rm -f $(INSTALL_LIB)/$(LIB_STATIC)
rm -rf $(INSTALL_INC)
ldconfig
@echo "==> Uninstall complete"
# Clean build artifacts
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
@echo "==> Clean complete"
# Show help
.PHONY: help
help:
@echo "PrometheusClient Makefile"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " all Build shared and static libraries (default)"
@echo " shared Build shared library (libprom.so)"
@echo " static Build static library (libprom.a)"
@echo " debug Build with debug symbols"
@echo " install Install to system (requires sudo)"
@echo " uninstall Remove from system (requires sudo)"
@echo " clean Remove build artifacts"
@echo " help Show this help message"
@echo ""
@echo "Examples:"
@echo " make # Build both libraries"
@echo " make shared # Build only shared library"
@echo " sudo make install # Install to /usr/local"
@echo " make PREFIX=/opt/prom install # Install to custom location"
@echo ""
@echo "After building, link your project with:"
@echo " g++ -std=c++17 -o myapp myapp.cpp -I$(INC_DIR) -L$(BUILD_DIR) -lprom"
@echo ""