common-defs.make 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Common definitions for the various Makefiles
  2. # No rules are defined here so this is safe to include at the beginning of other makefiles
  3. OS := $(shell uname -s)
  4. ARCH ?= $(subst aarch64,arm64,$(subst x86_64,amd64,$(shell uname -m)))
  5. ifneq (,$(findstring MINGW,$(OS))$(findstring MSYS,$(OS)))
  6. OS := windows
  7. ARCH := $(shell systeminfo 2>/dev/null | grep "System Type" | grep ARM64 > /dev/null && echo "arm64" || echo "amd64" )
  8. else ifeq ($(OS),Linux)
  9. OS := linux
  10. else ifeq ($(OS),Darwin)
  11. OS := darwin
  12. endif
  13. comma:= ,
  14. empty:=
  15. space:= $(empty) $(empty)
  16. uc = $(subst a,A,$(subst b,B,$(subst c,C,$(subst d,D,$(subst e,E,$(subst f,F,$(subst g,G,$(subst h,H,$(subst i,I,$(subst j,J,$(subst k,K,$(subst l,L,$(subst m,M,$(subst n,N,$(subst o,O,$(subst p,P,$(subst q,Q,$(subst r,R,$(subst s,S,$(subst t,T,$(subst u,U,$(subst v,V,$(subst w,W,$(subst x,X,$(subst y,Y,$(subst z,Z,$1))))))))))))))))))))))))))
  17. export CGO_CPPFLAGS_ALLOW = -mfma|-mf16c
  18. export HIP_PLATFORM = amd
  19. export CGO_ENABLED=1
  20. BUILD_DIR = ./llama/build/$(OS)-$(ARCH)
  21. DIST_BASE = ./dist/$(OS)-$(ARCH)
  22. ifeq ($(OS),windows)
  23. # Absolute paths with cygpath to convert to 8.3 without spaces
  24. PWD="$(shell pwd)"
  25. DIST_OLLAMA_EXE=$(DIST_BASE)/ollama$(EXE_EXT)
  26. else
  27. CCACHE:=$(shell command -v ccache 2>/dev/null || echo "")
  28. DIST_OLLAMA_EXE=$(DIST_BASE)/bin/ollama$(EXE_EXT)
  29. endif
  30. DIST_LIB_DIR = $(DIST_BASE)/lib/ollama
  31. RUNNERS_DIST_DIR = $(DIST_LIB_DIR)/runners
  32. RUNNERS_BUILD_DIR = $(BUILD_DIR)/runners
  33. VERSION?=$(shell git describe --tags --first-parent --abbrev=7 --long --dirty --always | sed -e "s/^v//g")
  34. # Conditionally enable ccache for cgo builds too
  35. ifneq ($(CCACHE),)
  36. CC?=$(CCACHE) gcc
  37. CXX?=$(CCACHE) g++
  38. export CC
  39. export CXX
  40. endif
  41. # Override in environment to tune CPU vector flags
  42. ifeq ($(ARCH),amd64)
  43. ifeq ($(origin CUSTOM_CPU_FLAGS),undefined)
  44. GPU_RUNNER_CPU_FLAGS=avx
  45. GPU_RUNNER_EXTRA_VARIANT=_avx
  46. else
  47. GPU_RUNNER_CPU_FLAGS=$(subst $(comma),$(space),$(CUSTOM_CPU_FLAGS))
  48. endif
  49. endif
  50. ifeq ($(OS),windows)
  51. CP := cp
  52. OBJ_EXT := obj
  53. SHARED_EXT := dll
  54. EXE_EXT := .exe
  55. SHARED_PREFIX :=
  56. CPU_FLAG_PREFIX := /arch:
  57. ifneq ($(HIP_PATH),)
  58. # If HIP_PATH has spaces, hipcc trips over them when subprocessing
  59. HIP_PATH := $(shell cygpath -m -s "$(patsubst %\,%,$(HIP_PATH))")
  60. export HIP_PATH
  61. endif
  62. else ifeq ($(OS),linux)
  63. CP := cp -df
  64. OBJ_EXT := o
  65. SHARED_EXT := so
  66. SHARED_PREFIX := lib
  67. CPU_FLAG_PREFIX := -m
  68. else
  69. OBJ_EXT := o
  70. SHARED_EXT := so
  71. CPU_FLAG_PREFIX := -m
  72. CP := cp -df
  73. endif
  74. COMMON_SRCS := \
  75. $(wildcard ./llama/*.c) \
  76. $(wildcard ./llama/*.cpp)
  77. COMMON_HDRS := \
  78. $(wildcard ./llama/*.h) \
  79. $(wildcard ./llama/*.hpp)
  80. OLLAMA_EXE=./ollama$(EXE_EXT)
  81. CPPFLAGS += \
  82. -I../ml/backend/ggml/ggml \
  83. -I../ml/backend/ggml/ggml/include \
  84. -I../ml/backend/ggml/ggml/ggml-cpu \
  85. -I../ml/backend/ggml/ggml/ggml-cpu/amx \