[f2d6445] | 1 | """ |
---|
| 2 | Installation script for SANS models |
---|
| 3 | |
---|
| 4 | - To compile and install: |
---|
| 5 | python setup.py install |
---|
| 6 | - To create distribution: |
---|
| 7 | python setup.py bdist_wininst |
---|
| 8 | |
---|
| 9 | """ |
---|
| 10 | import sys, os |
---|
| 11 | from distutils.core import setup, Extension |
---|
| 12 | from distutils import util |
---|
| 13 | from distutils import sysconfig |
---|
| 14 | |
---|
| 15 | def get_c_files(path): |
---|
| 16 | """ |
---|
| 17 | Utility function to return all files |
---|
| 18 | to be compiled in a directory |
---|
| 19 | """ |
---|
| 20 | clist = [] |
---|
| 21 | for file in os.listdir(path): |
---|
| 22 | if file.endswith(".cc") or file.endswith(".c"): |
---|
| 23 | clist.append("%s/%s" % (path, file)) |
---|
| 24 | return clist |
---|
| 25 | |
---|
[aa61e49] | 26 | # Top package name |
---|
| 27 | #pck_top = "sansModeling" |
---|
| 28 | pck_top = "sans.simulation" |
---|
| 29 | |
---|
[f2d6445] | 30 | # The temp directory that the compiled files will be put in |
---|
| 31 | tempdir = "build/temp."+util.get_platform()+'-'+sysconfig.get_python_version() |
---|
| 32 | if os.name=='nt': |
---|
| 33 | tempdir += "/Release" |
---|
| 34 | |
---|
| 35 | # List of sub modules |
---|
| 36 | mod_list = ["iqPy", "geoshapespy", "pointsmodelpy", "analmodelpy"] |
---|
| 37 | |
---|
| 38 | # Define package directors, will be extended below |
---|
[aa61e49] | 39 | pck_dirs = {pck_top:"."} |
---|
[f2d6445] | 40 | |
---|
| 41 | # List of modules to install, will be extende below |
---|
[aa61e49] | 42 | pck_list = [pck_top] |
---|
[f2d6445] | 43 | |
---|
| 44 | # List of python extensions, will be extended below |
---|
| 45 | exts = [] |
---|
| 46 | |
---|
| 47 | # List of include dirs, will be extended below |
---|
| 48 | incl_dirs = ["iqPy/libiqPy/tnt"] |
---|
| 49 | |
---|
| 50 | # List of files to compile, per module, will be extended below |
---|
| 51 | file_list = {} |
---|
| 52 | |
---|
| 53 | # List of dependencies |
---|
| 54 | deps = {} |
---|
| 55 | deps["iqPy"] = [] |
---|
| 56 | deps["geoshapespy"] = ["iqPy"] |
---|
| 57 | deps["analmodelpy"] = ["iqPy", "geoshapespy"] |
---|
| 58 | deps["pointsmodelpy"] = ["iqPy", "geoshapespy"] |
---|
| 59 | |
---|
| 60 | # List of extra objects to link with, per module, will be extended below |
---|
| 61 | libs = {} |
---|
| 62 | |
---|
| 63 | for module in mod_list: |
---|
[aa61e49] | 64 | pck_dirs["%s.%s" % (pck_top, module)] = "%s/%s" % (module, module) |
---|
| 65 | pck_list.append("%s.%s" % (pck_top, module)) |
---|
[f2d6445] | 66 | |
---|
| 67 | src_m = "%s/%smodule" % (module, module) |
---|
| 68 | src_l = "%s/lib%s" % (module, module) |
---|
| 69 | |
---|
| 70 | files = get_c_files(src_m) |
---|
| 71 | list_lib = get_c_files(src_l) |
---|
| 72 | |
---|
| 73 | libs[module] = [] |
---|
| 74 | for dep in deps[module]: |
---|
| 75 | |
---|
| 76 | for f in get_c_files("%s/lib%s" % (dep, dep)): |
---|
| 77 | index = f.rindex('.') |
---|
| 78 | if os.name=='nt': |
---|
| 79 | fo = f[:index]+'.obj' |
---|
| 80 | else: |
---|
| 81 | fo = f[:index]+'.o' |
---|
| 82 | libs[module].append("%s/%s" %(tempdir,fo)) |
---|
| 83 | |
---|
| 84 | files.extend(list_lib) |
---|
| 85 | file_list[module] = files |
---|
| 86 | |
---|
| 87 | incl_dirs.append(src_m) |
---|
| 88 | incl_dirs.append(src_l) |
---|
| 89 | |
---|
| 90 | for module in mod_list: |
---|
[aa61e49] | 91 | exts.append( Extension("%s.%s.%s" % (pck_top, module, module), |
---|
[f2d6445] | 92 | sources = file_list[module], |
---|
| 93 | extra_objects=libs[module], |
---|
| 94 | include_dirs=incl_dirs) ) |
---|
| 95 | |
---|
| 96 | setup( |
---|
| 97 | name="realspacesimulation", |
---|
| 98 | version = "0.2", |
---|
| 99 | description = "Python module for SANS simulation", |
---|
| 100 | author = "University of Tennessee", |
---|
| 101 | url = "http://danse.us/trac/sans", |
---|
| 102 | |
---|
| 103 | package_dir = pck_dirs, |
---|
| 104 | packages = pck_list, |
---|
| 105 | |
---|
| 106 | ext_modules = exts) |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | |
---|