-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (65 loc) · 3.44 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
# Makefile, v1
# Sistemas Operativos, DEI/IST/ULisboa 2021-22
#
# This makefile should be run from the *root* of the project
CC ?= gcc
LD ?= gcc
# space separated list of directories with header files
INCLUDE_DIRS := fs client .
# this creates a space separated list of -I<dir> where <dir> is each of the values in INCLUDE_DIRS
INCLUDES = $(addprefix -I, $(INCLUDE_DIRS))
SOURCES := $(wildcard */*.c)
HEADERS := $(wildcard */*.h)
OBJECTS := $(SOURCES:.c=.o)
TARGET_EXECS := fs/tfs_server tests/lib_destroy_after_all_closed_test tests/client_server_simple_test tests/client_server_shutdown_test tests/client_server_simple_multiclient_test tests/client_server_test1 tests/block_destroy_simple
# VPATH is a variable used by Makefile which finds *sources* and makes them available throughout the codebase
# vpath %.h <DIR> tells make to look for header files in <DIR>
vpath # clears VPATH
vpath %.h $(INCLUDE_DIRS)
CFLAGS = -std=c11 -D_POSIX_C_SOURCE=200809L
CFLAGS += $(INCLUDES)
# Warnings
CFLAGS += -fdiagnostics-color=always -Wall -Wextra -Wcast-align -Wconversion -Wfloat-equal -Wformat=2 -Wnull-dereference -Wshadow -Wsign-conversion -Wswitch-default -Wswitch-enum -Wundef -Wunreachable-code -Wunused
# Warning suppressions
CFLAGS += -Wno-sign-compare
# optional debug symbols: run make DEBUG=no to deactivate them
ifneq ($(strip $(DEBUG)), no)
CFLAGS += -g
endif
# optional O3 optimization symbols: run make OPTIM=no to deactivate them
ifeq ($(strip $(OPTIM)), no)
CFLAGS += -O0
else
CFLAGS += -O3
endif
CFLAGS += -pthread -fsanitize=thread
LDFLAGS = -pthread -fsanitize=thread
# A phony target is one that is not really the name of a file
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: all clean depend fmt
all: $(TARGET_EXECS)
# The following target can be used to invoke clang-format on all the source and header
# files. clang-format is a tool to format the source code based on the style specified
# in the file '.clang-format'.
# More info available here: https://clang.llvm.org/docs/ClangFormat.html
# The $^ keyword is used in Makefile to refer to the right part of the ":" in the
# enclosing rule. See https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
fmt: $(SOURCES) $(HEADERS)
clang-format -i $^
# Note the lack of a rule.
# make uses a set of default rules, one of which compiles C binaries
# the CC, LD, CFLAGS and LDFLAGS are used in this rule
tests/client_server_simple_test: tests/client_server_simple_test.o client/tecnicofs_client_api.o
fs/tfs_server: fs/operations.o fs/state.o
tests/lib_destroy_after_all_closed_test: fs/operations.o fs/state.o
tests/client_server_shutdown_test: tests/client_server_shutdown_test.o client/tecnicofs_client_api.o
tests/client_server_simple_multiclient_test: tests/client_server_simple_multiclient_test.o client/tecnicofs_client_api.o
tests/client_server_test1: tests/client_server_test1.o client/tecnicofs_client_api.o
tests/block_destroy_simple: tests/block_destroy_simple.o fs/operations.o fs/state.o
clean:
rm -f $(OBJECTS) $(TARGET_EXECS)
# This generates a dependency file, with some default dependencies gathered from the include tree
# The dependencies are gathered in the file autodep. You can find an example illustrating this GCC feature, without Makefile, at this URL: https://renenyffenegger.ch/notes/development/languages/C-C-plus-plus/GCC/options/MM
# Run `make depend` whenever you add new includes in your files
depend : $(SOURCES)
$(CC) $(INCLUDES) -MM $^ > autodep