1 | import os |
---|
2 | import re |
---|
3 | try: |
---|
4 | import SCons.Tool.applelink as applelink |
---|
5 | except: |
---|
6 | pass |
---|
7 | #include <Python.h> |
---|
8 | #include <boost/python.hpp> |
---|
9 | PYTHONPREFIX="/usr" |
---|
10 | FINKPREFIX=None |
---|
11 | env=Environment() |
---|
12 | platform=env['PLATFORM'] |
---|
13 | |
---|
14 | opts = Options('custom.py') |
---|
15 | if 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') |
---|
18 | else: |
---|
19 | opts.Add('CXX', 'The C++ compiler.') |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | |
---|
24 | class 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 |
---|
40 | PYTHONSEARCH=[\ |
---|
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 | |
---|
51 | env = Environment(options=opts) |
---|
52 | |
---|
53 | try: |
---|
54 | PYTHONSEARCH.insert(0,PythonConfig(version="2.4", prefix=env['FINK_PREFIX'],\ |
---|
55 | libdir=env['FINK_PREFIX']+"/lib/python2.4/config/")) |
---|
56 | except: |
---|
57 | pass |
---|
58 | |
---|
59 | print env['PLATFORM'] |
---|
60 | conf = Configure(env) |
---|
61 | PYTHON_CONFIG=None |
---|
62 | for c in PYTHONSEARCH: |
---|
63 | if conf.CheckCHeader(c.incdir+"/Python.h"): |
---|
64 | PYTHON_CONFIG=c |
---|
65 | break |
---|
66 | if 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) |
---|
72 | BOOST_PREFIX="/sw" |
---|
73 | env.Append(CPPPATH=[PYTHON_CONFIG.incdir]) |
---|
74 | if platform =="cygwin": |
---|
75 | env.Append(CPPPATH="/usr/local/include/boost-1_32") |
---|
76 | else: |
---|
77 | env.Append(CPPPATH=BOOST_PREFIX+"/include") |
---|
78 | print PYTHON_CONFIG.incdir |
---|
79 | print env['CPPPATH'] |
---|
80 | if not conf.CheckCXXHeader('boost/python.hpp'): |
---|
81 | print 'Boost/python must be installed' |
---|
82 | Exit(1) |
---|
83 | |
---|
84 | if not conf.CheckCXXHeader('boost/shared_ptr.hpp'): |
---|
85 | print 'Boost must be installed' |
---|
86 | Exit(1) |
---|
87 | |
---|
88 | conf.env.Append(CPPPATH=["../../kernel"]) |
---|
89 | if not conf.CheckCHeader('mod2.h'): |
---|
90 | print 'must have a Singular build directory' |
---|
91 | Exit(1) |
---|
92 | env = conf.Finish() |
---|
93 | |
---|
94 | env = Environment(options=opts) |
---|
95 | if (env['PLATFORM']=="darwin"): |
---|
96 | applelink.generate(env) |
---|
97 | |
---|
98 | SING_ROOT="../.." |
---|
99 | SING_ARCH=re.sub("\r|\n","",os.popen("../../singuname.sh").read()) |
---|
100 | #PYTHON_VERSION="2.3" |
---|
101 | sources=["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="") |
---|
111 | env['LDMODULESUFFIX'] = '.so' |
---|
112 | if platform=="cygwin": |
---|
113 | sources.append("mywrapper.cc") |
---|
114 | sources.remove("python.cc") |
---|
115 | def 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) |
---|
133 | module_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 | |
---|