11
11
##############################################################################
12
12
13
13
from __future__ import print_function
14
+ import sys , os
15
+
16
+ sys .path = [ os .path .dirname (os .path .abspath (__file__ )) ] + sys .path
17
+
14
18
from swigprocess import prepare_flat_header
15
19
from numpy .distutils import misc_util as np_dist
16
20
from distutils .core import setup , Extension
17
21
from distutils .cmd import Command
18
22
from distutils .command .build_ext import build_ext
19
23
from distutils .command .build import build
20
24
from distutils .command .install import install
21
- import os
22
25
import subprocess
23
26
24
27
def compile_dynlib (prefix ,colpackdir ,boostdir ):
@@ -88,14 +91,34 @@ def finalize_options(self):
88
91
prefix = self .lib_prefix
89
92
print ('prefix = ' , prefix )
90
93
self .include_dirs .append (os .path .join (prefix ,'include' ))
91
- self .library_dirs .append (os .path .join (prefix ,'lib64' ))
92
- self .rpath .append (os .path .join (prefix ,'lib64' ))
93
- prepare_flat_header ()
94
+ import ctypes as c
95
+ plen = c .sizeof (c .c_void_p (0 ))
96
+ if plen == 8 :
97
+ self .library_dirs .append (os .path .join (prefix ,'lib64' ))
98
+ self .rpath .append (os .path .join (prefix ,'lib64' ))
99
+ else :
100
+ self .library_dirs .append (os .path .join (prefix ,'lib' ))
101
+ self .rpath .append (os .path .join (prefix ,'lib' ))
102
+ buildobj = self .get_finalized_command ('build' )
103
+ self .src = buildobj .src
104
+ prepare_flat_header (self .src )
105
+ self .swig_opts = ['-c++' , '-I' + self .src ]
106
+ self .finalized = 1
94
107
108
+ def build_extension (self , ext ):
109
+ if self .src != '.' :
110
+ import shutil
111
+ sources = ext .sources
112
+ newSrc = []
113
+ for s in iter (sources ):
114
+ shutil .copy (self .src + '/' + s , '.' )
115
+ ext .include_dirs .append (self .src )
116
+ super (build_swigadolc ,self ).build_extension (ext )
95
117
96
118
class buildthis (build ,object ):
97
119
command_name = 'build'
98
120
user_options = build .user_options + [
121
+ ('src=' , None , 'path of the source directory of swig module' ),
99
122
('lib-prefix=' , None , 'prefix to install adolc library' ),
100
123
('colpack-dir=' , None , 'directory in which colpack is installed' ),
101
124
('boost-dir=' , None , 'directory in which boost is installed' ),
@@ -111,11 +134,26 @@ def lib_doesnot_exist(self):
111
134
112
135
def initialize_options (self ):
113
136
super (buildthis ,self ).initialize_options ()
137
+ self .src = None
114
138
self .lib_prefix = None
115
139
self .colpack_dir = None
116
140
self .boost_dir = None
117
141
self .only_swig = None
118
142
143
+ def finalize_options (self ):
144
+ super (buildthis ,self ).finalize_options ()
145
+ if self .src is None :
146
+ self .src = '.'
147
+ if self .lib_prefix is None :
148
+ self .lib_prefix = os .path .join (os .environ ['HOME' ],'adolc_base' )
149
+ if self .colpack_dir is None :
150
+ self .colpack_dir = os .path .join (os .environ ['HOME' ],'adolc_base' )
151
+ if self .boost_dir is None :
152
+ self .boost_dir = '/usr'
153
+ if self .only_swig is None :
154
+ self .only_swig = False
155
+ self .finalized = 1
156
+
119
157
#sub_commands = [ ('build_lib', lib_doesnot_exist),
120
158
# ('build_ext', None) ]
121
159
sub_commands = [ ('build_lib' , None ),
@@ -137,22 +175,13 @@ def initialize_options(self):
137
175
super (installthis ,self ).initialize_options ()
138
176
139
177
def finalize_options (self ):
178
+ self .set_undefined_options ('build' ,
179
+ ('lib_prefix' ,'lib_prefix' ),
180
+ ('colpack_dir' , 'colpack_dir' ),
181
+ ('boost_dir' , 'boost_dir' ),
182
+ ('only_swig' , 'only_swig' ))
140
183
super (installthis ,self ).finalize_options ()
141
- if self .lib_prefix is None :
142
- self .lib_prefix = os .path .join (os .environ ['HOME' ],'adolc_base' )
143
- if self .colpack_dir is None :
144
- self .colpack_dir = os .path .join (os .environ ['HOME' ],'adolc_base' )
145
- if self .boost_dir is None :
146
- self .boost_dir = '/usr'
147
- if self .only_swig is None :
148
- self .only_swig = False
149
184
self .finalized = 1
150
- buildobj = self .distribution .get_command_obj ('build' )
151
- buildobj .set_undefined_options ('install' ,
152
- ('lib_prefix' ,'lib_prefix' ),
153
- ('colpack_dir' , 'colpack_dir' ),
154
- ('boost_dir' , 'boost_dir' ),
155
- ('only_swig' , 'only_swig' ))
156
185
157
186
incdirs = np_dist .get_numpy_include_dirs ()
158
187
#python_ldflags = subprocess.check_output(['python-config','--ldflags'],universal_newlines=True)
0 commit comments