@@ -19,6 +19,20 @@ ifndef UNAME_M
19
19
UNAME_M := $(shell uname -m)
20
20
endif
21
21
22
+ ifeq '' '$(findstring clang,$(shell $(CC ) --version) ) '
23
+ CC_IS_GCC=1
24
+ CC_VER := $(shell $(CC) -dumpfullversion -dumpversion | awk -F. '{ printf("%02d%02d%02d", $$1, $$2, $$3) }')
25
+ else
26
+ CC_IS_CLANG=1
27
+ ifeq '' '$(findstring Apple LLVM,$(shell $(CC) --version))'
28
+ CC_IS_LLVM_CLANG=1
29
+ else
30
+ CC_IS_APPLE_CLANG=1
31
+ endif
32
+ CC_VER := $(shell $(CC) --version | sed -n 's/^.* version \([0-9.]*\) .*$$/\1/p' \
33
+ | awk -F. '{ printf("%02d%02d%02d", $$1, $$2, $$3) }')
34
+ endif
35
+
22
36
# Mac OS + Arm can report x86_64
23
37
# ref: https://github.com/ggerganov/whisper.cpp/issues/66#issuecomment-1282546789
24
38
ifeq ($(UNAME_S ) ,Darwin)
@@ -87,9 +101,6 @@ CC := riscv64-unknown-linux-gnu-gcc
87
101
CXX := riscv64-unknown-linux-gnu-g++
88
102
endif
89
103
90
- CCV := $(shell $(CC ) --version | head -n 1)
91
- CXXV := $(shell $(CXX ) --version | head -n 1)
92
-
93
104
#
94
105
# Compile flags
95
106
#
@@ -174,21 +185,36 @@ endif # LLAMA_DISABLE_LOGS
174
185
175
186
# warnings
176
187
WARN_FLAGS = -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function
177
- MK_CFLAGS += $(WARN_FLAGS ) -Wdouble-promotion - Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes \
178
- -Werror=implicit-int -Werror=implicit- function-declaration
179
- MK_CXXFLAGS += $(WARN_FLAGS ) -Wmissing-declarations -Wmissing-noreturn -Wextra-semi
188
+ MK_CFLAGS += $(WARN_FLAGS ) -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -Werror=implicit-int \
189
+ -Werror=implicit-function-declaration
190
+ MK_CXXFLAGS += $(WARN_FLAGS ) -Wmissing-declarations -Wmissing-noreturn
180
191
181
192
# TODO(cebtenzzre): remove this once PR #2632 gets merged
182
193
TTFS_CXXFLAGS = $(CXXFLAGS ) -Wno-missing-declarations
183
194
184
- ifneq '' ' $( findstring clang, $( shell $( CC ) --version) ) '
185
- # clang only
195
+ ifeq ( $( CC_IS_CLANG ) , 1)
196
+ # clang options
186
197
MK_CFLAGS += -Wunreachable-code-break -Wunreachable-code-return
187
- MK_HOST_CXXFLAGS += -Wunreachable-code-break -Wunreachable-code-return -Wmissing-prototypes
198
+ MK_HOST_CXXFLAGS += -Wunreachable-code-break -Wunreachable-code-return -Wmissing-prototypes -Wextra-semi
188
199
TTFS_CXXFLAGS += -Wno-missing-prototypes
200
+
201
+ ifneq '' '$(and $(CC_IS_LLVM_CLANG),$(filter 1,$(shell expr $(CC_VER) \>= 030800)))'
202
+ MK_CFLAGS += -Wdouble-promotion
203
+ endif
204
+ ifneq '' '$(and $(CC_IS_APPLE_CLANG),$(filter 1,$(shell expr $(CC_VER) \>= 070300)))'
205
+ MK_CFLAGS += -Wdouble-promotion
206
+ endif
189
207
else
190
- # gcc only
191
- MK_HOST_CXXFLAGS += -Wno-format-truncation -Wno-array-bounds
208
+ # gcc options
209
+ MK_CFLAGS += -Wdouble-promotion
210
+ MK_HOST_CXXFLAGS += -Wno-array-bounds
211
+
212
+ ifeq ($(shell expr $(CC_VER) \>= 070100), 1)
213
+ MK_HOST_CXXFLAGS += -Wno-format-truncation
214
+ endif
215
+ ifeq ($(shell expr $(CC_VER) \>= 080100), 1)
216
+ MK_HOST_CXXFLAGS += -Wextra-semi
217
+ endif
192
218
endif
193
219
194
220
# OS specific
@@ -472,8 +498,8 @@ $(info I CFLAGS: $(CFLAGS))
472
498
$(info I CXXFLAGS : $(CXXFLAGS ) )
473
499
$(info I NVCCFLAGS : $(NVCCFLAGS ) )
474
500
$(info I LDFLAGS : $(LDFLAGS ) )
475
- $(info I CC : $(CCV ) )
476
- $(info I CXX : $(CXXV ) )
501
+ $(info I CC : $(shell $( CC ) --version | head -n 1 ) )
502
+ $(info I CXX : $(shell $( CXX ) --version | head -n 1 ) )
477
503
$(info )
478
504
479
505
#
0 commit comments