Skip to content

Commit 349f9d7

Browse files
hyeongyun0916bongwoobakhhk7734
authored
Update Makefile to support non-Homebrew Python paths (#489)
Signed-off-by: HyunKyun Moon <mhg5303@gmail.com> Co-authored-by: bongwoobak <bongwoobak@gmail.com> Co-authored-by: Hyeonki Hong <hyeonki.hong@moreh.io>
1 parent 2bc23f8 commit 349f9d7

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

Makefile

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,27 @@ LDFLAGS ?= -extldflags '-L$(shell pwd)/lib'
6666
PYTHON_VERSION := 3.12
6767

6868
# Unified Python configuration detection. This block runs once.
69-
ifeq ($(TARGETOS),darwin)
70-
# macOS: Find Homebrew's python-config script for the most reliable flags.
71-
BREW_PREFIX := $(shell command -v brew >/dev/null 2>&1 && brew --prefix python@$(PYTHON_VERSION) 2>/dev/null)
72-
PYTHON_CONFIG := $(BREW_PREFIX)/bin/python$(PYTHON_VERSION)-config
73-
PYTHON_ERROR := "Could not execute 'python$(PYTHON_VERSION)-config' from Homebrew. Please ensure Python is installed correctly with: 'brew install python@$(PYTHON_VERSION)'"
74-
else ifeq ($(TARGETOS),linux)
75-
# Linux: Use standard system tools to find flags.
76-
PYTHON_CONFIG := $(shell command -v python$(PYTHON_VERSION)-config || command -v python3-config)
77-
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'"
78-
else
79-
$(error "Unsupported OS: $(TARGETOS)")
69+
PYTHON_CONFIG ?= $(shell command -v python$(PYTHON_VERSION)-config || command -v python3-config)
70+
ifeq ($(PYTHON_CONFIG),)
71+
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."
76+
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'"
79+
else
80+
PYTHON_ERROR := "you should set up PYTHON_CONFIG variable manually"
81+
endif
8082
endif
8183

8284
ifneq ($(shell $(PYTHON_CONFIG) --cflags 2>/dev/null),)
83-
PYTHON_CFLAGS := $(shell $(PYTHON_CONFIG) --cflags)
84-
# Use --ldflags --embed to get all necessary flags for linking
85-
PYTHON_LDFLAGS := $(shell $(PYTHON_CONFIG) --ldflags --embed)
85+
PYTHON_CFLAGS := $(shell $(PYTHON_CONFIG) --cflags)
86+
# Use --ldflags --embed to get all necessary flags for linking
87+
PYTHON_LDFLAGS := $(shell $(PYTHON_CONFIG) --ldflags --embed)
8688
else
87-
$(error ${PYTHON_ERROR})
89+
$(error ${PYTHON_ERROR})
8890
endif
8991

9092
# CGO flags with all dependencies

0 commit comments

Comments
 (0)