-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
51 lines (40 loc) · 1.21 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
42
43
44
45
46
47
48
49
50
51
# Compiler and flags
CC := gcc
CFLAGS := -Wall -Wextra -g -pthread
# Directories
BIN_DIR := bin
OBJ_DIR := obj
CLIENT_DIR := src/client
SERVER_DIR := src/server
# Targets
CLIENT_TARGET := $(BIN_DIR)/multithreadedfiletransfer.out
SERVER_TARGET := $(BIN_DIR)/server.out
# Source files
CLIENT_SRCS := $(wildcard $(CLIENT_DIR)/*.c)
SERVER_SRCS := $(wildcard $(SERVER_DIR)/*.c)
# Object files
CLIENT_OBJS := $(patsubst $(CLIENT_DIR)/%.c,$(OBJ_DIR)/client/%.o,$(CLIENT_SRCS))
SERVER_OBJS := $(patsubst $(SERVER_DIR)/%.c,$(OBJ_DIR)/server/%.o,$(SERVER_SRCS))
# Phony targets
.PHONY: all clean
# Default target
all: $(CLIENT_TARGET) $(SERVER_TARGET)
# Rule to compile the client executable
$(CLIENT_TARGET): $(CLIENT_OBJS)
@mkdir -p $(BIN_DIR)
$(CC) $(CFLAGS) $^ -o $@
# Rule to compile the server executable
$(SERVER_TARGET): $(SERVER_OBJS)
@mkdir -p $(BIN_DIR)
$(CC) $(CFLAGS) $^ -o $@
# Rule to compile client object files
$(OBJ_DIR)/client/%.o: $(CLIENT_DIR)/%.c
@mkdir -p $(OBJ_DIR)/client
$(CC) $(CFLAGS) -c $< -o $@
# Rule to compile server object files
$(OBJ_DIR)/server/%.o: $(SERVER_DIR)/%.c
@mkdir -p $(OBJ_DIR)/server
$(CC) $(CFLAGS) -c $< -o $@
# Clean the build artifacts
clean:
rm -rf $(BIN_DIR) $(OBJ_DIR)