]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
make : simplify Makefile (#1147)
authoralonfaraj <redacted>
Fri, 25 Aug 2023 12:20:44 +0000 (15:20 +0300)
committerGitHub <redacted>
Fri, 25 Aug 2023 12:20:44 +0000 (15:20 +0300)
* Simplify Architecture specific in Makefile

* unified OS specific check

Makefile

index 37ca3823de151048c22498bfddbd9d2dda30f7d4..5d5e7ad7a0657f73e8b67fd94b9ef7ac44189bbf 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -57,19 +57,7 @@ endif
 
 # OS specific
 # TODO: support Windows
-ifeq ($(UNAME_S),Linux)
-       CFLAGS   += -pthread
-       CXXFLAGS += -pthread
-endif
-ifeq ($(UNAME_S),Darwin)
-       CFLAGS   += -pthread
-       CXXFLAGS += -pthread
-endif
-ifeq ($(UNAME_S),FreeBSD)
-       CFLAGS   += -pthread
-       CXXFLAGS += -pthread
-endif
-ifeq ($(UNAME_S),Haiku)
+ifeq ($(filter $(UNAME_S),Linux Darwin FreeBSD Haiku),$(UNAME_S))
        CFLAGS   += -pthread
        CXXFLAGS += -pthread
 endif
@@ -79,60 +67,38 @@ endif
 #       feel free to update the Makefile for your architecture and send a pull request or issue
 ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686))
        ifeq ($(UNAME_S),Darwin)
-               CFLAGS += -mf16c
-               AVX1_M := $(shell sysctl machdep.cpu.features)
-               ifneq (,$(findstring FMA,$(AVX1_M)))
-                       CFLAGS += -mfma
-               endif
-               ifneq (,$(findstring AVX1.0,$(AVX1_M)))
-                       CFLAGS += -mavx
-               endif
-               AVX2_M := $(shell sysctl machdep.cpu.leaf7_features)
-               ifneq (,$(findstring AVX2,$(AVX2_M)))
-                       CFLAGS += -mavx2
-               endif
+               CPUINFO_CMD := sysctl machdep.cpu.features
        else ifeq ($(UNAME_S),Linux)
-               AVX2_M := $(shell grep "avx2 " /proc/cpuinfo)
+               CPUINFO_CMD := cat /proc/cpuinfo
+       else ifeq ($(UNAME_S),Haiku)
+               CPUINFO_CMD := sysinfo -cpu
+       endif
+
+       ifdef CPUINFO_CMD
+               AVX2_M := $(shell $(CPUINFO_CMD) | grep -m 1 "avx2 ")
                ifneq (,$(findstring avx2,$(AVX2_M)))
                        CFLAGS += -mavx2
                endif
-               FMA_M := $(shell grep "fma " /proc/cpuinfo)
+
+               FMA_M := $(shell $(CPUINFO_CMD) | grep -m 1 "fma ")
                ifneq (,$(findstring fma,$(FMA_M)))
                        CFLAGS += -mfma
                endif
-               F16C_M := $(shell grep "f16c " /proc/cpuinfo)
+
+               F16C_M := $(shell $(CPUINFO_CMD) | grep -m 1 "f16c ")
                ifneq (,$(findstring f16c,$(F16C_M)))
                        CFLAGS += -mf16c
 
-                       AVX1_M := $(shell grep "avx " /proc/cpuinfo)
+                       AVX1_M := $(shell $(CPUINFO_CMD) | grep -m 1 "avx ")
                        ifneq (,$(findstring avx,$(AVX1_M)))
                                CFLAGS += -mavx
                        endif
                endif
-               SSE3_M := $(shell grep "sse3 " /proc/cpuinfo)
+
+               SSE3_M := $(shell $(CPUINFO_CMD) | grep -m 1 "sse3 ")
                ifneq (,$(findstring sse3,$(SSE3_M)))
                        CFLAGS += -msse3
                endif
-       else ifeq ($(UNAME_S),Haiku)
-               AVX2_M := $(shell sysinfo -cpu | grep "AVX2 ")
-               ifneq (,$(findstring avx2,$(AVX2_M)))
-                       CFLAGS += -mavx2
-               endif
-               FMA_M := $(shell sysinfo -cpu | grep "FMA ")
-               ifneq (,$(findstring fma,$(FMA_M)))
-                       CFLAGS += -mfma
-               endif
-               F16C_M := $(shell sysinfo -cpu | grep "F16C ")
-               ifneq (,$(findstring f16c,$(F16C_M)))
-                       CFLAGS += -mf16c
-
-                       AVX1_M := $(shell sysinfo -cpu | grep "AVX ")
-                       ifneq (,$(findstring avx,$(AVX1_M)))
-                               CFLAGS += -mavx
-                       endif
-               endif
-       else
-               CFLAGS += -mfma -mf16c -mavx -mavx2
        endif
 endif
 ifeq ($(UNAME_M),amd64)