Skip to content

Commit c5f9acf

Browse files
authored
make : simplify Makefile (ggml-org#1147)
* Simplify Architecture specific in Makefile * unified OS specific check
1 parent 7decc85 commit c5f9acf

File tree

1 file changed

+16
-50
lines changed

1 file changed

+16
-50
lines changed

Makefile

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,7 @@ endif
5757

5858
# OS specific
5959
# TODO: support Windows
60-
ifeq ($(UNAME_S),Linux)
61-
CFLAGS += -pthread
62-
CXXFLAGS += -pthread
63-
endif
64-
ifeq ($(UNAME_S),Darwin)
65-
CFLAGS += -pthread
66-
CXXFLAGS += -pthread
67-
endif
68-
ifeq ($(UNAME_S),FreeBSD)
69-
CFLAGS += -pthread
70-
CXXFLAGS += -pthread
71-
endif
72-
ifeq ($(UNAME_S),Haiku)
60+
ifeq ($(filter $(UNAME_S),Linux Darwin FreeBSD Haiku),$(UNAME_S))
7361
CFLAGS += -pthread
7462
CXXFLAGS += -pthread
7563
endif
@@ -79,60 +67,38 @@ endif
7967
# feel free to update the Makefile for your architecture and send a pull request or issue
8068
ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686))
8169
ifeq ($(UNAME_S),Darwin)
82-
CFLAGS += -mf16c
83-
AVX1_M := $(shell sysctl machdep.cpu.features)
84-
ifneq (,$(findstring FMA,$(AVX1_M)))
85-
CFLAGS += -mfma
86-
endif
87-
ifneq (,$(findstring AVX1.0,$(AVX1_M)))
88-
CFLAGS += -mavx
89-
endif
90-
AVX2_M := $(shell sysctl machdep.cpu.leaf7_features)
91-
ifneq (,$(findstring AVX2,$(AVX2_M)))
92-
CFLAGS += -mavx2
93-
endif
70+
CPUINFO_CMD := sysctl machdep.cpu.features
9471
else ifeq ($(UNAME_S),Linux)
95-
AVX2_M := $(shell grep "avx2 " /proc/cpuinfo)
72+
CPUINFO_CMD := cat /proc/cpuinfo
73+
else ifeq ($(UNAME_S),Haiku)
74+
CPUINFO_CMD := sysinfo -cpu
75+
endif
76+
77+
ifdef CPUINFO_CMD
78+
AVX2_M := $(shell $(CPUINFO_CMD) | grep -m 1 "avx2 ")
9679
ifneq (,$(findstring avx2,$(AVX2_M)))
9780
CFLAGS += -mavx2
9881
endif
99-
FMA_M := $(shell grep "fma " /proc/cpuinfo)
82+
83+
FMA_M := $(shell $(CPUINFO_CMD) | grep -m 1 "fma ")
10084
ifneq (,$(findstring fma,$(FMA_M)))
10185
CFLAGS += -mfma
10286
endif
103-
F16C_M := $(shell grep "f16c " /proc/cpuinfo)
87+
88+
F16C_M := $(shell $(CPUINFO_CMD) | grep -m 1 "f16c ")
10489
ifneq (,$(findstring f16c,$(F16C_M)))
10590
CFLAGS += -mf16c
10691

107-
AVX1_M := $(shell grep "avx " /proc/cpuinfo)
92+
AVX1_M := $(shell $(CPUINFO_CMD) | grep -m 1 "avx ")
10893
ifneq (,$(findstring avx,$(AVX1_M)))
10994
CFLAGS += -mavx
11095
endif
11196
endif
112-
SSE3_M := $(shell grep "sse3 " /proc/cpuinfo)
97+
98+
SSE3_M := $(shell $(CPUINFO_CMD) | grep -m 1 "sse3 ")
11399
ifneq (,$(findstring sse3,$(SSE3_M)))
114100
CFLAGS += -msse3
115101
endif
116-
else ifeq ($(UNAME_S),Haiku)
117-
AVX2_M := $(shell sysinfo -cpu | grep "AVX2 ")
118-
ifneq (,$(findstring avx2,$(AVX2_M)))
119-
CFLAGS += -mavx2
120-
endif
121-
FMA_M := $(shell sysinfo -cpu | grep "FMA ")
122-
ifneq (,$(findstring fma,$(FMA_M)))
123-
CFLAGS += -mfma
124-
endif
125-
F16C_M := $(shell sysinfo -cpu | grep "F16C ")
126-
ifneq (,$(findstring f16c,$(F16C_M)))
127-
CFLAGS += -mf16c
128-
129-
AVX1_M := $(shell sysinfo -cpu | grep "AVX ")
130-
ifneq (,$(findstring avx,$(AVX1_M)))
131-
CFLAGS += -mavx
132-
endif
133-
endif
134-
else
135-
CFLAGS += -mfma -mf16c -mavx -mavx2
136102
endif
137103
endif
138104
ifeq ($(UNAME_M),amd64)

0 commit comments

Comments
 (0)