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

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.10    ! pearu      50: disable_opt = 0 # disable optimization flags, useful when debugging
1.7       pearu      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) +++++++++++++++++++++++++++
1.8       pearu      75: s,ginac_version=commands.getstatusoutput (ginac_config+' --version')
1.7       pearu      76: if not s:
                     77:     print 'GiNaC Version',ginac_version
1.8       pearu      78:     ginac_prefix=commands.getoutput (ginac_config+' --prefix')
1.7       pearu      79:     ginac_so = os.path.join (ginac_prefix,'lib','libginac.so')
                     80:     if os.path.isfile(ginac_so):
                     81:         extra_objects.append (ginac_so)
                     82:     else:
1.8       pearu      83:         extra_link_args.append (commands.getoutput (ginac_config +' --libs'))
                     84:     extra_compile_args.append (commands.getoutput (ginac_config+' --cppflags'))
1.7       pearu      85: else:
                     86:     print 'Failed to establish GiNaC using ginac-config. Using defaults.'
1.9       pearu      87:     libraries += ['ginac']
1.7       pearu      88: 
1.1       pearu      89: #++++++++++++++++++++ boost.python +++++++++++++++++++++
                     90: 
1.7       pearu      91: # Fix this path for Boost headers
1.2       pearu      92: boost_dir = 'boost'
1.1       pearu      93: if not os.path.isdir(boost_dir):
                     94:     print 'boost_dir=%s must be existing directory.'%(`boost_dir`)
                     95:     print '  Get Boost from http://www.boost.org/'
1.2       pearu      96:     print '  Fix its path in setup4.py'
1.1       pearu      97:     sys.exit()
1.7       pearu      98: else:
                     99:     include_dirs.append (boost_dir)
1.1       pearu     100: 
1.7       pearu     101: try:
                    102:     import _libboostpython
                    103:     libboost_so = _libboostpython.__file__
                    104: except ImportError:
1.10    ! pearu     105:     s = os.system ('cd libboostpython && %s ./setup.py install' % (sys.executable))
1.7       pearu     106:     if not s:
                    107:         try:
                    108:             import _libboostpython
                    109:             libboost_so = _libboostpython.__file__
                    110:             s = 0
                    111:         except ImportError: pass
                    112:     if s:
                    113:         # Fix this path if you have your own Boost.Python shared library
                    114:         libboost_so = 'XXX/usr/lib/libboost_python.so'
                    115: 
                    116: if not os.path.exists (libboost_so):
                    117:     print 'Using boost sources.'
                    118:     libboost = ''
                    119:     bpl_dir = os.path.join(boost_dir,'libs','python','src')
                    120:     bpl_src = map(lambda f:os.path.join(bpl_dir,f),
1.1       pearu     121:               ['classes.cpp',
                    122:                'conversions.cpp',
                    123:                'extension_class.cpp',
                    124:                #'cross_module.cpp',
                    125:                'functions.cpp',
                    126:                'init_function.cpp',
                    127:                'module_builder.cpp',
                    128:                'objects.cpp','types.cpp'])
1.7       pearu     129:     sources += bpl_src
                    130: else:
                    131:     extra_objects.append (libboost_so)
1.1       pearu     132: 
                    133: #++++++++++++++++++++++++++++++++++++++++++++++++
                    134: from distutils.core import setup, Extension
                    135: 
                    136: #+++HACK: replace linker gcc with g++ +++++++++++
1.7       pearu     137: #+++      turn off optimization if disable_opt +++++++++++
1.1       pearu     138: from distutils import sysconfig
                    139: save_init_posix = sysconfig._init_posix
                    140: def my_init_posix():
                    141:     save_init_posix()
                    142:     g = sysconfig._config_vars
                    143:     if g['LDSHARED'][:3]=='gcc':
                    144:         print 'my_init_posix: changing LDSHARED =',`g['LDSHARED']`,
                    145:         g['LDSHARED'] = 'g++'+g['LDSHARED'][3:]
                    146:         print 'to',`g['LDSHARED']`
                    147:     if disable_opt and g['OPT'][:6]=='-g -O2':
                    148:         print 'my_init_posix: changing OPT =',`g['OPT']`,
                    149:         g['OPT'] = '-g'+g['OPT'][6:]
                    150:         print 'to',`g['OPT']`
                    151: sysconfig._init_posix = my_init_posix
                    152: 
                    153: #+++++++++++++++++ PyGiNaC version ++++++++++++++
                    154: 
                    155: edition = 4
                    156: wrapper_dir = 'wrappers%d'%edition
                    157: lib_dir = 'lib%d'%edition
                    158: src_dir = 'src%d'%edition
                    159: 
                    160: major_version = 0
1.7       pearu     161: minor_version = 7
1.1       pearu     162: try: execfile(os.path.join('tools','get_revision.py'))
                    163: except: revision_version = 0
                    164: version='%d.%d.%d'%(major_version,minor_version,revision_version)
                    165: version_info = (major_version,minor_version,revision_version,'proto',edition)
                    166: 
1.2       pearu     167: print 'Creating %s/__version__.py'%lib_dir
1.1       pearu     168: f = open(os.path.join(lib_dir,'__version__.py'),'w')
                    169: f.write('__version__ = "%s"\n'%(version))
                    170: f.close()
                    171: 
1.7       pearu     172: include_dirs.append (wrapper_dir)
                    173: 
                    174: #+++++++++++++ print summary ++++++++++++++++++
                    175: print 'extra_link_args=',extra_link_args
                    176: print 'extra_compile_args=',extra_compile_args
                    177: print 'extra_objects=',extra_objects
                    178: print 'include_dirs=',include_dirs
                    179: print 'libraries=',libraries
                    180: print 'sources=',sources
                    181: if len(sys.argv)==1:
                    182:     print "PyGiNaC Version",version
                    183:     sys.exit()
1.1       pearu     184: #++++++++++++++++ ginac._ginac +++++++++++++++++++++
                    185: 
1.2       pearu     186: ginac_src = []
1.4       pearu     187: for n in ['_ginac.cpp',
1.8       pearu     188:           'ginac_enhancements.cpp',
                    189:           'slice.c'
1.4       pearu     190:           ]:
1.2       pearu     191:     ginac_src.append(os.path.join(wrapper_dir,n))
1.1       pearu     192: 
1.7       pearu     193: sources += ginac_src
1.1       pearu     194: 
1.3       pearu     195: if rebuild:
1.4       pearu     196:     for n in ['_ginac.cpp']:
                    197:         n = os.path.join(wrapper_dir,n)
1.3       pearu     198:         print 'touch '+n
                    199:         os.system('touch '+n)
                    200: 
1.2       pearu     201: _ginac_ext = Extension('ginac._ginac',
1.7       pearu     202:                        sources = sources,
                    203:                        include_dirs = include_dirs,
                    204:                        libraries = libraries,
                    205:                        library_dirs = library_dirs,
                    206:                        extra_objects = extra_objects,
                    207:                        extra_compile_args = extra_compile_args,
                    208:                        extra_link_args = extra_link_args,
1.1       pearu     209:                       )
1.2       pearu     210: 
                    211: #++++++++++++++ extension modules +++++++++++++++
1.1       pearu     212: 
1.2       pearu     213: ext_modules = [_ginac_ext]
1.1       pearu     214: 
                    215: #++++++++++++++++++++ setup +++++++++++++++++++++
                    216: 
                    217: setup (name = "PyGiNaC",
                    218:        version = version,
                    219:        description = "PyGiNaC --- the wrapper of C++ library GiNaC to Python",
                    220:        author = "Pearu Peterson",
                    221:        author_email = "pearu@cens.ioc.ee",
                    222:        maintainer = "Pearu Peterson",
                    223:        maintainer_email = "pearu@cens.ioc.ee",
                    224:        licence = "LGPL",
                    225:        long_description= """
                    226: GiNaC is an open framework for symbolic computation within the C++
                    227: programming language (http://www.ginac.de/).
                    228: PyGiNaC is a Python extension package that implements a complete
                    229: and transparent interface to the GiNaC library.
                    230: """,
                    231:        url = "http://cens.ioc.ee/projects/pyginac/",
                    232:        ext_modules = ext_modules,
                    233:        packages = ['ginac'],
                    234:        package_dir = {'ginac': lib_dir},
                    235:        )
                    236: 
                    237: print "PyGiNaC Version",version

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