-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
96 lines (72 loc) · 2.54 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
# use gcc with -fsanitize=thread bc clang on student vms (3.4) has buggy thread
# sanitizer
# this means we also need -ltsan in the link step. libtsan must be installed
# (sudo yum install libtsan on student vms)
OBJS_DIR = .objs
# define all the student executables
EXE_RENDE=rendezvous
EXE_SEM=semamore_tests
EXE_QUEUE=queue_tests
EXE_BAR=barrier_tests
EXES_STUDENT=$(EXE_BAR) $(EXE_SEM) $(EXE_RENDE) $(EXE_QUEUE)
# list object file dependencies for each
OBJS_RENDE=$(EXE_RENDE).o semamore.o
OBJS_SEM=$(EXE_SEM).o semamore.o
OBJS_QUEUE=$(EXE_QUEUE).o queue.o
OBJS_BAR=$(EXE_BAR).o barrier.o
# set up compiler
CC = clang
WARNINGS = -Wall -Wextra -Werror -Wno-error=unused-parameter
INCLUDES=-I./includes/
CFLAGS_DEBUG = $(INCLUDES) -O0 $(WARNINGS) -g -std=c99 -c -MMD -MP -D_GNU_SOURCE -DDEBUG
CFLAGS_RELEASE = $(INCLUDES) -O2 $(WARNINGS) -g -std=c99 -c -MMD -MP -D_GNU_SOURCE
# set up linker
LD = clang
LDFLAGS = -lrt -pthread -fPIC
# the string in grep must appear in the hostname, otherwise the Makefile will
# not allow the assignment to compile
IS_VM=$(shell hostname | grep "fa16")
ifeq ($(IS_VM),)
$(error This assignment must be compiled on the CS241 VMs)
endif
.PHONY: all
all: release
# build types
# run clean before building debug so that all of the release executables
# disappear
.PHONY: debug
.PHONY: release
.PHONY: tsan
release: $(EXES_STUDENT)
debug: clean $(EXE_QUEUE:%=%-debug) $(EXE_BAR:%=%-debug) $(EXE_SEM:%=%-debug)
# include dependencies
-include $(OBJS_DIR)/*.d
$(OBJS_DIR):
@mkdir -p $(OBJS_DIR)
# patterns to create objects
# keep the debug and release postfix for object files so that we can always
# separate them correctly
$(OBJS_DIR)/%-debug.o: %.c | $(OBJS_DIR)
$(CC) $(CFLAGS_DEBUG) $< -o $@
$(OBJS_DIR)/%-release.o: %.c | $(OBJS_DIR)
$(CC) $(CFLAGS_RELEASE) $< -o $@
# exes
# you will need a triple of exe and exe-debug and exe-tsan for each exe (other
# than provided exes)
$(EXE_BAR): $(OBJS_BAR:%.o=$(OBJS_DIR)/%-release.o)
$(LD) $^ $(LDFLAGS) -o $@
$(EXE_BAR)-debug: $(OBJS_BAR:%.o=$(OBJS_DIR)/%-debug.o)
$(LD) $^ $(LDFLAGS) -o $@
$(EXE_RENDE): $(OBJS_RENDE:%.o=$(OBJS_DIR)/%-release.o)
$(LD) $^ $(LDFLAGS) -o $@
$(EXE_QUEUE): $(OBJS_QUEUE:%.o=$(OBJS_DIR)/%-release.o)
$(LD) $^ $(LDFLAGS) -o $@
$(EXE_QUEUE)-debug: $(OBJS_QUEUE:%.o=$(OBJS_DIR)/%-debug.o)
$(LD) $^ $(LDFLAGS) -o $@
$(EXE_SEM): $(OBJS_SEM:%.o=$(OBJS_DIR)/%-release.o)
$(LD) $^ $(LDFLAGS) -o $@
$(EXE_SEM)-debug: $(OBJS_SEM:%.o=$(OBJS_DIR)/%-debug.o)
$(LD) $^ $(LDFLAGS) -o $@
.PHONY: clean
clean:
-rm -rf .objs $(EXES_STUDENT) $(EXES_STUDENT:%=%-debug)