-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
64 lines (48 loc) · 1.57 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
OBJS_DIR = .objs
# define all of student executables
EXE_PAR_MAP=par_map
EXES_STUDENT=$(EXE_PAR_MAP)
# list object file dependencies for each
OBJS_PAR_MAP=main.o map.o mappers.o par_map.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
# 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
.PHONY: release
.PHONY: debug
release: $(EXES_STUDENT)
debug: clean $(EXES_STUDENT:%=%-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 pair of exe and exe-debug targets for each exe
$(EXE_PAR_MAP)-debug: $(OBJS_PAR_MAP:%.o=$(OBJS_DIR)/%-debug.o)
$(LD) $^ $(LDFLAGS) -o $@
$(EXE_PAR_MAP): $(OBJS_PAR_MAP:%.o=$(OBJS_DIR)/%-release.o)
$(LD) $^ $(LDFLAGS) -o $@
.PHONY: clean
clean:
rm -rf .objs $(EXES_STUDENT) $(EXES_STUDENT:%=%-debug)