@@ -4,8 +4,8 @@ include Makefile.tools.mk
44SHELL := /usr/bin/env bash
55
66# Defaults
7- TARGETOS ?= $(shell go env GOOS)
8- TARGETARCH ?= $(shell go env GOARCH)
7+ TARGETOS ?= $(shell command -v go >/dev/null 2>&1 && go env GOOS || uname -s | tr '[:upper:]' '[:lower:]' )
8+ TARGETARCH ?= $(shell command -v go >/dev/null 2>&1 && go env GOARCH || uname -m | sed 's/x86_64/amd64/; s/aarch64/arm64/; s/armv7l/arm/' )
99PROJECT_NAME ?= llm-d-inference-scheduler
1010SIDECAR_IMAGE_NAME ?= llm-d-routing-sidecar
1111VLLM_SIMULATOR_IMAGE_NAME ?= llm-d-inference-sim
@@ -69,31 +69,29 @@ PYTHON_VERSION := 3.12
6969PYTHON_CONFIG ?= $(shell command -v python$(PYTHON_VERSION ) -config || command -v python3-config)
7070ifeq ($(PYTHON_CONFIG ) ,)
7171 ifeq ($(TARGETOS),darwin)
72- # macOS: Find Homebrew's python-config script for the most reliable flags.
73- BREW_PREFIX := $(shell command -v brew >/dev/null 2>&1 && brew --prefix python@$(PYTHON_VERSION) 2>/dev/null)
74- PYTHON_CONFIG ?= $(BREW_PREFIX)/bin/python$(PYTHON_VERSION)-config
75- PYTHON_ERROR := "Could not execute 'python$(PYTHON_VERSION)-config'. Please ensure Python is installed correctly with: 'brew install python@$(PYTHON_VERSION)' or install python3.12 manually."
72+ # macOS: Find Homebrew's python-config script for the most reliable flags.
73+ BREW_PREFIX := $(shell command -v brew >/dev/null 2>&1 && brew --prefix python@$(PYTHON_VERSION ) 2>/dev/null)
74+ PYTHON_CONFIG ?= $(BREW_PREFIX ) /bin/python$(PYTHON_VERSION ) -config
75+ PYTHON_ERROR := "Could not execute 'python$(PYTHON_VERSION ) -config'. Please ensure Python is installed correctly with: 'brew install python@$(PYTHON_VERSION ) ' or install python3.12 manually."
7676 else ifeq ($(TARGETOS),linux)
77- # Linux: Use standard system tools to find flags.
78- PYTHON_ERROR := "Python $(PYTHON_VERSION) development headers not found. Please install with: 'sudo apt install python$(PYTHON_VERSION)-dev' or 'sudo dnf install python$(PYTHON_VERSION)-devel'"
77+ # Linux: Use standard system tools to find flags.
78+ PYTHON_ERROR := "Python $(PYTHON_VERSION ) development headers not found. Please install with: 'sudo apt install python$(PYTHON_VERSION ) -dev' or 'sudo dnf install python$(PYTHON_VERSION ) -devel'"
7979 else
80- PYTHON_ERROR := "you should set up PYTHON_CONFIG variable manually"
80+ PYTHON_ERROR := "you should set up PYTHON_CONFIG variable manually"
8181 endif
8282endif
8383
84- # Check if PYTHON_CONFIG is found before using it
85- ifneq ($(PYTHON_CONFIG ) ,)
86- ifneq ($(shell $(PYTHON_CONFIG ) --cflags 2>/dev/null) ,)
87- PYTHON_CFLAGS := $(shell $(PYTHON_CONFIG) --cflags)
88- # Use --ldflags --embed to get all necessary flags for linking
89- PYTHON_LDFLAGS := $(shell $(PYTHON_CONFIG) --ldflags --embed)
90- else
91- $(error ${PYTHON_ERROR})
84+ ifeq ($(PYTHON_CONFIG ) ,)
85+ $(error ${PYTHON_ERROR})
9286endif
93- else
94- $(error ${PYTHON_ERROR})
87+
88+ ifeq ($(shell $(PYTHON_CONFIG ) --cflags 2>/dev/null) ,)
89+ $(error Python configuration tool cannot provide cflags)
9590endif
9691
92+ PYTHON_CFLAGS := $(shell $(PYTHON_CONFIG ) --cflags)
93+ PYTHON_LDFLAGS := $(shell $(PYTHON_CONFIG ) --ldflags --embed)
94+
9795# CGO flags with all dependencies
9896CGO_CFLAGS := $(PYTHON_CFLAGS ) '-I$(shell pwd) /lib'
9997CGO_LDFLAGS := $(PYTHON_LDFLAGS ) $(PYTHON_LIBS ) '-L$(shell pwd) /lib' -ltokenizers -ldl -lm
@@ -156,12 +154,12 @@ test: test-unit test-e2e ## Run unit tests and e2e tests
156154test-unit : test-unit-epp test-unit-sidecar
157155
158156.PHONY : test-unit-%
159- test-unit-% : download-tokenizer install -dependencies # # Run unit tests
157+ test-unit-% : download-tokenizer check -dependencies # # Run unit tests
160158 @printf " \033[33;1m==== Running Unit Tests ====\033[0m\n"
161159 CGO_CFLAGS=${$* _CGO_CFLAGS} CGO_LDFLAGS=${$* _CGO_LDFLAGS} go test $($* _LDFLAGS) -v $$($($* _TEST_FILES) | tr '\n' ' ')
162160
163161.PHONY : test-integration
164- test-integration : download-tokenizer install -dependencies # # Run integration tests
162+ test-integration : download-tokenizer check -dependencies # # Run integration tests
165163 @printf " \033[33;1m==== Running Integration Tests ====\033[0m\n"
166164 go test -ldflags=" $( LDFLAGS) " -v -tags=integration_tests ./test/integration/
167165
@@ -187,9 +185,9 @@ lint: check-golangci-lint check-typos ## Run lint
187185build : build-epp build-sidecar # # Build the project
188186
189187.PHONY : build-%
190- build-% : check-go install-dependencies download-tokenizer # # Build the project
188+ build-% : check-go download-tokenizer # # Build the project
191189 @printf " \033[33;1m==== Building ====\033[0m\n"
192- go build $($* _LDFLAGS) -o bin/$($* _NAME) cmd/$($* _NAME) /main.go
190+ CGO_CFLAGS= ${ $* _CGO_CFLAGS} CGO_LDFLAGS= ${ $* _CGO_LDFLAGS} go build $($* _LDFLAGS) -o bin/$($* _NAME) cmd/$($* _NAME) /main.go
193191
194192# #@ Container Build/Push
195193
@@ -465,26 +463,55 @@ clean-env-dev-kubernetes: check-kubectl check-kustomize check-envsubst
465463
466464# #@ Dependencies
467465
466+ .PHONY : check-dependencies
467+ check-dependencies : # # Check if development dependencies are installed
468+ @if [ " $( TARGETOS) " = " linux" ]; then \
469+ if [ -x " $$ (command -v apt)" ]; then \
470+ if ! dpkg -s libzmq3-dev > /dev/null 2>&1 || ! dpkg -s g++ > /dev/null 2>&1 || ! dpkg -s python$( PYTHON_VERSION) -dev > /dev/null 2>&1 ; then \
471+ echo " ERROR: Missing dependencies. Please run 'sudo make install-dependencies'" ; \
472+ exit 1; \
473+ fi ; \
474+ elif [ -x " $$ (command -v dnf)" ]; then \
475+ if ! rpm -q zeromq-devel > /dev/null 2>&1 || ! rpm -q gcc-c++ > /dev/null 2>&1 || ! rpm -q python$( PYTHON_VERSION) -devel > /dev/null 2>&1 ; then \
476+ echo " ERROR: Missing dependencies. Please run 'sudo make install-dependencies'" ; \
477+ exit 1; \
478+ fi ; \
479+ else \
480+ echo " WARNING: Unsupported Linux package manager. Cannot verify dependencies." ; \
481+ fi ; \
482+ elif [ " $( TARGETOS) " = " darwin" ]; then \
483+ if [ -x " $$ (command -v brew)" ]; then \
484+ if ! brew list zeromq pkg-config > /dev/null 2>&1 ; then \
485+ echo " ERROR: Missing dependencies. Please run 'make install-dependencies'" ; \
486+ exit 1; \
487+ fi ; \
488+ else \
489+ echo " ERROR: Homebrew is not installed and is required. Install it from https://brew.sh/" ; \
490+ exit 1; \
491+ fi ; \
492+ fi
493+ @echo " ✅ All dependencies are installed."
494+
468495.PHONY : install-dependencies
469496install-dependencies : # # Install development dependencies based on OS/ARCH
470497 @echo " Checking and installing development dependencies..."
471498 @if [ " $( TARGETOS) " = " linux" ]; then \
472499 if [ -x " $$ (command -v apt)" ]; then \
473- if ! dpkg -s libzmq3-dev > /dev/null 2>&1 || ! dpkg -s g++ > /dev/null 2>&1 ; then \
500+ if ! dpkg -s libzmq3-dev > /dev/null 2>&1 || ! dpkg -s g++ > /dev/null 2>&1 || ! dpkg -s python $( PYTHON_VERSION ) -dev > /dev/null 2>&1 ; then \
474501 echo " Installing dependencies with apt..." ; \
475- apt-get update && apt-get install -y libzmq3-dev g++; \
502+ apt-get update && apt-get install -y libzmq3-dev g++ python $( PYTHON_VERSION ) -dev ; \
476503 else \
477- echo " ✅ ZMQ and g++ are already installed." ; \
504+ echo " ✅ ZMQ, g++, and Python dev headers are already installed." ; \
478505 fi ; \
479506 elif [ -x " $$ (command -v dnf)" ]; then \
480- if ! dnf -q list installed zeromq-devel > /dev/null 2>&1 || ! dnf -q list installed gcc-c++ > /dev/null 2>&1 ; then \
507+ if ! rpm -q zeromq-devel > /dev/null 2>&1 || ! rpm -q gcc-c++ > /dev/null 2>&1 || ! rpm -q python $( PYTHON_VERSION ) -devel > /dev/null 2>&1 ; then \
481508 echo " Installing dependencies with dnf..." ; \
482- dnf install -y zeromq-devel gcc-c++; \
509+ dnf install -y zeromq-devel gcc-c++ python $( PYTHON_VERSION ) -devel ; \
483510 else \
484- echo " ✅ ZMQ and gcc-c++ are already installed." ; \
511+ echo " ✅ ZMQ, gcc-c++, and Python dev headers are already installed." ; \
485512 fi ; \
486513 else \
487- echo " Unsupported Linux package manager. Install libzmq and g++/gcc-c++ manually." ; \
514+ echo " ERROR: Unsupported Linux package manager. Install libzmq, g++/gcc-c++, and python-devel manually." ; \
488515 exit 1; \
489516 fi ; \
490517 elif [ " $( TARGETOS) " = " darwin" ]; then \
@@ -496,10 +523,10 @@ install-dependencies: ## Install development dependencies based on OS/ARCH
496523 echo " ✅ ZeroMQ and pkgconf are already installed." ; \
497524 fi ; \
498525 else \
499- echo " Homebrew is not installed and is required to install zeromq. Install it from https://brew.sh/" ; \
526+ echo " ERROR: Homebrew is not installed and is required to install zeromq. Install it from https://brew.sh/" ; \
500527 exit 1; \
501528 fi ; \
502529 else \
503- echo " Unsupported OS: $( TARGETOS) . Install development dependencies manually." ; \
530+ echo " ERROR: Unsupported OS: $( TARGETOS) . Install development dependencies manually." ; \
504531 exit 1; \
505532 fi
0 commit comments