-
Notifications
You must be signed in to change notification settings - Fork 703
Expand file tree
/
Copy pathMakefile
More file actions
155 lines (126 loc) · 4.12 KB
/
Makefile
File metadata and controls
155 lines (126 loc) · 4.12 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# MultiButton Library Makefile
# 支持编译库文件和示例程序
# Compiler and tools
CC = gcc
AR = ar
RM = rm -f
MKDIR = mkdir -p
# Project directories
SRC_DIR = .
EXAMPLES_DIR = examples
BUILD_DIR = build
LIB_DIR = $(BUILD_DIR)/lib
BIN_DIR = $(BUILD_DIR)/bin
OBJ_DIR = $(BUILD_DIR)/obj
# Compiler flags
CFLAGS = -Wall -Wextra -std=c99 -O2 -g
INCLUDES = -I$(SRC_DIR)
LDFLAGS =
LIBS =
# Source files
LIB_SOURCES = multi_button.c
LIB_OBJECTS = $(addprefix $(OBJ_DIR)/, $(LIB_SOURCES:.c=.o))
# Library name
LIB_NAME = libmultibutton
STATIC_LIB = $(LIB_DIR)/$(LIB_NAME).a
SHARED_LIB = $(LIB_DIR)/$(LIB_NAME).so
# Example programs
EXAMPLES = basic_example advanced_example poll_example
# Default target
all: library examples
# Create directories
$(BUILD_DIR):
$(MKDIR) $(BUILD_DIR)
$(LIB_DIR): $(BUILD_DIR)
$(MKDIR) $(LIB_DIR)
$(BIN_DIR): $(BUILD_DIR)
$(MKDIR) $(BIN_DIR)
$(OBJ_DIR): $(BUILD_DIR)
$(MKDIR) $(OBJ_DIR)
# Build object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
$(OBJ_DIR)/%.o: $(EXAMPLES_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
# Build static library
$(STATIC_LIB): $(LIB_OBJECTS) | $(LIB_DIR)
$(AR) rcs $@ $^
@echo "Static library created: $@"
# Build shared library
$(SHARED_LIB): $(LIB_OBJECTS) | $(LIB_DIR)
$(CC) -shared -fPIC $(CFLAGS) $(INCLUDES) $(LIB_SOURCES) -o $@
@echo "Shared library created: $@"
# Library target
library: $(STATIC_LIB)
# Shared library target
shared: $(SHARED_LIB)
# Example programs
basic_example: $(BIN_DIR)/basic_example
$(BIN_DIR)/basic_example: $(OBJ_DIR)/basic_example.o $(STATIC_LIB) | $(BIN_DIR)
$(CC) $< -L$(LIB_DIR) -lmultibutton -o $@
@echo "Example program created: $@"
advanced_example: $(BIN_DIR)/advanced_example
$(BIN_DIR)/advanced_example: $(OBJ_DIR)/advanced_example.o $(STATIC_LIB) | $(BIN_DIR)
$(CC) $< -L$(LIB_DIR) -lmultibutton -o $@
@echo "Example program created: $@"
poll_example: $(BIN_DIR)/poll_example
$(BIN_DIR)/poll_example: $(OBJ_DIR)/poll_example.o $(STATIC_LIB) | $(BIN_DIR)
$(CC) $< -L$(LIB_DIR) -lmultibutton -o $@
@echo "Example program created: $@"
# Build all examples
examples: $(addprefix $(BIN_DIR)/, $(EXAMPLES))
# Test target
test: examples
@echo "Running basic example..."
@cd $(BIN_DIR) && ./basic_example
# Clean build files
clean:
$(RM) -r $(BUILD_DIR)
@echo "Build directory cleaned"
# Install library (optional)
install: library
@echo "Installing library to /usr/local/lib..."
sudo cp $(STATIC_LIB) /usr/local/lib/
sudo cp multi_button.h /usr/local/include/
sudo ldconfig
# Uninstall library
uninstall:
sudo $(RM) /usr/local/lib/$(LIB_NAME).a
sudo $(RM) /usr/local/include/multi_button.h
# Show help
help:
@echo "MultiButton Library Build System"
@echo ""
@echo "Available targets:"
@echo " all - Build library and examples (default)"
@echo " library - Build static library only"
@echo " shared - Build shared library"
@echo " examples - Build all examples"
@echo " basic_example - Build basic example"
@echo " advanced_example - Build advanced example"
@echo " poll_example - Build poll example"
@echo " test - Build and run basic test"
@echo " clean - Remove build directory"
@echo " install - Install library to system"
@echo " uninstall - Remove library from system"
@echo " help - Show this help message"
@echo ""
@echo "Build configuration:"
@echo " CC = $(CC)"
@echo " CFLAGS = $(CFLAGS)"
@echo " BUILD_DIR = $(BUILD_DIR)"
# Print build info
info:
@echo "Project: MultiButton Library"
@echo "Sources: $(LIB_SOURCES)"
@echo "Examples: $(EXAMPLES)"
@echo "Build directory: $(BUILD_DIR)"
@echo "Compiler: $(CC)"
@echo "Flags: $(CFLAGS)"
# Phony targets
.PHONY: all library shared examples clean install uninstall help info test basic_example advanced_example poll_example
# Dependencies
$(OBJ_DIR)/multi_button.o: multi_button.c multi_button.h
$(OBJ_DIR)/basic_example.o: $(EXAMPLES_DIR)/basic_example.c multi_button.h
$(OBJ_DIR)/advanced_example.o: $(EXAMPLES_DIR)/advanced_example.c multi_button.h
$(OBJ_DIR)/poll_example.o: $(EXAMPLES_DIR)/poll_example.c multi_button.h