Skip to content

Commit cec6477

Browse files
committed
Separate overridable part of CFLAGS
An external build system might want to select for example a different optimization level, but overriding CFLAGS would also drop "-std=c99" and that breaks compilation. Fixed by using two separate Make variables for overridable and non-overridable compiler flags.
1 parent 992f9da commit cec6477

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
CFLAGS = -std=c99 -O2 -fomit-frame-pointer
2-
CFLAGS += -Wall -Wextra -Wundef -Wold-style-definition
1+
# CFLAGS can be overridden, CFLAGS_NOCUST should be left untouched.
2+
CFLAGS ?= -O2 -fomit-frame-pointer
3+
CFLAGS_NOCUST = -std=c99 -Wall -Wextra -Wundef -Wold-style-definition
34
LDFLAGS = -s -static
45

56
BINARIES = mininit-initramfs mininit-syspart splashkill
@@ -23,5 +24,8 @@ splashkill: $(S_OBJS)
2324
# on any header change.
2425
$(OBJS): $(wildcard *.h)
2526

27+
$(OBJS): %.o: %.c
28+
$(CC) $(CFLAGS_NOCUST) $(CFLAGS) -o $@ -c $<
29+
2630
$(BINARIES):
27-
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.o,$^)
31+
$(CC) $(CFLAGS_NOCUST) $(CFLAGS) $(LDFLAGS) -o $@ $(filter %.o,$^)

0 commit comments

Comments
 (0)