source: git/dyn_modules/python/SConstruct @ 6ce030f

spielwiese
Last change on this file since 6ce030f was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 4.6 KB
Line 
1import os
2import re
3try:
4        import SCons.Tool.applelink as applelink
5except:
6        pass
7#include <Python.h>
8#include <boost/python.hpp>
9PYTHONPREFIX="/usr"
10FINKPREFIX=None
11env=Environment()
12platform=env['PLATFORM']
13
14opts = Options('custom.py')
15if platform=="darwin":
16    opts.Add('CXX', 'The C++ compiler.',"g++-3.3")
17    opts.Add('FINK_PREFIX', 'Prefix for fink on Mac OS X, usually /sw','/sw')
18else:
19    opts.Add('CXX', 'The C++ compiler.')
20
21
22
23
24class PythonConfig(object):
25    def __init__(self, version="2.3", prefix="/usr", libdir=None, incdir=None, libname=None):
26        self.version=version
27        if libdir:
28            self.libdir=libdir
29        else:
30            self.libdir=prefix+"/lib"
31        self.prefix=prefix
32        if libname:
33            self.libname=libname
34        else:
35            self.libname="python"+self.version
36        if incdir:
37            self.incdir=incdir
38        else:
39            self.incdir=self.prefix+"/include/python"+self.version
40PYTHONSEARCH=[\
41    PythonConfig(version="2.4"),\
42    PythonConfig(version="2.3"),\
43    PythonConfig(version="2.4",\
44                    libdir="/Library/Frameworks/Python.framework/Versions/2.4/lib",\
45                    libname="python",\
46                    incdir="/Library/Frameworks/Python.framework/Versions/2.4/include/python2.4"),\
47                    PythonConfig(version="2.3"),\
48                    PythonConfig(version="2.4")]
49
50
51env = Environment(options=opts)
52
53try:
54  PYTHONSEARCH.insert(0,PythonConfig(version="2.4", prefix=env['FINK_PREFIX'],\
55        libdir=env['FINK_PREFIX']+"/lib/python2.4/config/"))
56except:
57    pass
58
59print env['PLATFORM']
60conf = Configure(env)
61PYTHON_CONFIG=None
62for c in PYTHONSEARCH:
63    if conf.CheckCHeader(c.incdir+"/Python.h"):
64        PYTHON_CONFIG=c
65        break
66if not PYTHON_CONFIG:
67    print 'Python header not found'
68    Exit(1)
69#if not conf.CheckCHeader('/usr/include/python2.3/Python.h'):
70#    print 'Python 2.3 must be installed'
71#    Exit(1)
72BOOST_PREFIX="/sw"
73env.Append(CPPPATH=[PYTHON_CONFIG.incdir])
74if platform =="cygwin":
75  env.Append(CPPPATH="/usr/local/include/boost-1_32")
76else:
77  env.Append(CPPPATH=BOOST_PREFIX+"/include")
78print PYTHON_CONFIG.incdir
79print env['CPPPATH']
80if not conf.CheckCXXHeader('boost/python.hpp'):
81    print 'Boost/python must be installed'
82    Exit(1)
83
84if not conf.CheckCXXHeader('boost/shared_ptr.hpp'):
85    print 'Boost must be installed'
86    Exit(1)
87   
88conf.env.Append(CPPPATH=["../../kernel"])
89if not conf.CheckCHeader('mod2.h'):
90    print 'must have a Singular build directory'
91    Exit(1)
92env = conf.Finish()
93
94env = Environment(options=opts)
95if (env['PLATFORM']=="darwin"):
96    applelink.generate(env)
97   
98SING_ROOT="../.."
99SING_ARCH=re.sub("\r|\n","",os.popen("../../singuname.sh").read())
100#PYTHON_VERSION="2.3"
101sources=["python.cc", "poly_wrap.cc", "vector_wrap.cc", "CF_wrap.cc",\
102             "number_wrap.cc", "playground.cc", "ideal_wrap.cc", "interpreter_support.cc",\
103             "ring_wrap.cc", "intvec_wrap.cc"]
104#Program("boosttest",
105#                 "boost.cpp",\
106#                 CXX="g++-3.3",\
107#              CPPPATH=[".", SING_ROOT+"/kernel",\
108#                       SING_ROOT+"/Singular", SING_ROOT+"/"+SING_ARCH +"/include",\
109#                       PYTHON_CONFIG.incdir, BOOST_PREFIX+"/include", "/sw/include"],
110#              LIBS=["boost_python",PYTHON_CONFIG.libname], CPPDEFINES=["NDEBUG","BUILD_MODULE"], SHLIBPREFIX="")
111env['LDMODULESUFFIX'] = '.so'
112if platform=="cygwin":
113  sources.append("mywrapper.cc")
114  sources.remove("python.cc")
115def module_target(*args,**keywords):
116    if env['PLATFORM']=="darwin":
117        print "Hello this is a Mac"
118        keywords['LINKFLAGS']="-bundle_loader ../../Singular/Singular"
119        try:
120            keywords['LIBPATH'].append(env['FINK_PREFIX']+"/lib")
121            keywords['CPPPATH'].append(env['FINK_PREFIX']+"/include")
122        except:
123            pass
124        return env.LoadableModule(*args,**keywords)
125    else:
126        if platform=="cygwin":
127          keywords['CPPPATH'].append("/usr/local/include/boost-1_32")
128          keywords['LIBPATH'].append("/usr/local/lib")
129          keywords['LIBPATH'].append("/bin")
130          return env.StaticLibrary(*args,**keywords)
131        else:
132          return env.SharedLibrary(*args,**keywords)
133module_target("python_module",
134              sources,\
135              CPPPATH=[SING_ROOT+"/kernel",\
136                       SING_ROOT+"/Singular", SING_ROOT+"/"+SING_ARCH +"/include",\
137                       PYTHON_CONFIG.incdir],\
138              LIBPATH=[PYTHON_CONFIG.libdir],\
139              CXXFLAGS="-O2",\
140              LIBS=["boost_python",PYTHON_CONFIG.libname], CPPDEFINES=["NDEBUG","BUILD_MODULE"], SHLIBPREFIX="")
141
142
Note: See TracBrowser for help on using the repository browser.