setup.py.in 2.2 KB
Newer Older
1
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved
Z
zhangjinchao01 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file is used to build paddle python binding package.
# It will be invoked by Makefile that generated by COMAKE
L
liaogang 已提交
17

Z
zhangjinchao01 已提交
18
from setuptools import setup, Extension
L
liaogang 已提交
19

Z
zhangjinchao01 已提交
20 21
import numpy as np
import api.paddle_ld_flags
L
liaogang 已提交
22
import platform
G
gangliao 已提交
23
import os
L
liaogang 已提交
24 25 26 27 28 29 30

system = platform.system().lower()

is_osx = (system == 'darwin')
is_win = (system == 'windows')
is_lin = (system == 'linux')

Z
zhangjinchao01 已提交
31 32 33 34

# The extra links will passed from COMAKE
#   because generate paddle LDFLAGS is too complicated to do in setup.py
#   it just read COMAKE generated LDFLAGS.
L
liaogang 已提交
35
extra_comps = []
Z
zhangjinchao01 已提交
36
extra_links = []
Y
Yu Yang 已提交
37
obj = api.paddle_ld_flags.PaddleLDFlag()
L
liaogang 已提交
38
extra_comps = obj.c_flag()
Y
Yu Yang 已提交
39
ldflags = obj.ldflag_str()
Z
zhangjinchao01 已提交
40 41 42 43 44 45 46 47 48 49
if ldflags is not None:
  extra_links.extend(ldflags.split(" "))

try:
  with open('.py_paddle_extra_link_flags', 'r') as f:
    for line in f:
      extra_links += line.split()
except:
  pass

L
liaogang 已提交
50 51 52
if is_lin == True:
    extra_links = ["-Xlinker", '-start-group'] + extra_links + ["-Xlinker", "-end-group"]
elif is_osx == True:
G
gangliao 已提交
53
    os.environ["ARCHFLAGS"] = "-arch x86_64"
L
liaogang 已提交
54 55 56 57
    extra_links = ["-Wl,-all_load"] + extra_links

include_dirs = [np.get_include(), "../"]    # include numpy and paddle.

Z
zhangjinchao01 已提交
58
setup(name="py_paddle",
L
liuyuan04 已提交
59
  version="@PADDLE_VERSION@",
Z
zhangjinchao01 已提交
60 61
  ext_modules=[
    Extension('py_paddle._swig_paddle',      # Build SWIG Extension.
L
liaogang 已提交
62
       ['Paddle_wrap.cxx'],
L
liaogang 已提交
63
       language = "c++",
L
liaogang 已提交
64
       include_dirs = include_dirs,
Y
Yu Yang 已提交
65
       extra_link_args = extra_links,
L
liaogang 已提交
66
       extra_compile_args = extra_comps
Z
zhangjinchao01 已提交
67 68 69
    )
  ],
  packages=['py_paddle'],
L
liaogang 已提交
70
  include_dirs = include_dirs,
Z
zhangjinchao01 已提交
71
  install_requires = [
72
    'numpy>=1.8.0',      # The numpy is required.
Z
zhangjinchao01 已提交
73
    'protobuf>=2.4.1' # The paddle protobuf version
74 75
  ],
)