Skip to content

Commit 36e17ae

Browse files
committed
feat: enhance Makefile for platform-specific library linking and support for Vulkan/OpenCL
1 parent 7d0cb22 commit 36e17ae

1 file changed

Lines changed: 41 additions & 2 deletions

File tree

Makefile

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,15 @@ SQLITE_FLAGS := -DSQLITE_THREADSAFE=1 \
7777
-DSQLITE_OMIT_AUTOINIT
7878

7979
# Android's bionic libc has pthread built in — no separate libpthread.so to link.
80+
# -lz lives at the END of LIBS (single-pass GNU ld + strict musl loader);
81+
# Windows pulls in -lws2_32 / -lcrypt32 / -lbcrypt there too. See the LIBS
82+
# blocks below.
8083
ifeq ($(PLATFORM),android)
81-
LDFLAGS := -lz
84+
LDFLAGS :=
85+
else ifeq ($(PLATFORM),windows)
86+
LDFLAGS :=
8287
else
83-
LDFLAGS := -lpthread -lz
88+
LDFLAGS := -lpthread
8489
endif
8590

8691
# ============================================================================
@@ -99,6 +104,19 @@ LLAMA_LIBS := $(LLAMA_BUILD)/tools/mtmd/libmtmd.a \
99104
$(call ggml_lib,ggml-cpu) \
100105
$(call ggml_lib,ggml-base)
101106

107+
# Optional GPU backends — wildcards resolve only when llama.cpp was built
108+
# with -DGGML_VULKAN=ON / -DGGML_OPENCL=ON. Static archives go at the end
109+
# of LLAMA_LIBS; matching `-lvulkan` / `-lOpenCL` runtime loaders are
110+
# appended to LIBS by each platform block below.
111+
GGML_VULKAN_LIB := $(firstword $(wildcard $(LLAMA_BUILD)/ggml/src/ggml-vulkan/libggml-vulkan.a $(LLAMA_BUILD)/ggml/src/ggml-vulkan/ggml-vulkan.a))
112+
GGML_OPENCL_LIB := $(firstword $(wildcard $(LLAMA_BUILD)/ggml/src/ggml-opencl/libggml-opencl.a $(LLAMA_BUILD)/ggml/src/ggml-opencl/ggml-opencl.a))
113+
ifneq ($(GGML_VULKAN_LIB),)
114+
LLAMA_LIBS += $(GGML_VULKAN_LIB)
115+
endif
116+
ifneq ($(GGML_OPENCL_LIB),)
117+
LLAMA_LIBS += $(GGML_OPENCL_LIB)
118+
endif
119+
102120
# Whisper uses llama's ggml (symlinked: whisper.cpp/ggml → llama.cpp/ggml).
103121
# Only libwhisper.a is needed — ggml symbols come from LLAMA_LIBS.
104122
WHISPER_LIBS := $(WHISPER_BUILD)/src/libwhisper.a
@@ -181,6 +199,7 @@ else ifeq ($(PLATFORM),android)
181199
LIBS += $(MBEDTLS_BUILD)/library/libmbedtls.a
182200
LIBS += $(MBEDTLS_BUILD)/library/libmbedx509.a
183201
LIBS += $(MBEDTLS_BUILD)/library/libmbedcrypto.a
202+
LIBS += -lz
184203
else ifeq ($(PLATFORM),linux)
185204
# Linux: use libcurl + mbedtls
186205
CFLAGS += -I$(CURL_DIR)/include -I$(MBEDTLS_DIR)/include
@@ -192,6 +211,13 @@ else ifeq ($(PLATFORM),linux)
192211
LIBS += $(MBEDTLS_BUILD)/library/libmbedtls.a
193212
LIBS += $(MBEDTLS_BUILD)/library/libmbedx509.a
194213
LIBS += $(MBEDTLS_BUILD)/library/libmbedcrypto.a
214+
ifneq ($(GGML_VULKAN_LIB),)
215+
LIBS += -lvulkan
216+
endif
217+
ifneq ($(GGML_OPENCL_LIB),)
218+
LIBS += -lOpenCL
219+
endif
220+
LIBS += -lz
195221
else
196222
# Windows/other: use libcurl + mbedtls.
197223
# -DCURL_STATICLIB: curl.h on Windows declares functions as dllimport
@@ -205,6 +231,19 @@ else
205231
LIBS += $(MBEDTLS_BUILD)/library/libmbedtls.a
206232
LIBS += $(MBEDTLS_BUILD)/library/libmbedx509.a
207233
LIBS += $(MBEDTLS_BUILD)/library/libmbedcrypto.a
234+
# Win32 system libs MUST come after static archives that reference them
235+
# (single-pass GNU ld). curl needs Winsock + crypt32; mbedtls needs
236+
# bcrypt for BCryptGenRandom; curl uses zlib for gzip.
237+
# The Vulkan loader DLL on Windows is `vulkan-1.dll`, so the import
238+
# library is `libvulkan-1.dll.a` and the flag is `-lvulkan-1`.
239+
LIBS += -lws2_32 -lcrypt32 -lbcrypt
240+
ifneq ($(GGML_VULKAN_LIB),)
241+
LIBS += -lvulkan-1
242+
endif
243+
ifneq ($(GGML_OPENCL_LIB),)
244+
LIBS += -lOpenCL
245+
endif
246+
LIBS += -lz
208247
endif
209248

210249
# ============================================================================

0 commit comments

Comments
 (0)