-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (113 loc) · 3.68 KB
/
Copy pathMakefile
File metadata and controls
133 lines (113 loc) · 3.68 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
# Makefile for Secure Calculator Server and Client
CC = gcc
CFLAGS = -Wall -Wextra -std=c11 -O2 -pthread -D_REENTRANT
LDFLAGS = -lssl -lcrypto -pthread -lm
# Target executables
SERVER = server
CLIENT = client
TARGETS = $(SERVER) $(CLIENT)
# Source files
SERVER_SRC = server.c
CLIENT_SRC = client.c
# Default target - build both server and client
all: $(TARGETS)
# Build the server
$(SERVER): $(SERVER_SRC)
$(CC) $(CFLAGS) -o $(SERVER) $(SERVER_SRC) $(LDFLAGS)
# Build the client
$(CLIENT): $(CLIENT_SRC)
$(CC) $(CFLAGS) -o $(CLIENT) $(CLIENT_SRC) $(LDFLAGS)
# Generate SSL certificate (for development)
cert:
@if [ -f generate_cert.sh ]; then \
chmod +x generate_cert.sh; \
./generate_cert.sh; \
else \
echo "Generating self-signed certificate..."; \
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem \
-sha256 -days 365 -nodes \
-subj "/C=US/ST=State/L=City/O=Organization/OU=Department/CN=localhost"; \
chmod 600 key.pem; \
chmod 644 cert.pem; \
fi
# Clean build artifacts
clean:
rm -f $(TARGETS)
rm -f *.o
rm -f test_output.txt
# Clean everything including certificates
distclean: clean
rm -f cert.pem key.pem
# Run the server
run-server: $(SERVER)
@if [ ! -f cert.pem ] || [ ! -f key.pem ]; then \
echo "Certificates not found. Generating..."; \
$(MAKE) cert; \
fi
./$(SERVER)
# Run the client (default: connect to localhost)
run-client: $(CLIENT)
./$(CLIENT)
# Run client with custom server
run-client-remote: $(CLIENT)
@echo "Usage: make run-client-remote SERVER=<ip_address>"
./$(CLIENT) $(SERVER)
# Build with debug symbols
debug: CFLAGS += -g -DDEBUG -fsanitize=address
debug: LDFLAGS += -fsanitize=address
debug: $(TARGETS)
# Run tests
test: $(TARGETS)
@if [ ! -f cert.pem ] || [ ! -f key.pem ]; then \
$(MAKE) cert; \
fi
@if [ -f test_server.sh ]; then \
chmod +x test_server.sh; \
echo "Starting server for tests..."; \
./$(SERVER) & SERVER_PID=$$!; \
sleep 2; \
./test_server.sh; \
TEST_RESULT=$$?; \
kill $$SERVER_PID 2>/dev/null || true; \
exit $$TEST_RESULT; \
else \
echo "test_server.sh not found"; \
fi
# Static analysis with clang
analyze:
@if command -v clang >/dev/null 2>&1; then \
clang --analyze $(SERVER_SRC); \
clang --analyze $(CLIENT_SRC); \
else \
echo "clang not found. Install clang for static analysis."; \
fi
# Check for memory leaks with valgrind
memcheck-server: $(SERVER)
valgrind --leak-check=full --show-leak-kinds=all ./$(SERVER)
memcheck-client: $(CLIENT)
valgrind --leak-check=full --show-leak-kinds=all ./$(CLIENT)
# Format code with clang-format
format:
@if command -v clang-format >/dev/null 2>&1; then \
clang-format -i $(SERVER_SRC) $(CLIENT_SRC); \
else \
echo "clang-format not found."; \
fi
# Help target
help:
@echo "Available targets:"
@echo " make - Build both server and client"
@echo " make secure_server - Build only the server"
@echo " make secure_client - Build only the client"
@echo " make cert - Generate SSL certificates"
@echo " make run-server - Build and run the server"
@echo " make run-client - Build and run the client"
@echo " make test - Run automated tests"
@echo " make debug - Build with debug symbols and AddressSanitizer"
@echo " make clean - Remove build artifacts"
@echo " make distclean - Remove everything including certificates"
@echo " make analyze - Run static analysis"
@echo " make memcheck-* - Check for memory leaks with valgrind"
@echo " make format - Format code with clang-format"
@echo " make help - Show this help message"
.PHONY: all clean distclean run-server run-client run-client-remote cert debug test analyze memcheck-server memcheck-client format help