-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
143 lines (103 loc) · 3.91 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
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
# Compilation options
CC = gcc
CFLAGS += -std=c99 -Wall -pedantic -g -I./includes -D_POSIX_C_SOURCE=200112L -D_DEFAULT_SOURCE
# Directories
SRC_DIR = ./src
OBJ_DIR = ./obj
LIB_DIR = ./libs
INC_DIR = ./includes
BIN_DIR = ./bin
TEST_DIR = ./tests
LOG_DIR = ./logs
SCRIPT_DIR = ./scripts
# Dynamic linking
DYN_LINK = -L$(LIB_DIR) -Wl,-rpath,$(LIB_DIR)
# Dependency list for client
# ---------------- Default rule ---------------- #
all : create_dirs $(BIN_DIR)/client $(BIN_DIR)/server
# ---------------- Debug macro ----------------- #
debug : CFLAGS += -D DEBUG
debug : all
# ------------------- Client ------------------- #
CLIENT_SRC := $(wildcard $(SRC_DIR)/client/*.c)
CLIENT_OBJ := $(patsubst $(SRC_DIR)/client/%.c, $(OBJ_DIR)/client/%.o, $(CLIENT_SRC))
CLIENT_INC := $(INC_DIR)/client.h
CLIENT_DEPS = $(LIB_DIR)/libutil.so $(LIB_DIR)/libapi.so
CLIENT_LIBS = $(DYN_LINK) -lutil -lapi
$(BIN_DIR)/client : $(CLIENT_OBJ)
$(CC) $(CFLAGS) $^ -o $@ $(CLIENT_LIBS)
$(OBJ_DIR)/client/%.o : $(SRC_DIR)/client/%.c $(CLIENT_INC) $(CLIENT_DEPS)
$(CC) $(CFLAGS) -c $< -o $@
# ------------------- Server ------------------- #
SERVER_SRC := $(wildcard $(SRC_DIR)/server/*.c)
SERVER_OBJ := $(patsubst $(SRC_DIR)/server/%.c, $(OBJ_DIR)/server/%.o, $(SERVER_SRC))
SERVER_INC := $(INC_DIR)/server.h
SERVER_DEPS := $(LIB_DIR)/libutil.so
SERVER_LIBS := $(DYN_LINK) -lutil -lpthread
$(BIN_DIR)/server : $(SERVER_OBJ)
$(CC) $(CFLAGS) $^ -o $@ $(SERVER_LIBS)
$(OBJ_DIR)/server/%.o : $(SRC_DIR)/server/%.c $(SERVER_INC) $(SERVER_DEPS)
$(CC) $(CFLAGS) $< -c -o $@
# ----------------- Server API ----------------- #
API_SRC := $(wildcard $(SRC_DIR)/api/*.c)
API_OBJ := $(patsubst $(SRC_DIR)/api/%.c, $(OBJ_DIR)/api/%.o, $(API_SRC))
API_INC := $(INC_DIR)/api.h $(wildcard $(INC_DIR)/api/*.h)
$(LIB_DIR)/libapi.so : $(API_OBJ) $(DEP_LIST)
$(CC) $(CFLAGS) -shared $(API_OBJ) -o $@
$(OBJ_DIR)/api/%.o : $(SRC_DIR)/api/%.c $(API_INC) $(DEP_LIST)
$(CC) -fPIC $(CFLAGS) $< -c -o $@
# -------------- Utilities Library ------------- #
UTIL_SRC := $(wildcard $(SRC_DIR)/util/*.c) $(wildcard $(SRC_DIR)/util/*/*.c)
UTIL_OBJ := $(patsubst $(SRC_DIR)/util/%.c, $(OBJ_DIR)/util/%.o, $(UTIL_SRC))
UTIL_INC := $(patsubst $(SRC_DIR)/util/%.c, $(INC_DIR)/util/%.h, $(UTIL_SRC))
$(LIB_DIR)/libutil.so : $(UTIL_OBJ)
$(CC) $(CFLAGS) -shared $^ -o $@
$(OBJ_DIR)/util/%.o : $(SRC_DIR)/util/%.c $(INC_DIR)/util/%.h $(OBJ_DIR)/util/util.o
$(CC) $(CFLAGS) $< -c -fPIC -o $@
$(OBJ_DIR)/util/hash/%.o : $(SRC_DIR)/util/hash/%.c $(INC_DIR)/util/hash/%.h $(OBJ_DIR)/util/util.o
$(CC) $(CFLAGS) $< -c -fPIC -o $@
$(OBJ_DIR)/util/util.o : $(SRC_DIR)/util/util.c $(INC_DIR)/util/util.h
$(CC) $(CFLAGS) $< -c -fPIC -o $@
# --------------- Directory utils -------------- #
.PHONY: create_dirs
create_dirs:
@bash scripts/create_dirs.sh
# ------------------ Cleaning ------------------ #
.PHONY: clean
clean: cleanTests
@echo "Removing object files, libraries, logs and executables..."
@rm -f vgcore.*
@rm -rf $(OBJ_DIR)/*
@rm -rf $(BIN_DIR)/*
@rm -rf $(LIB_DIR)/*
@rm -rf $(LOG_DIR)/*
@rm -f /tmp/LSO_socket.sk
@echo "Cleaning complete!"
# ---------------- Official Tests ---------------- #
.PHONY : test1 test2 stats
.PHONY : cleanTests cleanTest1 cleanTest2
cleanTests: cleanTest1 cleanTest2
test1: cleanTest1
$(SCRIPT_DIR)/test1.sh
cleanTest1:
@echo "Cleaning files created by test1..."
@rm -rf $(TEST_DIR)/test1/deleted
@rm -rf $(TEST_DIR)/test1/readnfiles
@rm -rf $(TEST_DIR)/test1/readsingle
@echo "Cleaning complete!"
test2: cleanTest2
$(SCRIPT_DIR)/test2.sh LRU
test2FIFO: cleanTest2
$(SCRIPT_DIR)/test2.sh FIFO
test2LRU: cleanTest2
$(SCRIPT_DIR)/test2.sh LRU
cleanTest2:
@echo "Cleaning files created by test2..."
@rm -rf $(TEST_DIR)/test2/deleted_1
@rm -rf $(TEST_DIR)/test2/deleted_2
@rm -rf $(TEST_DIR)/test2/deleted_3
@rm -rf $(TEST_DIR)/test2/deleted_4
@rm -rf $(TEST_DIR)/test2/read_files
@echo "Cleaning complete!"
stats:
$(SCRIPT_DIR)/statistiche.sh