From: Kentaro Hayashi <kenhys@xdump.org>
Date: Sat, 1 Aug 2026 21:47:10 +0900
Subject: Support to build python module with pybuild

Description: Support to build python module with pybuild
Forwarded: not-needed
Last-Update: 2026-08-01
---
 python/setup.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/python/setup.py b/python/setup.py
index 60e0811..078a258 100755
--- a/python/setup.py
+++ b/python/setup.py
@@ -69,6 +69,18 @@ def get_protobuf_includes():
 
 
 def get_cflags_and_libs(root):
+  if os.environ.get('USE_SHARED_SENTENCEPIECE') == '1':
+    include_dirs = os.environ['SENTENCEPIECE_INCLUDE_DIR']
+    library_dir = os.environ['SENTENCEPIECE_LIBRARY_DIR']
+    cflags = ['-std=c++17']
+    for include_dir in include_dirs.split(os.pathsep):
+      if include_dir:
+        cflags.append('-I' + os.path.normpath(include_dir))
+    return cflags, [
+      '-L' + os.path.normpath(library_dir),
+      '-lsentencepiece',
+      '-lsentencepiece_train',
+    ]
   cflags = [
       '-std=c++17',
       '-I' + os.path.normpath(os.path.join(root, 'include')),
