Annotation of python/pyGiNaC/setup4.py, revision 1.8

1.1       pearu       1: #!/usr/bin/env python
                      2: #
                      3: #   Setup file for building/installing PyGiNaC
                      4: #
                      5: # Requirements:
1.2       pearu       6: #   See README.txt
1.1       pearu       7: #  
                      8: # Usage:
1.6       pearu       9: #   First read README.txt
1.2       pearu      10: #   > python setup4.py install        # build _ginac
                     11: #                                     # and install the package.
                     12: #   > cd test4 && python test_all.py  # run doctests.
1.1       pearu      13: #
1.2       pearu      14: # In Python `import ginac'. Module `ginac' extension classes expose
1.1       pearu      15: # almost all GiNaC classes to Python.
                     16: # See GiNaC documentation (http://www.ginac.de/tutorial/) for usage.
                     17: #
                     18: # Pearu Peterson <pearu@cens.ioc.ee>
                     19: # 30 March 2001
                     20: # 23 April 2001
                     21: # 11 August 2001
1.6       pearu      22: # 24 August 2001
1.7       pearu      23: # 20 November 2001
1.1       pearu      24: 
                     25: __credits__ = """\
                     26: GiNaC group (www.ginac.de), for the GiNaC library.
                     27: Boost.Python group (www.boost.org), for BPL that considerably
1.2       pearu      28: simplified exposure of GiNaC C++ classes to Python.
1.1       pearu      29: """
                     30: 
1.8     ! pearu      31: 
        !            32: ginac_config = '/opt/GiNaC-1.0.1-print_python-23Nov2001/bin/ginac-config'
        !            33: ginac_config = 'ginac-config'
        !            34: 
1.7       pearu      35: import sys,os,string,time,commands,re
1.1       pearu      36: 
                     37: __today__ = time.asctime(time.localtime())
                     38: __author__ = 'Pearu Peterson <pearu@cens.ioc.ee>'
                     39: 
                     40: #++++++++++++++ Require Python 2.x +++++++++++++
                     41: 
                     42: if eval(sys.version[0])<2:
                     43:     print "You'll need Python 2.0 or higher to build PyGiNaC"
                     44:     sys.exit()
                     45: print 'Python Version',sys.version.split()[0]
                     46: 
                     47: #++++++++++++++ Rebuild ++++++++++++++++++++++++
                     48: rebuild = 0
1.8     ! pearu      49: relink = 0
1.7       pearu      50: disable_opt = 1 # disable optimization flags, useful when debugging
                     51:                 # set 0 for final compilation
1.1       pearu      52: 
1.8     ! pearu      53: if 'relink' in sys.argv:
        !            54:     from distutils import util
        !            55:     sys.argv[sys.argv.index('relink')] = 'build'
        !            56:     com = 'rm -fv build/lib.%s-%s/ginac/*.so'%(util.get_platform(),sys.version[0:3])
        !            57:     os.system (com)
1.1       pearu      58: if 'rebuild' in sys.argv:
                     59:     sys.argv[sys.argv.index('rebuild')] = 'build'
                     60:     rebuild = 1
                     61: if 'reinstall' in sys.argv:
                     62:     sys.argv[sys.argv.index('reinstall')] = 'install'
                     63:     rebuild = 1
                     64: 
1.7       pearu      65: #+++++++++++++++++ arguments for Extension ++++++++++++++++
                     66: libraries = []
                     67: library_dirs = []
                     68: extra_objects = []
                     69: extra_link_args = []
                     70: extra_compile_args = []
                     71: include_dirs = [] #['tools']  # Uncomment if sstream cannot be found.
                     72: sources = []
                     73: 
                     74: #++++++++++++++++ GiNaC,CLN (,GMP) +++++++++++++++++++++++++++
                     75: gmp_so = '/usr/lib/libgmp.so' # fix this path if CLN uses gmp.
1.8     ! pearu      76: s,ginac_version=commands.getstatusoutput (ginac_config+' --version')
1.7       pearu      77: if not s:
                     78:     print 'GiNaC Version',ginac_version
1.8     ! pearu      79:     ginac_prefix=commands.getoutput (ginac_config+' --prefix')
1.7       pearu      80:     ginac_so = os.path.join (ginac_prefix,'lib','libginac.so')
                     81:     if os.path.isfile(ginac_so):
                     82:         extra_objects.append (ginac_so)
                     83:         s,cln_version=commands.getstatusoutput ('cln-config --version')
                     84:         if not s:
                     85:             print 'CLN Version',cln_version
                     86:             cln_prefix = commands.getoutput ('cln-config --prefix')
                     87:             cln_so = os.path.join (cln_prefix,'lib','libcln.so')
                     88:             cln_libs = commands.getoutput ('cln-config --libs')
                     89:             if os.path.isfile (cln_so):
                     90:                 extra_objects.append(cln_so)
                     91:                 cln_libs = cln_libs.replace ('-lcln ',' ')
                     92:             if re.match (r'.*-lgmp\b',cln_libs) and os.path.isfile (gmp_so):
                     93:                 extra_objects.append(gmp_so)
                     94:                 cln_libs = cln_libs.replace ('-lgmp',' ')
                     95:             if re.match (r'.*-l',cln_libs):
                     96:                 extra_link_args.append(cln_libs)
                     97:             cln_flags = commands.getoutput ('cln-config --cppflags')
                     98:             if cln_flags:
                     99:                 extra_compile_args.append (cln_flags)
                    100:         else:
                    101:             libraries += ['cln']
                    102:             print 'Failed to establish CLN using cln-config. Using defaults.'
                    103:     else:
1.8     ! pearu     104:         extra_link_args.append (commands.getoutput (ginac_config +' --libs'))
        !           105:     extra_compile_args.append (commands.getoutput (ginac_config+' --cppflags'))
1.7       pearu     106: else:
                    107:     print 'Failed to establish GiNaC using ginac-config. Using defaults.'
                    108:     libraries += ['ginac','cln']
                    109: 
1.1       pearu     110: #++++++++++++++++++++ boost.python +++++++++++++++++++++
                    111: 
1.7       pearu     112: # Fix this path for Boost headers
1.2       pearu     113: boost_dir = 'boost'
1.1       pearu     114: if not os.path.isdir(boost_dir):
                    115:     print 'boost_dir=%s must be existing directory.'%(`boost_dir`)
                    116:     print '  Get Boost from http://www.boost.org/'
1.2       pearu     117:     print '  Fix its path in setup4.py'
1.1       pearu     118:     sys.exit()
1.7       pearu     119: else:
                    120:     include_dirs.append (boost_dir)
1.1       pearu     121: 
1.7       pearu     122: try:
                    123:     import _libboostpython
                    124:     libboost_so = _libboostpython.__file__
                    125: except ImportError:
                    126:     s = os.system ('cd libboostpython && ./setup.py install')
                    127:     if not s:
                    128:         try:
                    129:             import _libboostpython
                    130:             libboost_so = _libboostpython.__file__
                    131:             s = 0
                    132:         except ImportError: pass
                    133:     if s:
                    134:         # Fix this path if you have your own Boost.Python shared library
                    135:         libboost_so = 'XXX/usr/lib/libboost_python.so'
                    136: 
                    137: if not os.path.exists (libboost_so):
                    138:     print 'Using boost sources.'
                    139:     libboost = ''
                    140:     bpl_dir = os.path.join(boost_dir,'libs','python','src')
                    141:     bpl_src = map(lambda f:os.path.join(bpl_dir,f),
1.1       pearu     142:               ['classes.cpp',
                    143:                'conversions.cpp',
                    144:                'extension_class.cpp',
                    145:                #'cross_module.cpp',
                    146:                'functions.cpp',
                    147:                'init_function.cpp',
                    148:                'module_builder.cpp',
                    149:                'objects.cpp','types.cpp'])
1.7       pearu     150:     sources += bpl_src
                    151: else:
                    152:     extra_objects.append (libboost_so)
1.1       pearu     153: 
                    154: #++++++++++++++++++++++++++++++++++++++++++++++++
                    155: from distutils.core import setup, Extension
                    156: 
                    157: #+++HACK: replace linker gcc with g++ +++++++++++
1.7       pearu     158: #+++      turn off optimization if disable_opt +++++++++++
1.1       pearu     159: from distutils import sysconfig
                    160: save_init_posix = sysconfig._init_posix
                    161: def my_init_posix():
                    162:     save_init_posix()
                    163:     g = sysconfig._config_vars
                    164:     if g['LDSHARED'][:3]=='gcc':
                    165:         print 'my_init_posix: changing LDSHARED =',`g['LDSHARED']`,
                    166:         g['LDSHARED'] = 'g++'+g['LDSHARED'][3:]
                    167:         print 'to',`g['LDSHARED']`
                    168:     if disable_opt and g['OPT'][:6]=='-g -O2':
                    169:         print 'my_init_posix: changing OPT =',`g['OPT']`,
                    170:         g['OPT'] = '-g'+g['OPT'][6:]
                    171:         print 'to',`g['OPT']`
                    172: sysconfig._init_posix = my_init_posix
                    173: 
                    174: #+++++++++++++++++ PyGiNaC version ++++++++++++++
                    175: 
                    176: edition = 4
                    177: wrapper_dir = 'wrappers%d'%edition
                    178: lib_dir = 'lib%d'%edition
                    179: src_dir = 'src%d'%edition
                    180: 
                    181: major_version = 0
1.7       pearu     182: minor_version = 7
1.1       pearu     183: try: execfile(os.path.join('tools','get_revision.py'))
                    184: except: revision_version = 0
                    185: version='%d.%d.%d'%(major_version,minor_version,revision_version)
                    186: version_info = (major_version,minor_version,revision_version,'proto',edition)
                    187: 
1.2       pearu     188: print 'Creating %s/__version__.py'%lib_dir
1.1       pearu     189: f = open(os.path.join(lib_dir,'__version__.py'),'w')
                    190: f.write('__version__ = "%s"\n'%(version))
                    191: f.close()
                    192: 
1.7       pearu     193: include_dirs.append (wrapper_dir)
                    194: 
                    195: #+++++++++++++ print summary ++++++++++++++++++
                    196: print 'extra_link_args=',extra_link_args
                    197: print 'extra_compile_args=',extra_compile_args
                    198: print 'extra_objects=',extra_objects
                    199: print 'include_dirs=',include_dirs
                    200: print 'libraries=',libraries
                    201: print 'sources=',sources
                    202: if len(sys.argv)==1:
                    203:     print "PyGiNaC Version",version
                    204:     sys.exit()
1.1       pearu     205: #++++++++++++++++ ginac._ginac +++++++++++++++++++++
                    206: 
1.2       pearu     207: ginac_src = []
1.4       pearu     208: for n in ['_ginac.cpp',
1.8     ! pearu     209:           'ginac_enhancements.cpp',
        !           210:           'slice.c'
1.4       pearu     211:           ]:
1.2       pearu     212:     ginac_src.append(os.path.join(wrapper_dir,n))
1.1       pearu     213: 
1.7       pearu     214: sources += ginac_src
1.1       pearu     215: 
1.3       pearu     216: if rebuild:
1.4       pearu     217:     for n in ['_ginac.cpp']:
                    218:         n = os.path.join(wrapper_dir,n)
1.3       pearu     219:         print 'touch '+n
                    220:         os.system('touch '+n)
                    221: 
1.2       pearu     222: _ginac_ext = Extension('ginac._ginac',
1.7       pearu     223:                        sources = sources,
                    224:                        include_dirs = include_dirs,
                    225:                        libraries = libraries,
                    226:                        library_dirs = library_dirs,
                    227:                        extra_objects = extra_objects,
                    228:                        extra_compile_args = extra_compile_args,
                    229:                        extra_link_args = extra_link_args,
1.1       pearu     230:                       )
1.2       pearu     231: 
                    232: #++++++++++++++ extension modules +++++++++++++++
1.1       pearu     233: 
1.2       pearu     234: ext_modules = [_ginac_ext]
1.1       pearu     235: 
                    236: #++++++++++++++++++++ setup +++++++++++++++++++++
                    237: 
                    238: setup (name = "PyGiNaC",
                    239:        version = version,
                    240:        description = "PyGiNaC --- the wrapper of C++ library GiNaC to Python",
                    241:        author = "Pearu Peterson",
                    242:        author_email = "pearu@cens.ioc.ee",
                    243:        maintainer = "Pearu Peterson",
                    244:        maintainer_email = "pearu@cens.ioc.ee",
                    245:        licence = "LGPL",
                    246:        long_description= """
                    247: GiNaC is an open framework for symbolic computation within the C++
                    248: programming language (http://www.ginac.de/).
                    249: PyGiNaC is a Python extension package that implements a complete
                    250: and transparent interface to the GiNaC library.
                    251: """,
                    252:        url = "http://cens.ioc.ee/projects/pyginac/",
                    253:        ext_modules = ext_modules,
                    254:        packages = ['ginac'],
                    255:        package_dir = {'ginac': lib_dir},
                    256:        )
                    257: 
                    258: print "PyGiNaC Version",version

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>