Commits

ariovistus committed 145dc4f

pydexe support static built python

cuz you can't link against *.so files that ain't there
(or that are there, but with python pretending they ain't
because you configured it weirdly, <i> Ubuntu </i>)

Don't know if extensions need to be built differently in
static built python or if they even can.

Comments (0)

Files changed (3)

 import os, os.path, sys
 
 from distutils import ccompiler as cc
+from distutils.sysconfig import get_config_var 
 from distutils.ccompiler import gen_lib_options
 from distutils.errors import (
     DistutilsExecError, DistutilsFileError, DistutilsPlatformError,
         return stdout.strip()
     else:
         return path_
+
+def is_posix_static_python():
+    if (sys.platform == "win32" or 
+       sys.platform[:6] == "cygwin"):
+        return False
+    else:
+        return not get_config_var('Py_ENABLE_SHARED')
+def posix_static_python_opts():
+    ls = [l for l in get_config_var('LIBS').split(' ') if l]
+    ls.extend([l for l in get_config_var('MODLIBS').split(' ') if l])
+    return ls
+
+def posix_static_python_lib():
+    return os.path.join(get_config_var('LIBPL'),get_config_var('LIBRARY'))
+
 _isPlatWin = sys.platform.lower().startswith('win') or _isPlatCygwin
 
 _infraDir = os.path.join(os.path.dirname(__file__), 'infrastructure')
         # _outputOpts
         self._outputOpts = ['-of%s']
         # _linkOpts
-        self._exeLinkOpts = []
+        if is_posix_static_python():
+            self._exeLinkOpts = ['-L'+l for l in posix_static_python_opts()]
+            self._exeLinkOpts.append(posix_static_python_lib())
+        else:
+            self._exeLinkOpts = []
         self._linkOpts = []
         # _includeOpts
         self._includeOpts = ['-I%s']
         self._compileOpts = ['-fPIC', '-c']
         # _outputOpts
         self._outputOpts = ['-o', '%s']
-        self._exeLinkOpts = []
+        if is_posix_static_python():
+            self._exeLinkOpts = posix_static_python_opts()
+            self._exeLinkOpts.append(posix_static_python_lib())
+        else:
+            self._exeLinkOpts = []
         # _linkOpts
         self._linkOpts = ['-fPIC', '-nostartfiles', '-shared']
         # _includeOpts
         # _outputOpts
         self._outputOpts = ['-of', '%s']
         self._linkOutputOpts = ['-o', '%s']
-        self._exeLinkOpts = []
+        # bloody ubuntu has to make things difficult
+        if is_posix_static_python():
+            self._exeLinkOpts = ['-L'+l for l in posix_static_python_opts()]
+            self._exeLinkOpts.append(posix_static_python_lib())
+        else:
+            self._exeLinkOpts = []
         # _linkOpts
         self._SharedLinkOpts = ['-nostartfiles', '-shared','-Wl,--no-as-needed','-lphobos-ldc','-ldruntime-ldc', '-lrt','-lpthread','-ldl','-lm']
-        self._ExeLinkOpts = []
         # _includeOpts
         self._includeOpts = ['-I', '%s']
         # _versionOpt
             self._linkOpts = self._SharedLinkOpts
         elif target_desc == cc.CCompiler.EXECUTABLE:
             self._binpath = self.executables['linker_exe'][0]
-            self._linkOpts = self._ExeLinkOpts
+            self._linkOpts = self._exeLinkOpts
             self._linkOutputOpts = self._outputOpts
         else:
             raise LinkError('This CCompiler implementation does not know'

examples/pyd_unittests/setup.py

     ext_modules=[
         Extension(ext(e), [ext(e)+".d"],
             d_unittest=True,
+            build_deimos=True,
             string_imports = string_imports.get(e, [])
             )
             for e in exts 
 use_parts = set()
 exe_ext = get_config_var("EXE")
 verz_maj = platform.python_version_tuple()[0]
-print "%r" % (verz_maj,), verz_maj == 2
+print ("%r" % (verz_maj,), verz_maj == 2)
 if verz_maj == "3":
     pass
 elif verz_maj == "2":
     old_path = os.getenv("PYTHONPATH")
     if not os.path.exists(build):
         subprocess.check_call([sys.executable, "setup.py", "build"]);
-    print "using build: %r" % build
+    print ("using build: %r" % build)
     os.putenv("PYTHONPATH", build)
 
 def check_exe(cmd):