2025-08-15 05:42:58 +08:00
|
|
|
UPSTREAM=https://github.com/ggml-org/llama.cpp.git
|
2025-01-30 07:03:38 +08:00
|
|
|
WORKDIR=llama/vendor
|
2025-10-03 05:47:10 +08:00
|
|
|
FETCH_HEAD=364a7a6d4a786e98947c8a90430ea581213c0ba9
|
2025-01-30 07:03:38 +08:00
|
|
|
|
|
|
|
.PHONY: help
|
|
|
|
help:
|
|
|
|
@echo "Available targets:"
|
|
|
|
@echo " sync Sync with upstream repositories"
|
|
|
|
@echo " checkout Checkout upstream repository"
|
|
|
|
@echo " apply-patches Apply patches to local repository"
|
|
|
|
@echo " format-patches Format patches from local repository"
|
|
|
|
@echo " clean Clean local repository"
|
|
|
|
@echo
|
|
|
|
@echo "Example:"
|
2025-08-15 05:42:58 +08:00
|
|
|
@echo " make -f $(lastword $(MAKEFILE_LIST)) clean apply-patches sync"
|
2025-01-30 07:03:38 +08:00
|
|
|
|
|
|
|
.PHONY: sync
|
2025-05-14 08:36:02 +08:00
|
|
|
sync: llama/build-info.cpp ml/backend/ggml/ggml/src/ggml-metal/ggml-metal-embed.metal
|
2025-02-06 08:37:18 +08:00
|
|
|
|
2025-05-14 08:36:02 +08:00
|
|
|
llama/build-info.cpp: llama/build-info.cpp.in llama/llama.cpp
|
|
|
|
sed -e 's|@FETCH_HEAD@|$(FETCH_HEAD)|' <$< >$@
|
|
|
|
|
|
|
|
ml/backend/ggml/ggml/src/ggml-metal/ggml-metal-embed.metal: ml/backend/ggml/ggml
|
|
|
|
go generate ./$(@D)
|
2025-01-30 07:03:38 +08:00
|
|
|
|
|
|
|
.PHONY: llama/llama.cpp
|
2025-08-15 05:42:58 +08:00
|
|
|
llama/llama.cpp: llama/vendor
|
|
|
|
rsync -arvzc --delete -f "include LICENSE" -f "merge $@/.rsync-filter" $(addprefix $<,/LICENSE /) $@
|
2025-01-30 07:03:38 +08:00
|
|
|
|
2025-04-17 06:14:01 +08:00
|
|
|
.PHONY: ml/backend/ggml/ggml
|
2025-08-15 05:42:58 +08:00
|
|
|
ml/backend/ggml/ggml: llama/vendor
|
|
|
|
rsync -arvzc --delete -f "include LICENSE" -f "merge $@/.rsync-filter" $(addprefix $<,/LICENSE /ggml/) $@
|
2025-01-30 07:03:38 +08:00
|
|
|
|
|
|
|
PATCHES=$(wildcard llama/patches/*.patch)
|
2025-05-14 08:36:02 +08:00
|
|
|
PATCHED=$(join $(dir $(PATCHES)), $(addsuffix ed, $(addprefix ., $(notdir $(PATCHES)))))
|
2025-01-30 07:03:38 +08:00
|
|
|
|
|
|
|
.PHONY: apply-patches
|
|
|
|
.NOTPARALLEL:
|
2025-05-14 08:36:02 +08:00
|
|
|
apply-patches: $(PATCHED)
|
2025-01-30 07:03:38 +08:00
|
|
|
|
2025-05-14 08:36:02 +08:00
|
|
|
llama/patches/.%.patched: llama/patches/%.patch
|
2025-08-15 05:42:58 +08:00
|
|
|
@if git -c user.name=nobody -c 'user.email=<>' -C $(WORKDIR) am -3 $(realpath $<); then \
|
|
|
|
touch $@; \
|
|
|
|
else \
|
|
|
|
echo "Patch failed. Resolve any conflicts then continue."; \
|
|
|
|
echo "1. Run 'git -C $(WORKDIR) am --continue'"; \
|
|
|
|
echo "2. Run 'make -f $(lastword $(MAKEFILE_LIST)) format-patches'"; \
|
|
|
|
echo "3. Run 'make -f $(lastword $(MAKEFILE_LIST)) clean apply-patches'"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
2025-01-30 07:03:38 +08:00
|
|
|
|
|
|
|
.PHONY: checkout
|
|
|
|
checkout: $(WORKDIR)
|
|
|
|
git -C $(WORKDIR) fetch
|
|
|
|
git -C $(WORKDIR) checkout -f $(FETCH_HEAD)
|
|
|
|
|
|
|
|
$(WORKDIR):
|
|
|
|
git clone $(UPSTREAM) $(WORKDIR)
|
|
|
|
|
|
|
|
.PHONE: format-patches
|
|
|
|
format-patches: llama/patches
|
|
|
|
git -C $(WORKDIR) format-patch \
|
|
|
|
--no-signature \
|
|
|
|
--no-numbered \
|
|
|
|
--zero-commit \
|
|
|
|
-o $(realpath $<) \
|
|
|
|
$(FETCH_HEAD)
|
|
|
|
|
|
|
|
.PHONE: clean
|
|
|
|
clean: checkout
|
2025-08-15 05:42:58 +08:00
|
|
|
@git -C $(WORKDIR) am --abort || true
|
2025-05-14 08:36:02 +08:00
|
|
|
$(RM) llama/patches/.*.patched
|