1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
|
#!/usr/bin/env python
import os
import sys
from distutils import dir_util
from scipy_distutils.misc_util import get_path, default_config_dict, dot_join
from scipy_distutils.misc_util import dict_append, get_build_temp
from scipy_distutils.misc_util import SourceFilter
from scipy_distutils.core import Extension
from scipy_distutils.system_info import get_info
from distutils.sysconfig import get_python_lib
from config_pygist import config_pygist
def get_special_dirs(plat):
if plat in ['aix4', 'aix5','sunos5']:
return ['/usr/local/lib']
elif plat in ['linux2','cygwin']:
return ['/usr/lib']
return []
cygwin = 0
if sys.platform=='cygwin':
cygwin = 1
macosx = 0
if sys.platform=='darwin':
macosx = 1
for keyword in sys.argv:
if keyword=='--x11':
sys.argv.remove(keyword)
cygwin = 0
macosx = 0
windows = 0
if sys.platform=='win32':
windows = 1
x11 = 0
if not (windows or cygwin or macosx):
x11 = 1
if 'NO_XLIB' in os.environ:
x11 = 0
gistsource = ["src/gist/gist.c",
"src/gist/tick.c",
"src/gist/tick60.c",
"src/gist/engine.c",
"src/gist/gtext.c",
"src/gist/draw.c",
"src/gist/draw0.c",
"src/gist/clip.c",
"src/gist/gread.c",
"src/gist/gcntr.c",
"src/gist/hlevel.c",
"src/gist/ps.c",
"src/gist/cgm.c",
"src/gist/eps.c",
"src/gist/style.c",
"src/gist/xfancy.c",
"src/gist/xbasic.c"]
if cygwin:
unixsource = ["src/play/unix/dir.c",
"src/play/unix/files.c",
"src/play/unix/pathnm.c",
"src/play/unix/slinks.c",
"src/play/unix/stdinit.c",
"src/play/unix/uevent.c",
"src/play/unix/uinbg.c",
"src/play/unix/usernm.c"]
elif macosx:
unixsource = ["src/play/unix/dir.c",
"src/play/unix/files.c",
"src/play/unix/pathnm.c",
"src/play/unix/timew.c",
"src/play/unix/slinks.c",
"src/play/unix/stdinit.c",
"src/play/unix/uevent.c",
"src/play/unix/uinbg.c",
"src/play/unix/usernm.c"]
elif not (windows):
unixsource = ["src/play/unix/dir.c",
"src/play/unix/files.c",
"src/play/unix/fpuset.c",
"src/play/unix/pathnm.c",
"src/play/unix/timew.c",
"src/play/unix/uevent.c",
"src/play/unix/ugetc.c",
"src/play/unix/umain.c",
"src/play/unix/usernm.c",
"src/play/unix/slinks.c"]
if not (windows or cygwin or macosx):
x11source = ["src/play/x11/colors.c",
"src/play/x11/connect.c",
"src/play/x11/cursors.c",
"src/play/x11/errors.c",
"src/play/x11/events.c",
"src/play/x11/fills.c",
"src/play/x11/fonts.c",
"src/play/x11/images.c",
"src/play/x11/lines.c",
"src/play/x11/pals.c",
"src/play/x11/pwin.c",
"src/play/x11/resource.c",
"src/play/x11/rgbread.c",
"src/play/x11/textout.c",
"src/play/x11/rect.c",
"src/play/x11/clips.c",
"src/play/x11/points.c"]
if windows:
winsource = ["src/play/win/pscr.c",
"src/play/win/pals.c",
"src/play/win/ptext.c",
"src/play/win/pfill.c",
"src/play/win/pcell.c",
"src/play/win/pmin.c",
"src/play/win/plines.c",
"src/play/win/prect.c",
"src/play/win/points.c",
"src/play/win/cursors.c",
"src/play/win/pwin.c",
"src/play/win/timew.c",
"src/play/win/clips.c",
"src/play/win/getdc.c",
"src/play/win/files.c",
"src/play/win/usernm.c",
"src/play/win/pathnm.c"]
elif cygwin:
winsource = ["src/play/win/pscr.c",
"src/play/win/pals.c",
"src/play/win/ptext.c",
"src/play/win/pfill.c",
"src/play/win/pcell.c",
"src/play/win/pmin.c",
"src/play/win/plines.c",
"src/play/win/prect.c",
"src/play/win/points.c",
"src/play/win/cursors.c",
"src/play/win/pwin.c",
"src/play/win/timew.c",
"src/play/win/clips.c",
"src/play/win/getdc.c"]
elif macosx:
macsource = ["src/play/mac/pscr.m",
"src/play/mac/pals.m",
"src/play/mac/text.m",
"src/play/mac/cell.m",
"src/play/mac/bitblt.m",
"src/play/mac/points.m",
"src/play/mac/cursors.m",
"src/play/mac/pwin.m",
"src/play/mac/clips.m",
"src/play/mac/pen.m",
"src/play/mac/color.m",
"src/play/mac/font.m"]
allsource = ["src/play/all/hash.c",
"src/play/all/hash0.c",
"src/play/all/mm.c",
"src/play/all/alarms.c",
"src/play/all/pstrcpy.c",
"src/play/all/pstrncat.c",
"src/play/all/p595.c",
"src/play/all/bitrev.c",
"src/play/all/bitlrot.c",
"src/play/all/bitmrot.c"]
def filter_playsource(sources,local_path):
if windows:
playsource = winsource + allsource
elif cygwin:
playsource = unixsource + winsource + allsource
elif macosx:
playsource = unixsource + macsource + allsource
else:
playsource = unixsource + x11source + allsource
return [os.path.join(local_path,n) for n in playsource]
def getallparams(gistpath,local_path,config_path):
x11_info = get_info('x11')
extra_compile_args = ['-DGISTPATH="\\"' + gistpath + '\\""' ]
extra_link_args = []
if windows or cygwin:
extra_compile_args.append("-DWINDOWS")
extra_compile_args.append("-mwindows")
extra_link_args.append("-mwindows")
libraries = []
else:
libraries = x11_info.get('libraries',['X11'])
if cygwin:
extra_compile_args.append("-DCYGWIN")
if macosx:
extra_compile_args.append("-DMACOSX")
extra_link_args.append('-framework')
extra_link_args.append('Cocoa')
include_dirs = ['src/gist', 'src/play', 'src/play/unix' ]
library_dirs = [os.path.join(local_path,x) for x in ['.','src']]
library_dirs.extend(x11_info.get('library_dirs',[]))
library_dirs.extend(get_special_dirs(sys.platform))
include_dirs = [os.path.join(local_path,x) for x in include_dirs]
include_dirs.extend(x11_info.get('include_dirs',[]))
if 1:
inputfile = open(os.path.join(config_path,"Make.cfg"))
lines = inputfile.readlines()
inputfile.close()
for line in lines:
if line[:8]=="MATHLIB=":
mathlib = line[8:-1] #removing the \n
# remove the -l
mathlib = mathlib[2:]
libraries.append(mathlib)
if line[:9]=="NO_EXP10=":
no_exp10 = line[9:-1] # removing \n
if no_exp10: extra_compile_args.append(no_exp10)
if line[:5]=="XINC=":
xinc = line[5:-1] # removing \n
if xinc and sys.platform not in ['cygwin','win32']:
# remove the -I
xinc = xinc[2:]
if xinc: include_dirs.append(xinc)
if line[:5]=="XLIB=":
xlib = line[5:-1] # removing \n
if xlib and sys.platform not in ['cygwin','win32']:
# remove the -L
xlib = xlib[2:]
library_dirs.append(xlib)
return include_dirs, library_dirs, libraries, \
extra_compile_args, extra_link_args
def configuration(parent_package='',parent_path=None):
"""
This will install *.gs and *.gp files to
'site-packages/scipy/xplt/gistdata'
"""
from scipy_distutils.system_info import get_info, dict_append
from glob import glob
local_path = get_path(__name__,parent_path)
config_path = os.path.join(get_build_temp(),'config_pygist')
dir_util.mkpath(config_path,verbose=1)
conf = config_pygist(local_path,config_path)
# Look to see if compiler is set on command line and add it
# This is repeating code, but I'm not sure how to avoid it
# As this gets run before overall setup does.
# This is needed so that compiler can be over-ridden from the
# platform default in the configuration section of xplt.
for arg in sys.argv[1:]:
if arg[:11] == '--compiler=':
conf.compiler = arg[11:]
break
if arg[:2] == '-c':
conf.compiler = arg[2:]
break
# Generate Make.cfg and config.h:
conf.run()
package = 'xplt'
xplt_path = os.path.join(parent_package,'xplt')
config = default_config_dict(package,parent_package)
all_playsource = glob(os.path.join(local_path,'src','play','*','*.c')) + \
glob(os.path.join(local_path,'src','play','*.h'))
playsource = SourceFilter(filter_playsource, all_playsource, local_path)
gistpath = os.path.join(get_python_lib(1),xplt_path,"gistdata")
gistpath = gistpath.replace("\\",r"\\\\")
gistC = os.path.join(local_path,'pygist','gistCmodule.c')
sources = [os.path.join(local_path,x) for x in gistsource]
sources = [gistC] + sources + [playsource]
include_dirs, library_dirs, libraries, \
extra_compile_args, extra_link_args \
= getallparams(gistpath,local_path,config_path)
include_dirs.insert(0,os.path.dirname(conf.config_h))
ext_arg = {'name':dot_join(parent_package,package,'gistC'),
'sources':sources,
'include_dirs':include_dirs,
'library_dirs':library_dirs,
'libraries':libraries,
'extra_compile_args':extra_compile_args,
'extra_link_args':extra_link_args,
'depends':[os.path.join(local_path,'src')]}
ext = Extension (**ext_arg)
config['ext_modules'].append(ext)
file_ext = ['*.gs','*.gp', '*.ps', '*.help']
xplt_files = [glob(os.path.join(local_path,'gistdata',x)) for x in file_ext]
xplt_files += [glob(os.path.join(local_path,'src','g',x)) for x in file_ext]
xplt_files = reduce(lambda x,y:x+y,xplt_files,[])
data_path = os.path.join(xplt_path,'gistdata')
config['data_files'].extend( [(data_path,xplt_files)])
return config
if __name__ == '__main__':
from scipy_distutils.core import setup
setup(**configuration(parent_path=''))
|