source: anuga_core/source/pypar-numeric/setup.py @ 5839

Last change on this file since 5839 was 5839, checked in by steve, 16 years ago

Updated setup.py from the later version of pypar, added file metsdata.py
and added the link -lg2c (can't hurt) as for some reason the linker
was looking for getarg_

File size: 5.6 KB
Line 
1#!/usr/bin/env python
2
3# Examples of setup
4#
5# python setup.py install
6# python setup.py install --prefix=/opt/python-2.3
7# python setup.py install --home=~
8#
9# Some times you'll have to add a file called pypar.pth
10# containing the word pypar to site-packages
11#
12# See http://docs.python.org/dist/pure-pkg.html for more on distutils
13
14# FIXME: Now mpiext.c and pypar.py are assumed to be in this directory.
15# Maybe, we should put them in the default package directory, pypar.
16# The repository structure would then be
17#
18# pypar
19#     demos
20#     documentation
21#     source
22#          pypar
23
24from distutils.core import setup, Extension
25
26# FIXME (Ole): This works, but I don't know how to use it
27# Generate Python EGG if possible.
28#try:
29#   from setuptools import setup, Extension
30#except ImportError:
31#   pass
32
33import distutils.sysconfig
34import distutils.debug
35import os, sys
36import popen2
37import string
38import tempfile
39import numpy
40from __metadata__ import __version__, __date__, __author__
41
42
43def setup_compiler():
44    distutils.sysconfig.get_config_vars()
45    config_vars = distutils.sysconfig._config_vars
46   
47    if sys.platform == 'sunos5':
48        config_vars['LDSHARED'] = "gcc -G"
49        config_vars['CCSHARED'] = ""
50       
51
52def uniq_arr(arr):
53    """Remove repeated values from an array and return new array."""
54    ret = []
55    for i in arr:
56        if i not in ret:
57            ret.append(i)
58    return ret
59
60
61def _run_command(cmd):
62    out_file, in_file, err_file = popen2.popen3(cmd)
63    output = out_file.read() + err_file.read()
64    out_file.close()
65    in_file.close()
66    err_file.close()
67    # need this hack to get the exit status
68    out_file = os.popen(cmd)
69    if out_file.close():
70        # close returns exit status of command.
71        return ""
72    else:
73        # no errors, out_file.close() returns None.
74        return output
75
76
77def _get_mpi_cmd():
78    """Returns the output of the command used to compile using
79    mpicc."""
80    # LAM
81    output = _run_command("mpicc -showme")
82    if output:
83        return output
84
85    # MPICH
86    # works with MPICH version 1.2.1 (on Debian)
87    output = _run_command("mpicc -compile_info -link_info")
88    if output:
89        return output
90
91    # old version of MPICH needs this hack.
92    tmp_base = tempfile.mktemp()
93    tmp_c = tmp_base + ".c"
94    tmp_o = tmp_base + ".o"
95    tmp_file = open(tmp_c, "w")
96    tmp_file.write('#include "mpi.h"\nint main(){return 0;}\n')
97    tmp_file.close()
98    output = _run_command("mpicc -show;"\
99                          "mpicc -echo -c %s -o %s"%(tmp_c, tmp_o))
100    os.remove(tmp_c)
101    if os.path.exists(tmp_o):
102        os.remove(tmp_o)
103    if output:
104        return output
105    else:
106        return ""
107
108
109def get_mpi_flags():
110    output = _get_mpi_cmd()
111    print output
112    if not output:
113        if sys.platform=='win32': #From Simon Frost
114            output = "gcc -L$MPICH_DIR\SDK.gcc\lib -lmpich -I$MPICH_DIR\SDK.gcc\include"
115        else:
116            output = "cc -L/usr/opt/mpi -lmpi -lelan"
117
118
119    # now get the include, library dirs and the libs to link with.
120    flags = string.split(output)
121    flags = uniq_arr(flags) # remove repeated values.
122    inc_dirs = []
123    lib_dirs = []
124    libs = []
125    def_macros = []
126    undef_macros = []
127    for f in flags:
128        if f[:2] == '-I':
129            inc_dirs.append(f[2:])
130        elif f[:2] == '-L':
131            lib_dirs.append(f[2:])
132        elif f[:2] == '-l':
133            libs.append(f[2:])
134        elif f[:2] == '-U':
135            undef_macros.append(f[2:])
136        elif f[:2] == '-D':
137            tmp = string.split(f[2:], '=')
138            if len(tmp) == 1:
139                def_macros.append((tmp[0], None))
140            else:
141                def_macros.append(tuple(tmp))
142    return {'inc_dirs': inc_dirs, 'lib_dirs': lib_dirs, 'libs':libs,
143            'def_macros': def_macros, 'undef_macros': undef_macros}
144
145
146if __name__ == "__main__":
147    setup_compiler()
148   
149    mpi_flags = get_mpi_flags()
150    mpi_flags['inc_dirs'].append(numpy.get_include())
151    mpi_flags['libs'].append('g2c')
152
153    # setting some extra compile flags for AMD64, utilizing
154    # distutils.sysconfig to check which compiler to use
155    if os.name == 'posix' and os.uname()[4] == 'x86_64':
156        #Extra flags for 64 bit architectures
157        if 'pgcc' in distutils.sysconfig.get_config_var('CC'):
158            extra_compile_args = [' -fPIC -tp amd64'] #Valid for pgcc
159        elif 'gcc' in distutils.sysconfig.get_config_var('CC'):
160            extra_compile_args = [' -fPIC -m64'] #Valid for gcc
161        elif 'icc' in distutils.sysconfig.get_config_var('CC'):
162            extra_compile_args = [' -fPIC'] #Valid for icc
163        else:
164            extra_compile_args = None
165    else:
166        extra_compile_args = None
167
168
169
170    setup(name='Pypar',
171          version=__version__,
172          description='Pypar - Parallel Python',
173          long_description='Pypar - Parallel Python, no-frills MPI interface',
174          author=__author__,
175          author_email='ole.moller.nielsen@gmail.com',
176          url='http://sourceforge.net/projects/pypar',
177          package_dir = {'pypar': ''}, # Use files in this dirctory
178          packages  = ['pypar'],
179          ext_modules = [Extension('pypar.mpiext',
180                                   ['mpiext.c'], 
181                                   include_dirs=mpi_flags['inc_dirs'],
182                                   library_dirs=mpi_flags['lib_dirs'],
183                                   libraries=mpi_flags['libs'],
184                                   define_macros=mpi_flags['def_macros'],
185                                   undef_macros=mpi_flags['undef_macros'],
186                                   extra_compile_args=extra_compile_args)]
187         )
Note: See TracBrowser for help on using the repository browser.