-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
46 lines (34 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
COMPILER = gcc
BASE_FLAGS = -std=c18 -Werror -Wall -Wshadow -c
DEBUG_FLAGS = -ggdb3
LIBRARY_FLAGS = -pthread
DIR_BIN = bin
DIR_BUILD = build
DIR_SRC = src
FILE_EXECUTABLE = mutex
FILES_C = $(wildcard $(DIR_SRC)/*.c)
FILES_H = $(wildcard $(DIR_SRC)/*.h)
FILES_O = $(subst src/,$(DIR_BUILD)/,$(subst .c,.o,$(FILES_C)))
release: COMPILER_FLAGS = $(BASE_FLAGS)
release: $(DIR_BIN)/$(FILE_EXECUTABLE)
debug: COMPILER_FLAGS = $(BASE_FLAGS) $(DEBUG_FLAGS)
debug: $(DIR_BIN)/$(FILE_EXECUTABLE)
$(DIR_BIN)/$(FILE_EXECUTABLE): make_directories $(FILES_O)
$(COMPILER) $(COMPILER_FLAGS) $(FILES_O) -o $@ $(LIBRARY_FLAGS)
$(DIR_BUILD)/logger.o: $(DIR_SRC)/logger.c $(FILES_H)
$(COMPILER) $(COMPILER_FLAGS) -c $< -o $@
$(DIR_BUILD)/thread.o: $(DIR_SRC)/thread.c $(FILES_H)
$(COMPILER) $(COMPILER_FLAGS) -c $< -o $@
make_directories:
mkdir -p $(DIR_BIN)
mkdir -p $(DIR_BUILD)
clean:
rm -f $(DIR_BIN)/*
rm -f $(DIR_BUILD)/*
rm -f errors.txt
rm -f valgrind.txt
run: $(DIR_BIN)/$(FILE_EXECUTABLE)
$(DIR_BIN)/$(FILE_EXECUTABLE)
run_valgrind: $(DIR_BIN)/$(FILE_EXECUTABLE)
rm -f valgrind.txt
valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind.txt $(DIR_BIN)/$(FILE_EXECUTABLE)