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

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.1       pearu      23: 
                     24: __credits__ = """\
                     25: GiNaC group (www.ginac.de), for the GiNaC library.
                     26: Boost.Python group (www.boost.org), for BPL that considerably
1.2       pearu      27: simplified exposure of GiNaC C++ classes to Python.
1.1       pearu      28: """
                     29: 
                     30: import sys,os,string,time
                     31: 
                     32: __today__ = time.asctime(time.localtime())
                     33: __author__ = 'Pearu Peterson <pearu@cens.ioc.ee>'
                     34: 
                     35: #++++++++++++++ Require Python 2.x +++++++++++++
                     36: 
                     37: if eval(sys.version[0])<2:
                     38:     print "You'll need Python 2.0 or higher to build PyGiNaC"
                     39:     sys.exit()
                     40: print 'Python Version',sys.version.split()[0]
                     41: 
                     42: #++++++++++++++ Rebuild ++++++++++++++++++++++++
                     43: rebuild = 0
1.6     ! pearu      44: disable_opt = 0 # set 0 for final compilation
1.1       pearu      45: 
                     46: if 'rebuild' in sys.argv:
                     47:     sys.argv[sys.argv.index('rebuild')] = 'build'
                     48:     rebuild = 1
                     49: if 'reinstall' in sys.argv:
                     50:     sys.argv[sys.argv.index('reinstall')] = 'install'
                     51:     rebuild = 1
                     52: 
                     53: #++++++++++++++++++++ boost.python +++++++++++++++++++++
                     54: 
                     55: boost_dir = '/usr/local/share/boost'
1.2       pearu      56: boost_dir = 'boost'
1.1       pearu      57: 
                     58: if not os.path.isdir(boost_dir):
                     59:     print 'boost_dir=%s must be existing directory.'%(`boost_dir`)
                     60:     print '  Get Boost from http://www.boost.org/'
1.2       pearu      61:     print '  Fix its path in setup4.py'
1.1       pearu      62:     sys.exit()
                     63: 
                     64: bpl_dir = os.path.join(boost_dir,'libs','python','src')
                     65: bpl_src = map(lambda f:os.path.join(bpl_dir,f),
                     66:               ['classes.cpp',
                     67:                'conversions.cpp',
                     68:                'extension_class.cpp',
                     69:                #'cross_module.cpp',
                     70:                'functions.cpp',
                     71:                'init_function.cpp',
                     72:                'module_builder.cpp',
                     73:                'objects.cpp','types.cpp'])
                     74: 
                     75: #++++++++++++++++++++++++++++++++++++++++++++++++
                     76: from distutils.core import setup, Extension
                     77: 
                     78: #+++HACK: replace linker gcc with g++ +++++++++++
                     79: #+++      turn off optimization       +++++++++++
                     80: from distutils import sysconfig
                     81: save_init_posix = sysconfig._init_posix
                     82: def my_init_posix():
                     83:     save_init_posix()
                     84:     g = sysconfig._config_vars
                     85:     if g['LDSHARED'][:3]=='gcc':
                     86:         print 'my_init_posix: changing LDSHARED =',`g['LDSHARED']`,
                     87:         g['LDSHARED'] = 'g++'+g['LDSHARED'][3:]
                     88:         print 'to',`g['LDSHARED']`
                     89:     if disable_opt and g['OPT'][:6]=='-g -O2':
                     90:         print 'my_init_posix: changing OPT =',`g['OPT']`,
                     91:         g['OPT'] = '-g'+g['OPT'][6:]
                     92:         print 'to',`g['OPT']`
                     93: sysconfig._init_posix = my_init_posix
                     94: 
                     95: #+++++++++++++++++ PyGiNaC version ++++++++++++++
                     96: 
                     97: edition = 4
                     98: wrapper_dir = 'wrappers%d'%edition
                     99: lib_dir = 'lib%d'%edition
                    100: src_dir = 'src%d'%edition
                    101: 
                    102: major_version = 0
                    103: minor_version = 6
                    104: try: execfile(os.path.join('tools','get_revision.py'))
                    105: except: revision_version = 0
                    106: version='%d.%d.%d'%(major_version,minor_version,revision_version)
                    107: version_info = (major_version,minor_version,revision_version,'proto',edition)
                    108: 
1.2       pearu     109: print 'Creating %s/__version__.py'%lib_dir
1.1       pearu     110: f = open(os.path.join(lib_dir,'__version__.py'),'w')
                    111: f.write('__version__ = "%s"\n'%(version))
                    112: f.close()
                    113: 
                    114: #++++++++++++++++ ginac._ginac +++++++++++++++++++++
                    115: 
1.2       pearu     116: ginac_src = []
1.4       pearu     117: for n in ['_ginac.cpp',
1.5       pearu     118:           'ginac_enhancements.cpp'
1.4       pearu     119:           ]:
1.2       pearu     120:     ginac_src.append(os.path.join(wrapper_dir,n))
1.1       pearu     121: 
                    122: if len(sys.argv)==1:
                    123:     print "PyGiNaC Version",version
                    124:     sys.exit()
                    125: 
1.3       pearu     126: if rebuild:
1.4       pearu     127:     for n in ['_ginac.cpp']:
                    128:         n = os.path.join(wrapper_dir,n)
1.3       pearu     129:         print 'touch '+n
                    130:         os.system('touch '+n)
                    131: 
1.2       pearu     132: _ginac_ext = Extension('ginac._ginac',
                    133:                       sources=ginac_src+bpl_src,
1.4       pearu     134:                       include_dirs=[boost_dir,
                    135:                                     wrapper_dir,
1.6     ! pearu     136:                                     'tools',       # for sstream
1.4       pearu     137:                                     ],
1.1       pearu     138:                       libraries=['ginac','cln'],
                    139:                       library_dirs=[],
                    140:                       )
                    141: 
1.2       pearu     142: #+++++++++++++++ force rebuild ++++++++++++++++++
                    143: 
                    144: 
                    145: #++++++++++++++ extension modules +++++++++++++++
1.1       pearu     146: 
1.2       pearu     147: ext_modules = [_ginac_ext]
1.1       pearu     148: 
                    149: #++++++++++++++++++++ setup +++++++++++++++++++++
                    150: 
                    151: setup (name = "PyGiNaC",
                    152:        version = version,
                    153:        description = "PyGiNaC --- the wrapper of C++ library GiNaC to Python",
                    154:        author = "Pearu Peterson",
                    155:        author_email = "pearu@cens.ioc.ee",
                    156:        maintainer = "Pearu Peterson",
                    157:        maintainer_email = "pearu@cens.ioc.ee",
                    158:        licence = "LGPL",
                    159:        long_description= """
                    160: GiNaC is an open framework for symbolic computation within the C++
                    161: programming language (http://www.ginac.de/).
                    162: PyGiNaC is a Python extension package that implements a complete
                    163: and transparent interface to the GiNaC library.
                    164: """,
                    165:        url = "http://cens.ioc.ee/projects/pyginac/",
                    166:        ext_modules = ext_modules,
                    167:        packages = ['ginac'],
                    168:        package_dir = {'ginac': lib_dir},
                    169:        )
                    170: 
                    171: print "PyGiNaC Version",version

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