-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
85 lines (72 loc) · 2.06 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
# Targets:
# make linux version
# make main
# ./main
#
# run linux version:
# make run
#
# runs a smaller debug-test case with assertions on
# make run_small
#
# run in GDB
# make run_debug
#
# check for memory leaks
# make run_memcheck
CC:=gcc
WFLAGS:= -Wall -Wextra
IFLAGS:=-I./include/
CVERSION := -std=gnu99
include src/app/macros.mk
# from nautilus/Makefile
CFLAGS_NAUT := -O2 \
-fno-omit-frame-pointer \
-fno-stack-protector \
-fno-strict-aliasing \
-fno-strict-overflow \
-fno-delete-null-pointer-checks \
-mno-red-zone \
-mno-sse2 \
-mcmodel=large \
-fno-common \
-Wstrict-overflow=5 \
-fgnu89-inline \
-g \
-m64
CFLAGS_OPT := $(CVERSION) $(IFLAGS) $(WFLAGS) $(CFLAGS_NAUT)
# that line ^ should have no extra flags.
# -std=* -I* and -W* won't affect the outputed code, so they are fine.
# All flags which do (eg. -f* -O* -m*) should be a part of CFLAGS_NAUT
CFLAGS_DEBUG:= $(CVERSION) $(IFLAGS) $(WFLAGS) -fno-inline -static -Og -g -DVERBOSE -DSMALL
# -DREPLACE_MALLOC
SOURCES:=$(shell find src/ -name '*.c' -printf '%P\n')
OBJECTS:=$(addprefix build/,$(SOURCES:.c=.o))
OBJECTS_DBG:=$(addprefix build/,$(SOURCES:.c=.o_debug))
all: main
run: main
./main
.PHONY: run
run_debug: main_debug
gdb -q main_debug -ex r
.PHONY: run_debug
run_small: main
./main --chunksize 3 --numchunks 3 --throwout 0 --trials 1
.PHONY: run_small
run_memcheck: main_debug
valgrind --leak-check=full --show-leak-kinds=all ./main_debug --chunksize 3000 --numchunks 10 --throwout 0 --trials 1
.PHONY: run_memcheck
build/%.o_debug: src/%.c
mkdir -p $(shell dirname $@)
$(CC) $(CFLAGS_DBG) -c -o $@ $<
build/%.o: src/%.c
mkdir -p $(shell dirname $@)
$(CC) $(CFLAGS_OPT) -c -o $@ $<
main_debug: $(OBJECTS_DEBUG)
$(CC) $(LDFLAGS) -o $@ $^
main: $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $^
clean:
rm -f main main_debug $(shell find . -name '*.o' -o -name '*.cmd')
rm -rf build/
.PHONY: clean