-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
41 lines (31 loc) · 1.01 KB
/
Makefile
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
# Compiler and flags
CC = gcc
CFLAGS = -Wall -std=gnu17
# Target executables
SERVER_TARGET = tcp_server
CLIENT_TARGET = tcp_client
# Source files
SERVER_SRC = messaging/$(SERVER_TARGET).c
CLIENT_SRC = messaging/$(CLIENT_TARGET).c
# Run 'make' to compile all targets
.PHONY: all clean run_server run_client
all: clean bin bin/$(SERVER_TARGET) bin/$(CLIENT_TARGET)
# Creates 'bin' directory if it doesn't exist
bin:
mkdir -p bin
# Compiles tcp_server.c into the SERVER_TARGET executable
bin/$(SERVER_TARGET): $(SERVER_SRC) | bin
$(CC) $(CFLAGS) -o $@ $<
# Compiles tcp_client.c into the CLIENT_TARGET executable
bin/$(CLIENT_TARGET): $(CLIENT_SRC) | bin
$(CC) $(CFLAGS) -o $@ $<
# Clean up build files
clean:
rm -rf bin/*.o
rm -rf bin
# Run the tcp_server program with optional arguments
run_server: bin/$(SERVER_TARGET)
./bin/$(SERVER_TARGET) $(ARGS)
# Run the tcp_client program with optional arguments
run_client: bin/$(CLIENT_TARGET)
./bin/$(CLIENT_TARGET) $(ARGS)