File:  [CENS] / python / pyGiNaC / setup4.py
Revision 1.6: download - view: text, annotated - select for diffs - revision graph
Fri Aug 24 16:40:27 2001 UTC (16 years, 3 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Prepared for a work-in-progress release

#!/usr/bin/env python
#
#   Setup file for building/installing PyGiNaC
#
# Requirements:
#   See README.txt
#  
# Usage:
#   First read README.txt
#   > python setup4.py install        # build _ginac
#                                     # and install the package.
#   > cd test4 && python test_all.py  # run doctests.
#
# In Python `import ginac'. Module `ginac' extension classes expose
# almost all GiNaC classes to Python.
# See GiNaC documentation (http://www.ginac.de/tutorial/) for usage.
#
# Pearu Peterson <pearu@cens.ioc.ee>
# 30 March 2001
# 23 April 2001
# 11 August 2001
# 24 August 2001

__credits__ = """\
GiNaC group (www.ginac.de), for the GiNaC library.
Boost.Python group (www.boost.org), for BPL that considerably
simplified exposure of GiNaC C++ classes to Python.
"""

import sys,os,string,time

__today__ = time.asctime(time.localtime())
__author__ = 'Pearu Peterson <pearu@cens.ioc.ee>'

#++++++++++++++ Require Python 2.x +++++++++++++

if eval(sys.version[0])<2:
    print "You'll need Python 2.0 or higher to build PyGiNaC"
    sys.exit()
print 'Python Version',sys.version.split()[0]

#++++++++++++++ Rebuild ++++++++++++++++++++++++
rebuild = 0
disable_opt = 0 # set 0 for final compilation

if 'rebuild' in sys.argv:
    sys.argv[sys.argv.index('rebuild')] = 'build'
    rebuild = 1
if 'reinstall' in sys.argv:
    sys.argv[sys.argv.index('reinstall')] = 'install'
    rebuild = 1

#++++++++++++++++++++ boost.python +++++++++++++++++++++

boost_dir = '/usr/local/share/boost'
boost_dir = 'boost'

if not os.path.isdir(boost_dir):
    print 'boost_dir=%s must be existing directory.'%(`boost_dir`)
    print '  Get Boost from http://www.boost.org/'
    print '  Fix its path in setup4.py'
    sys.exit()

bpl_dir = os.path.join(boost_dir,'libs','python','src')
bpl_src = map(lambda f:os.path.join(bpl_dir,f),
              ['classes.cpp',
               'conversions.cpp',
               'extension_class.cpp',
               #'cross_module.cpp',
               'functions.cpp',
               'init_function.cpp',
               'module_builder.cpp',
               'objects.cpp','types.cpp'])

#++++++++++++++++++++++++++++++++++++++++++++++++
from distutils.core import setup, Extension

#+++HACK: replace linker gcc with g++ +++++++++++
#+++      turn off optimization       +++++++++++
from distutils import sysconfig
save_init_posix = sysconfig._init_posix
def my_init_posix():
    save_init_posix()
    g = sysconfig._config_vars
    if g['LDSHARED'][:3]=='gcc':
        print 'my_init_posix: changing LDSHARED =',`g['LDSHARED']`,
        g['LDSHARED'] = 'g++'+g['LDSHARED'][3:]
        print 'to',`g['LDSHARED']`
    if disable_opt and g['OPT'][:6]=='-g -O2':
        print 'my_init_posix: changing OPT =',`g['OPT']`,
        g['OPT'] = '-g'+g['OPT'][6:]
        print 'to',`g['OPT']`
sysconfig._init_posix = my_init_posix

#+++++++++++++++++ PyGiNaC version ++++++++++++++

edition = 4
wrapper_dir = 'wrappers%d'%edition
lib_dir = 'lib%d'%edition
src_dir = 'src%d'%edition

major_version = 0
minor_version = 6
try: execfile(os.path.join('tools','get_revision.py'))
except: revision_version = 0
version='%d.%d.%d'%(major_version,minor_version,revision_version)
version_info = (major_version,minor_version,revision_version,'proto',edition)

print 'Creating %s/__version__.py'%lib_dir
f = open(os.path.join(lib_dir,'__version__.py'),'w')
f.write('__version__ = "%s"\n'%(version))
f.close()

#++++++++++++++++ ginac._ginac +++++++++++++++++++++

ginac_src = []
for n in ['_ginac.cpp',
          'ginac_enhancements.cpp'
          ]:
    ginac_src.append(os.path.join(wrapper_dir,n))

if len(sys.argv)==1:
    print "PyGiNaC Version",version
    sys.exit()

if rebuild:
    for n in ['_ginac.cpp']:
        n = os.path.join(wrapper_dir,n)
        print 'touch '+n
        os.system('touch '+n)

_ginac_ext = Extension('ginac._ginac',
                      sources=ginac_src+bpl_src,
                      include_dirs=[boost_dir,
                                    wrapper_dir,
                                    'tools',       # for sstream
                                    ],
                      libraries=['ginac','cln'],
                      library_dirs=[],
                      )

#+++++++++++++++ force rebuild ++++++++++++++++++


#++++++++++++++ extension modules +++++++++++++++

ext_modules = [_ginac_ext]

#++++++++++++++++++++ setup +++++++++++++++++++++

setup (name = "PyGiNaC",
       version = version,
       description = "PyGiNaC --- the wrapper of C++ library GiNaC to Python",
       author = "Pearu Peterson",
       author_email = "pearu@cens.ioc.ee",
       maintainer = "Pearu Peterson",
       maintainer_email = "pearu@cens.ioc.ee",
       licence = "LGPL",
       long_description= """
GiNaC is an open framework for symbolic computation within the C++
programming language (http://www.ginac.de/).
PyGiNaC is a Python extension package that implements a complete
and transparent interface to the GiNaC library.
""",
       url = "http://cens.ioc.ee/projects/pyginac/",
       ext_modules = ext_modules,
       packages = ['ginac'],
       package_dir = {'ginac': lib_dir},
       )

print "PyGiNaC Version",version

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