Skip to content

Commit 374fa1a

Browse files
committed
Define default CFLAGS for GNU and LLVM compilers
1 parent 520b790 commit 374fa1a

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

Makefile

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,30 @@ endif
3434
LIBLINK = $(subst .$(VERSION),,$(LIBFILE))
3535

3636
ifndef CFLAGS
37-
CFLAGS = -Wall -Wextra -pedantic -Wno-unused-parameter
37+
cc_std = c89
38+
cc_version := $(shell $(CC) --version)
39+
cc_is_gnu := $(if $(findstring Free Software Foundation,$(cc_version)),1)
40+
ifdef cc_is_gnu
41+
CFLAGS = $(if $(cc_std),-std=$(cc_std))
42+
CFLAGS += -pedantic -Wall -Wextra
43+
CFLAGS += -Wno-unused-parameter
44+
CFLAGS += -Wno-unreachable-code-return
45+
else
46+
CFLAGS = $(if $(cc_std),-std=$(cc_std))
47+
CFLAGS += -pedantic -Weverything
48+
CFLAGS += -Wno-unused-parameter
49+
CFLAGS += -Wno-unreachable-code-return
50+
endif
3851
endif
3952

4053
.SECONDEXPANSION: # to expand $$(@D)/.DIR
4154

42-
$(BUILD)/mpicc: CC := CC
43-
$(BUILD)/mpicc: cc := cc
44-
$(BUILD)/mpicc: op := cc
45-
$(BUILD)/mpicxx: CC := CXX
46-
$(BUILD)/mpicxx: cc := c++
47-
$(BUILD)/mpicxx: op := cxx
55+
$(BUILD)/mpicc: override CC := CC
56+
$(BUILD)/mpicc: override cc := cc
57+
$(BUILD)/mpicc: override op := cc
58+
$(BUILD)/mpicxx: override CC := CXX
59+
$(BUILD)/mpicxx: override cc := c++
60+
$(BUILD)/mpicxx: override op := cxx
4861
$(BUILD)/mpic%: mpicc.in | $$(@D)/.DIR
4962
cp $< $@
5063
$(SED_I) -e 's:@includedir@:$(abspath $(PREFIX))/$(INCDIR):' $@

0 commit comments

Comments
 (0)