common-defs.make 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_CFLAGS_ALLOW = -mfma|-mf16c
  18. export CGO_CXXFLAGS_ALLOW = -mfma|-mf16c
  19. export HIP_PLATFORM = amd
  20. export CGO_ENABLED=1
  21. BUILD_DIR = ./llama/build/$(OS)-$(ARCH)
  22. DIST_BASE = ./dist/$(OS)-$(ARCH)
  23. ifeq ($(OS),windows)
  24. # Absolute paths with cygpath to convert to 8.3 without spaces
  25. PWD="$(shell pwd)"
  26. DIST_OLLAMA_EXE=$(DIST_BASE)/ollama$(EXE_EXT)
  27. else
  28. CCACHE:=$(shell command -v ccache 2>/dev/null || echo "")
  29. DIST_OLLAMA_EXE=$(DIST_BASE)/bin/ollama$(EXE_EXT)
  30. endif
  31. DIST_LIB_DIR = $(DIST_BASE)/lib/ollama
  32. RUNNERS_DIST_DIR = $(DIST_LIB_DIR)/runners
  33. RUNNERS_BUILD_DIR = $(BUILD_DIR)/runners
  34. VERSION?=$(shell git describe --tags --first-parent --abbrev=7 --long --dirty --always | sed -e "s/^v//g")
  35. # Conditionally enable ccache for cgo builds too
  36. ifneq ($(CCACHE),)
  37. CC?=$(CCACHE) gcc
  38. CXX?=$(CCACHE) g++
  39. export CC
  40. export CXX
  41. endif
  42. # Override in environment to tune CPU vector flags
  43. ifeq ($(ARCH),amd64)
  44. ifeq ($(origin CUSTOM_CPU_FLAGS),undefined)
  45. GPU_RUNNER_CPU_FLAGS=avx
  46. GPU_RUNNER_EXTRA_VARIANT=_avx
  47. else
  48. GPU_RUNNER_CPU_FLAGS=$(subst $(comma),$(space),$(CUSTOM_CPU_FLAGS))
  49. endif
  50. endif
  51. ifeq ($(OS),windows)
  52. CP := cp
  53. OBJ_EXT := obj
  54. SHARED_EXT := dll
  55. EXE_EXT := .exe
  56. SHARED_PREFIX :=
  57. CPU_FLAG_PREFIX := /arch:
  58. ifneq ($(HIP_PATH),)
  59. # If HIP_PATH has spaces, hipcc trips over them when subprocessing
  60. HIP_PATH := $(shell cygpath -m -s "$(patsubst %\,%,$(HIP_PATH))")
  61. export HIP_PATH
  62. endif
  63. else ifeq ($(OS),linux)
  64. CP := cp -df
  65. OBJ_EXT := o
  66. SHARED_EXT := so
  67. SHARED_PREFIX := lib
  68. CPU_FLAG_PREFIX := -m
  69. else
  70. OBJ_EXT := o
  71. SHARED_EXT := so
  72. CPU_FLAG_PREFIX := -m
  73. CP := cp -df
  74. endif
  75. COMMON_SRCS := \
  76. $(wildcard ./llama/*.c) \
  77. $(wildcard ./llama/*.cpp)
  78. COMMON_HDRS := \
  79. $(wildcard ./llama/*.h) \
  80. $(wildcard ./llama/*.hpp)
  81. OLLAMA_EXE=./ollama$(EXE_EXT)