-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
100 lines (80 loc) · 5.14 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
# 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 .
# 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 := tests/test1 tests/copy_to_external_simple tests/copy_to_external_errors tests/write_10_blocks_spill tests/write_10_blocks_simple tests/write_more_than_10_blocks_simple tests/my_test1 tests/my_test2 tests/my_test3 tests/copy_to_external_different_char tests/copy_to_external_direct_blocks tests/copy_to_external_huge_file tests/copy_to_external_indirect_blocks tests/copy_to_external_int tests/copy_to_external_multiple_char tests/copy_to_external_short_str tests/max_storage_exceeded tests/tfs_built_in_functions tests/write_all_direct_blocks tests/write_max_bytes tests/write_more_than_10_blocks_spill tests/write_more_than_1_block
# 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 -pthread -fsanitize=thread
CFLAGS += $(INCLUDES)
LDFLAGS += -pthread -fsanitize=thread
# Warnings
CFLAGS += -fdiagnostics-color=always -Wall -Werror -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
# 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/test1: tests/test1.o fs/operations.o fs/state.o
tests/copy_to_external_errors: tests/copy_to_external_errors.o fs/operations.o fs/state.o
tests/copy_to_external_simple: tests/copy_to_external_simple.o fs/operations.o fs/state.o
tests/write_10_blocks_spill: tests/write_10_blocks_spill.o fs/operations.o fs/state.o
tests/write_10_blocks_simple: tests/write_10_blocks_simple.o fs/operations.o fs/state.o
tests/write_more_than_10_blocks_simple: tests/write_more_than_10_blocks_simple.o fs/operations.o fs/state.o
tests/my_test1: tests/my_test1.o fs/operations.o fs/state.o
tests/my_test2: tests/my_test2.o fs/operations.o fs/state.o
tests/my_test3: tests/my_test3.o fs/operations.o fs/state.o
#sofia
tests/copy_to_external_different_char: tests/copy_to_external_different_char.o fs/operations.o fs/state.o
tests/copy_to_external_direct_blocks: tests/copy_to_external_direct_blocks.o fs/operations.o fs/state.o
tests/copy_to_external_huge_file: tests/copy_to_external_huge_file.o fs/operations.o fs/state.o
tests/copy_to_external_indirect_blocks: tests/copy_to_external_indirect_blocks.o fs/operations.o fs/state.o
tests/copy_to_external_int: tests/copy_to_external_int.o fs/operations.o fs/state.o
tests/copy_to_external_multiple_char: tests/copy_to_external_multiple_char.o fs/operations.o fs/state.o
tests/copy_to_external_short_str: tests/copy_to_external_short_str.o fs/operations.o fs/state.o
tests/max_storage_exceeded: tests/max_storage_exceeded.o fs/operations.o fs/state.o
tests/tfs_built_in_functions: tests/tfs_built_in_functions.o fs/operations.o fs/state.o
tests/write_all_direct_blocks: tests/write_all_direct_blocks.o fs/operations.o fs/state.o
tests/write_max_bytes: tests/write_max_bytes.o fs/operations.o fs/state.o
tests/write_more_than_10_blocks_spill: tests/write_more_than_10_blocks_spill.o fs/operations.o fs/state.o
tests/write_more_than_1_block: tests/write_more_than_1_block.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