-
-
Notifications
You must be signed in to change notification settings - Fork 649
Expand file tree
/
Copy pathMakefile_v3
More file actions
96 lines (80 loc) · 2.53 KB
/
Copy pathMakefile_v3
File metadata and controls
96 lines (80 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Makefile for TinyObjLoader v3 Python bindings
# Quick build without needing setuptools or Python headers
CXX ?= g++
PYTHON ?= python3
# Detect Python version
PYTHON_VERSION := $(shell $(PYTHON) -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
PYTHON_MIN_VERSION := 3.10
# Compiler flags
CXXFLAGS := -std=c++14 -fPIC -Wall -Wextra -fno-exceptions -fno-rtti -fvisibility=hidden
CXXFLAGS += -DPy_LIMITED_API=0x030A0000
CXXFLAGS += -I.. -I.
# Platform detection
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
# macOS
LDFLAGS := -bundle -undefined dynamic_lookup
SUFFIX := .so
CXXFLAGS += -mmacosx-version-min=10.13
else ifeq ($(UNAME_S),Linux)
# Linux
LDFLAGS := -shared -Wl,--exclude-libs,ALL
SUFFIX := .so
else
# Windows (MinGW or similar)
LDFLAGS := -shared
SUFFIX := .pyd
endif
# Output
TARGET := tinyobjloader_v3$(SUFFIX)
# Sources
SRCS := tinyobj_v3_bindings.cc tinyobj_v3_loader.cc
OBJS := $(SRCS:.cc=.o)
.PHONY: all clean test install check_python
all: check_python $(TARGET)
check_python:
@echo "Checking Python version..."
@if [ "$$(printf '%s\n' "$(PYTHON_VERSION)" "$(PYTHON_MIN_VERSION)" | sort -V | head -n1)" != "$(PYTHON_MIN_VERSION)" ]; then \
echo "ERROR: Python $(PYTHON_MIN_VERSION)+ required, found $(PYTHON_VERSION)"; \
exit 1; \
fi
@echo "✓ Python $(PYTHON_VERSION) >= $(PYTHON_MIN_VERSION)"
$(TARGET): $(OBJS)
@echo "Linking $@..."
$(CXX) $(LDFLAGS) -o $@ $(OBJS)
@echo "✓ Built $@"
%.o: %.cc
@echo "Compiling $<..."
$(CXX) $(CXXFLAGS) -c $< -o $@
clean:
@echo "Cleaning..."
rm -f $(OBJS) $(TARGET)
rm -rf __pycache__ *.pyc
@echo "✓ Clean"
test: $(TARGET)
@echo "Running tests..."
PYTHONPATH=. $(PYTHON) sample_v3.py
install: $(TARGET)
@echo "Installing to Python site-packages..."
@SITE_PACKAGES=$$($(PYTHON) -c "import sysconfig; print(sysconfig.get_path('platlib'))"); \
echo "Install path: $$SITE_PACKAGES"; \
cp $(TARGET) $$SITE_PACKAGES/
@echo "✓ Installed"
help:
@echo "TinyObjLoader v3 Python Bindings Makefile"
@echo ""
@echo "Targets:"
@echo " all - Build the extension module (default)"
@echo " clean - Remove built files"
@echo " test - Build and run tests"
@echo " install - Install to Python site-packages"
@echo " help - Show this help"
@echo ""
@echo "Variables:"
@echo " CXX - C++ compiler (default: g++)"
@echo " PYTHON - Python interpreter (default: python3)"
@echo ""
@echo "Example:"
@echo " make CXX=clang++ PYTHON=python3.11"
@echo " make test"
@echo " make install"