From 01d8e9c0a5aea138dd1d5999a5a808e09e8c9eb1 Mon Sep 17 00:00:00 2001
From: Scott Talbert <swt@techie.net>
Date: Thu, 1 Feb 2018 19:52:37 -0500
Subject: [PATCH] Copy shared libraries to build/lib dir instead of wx

This enables better support for building python2 and python3 versions in the
same directory.
---
 wscript | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/wscript b/wscript
index d051ebbc..b6604ada 100644
--- a/wscript
+++ b/wscript
@@ -586,12 +586,15 @@ def makeExtCopyRule(bld, name):
 
 # This is the task function to be called by the above rule.
 def copyFileToPkg(task):
+    from distutils.dir_util  import mkpath
     from distutils.file_util import copy_file
     from buildtools.config   import opj
     src = task.inputs[0].abspath()
     tgt = task.outputs[0].abspath()
     open(tgt, "wb").close() # essentially just a unix 'touch' command
-    tgt = opj(cfg.PKGDIR, os.path.basename(src))
+    tgtdir = opj(getBuildLibDir(), cfg.PKGDIR)
+    mkpath(tgtdir)
+    tgt = opj(tgtdir, os.path.basename(src))
     copy_file(src, tgt, verbose=1)
     if isWindows and task.env.msvc_relwithdebug:
         # also copy the .pdb file
@@ -601,6 +604,14 @@ def copyFileToPkg(task):
     return 0
 
 
+def getBuildLibDir():
+    import sysconfig
+    from buildtools.config import opj
+    f = "lib.{platform}-{version[0]}.{version[1]}"
+    libdir = f.format(platform=sysconfig.get_platform(),
+                      version=sys.version_info)
+    return opj('build', libdir)
+
 # Copy all the items in env with a matching postfix to a similarly
 # named item with the dest postfix.
 def _copyEnvGroup(env, srcPostfix, destPostfix):
-- 
2.14.3

