-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
161 lines (136 loc) · 4.88 KB
/
Makefile
File metadata and controls
161 lines (136 loc) · 4.88 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
156
157
158
159
160
161
# Computer Network Internship Project Makefile
# 计算机网络实习项目构建脚本
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -O2
LDFLAGS =
# Targets
HTTP_SERVER = server
FTP_SERVER = ftp_server
FTP_CLIENT = ftp_client
# Source files
HTTP_SERVER_SRC = server.c
FTP_SERVER_SRC = ftp_server.c
FTP_CLIENT_SRC = ftp_client.c
# Libraries
HTTP_LIBS = -lcurl -lm
FTP_SERVER_LIBS = -lpthread
FTP_CLIENT_LIBS =
# Default target
all: $(HTTP_SERVER) $(FTP_SERVER) $(FTP_CLIENT)
# HTTP Web Server
$(HTTP_SERVER): $(HTTP_SERVER_SRC)
@echo "🔨 Building HTTP Web Server..."
$(CC) $(CFLAGS) -o $@ $< $(HTTP_LIBS)
@echo "✅ HTTP Server built successfully!"
# FTP Server
$(FTP_SERVER): $(FTP_SERVER_SRC)
@echo "🔨 Building FTP Server..."
$(CC) $(CFLAGS) -o $@ $< $(FTP_SERVER_LIBS)
@echo "✅ FTP Server built successfully!"
# FTP Client
$(FTP_CLIENT): $(FTP_CLIENT_SRC)
@echo "🔨 Building FTP Client..."
$(CC) $(CFLAGS) -o $@ $< $(FTP_CLIENT_LIBS)
@echo "✅ FTP Client built successfully!"
# Individual targets
http_server: $(HTTP_SERVER)
ftp_server: $(FTP_SERVER)
ftp_client: $(FTP_CLIENT)
# Setup directories for HTTP server
setup_dirs:
@echo "📁 Setting up directory structure..."
@mkdir -p web_root/upload_dir web_root/crawl_result
@cp index.html web_root/ 2>/dev/null || true
@chmod 755 web_root web_root/upload_dir web_root/crawl_result
@echo "✅ Directories created successfully!"
# Install dependencies (Ubuntu/Debian)
install_deps_ubuntu:
@echo "📦 Installing dependencies for Ubuntu/Debian..."
sudo apt-get update
sudo apt-get install -y build-essential libcurl4-openssl-dev
# Install dependencies (CentOS/RHEL)
install_deps_centos:
@echo "📦 Installing dependencies for CentOS/RHEL..."
sudo yum install -y gcc libcurl-devel
# Install dependencies (Fedora)
install_deps_fedora:
@echo "📦 Installing dependencies for Fedora..."
sudo dnf install -y gcc libcurl-devel
# Run HTTP server
run_http: $(HTTP_SERVER) setup_dirs
@echo "🚀 Starting HTTP Web Server on port 8080..."
./$(HTTP_SERVER)
# Run FTP server
run_ftp: $(FTP_SERVER)
@echo "🚀 Starting FTP Server on port 2121..."
./$(FTP_SERVER)
# Run FTP client
run_client: $(FTP_CLIENT)
@echo "🚀 Starting FTP Client..."
@echo "Usage: ./$(FTP_CLIENT) <server_ip> <server_port>"
@echo "Example: ./$(FTP_CLIENT) 127.0.0.1 2121"
# Clean compiled files
clean:
@echo "🧹 Cleaning up..."
rm -f $(HTTP_SERVER) $(FTP_SERVER) $(FTP_CLIENT)
rm -f *.o *.out core
@echo "✅ Cleanup completed!"
# Clean all including generated directories
clean_all: clean
@echo "🧹 Deep cleaning..."
rm -rf web_root/upload_dir/* web_root/crawl_result/*
@echo "✅ Deep cleanup completed!"
# Check system requirements
check_deps:
@echo "🔍 Checking system dependencies..."
@which gcc > /dev/null && echo "✅ GCC compiler found" || echo "❌ GCC compiler not found"
@pkg-config --exists libcurl && echo "✅ libcurl found" || echo "❌ libcurl not found - install libcurl4-openssl-dev (Ubuntu) or libcurl-devel (CentOS)"
@echo "ℹ️ To install dependencies:"
@echo " Ubuntu/Debian: make install_deps_ubuntu"
@echo " CentOS/RHEL: make install_deps_centos"
@echo " Fedora: make install_deps_fedora"
# Display help
help:
@echo "📚 Computer Network Internship Project - Available Commands:"
@echo ""
@echo "🔨 Building:"
@echo " make - Build all components"
@echo " make http_server - Build only HTTP server"
@echo " make ftp_server - Build only FTP server"
@echo " make ftp_client - Build only FTP client"
@echo ""
@echo "🚀 Running:"
@echo " make run_http - Start HTTP server (port 8080)"
@echo " make run_ftp - Start FTP server (port 2121)"
@echo " make run_client - Show FTP client usage"
@echo ""
@echo "📦 Dependencies:"
@echo " make check_deps - Check system dependencies"
@echo " make install_deps_ubuntu - Install deps (Ubuntu/Debian)"
@echo " make install_deps_centos - Install deps (CentOS/RHEL)"
@echo " make install_deps_fedora - Install deps (Fedora)"
@echo ""
@echo "🧹 Cleanup:"
@echo " make clean - Remove compiled files"
@echo " make clean_all - Remove compiled files and generated content"
@echo ""
@echo "🛠️ Setup:"
@echo " make setup_dirs - Create necessary directories"
@echo ""
# Test targets
test: test_compile test_syntax
test_compile: all
@echo "🧪 Testing compilation..."
@echo "✅ All components compiled successfully!"
test_syntax:
@echo "🧪 Testing syntax..."
$(CC) -fsyntax-only $(HTTP_SERVER_SRC)
$(CC) -fsyntax-only $(FTP_SERVER_SRC)
$(CC) -fsyntax-only $(FTP_CLIENT_SRC)
@echo "✅ Syntax check passed!"
# Phony targets
.PHONY: all clean clean_all setup_dirs run_http run_ftp run_client help
.PHONY: http_server ftp_server ftp_client test test_compile test_syntax
.PHONY: install_deps_ubuntu install_deps_centos install_deps_fedora check_deps
# Default goal
.DEFAULT_GOAL := all