Makefile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # top level makefile for Ollama
  2. include make/common-defs.make
  3. # Determine which if any GPU runners we should build
  4. include make/cuda-v11-defs.make
  5. include make/cuda-v12-defs.make
  6. include make/rocm-defs.make
  7. ifeq ($(CUSTOM_CPU_FLAGS),)
  8. ifneq ($(OS),darwin)
  9. ifeq ($(ARCH),amd64)
  10. RUNNER_TARGETS=cpu
  11. endif
  12. endif
  13. # Without CUSTOM_CPU_FLAGS we default to build both v11 and v12 if present
  14. ifeq ($(OLLAMA_SKIP_CUDA_GENERATE),)
  15. ifneq ($(CUDA_11_COMPILER),)
  16. RUNNER_TARGETS += cuda_v11
  17. endif
  18. ifneq ($(CUDA_12_COMPILER),)
  19. RUNNER_TARGETS += cuda_v12
  20. endif
  21. endif
  22. else # CUSTOM_CPU_FLAGS is set, we'll build only the latest cuda version detected
  23. ifneq ($(CUDA_12_COMPILER),)
  24. RUNNER_TARGETS += cuda_v12
  25. else ifneq ($(CUDA_11_COMPILER),)
  26. RUNNER_TARGETS += cuda_v11
  27. endif
  28. endif
  29. ifeq ($(OLLAMA_SKIP_ROCM_GENERATE),)
  30. ifneq ($(HIP_COMPILER),)
  31. RUNNER_TARGETS += rocm
  32. endif
  33. endif
  34. all: runners exe
  35. dist: $(addprefix dist_, $(RUNNER_TARGETS)) dist_exe
  36. dist_%:
  37. @$(MAKE) --no-print-directory -f make/Makefile.$* dist
  38. runners: $(RUNNER_TARGETS)
  39. $(RUNNER_TARGETS):
  40. @$(MAKE) --no-print-directory -f make/Makefile.$@
  41. exe dist_exe:
  42. @$(MAKE) --no-print-directory -f make/Makefile.ollama $@
  43. help-sync apply-patches create-patches sync sync-clean:
  44. @$(MAKE) --no-print-directory -f make/Makefile.sync $@
  45. test integration lint:
  46. @$(MAKE) --no-print-directory -f make/Makefile.test $@
  47. clean:
  48. rm -rf $(BUILD_DIR) $(DIST_LIB_DIR) $(OLLAMA_EXE) $(DIST_OLLAMA_EXE)
  49. go clean -cache
  50. help:
  51. @echo "The following make targets will help you build Ollama"
  52. @echo ""
  53. @echo " make all # (default target) Build Ollama llm subprocess runners, and the primary ollama executable"
  54. @echo " make runners # Build Ollama llm subprocess runners; after you may use 'go build .' to build the primary ollama exectuable"
  55. @echo " make <runner> # Build specific runners. Enabled: '$(RUNNER_TARGETS)'"
  56. @echo " make dist # Build the runners and primary ollama executable for distribution"
  57. @echo " make help-sync # Help information on vendor update targets"
  58. @echo " make help-runners # Help information on runner targets"
  59. @echo ""
  60. @echo "The following make targets will help you test Ollama"
  61. @echo ""
  62. @echo " make test # Run unit tests"
  63. @echo " make integration # Run integration tests. You must 'make all' first"
  64. @echo " make lint # Run lint and style tests"
  65. @echo ""
  66. @echo "For more information see 'docs/development.md'"
  67. @echo ""
  68. help-runners:
  69. @echo "The following runners will be built based on discovered GPU libraries: '$(RUNNER_TARGETS)'"
  70. @echo ""
  71. @echo "GPU Runner CPU Flags: '$(GPU_RUNNER_CPU_FLAGS)' (Override with CUSTOM_CPU_FLAGS)"
  72. @echo ""
  73. @echo "# CUDA_PATH sets the location where CUDA toolkits are present"
  74. @echo "CUDA_PATH=$(CUDA_PATH)"
  75. @echo " CUDA_11_PATH=$(CUDA_11_PATH)"
  76. @echo " CUDA_11_COMPILER=$(CUDA_11_COMPILER)"
  77. @echo " CUDA_12_PATH=$(CUDA_12_PATH)"
  78. @echo " CUDA_12_COMPILER=$(CUDA_12_COMPILER)"
  79. @echo ""
  80. @echo "# HIP_PATH sets the location where the ROCm toolkit is present"
  81. @echo "HIP_PATH=$(HIP_PATH)"
  82. @echo " HIP_COMPILER=$(HIP_COMPILER)"
  83. .PHONY: all exe dist help help-sync help-runners test integration lint runners clean $(RUNNER_TARGETS)
  84. # Handy debugging for make variables
  85. print-%:
  86. @echo '$*=$($*)'