@@ -53,6 +53,23 @@ SRC = $(shell find . -type f -name '*.go')
5353help : # # Print help
5454 @awk ' BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST )
5555
56+ PYTHON_INCLUDE := $(shell python3 -c "import sysconfig; print(sysconfig.get_path('include') )")
57+ CGO_CFLAGS := $(shell python3-config --cflags --embed)
58+ CGO_LDFLAGS := $(shell python3-config --ldflags --embed)
59+
60+ export PKG_CONFIG_PATH =/usr/lib/pkgconfig
61+
62+ GOMODCACHE := $(shell go env GOMODCACHE)
63+ KV_CACHE_MGR_VERSION := $(shell go list -m -f '{{.Version}}' github.com/llm-d/llm-d-kv-cache-manager)
64+ KV_CACHE_MGR_PATH := $(GOMODCACHE ) /github.com/llm-d/llm-d-kv-cache-manager@$(KV_CACHE_MGR_VERSION ) /pkg/preprocessing/chat_completions
65+ export PYTHONPATH := $(KV_CACHE_MGR_PATH ) :$(PYTHONPATH )
66+
67+ # Export them for all targets (optional)
68+ export CGO_ENABLED =1
69+ export CGO_CFLAGS
70+ export CGO_LDFLAGS
71+ export CPATH := $(PYTHON_INCLUDE ) :$(CPATH )
72+
5673GO_LDFLAGS := -extldflags '-L$(shell pwd) /lib $(LDFLAGS ) '
5774CGO_ENABLED =1
5875TOKENIZER_LIB = lib/libtokenizers.a
@@ -82,7 +99,7 @@ format: ## Format Go source files
8299 @gofmt -l -w $(SRC )
83100
84101.PHONY : test
85- test : $(GINKGO ) download-tokenizer download-zmq # # Run tests
102+ test : $(GINKGO ) install-dependencies # # Run tests
86103 @printf " \033[33;1m==== Running tests ====\033[0m\n"
87104ifdef GINKGO_FOCUS
88105 CGO_ENABLED=1 ginkgo -ldflags="$(GO_LDFLAGS)" -v -r -- -ginkgo.v -ginkgo.focus="$(GINKGO_FOCUS)"
@@ -103,7 +120,7 @@ lint: $(GOLANGCI_LINT) ## Run lint
103120# #@ Build
104121
105122.PHONY : build
106- build : check-go download-tokenizer download-zmq
123+ build : check-go install-dependencies
107124 @printf " \033[33;1m==== Building ====\033[0m\n"
108125 go build -ldflags=" $( GO_LDFLAGS) " -o $(LOCALBIN ) /$(PROJECT_NAME ) cmd/$(PROJECT_NAME ) /main.go
109126
@@ -217,32 +234,41 @@ install-hooks: ## Install git hooks
217234
218235# #@ ZMQ Setup
219236
220- .PHONY : download-zmq
221- download-zmq : # # Install ZMQ dependencies based on OS/ARCH
222- @echo " ⏳ Checking if ZMQ is already installed..."
223- @if pkg-config --exists libzmq; then \
224- echo " ✅ ZMQ is already installed." ; \
225- else \
226- echo " ⏳ Installing ZMQ dependencies..." ; \
227- if [ " $( TARGETOS) " = " linux" ]; then \
228- if command -v apt > /dev/null 2>&1 ; then \
229- sudo apt update && sudo apt install -y libzmq3-dev; \
230- elif command -v dnf > /dev/null 2>&1 ; then \
231- sudo dnf install -y zeromq-devel; \
237+ .PHONY : install-dependencies
238+ install-dependencies : download-tokenizer # # Install development dependencies based on OS/ARCH
239+ @echo " Checking and installing development dependencies..."
240+ @if [ " $( TARGETOS) " = " linux" ]; then \
241+ if [ -x " $$ (command -v apt)" ]; then \
242+ if ! dpkg -s libzmq3-dev > /dev/null 2>&1 || ! dpkg -s g++ > /dev/null 2>&1 ; then \
243+ echo " Installing dependencies with apt..." ; \
244+ sudo apt-get update && apt-get install -y libzmq3-dev g++; \
232245 else \
233- echo -e " ⚠️ Unsupported Linux package manager. Follow installation guides: https://github.com/zeromq/libzmq#installation-of-binary-packages-\n" ; \
234- exit 1; \
246+ echo " ✅ ZMQ and g++ are already installed." ; \
235247 fi ; \
236- elif [ " $( TARGETOS) " = " darwin" ]; then \
237- if command -v brew > /dev/null 2>&1 ; then \
238- brew install zeromq; \
248+ elif [ -x " $$ (command -v dnf)" ]; then \
249+ if ! dnf -q list installed zeromq-devel > /dev/null 2>&1 || ! dnf -q list installed gcc-c++ > /dev/null 2>&1 ; then \
250+ echo " Installing dependencies with dnf..." ; \
251+ sudo dnf install -y zeromq-devel gcc-c++; \
239252 else \
240- echo " ⚠️ Homebrew is not installed and is required to install zeromq. Install it from https://brew.sh/" ; \
241- exit 1; \
253+ echo " ✅ ZMQ and gcc-c++ are already installed." ; \
242254 fi ; \
243255 else \
244- echo " ⚠️ Unsupported OS: $( TARGETOS ) . Install libzmq manually - see https://zeromq.org/download/ " ; \
256+ echo " Unsupported Linux package manager . Install libzmq and g++/gcc-c++ manually. " ; \
245257 exit 1; \
246258 fi ; \
247- echo " ✅ ZMQ dependencies installed." ; \
259+ elif [ " $( TARGETOS) " = " darwin" ]; then \
260+ if [ -x " $$ (command -v brew)" ]; then \
261+ if ! brew list zeromq pkg-config > /dev/null 2>&1 ; then \
262+ echo " Installing dependencies with brew..." ; \
263+ brew install zeromq pkg-config; \
264+ else \
265+ echo " ✅ ZeroMQ and pkgconf are already installed." ; \
266+ fi ; \
267+ else \
268+ echo " Homebrew is not installed and is required to install zeromq. Install it from https://brew.sh/" ; \
269+ exit 1; \
270+ fi ; \
271+ else \
272+ echo " Unsupported OS: $( TARGETOS) . Install development dependencies manually." ; \
273+ exit 1; \
248274 fi
0 commit comments