-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
61 lines (47 loc) · 1.31 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
# C++ compiler
CC=g++ # change g++ to gcc when using C!
# predefine macros
DEFS=
# executable name
EXEC= loadBalancing
CFLAGS= $(DEFS) -g -Wall -std=c++17
# LIBS=-lm
LIBS = -lX11 -lGL -lpthread -lpng -lstdc++fs -std=c++17
# headers directory
HDIR = header
# source code directory
CDIR = src
# build directory ( where the object files will be stored )
ODIR = build
# list of header files
_DEPS = receiver.h sender.h mediator.h peer.h load_balancing.h
DEPS = $(patsubst %,$(HDIR)/%,$(_DEPS))
# list of source code files ( replacing the .c/.cpp extension with .o )
_OBJ = receiver.o sender.o mediator.o peer.o load_balancing.o main.o
OBJ = $(patsubst %, $(ODIR)/%,$(_OBJ))
# used to create the build directory if it doesn't exist
dir_guard = @mkdir -p $(@D)
# rule for files ending in .o
$(ODIR)/%.o: $(CDIR)/%.cpp $(DEPS) # change cpp to c when using C!
$(dir_guard)
$(CC) -c -o $@ $< $(CFLAGS)
# "make all" to compile
.PHONY: all
all: $(OBJ)
$(CC) -o $(EXEC) $^ $(CFLAGS) $(LIBS)
# "make run" to execute
.PHONY: run
run:
./$(EXEC)
# "make debug" to execute with debugger
.PHONY: debug
debug:
gdb ./$(EXEC)
# "make valgrind" to execute with valgrind (memory leak detection)
.PHONY: valgrind
valgrind:
valgrind --leak-check=full ./$(EXEC)
# "make clean" to remove object files
.PHONY: clean
clean:
rm -f $(ODIR)/*.o