|
16 | 16 | CCV := $(shell $(CC) --version | head -n 1)
|
17 | 17 | CXXV := $(shell $(CXX) --version | head -n 1)
|
18 | 18 |
|
19 |
| -GIT_INDEX = $(wildcard .git/index) |
20 |
| - |
21 | 19 | # Mac OS + Arm can report x86_64
|
22 | 20 | # ref: https://github.com/ggerganov/whisper.cpp/issues/66#issuecomment-1282546789
|
23 | 21 | ifeq ($(UNAME_S),Darwin)
|
@@ -183,77 +181,56 @@ llama.o: llama.cpp ggml.h ggml-cuda.h llama.h llama-util.h
|
183 | 181 | common.o: examples/common.cpp examples/common.h
|
184 | 182 | $(CXX) $(CXXFLAGS) -c $< -o $@
|
185 | 183 |
|
186 |
| -clean: |
187 |
| - rm -vf *.o main quantize quantize-stats perplexity embedding benchmark-matmult build-info.h |
| 184 | +libllama.so: llama.o ggml.o $(OBJS) |
| 185 | + $(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS) |
188 | 186 |
|
189 |
| -build-info.h: $(GIT_INDEX) |
190 |
| - scripts/build-info.sh > $@ |
| 187 | +clean: |
| 188 | + rm -vf *.o main quantize quantize-stats perplexity embedding benchmark-matmult save-load-state build-info.h |
191 | 189 |
|
192 | 190 | #
|
193 | 191 | # Examples
|
194 | 192 | #
|
195 | 193 |
|
196 |
| -TARGETS_CPP += main |
197 |
| -DEPS_main := examples/main/main.cpp ggml.o llama.o common.o |
198 |
| -EXEC_main :=\ |
199 |
| -@echo;\ |
200 |
| -echo "==== Run ./main -h for help. ====";\ |
201 |
| -echo |
202 |
| - |
203 |
| -TARGETS_CPP += quantize |
204 |
| -DEPS_quantize := examples/quantize/quantize.cpp ggml.o llama.o |
| 194 | +main: examples/main/main.cpp build-info.h ggml.o llama.o common.o $(OBJS) |
| 195 | + $(CXX) $(CXXFLAGS) $(filter-out *.h,$^) -o $@ $(LDFLAGS) |
| 196 | + @echo |
| 197 | + @echo '==== Run ./main -h for help. ====' |
| 198 | + @echo |
205 | 199 |
|
206 |
| -TARGETS_CPP += quantize-stats |
207 |
| -DEPS_quantize-stats := examples/quantize-stats/quantize-stats.cpp ggml.o llama.o |
| 200 | +quantize: examples/quantize/quantize.cpp build-info.h ggml.o llama.o $(OBJS) |
| 201 | + $(CXX) $(CXXFLAGS) $(filter-out *.h,$^) -o $@ $(LDFLAGS) |
208 | 202 |
|
209 |
| -TARGETS_CPP += perplexity |
210 |
| -DEPS_perplexity := examples/perplexity/perplexity.cpp ggml.o llama.o common.o |
| 203 | +quantize-stats: examples/quantize-stats/quantize-stats.cpp build-info.h ggml.o llama.o $(OBJS) |
| 204 | + $(CXX) $(CXXFLAGS) $(filter-out *.h,$^) -o $@ $(LDFLAGS) |
211 | 205 |
|
212 |
| -TARGETS_CPP += embedding |
213 |
| -DEPS_embedding := examples/embedding/embedding.cpp ggml.o llama.o common.o |
| 206 | +perplexity: examples/perplexity/perplexity.cpp build-info.h ggml.o llama.o common.o $(OBJS) |
| 207 | + $(CXX) $(CXXFLAGS) $(filter-out *.h,$^) -o $@ $(LDFLAGS) |
214 | 208 |
|
215 |
| -TARGETS_CPP += save-load-state |
216 |
| -DEPS_save-load-state := examples/save-load-state/save-load-state.cpp ggml.o llama.o common.o |
| 209 | +embedding: examples/embedding/embedding.cpp build-info.h ggml.o llama.o common.o $(OBJS) |
| 210 | + $(CXX) $(CXXFLAGS) $(filter-out *.h,$^) -o $@ $(LDFLAGS) |
217 | 211 |
|
218 |
| -TARGETS_CPP += vdot |
219 |
| -DEPS_vdot := pocs/vdot/vdot.cpp ggml.o |
220 |
| - |
221 |
| -# |
222 |
| -# libllama |
223 |
| -# |
| 212 | +save-load-state: examples/save-load-state/save-load-state.cpp build-info.h ggml.o llama.o common.o $(OBJS) |
| 213 | + $(CXX) $(CXXFLAGS) $(filter-out *.h,$^) -o $@ $(LDFLAGS) |
224 | 214 |
|
225 |
| -libllama.so: llama.o ggml.o $(OBJS) |
226 |
| - $(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS) |
| 215 | +build-info.h: $(wildcard .git/index) scripts/build-info.sh |
| 216 | + @scripts/build-info.sh > $@.tmp |
| 217 | + @if ! cmp -s $@.tmp $@; then \ |
| 218 | + mv $@.tmp $@; \ |
| 219 | + else \ |
| 220 | + rm $@.tmp; \ |
| 221 | + fi |
227 | 222 |
|
228 | 223 | #
|
229 | 224 | # Tests
|
230 | 225 | #
|
231 | 226 |
|
232 |
| -TARGETS_CPP += benchmark |
233 |
| -DEPS_benchmark := examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o $(OBJS) |
234 |
| -OUTP_benchmark := benchmark-matmult |
235 |
| -EXEC_benchmark := ./benchmark-matmult |
| 227 | +benchmark-matmult: examples/benchmark/benchmark-matmult.cpp build-info.h ggml.o $(OBJS) |
| 228 | + $(CXX) $(CXXFLAGS) $(filter-out *.h,$^) -o $@ $(LDFLAGS) |
| 229 | + ./$@ |
| 230 | + |
| 231 | +vdot: pocs/vdot/vdot.cpp ggml.o $(OBJS) |
| 232 | + $(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS) |
236 | 233 |
|
237 | 234 | .PHONY: tests
|
238 | 235 | tests:
|
239 | 236 | bash ./tests/run-tests.sh
|
240 |
| - |
241 |
| -# |
242 |
| -# Templates |
243 |
| -# |
244 |
| - |
245 |
| -# C++ template |
246 |
| -# To use this template: |
247 |
| -# 1. Add your target to the TARGETS variable: TARGETS_CPP += target |
248 |
| -# 2. Set target-specific dependencies: DEPS_target := source1 dependency1 dependency2 ... |
249 |
| -# 3. Optionally, set target-specific output: OUTP_target := output_name |
250 |
| -# 4. Optionally, set target-specific command: EXEC_target := command |
251 |
| -define template_cpp |
252 |
| -OUTP_$(1) ?= $(1) |
253 |
| -$(1): $$(DEPS_$(1)) $$(OBJS) build-info.h |
254 |
| - $$(CXX) $$(CXXFLAGS) $$(filter-out build-info.h,$$^) -o $$(OUTP_$(1)) $$(LDFLAGS) |
255 |
| - $$(if $$(value EXEC_$(1)),$$(EXEC_$(1))) |
256 |
| -endef |
257 |
| - |
258 |
| -# This iterates through TARGETS_CPP and call the template for each target |
259 |
| -$(foreach target,$(TARGETS_CPP),$(eval $(call template_cpp,$(target)))) |
0 commit comments