From c26010425f7ebd70517f3fc8f95885c014b71eb1 Mon Sep 17 00:00:00 2001
From: Ray Donnelly <mingw.android@gmail.com>
Date: Wed, 1 Mar 2017 17:16:37 +0000
Subject: [PATCH 1/5] conda: Unbundle libxgboost.{dll,dylib,so}

.. and put libxgboost.{dylib,so} into $PREFIX/lib/
.. and libxgboost.dll into $PREFIX/Library/mingw-w64/lib/
---
 python-package/setup.py           |    9 +++++++--
 python-package/xgboost/libpath.py |    4 ++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/python-package/setup.py b/python-package/setup.py
index e6c3386..716bee8 100644
--- a/python-package/setup.py
+++ b/python-package/setup.py
@@ -17,7 +17,12 @@ libpath = {'__file__': libpath_py}
 exec(compile(open(libpath_py, "rb").read(), libpath_py, 'exec'), libpath, libpath)
 
 LIB_PATH = [os.path.relpath(libfile, CURRENT_DIR) for libfile in libpath['find_lib_path']()]
-print("Install libxgboost from: %s" % LIB_PATH)
+if os.getenv('CONDA_BUILD'):
+    print("Conda-build detected, not installing (xgboost nor) libxgboost from: %s" % LIB_PATH)
+    data_files=('xgboost')
+else:
+    print("Install libxgboost from: %s" % LIB_PATH)
+    data_files=('xgboost', LIB_PATH)
 # Please use setup_pip.py for generating and deploying pip installation
 # detailed instruction in setup_pip.py
 setup(name='xgboost',
@@ -35,7 +40,7 @@ setup(name='xgboost',
       # this will use MANIFEST.in during install where we specify additional files,
       # this is the golden line
       include_package_data=True,
-      data_files=[('xgboost', LIB_PATH)],
+      data_files=[data_files],
       license='Apache-2.0',
       classifiers=['License :: OSI Approved :: Apache Software License'],
       url='https://github.com/dmlc/xgboost')
diff --git a/python-package/xgboost/libpath.py b/python-package/xgboost/libpath.py
index 6abb9ad..b6904e6 100644
--- a/python-package/xgboost/libpath.py
+++ b/python-package/xgboost/libpath.py
@@ -25,6 +25,10 @@ def find_lib_path():
                 os.path.join(curr_path, './lib/'),
                 os.path.join(sys.prefix, 'xgboost')]
     if sys.platform == 'win32':
+        dll_path = [os.path.join(sys.prefix, 'Library', 'mingw-w64', 'bin')]
+    else:
+        dll_path = [os.path.join(sys.prefix, 'lib')]
+    if sys.platform == 'win32':
         if platform.architecture()[0] == '64bit':
             dll_path.append(os.path.join(curr_path, '../../windows/x64/Release/'))
             # hack for pip installation when copy all parent source directory here
-- 
1.7.1

