Makefile.sync 1.87 KB
Newer Older
Michael Yang's avatar
Michael Yang committed
1
2
UPSTREAM=https://github.com/ggerganov/llama.cpp.git
WORKDIR=llama/vendor
3
FETCH_HEAD=de4c07f93783a1a96456a44dc16b9db538ee1618
Michael Yang's avatar
Michael Yang committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17

.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:"
	@echo "    make -f $(lastword $(MAKEFILE_LIST)) clean sync"

.PHONY: sync
18
sync: llama/build-info.cpp ml/backend/ggml/ggml/src/ggml-metal/ggml-metal-embed.metal
19

20
21
22
23
24
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)
Michael Yang's avatar
Michael Yang committed
25
26

.PHONY: llama/llama.cpp
27
llama/llama.cpp: llama/vendor/
Michael Yang's avatar
Michael Yang committed
28
29
	rsync -arvzc -f "merge $@/.rsync-filter" $< $@

30
31
.PHONY: ml/backend/ggml/ggml
ml/backend/ggml/ggml: llama/vendor/ggml/
Michael Yang's avatar
Michael Yang committed
32
33
34
	rsync -arvzc -f "merge $@/.rsync-filter" $< $@

PATCHES=$(wildcard llama/patches/*.patch)
35
PATCHED=$(join $(dir $(PATCHES)), $(addsuffix ed, $(addprefix ., $(notdir $(PATCHES)))))
Michael Yang's avatar
Michael Yang committed
36
37
38

.PHONY: apply-patches
.NOTPARALLEL:
39
apply-patches: $(PATCHED)
Michael Yang's avatar
Michael Yang committed
40

41
llama/patches/.%.patched: llama/patches/%.patch
Michael Yang's avatar
Michael Yang committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
	@if git -c user.name=nobody -c 'user.email=<>' -C $(WORKDIR) am -3 $(realpath $<); then touch $@; else git -C $(WORKDIR) am --abort; exit 1; fi

.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
63
	$(RM) llama/patches/.*.patched