Skip to content

Commit faa6cf6

Browse files
committed
Makefiles: Put flags in CFLAGS, allow SANITIZE=1 for old GCCs.
1 parent e9bcf83 commit faa6cf6

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

common/rules.mk

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
# are we using clang?
22
ISCLANG := $(shell if $(CC) --version | grep LLVM >/dev/null; then echo 1; else echo 0; fi)
33

4-
CC += -std=gnu11 -W -Wall -Wshadow
5-
CFLAGS ?= -g $(DEFS)
4+
CFLAGS ?= -std=gnu11 -W -Wall -Wshadow -g $(DEFS)
65
O ?= -O3
76
ifeq ($(filter 0 1 2 3 s,$(O)),$(strip $(O)))
87
override O := -O$(O)
98
endif
109
ifeq ($(SANITIZE),1)
11-
CC += -fsanitize=address -fsanitize=undefined
10+
ifeq ($(strip $(shell $(CC) -fsanitize=address -x c -E /dev/null 2>&1 | grep sanitize=)),)
11+
CFLAGS += -fsanitize=address
12+
else
13+
$(info ** WARNING: Your C compiler does not support `-fsanitize=address`.)
14+
endif
15+
ifeq ($(strip $(shell $(CC) -fsanitize=undefined -x c -E /dev/null 2>&1 | grep sanitize=)),)
16+
CFLAGS += -fsanitize=undefined
17+
else
18+
$(info ** WARNING: Your C compiler does not support `-fsanitize=undefined`.)
19+
$(info ** You may want to install gcc-4.9 or greater.)
20+
endif
1221
endif
1322

1423
# these rules ensure dependencies are created
@@ -44,6 +53,7 @@ endif
4453
# cancel implicit rules we don't want
4554
%: %.c
4655
%.o: %.c
56+
%: %.o
4757

4858
$(BUILDSTAMP):
4959
@mkdir -p $(@D)

fundamentals4/GNUmakefile

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ add: add.o
1616
addu: addu.o
1717
$(CC) $(CFLAGS) $(O) -o $@ $^
1818

19+
fib: fib.o
20+
$(CC) $(CFLAGS) $(O) -o $@ $^
21+
1922
membench-%: membench.o mb-%.o
2023
$(CC) $(CFLAGS) $(O) -o $@ $^
2124

0 commit comments

Comments
 (0)