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

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

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