#!/usr/bin/env python2.2 """ Build Boost.Python V2 shared library. Requires: Python 2.2, gcc-3.0, BPL V2 Copyright 2002 Pearu Peterson all rights reserved, Pearu Peterson Permission to use, modify, and distribute this software is given under the terms of the LGPL. See http://www.fsf.org NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. $Revision: 1.4 $ $Date: 2002/05/15 07:37:18 $ Pearu Peterson """ __version__ = "$Id: setup_libbpl2.py,v 1.4 2002/05/15 07:37:18 pearu Exp $" boost_dir = 'boost' gcc_exe = 'gcc-3.0' gpp_exe = 'g++-3.0' gcc_exe = 'gcc' gpp_exe = 'g++' import sys,os if sys.version < '2.2': print 'Python >=2.2 is required but got '+sys.version[:6] sys.exit() if not os.path.isdir(boost_dir): print 'No Boost directory',boost_dir sys.exit() bpl_dir = os.path.join(boost_dir,'libs/python/src') bpl_src = ['converter/from_python.cpp', 'converter/registry.cpp', 'converter/type_id.cpp', 'object/class.cpp', 'object/function.cpp', 'object/inheritance.cpp', 'object/life_support.cpp', 'errors.cpp', 'module.cpp', 'objects.cpp', 'converter/builtin_converters.cpp', 'converter/callback.cpp', ] bpl_src = [os.path.join(bpl_dir,s) for s in bpl_src] src_file = os.path.join('tmp_libbpl2.c') if not os.path.exists(src_file): print 'Creating file',src_file f = open(src_file,'w') f.write(''' #ifdef __CPLUSPLUS__ extern "C" { #endif #include "Python.h" static PyMethodDef module_methods[] = { {NULL,NULL} }; DL_EXPORT(void) initlibbpl2(void) { Py_InitModule("libbpl2", module_methods); } #ifdef __CPLUSCPLUS__ } #endif ''') f.close() from distutils.core import setup, Extension ext = Extension('libbpl2', sources=bpl_src + [src_file], include_dirs=[boost_dir], define_macros = [('BOOST_PYTHON_SOURCE',None), ('BOOST_PYTHON_DYNAMIC_LIB',None), ('BOOST_PYTHON_V2',None)], #extra_compile_args=['-ftemplate-depth-20'] # for gcc-2.95.x ) #+++HACK: replace linker gcc with g++ +++++++++++ from distutils import sysconfig save_init_posix = sysconfig._init_posix def my_init_posix(): save_init_posix() g = sysconfig._config_vars for n,r in [('LDSHARED',gpp_exe),('CC',gcc_exe)]: if g[n][:3]=='gcc': print 'my_init_posix: changing %s = %r'%(n,g[n]), g[n] = r+g[n][3:] print 'to',`g[n]` sysconfig._init_posix = my_init_posix if __name__ == "__main__": setup (name = "libbpl2", version = '0.2', description = "libbpl2 - Boost.Python V2 shared library", author = "Pearu Peterson", author_email = "pearu@cens.ioc.ee", maintainer = "Pearu Peterson", maintainer_email = "pearu@cens.ioc.ee", licence = "LGPL", url = "http://cens.ioc.ee/projects/pyginac/", ext_modules = [ext], )