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