common-defs.make 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. SRC_DIR := $(dir $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST))))))
  22. BUILD_DIR = $(SRC_DIR)build/$(OS)-$(ARCH)
  23. DIST_BASE = $(abspath $(SRC_DIR)/../dist/$(OS)-$(ARCH))
  24. DIST_LIB_DIR = $(DIST_BASE)/lib/ollama
  25. RUNNERS_DIST_DIR = $(DIST_LIB_DIR)/runners
  26. RUNNERS_PAYLOAD_DIR = $(abspath $(SRC_DIR)/../build/$(OS)/$(ARCH))
  27. RUNNERS_BUILD_DIR = $(BUILD_DIR)/runners
  28. DEFAULT_RUNNER := $(if $(and $(filter darwin,$(OS)),$(filter arm64,$(ARCH))),metal,cpu)
  29. GZIP:=$(shell command -v pigz 2>/dev/null || echo "gzip")
  30. ifneq ($(OS),windows)
  31. CCACHE:=$(shell command -v ccache 2>/dev/null || echo "")
  32. endif
  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 space separated to tune GPU runner CPU vector flags
  42. ifeq ($(ARCH),amd64)
  43. GPU_RUNNER_CPU_FLAGS ?= avx
  44. endif
  45. ifeq ($(OS),windows)
  46. CP := cp
  47. SRC_DIR := $(shell cygpath -m -s "$(SRC_DIR)")
  48. OBJ_EXT := obj
  49. SHARED_EXT := dll
  50. EXE_EXT := .exe
  51. SHARED_PREFIX :=
  52. CPU_FLAG_PREFIX := /arch:
  53. ifneq ($(HIP_PATH),)
  54. # If HIP_PATH has spaces, hipcc trips over them when subprocessing
  55. HIP_PATH := $(shell cygpath -m -s "$(patsubst %\,%,$(HIP_PATH))")
  56. export HIP_PATH
  57. endif
  58. else ifeq ($(OS),linux)
  59. CP := cp -af
  60. OBJ_EXT := o
  61. SHARED_EXT := so
  62. SHARED_PREFIX := lib
  63. CPU_FLAG_PREFIX := -m
  64. HIP_PATH?=/opt/rocm
  65. else
  66. OBJ_EXT := o
  67. SHARED_EXT := so
  68. CPU_FLAG_PREFIX := -m
  69. CP := cp -af
  70. endif
  71. COMMON_SRCS := \
  72. $(wildcard *.c) \
  73. $(wildcard *.cpp)
  74. COMMON_HDRS := \
  75. $(wildcard *.h) \
  76. $(wildcard *.hpp)