source: setup.py @ 3047:94e5e1f7f2ff

Revision 3047:94e5e1f7f2ff, 30.2 KB checked in by William Stein <wstein@…>, 6 years ago (diff)

link in gmp

Line 
1#!/usr/bin/env python
2DEVEL = False
3
4import distutils.sysconfig, os, sys
5from distutils.core import setup, Extension
6
7
8## Choose cblas library -- note -- make sure to update sage/misc/sagex.py
9## if you change this!!
10if os.environ.has_key('SAGE_CBLAS'):
11    CBLAS=os.environ['SAGE_CBLAS']
12elif os.path.exists('/usr/lib/libcblas.dylib') or \
13     os.path.exists('/usr/lib/libcblas.so'):
14    CBLAS='cblas'
15elif os.path.exists('/usr/lib/libblas.dll.a'):   
16    CBLAS='blas'
17else:
18    # This is very slow  (?), but *guaranteed* to be available.
19    CBLAS='gslcblas' 
20
21if len(sys.argv) > 1 and sys.argv[1] == "sdist":
22    sdist = True
23else:
24    sdist = False
25
26NO_WARN = True
27
28if not os.environ.has_key('SAGE_ROOT'):
29    print "    ERROR: The environment variable SAGE_ROOT must be defined."
30    sys.exit(1)
31else:
32    SAGE_ROOT  = os.environ['SAGE_ROOT']
33    SAGE_LOCAL = SAGE_ROOT + '/local/'
34    SAGE_DEVEL = SAGE_ROOT + '/devel/'
35
36
37if not os.environ.has_key('SAGE_VERSION'):
38    SAGE_VERSION=0
39else:
40    SAGE_VERSION = os.environ['SAGE_VERSION']
41
42SITE_PACKAGES = '%s/lib/python/site-packages/'%SAGE_LOCAL
43if not os.path.exists(SITE_PACKAGES):
44    SITE_PACKAGES = '%s/lib/python2.5/site-packages/'%SAGE_LOCAL
45    if not os.path.exists(SITE_PACKAGES):
46        SITE_PACKAGES = '%s/lib/python2.4/site-packages/'%SAGE_LOCAL
47        if not os.path.exists(SITE_PACKAGES):       
48            raise RuntimeError, "Unable to find site-packages directory (see setup.py file in sage python code)."
49
50SITE_PACKAGES_REL=SITE_PACKAGES[len(SAGE_LOCAL)+5:]
51       
52if not os.path.exists('build/sage'):
53    os.makedirs('build/sage')
54
55sage_link = SITE_PACKAGES + '/sage'
56if not os.path.islink(sage_link) or not os.path.exists(sage_link):
57    os.system('rm -rf "%s"'%sage_link)
58    os.system('cd %s; ln -sf ../../../../devel/sage/build/sage .'%SITE_PACKAGES)
59
60
61include_dirs = ['%s/include'%SAGE_LOCAL, '%s/include/python'%SAGE_LOCAL, \
62                '%s/sage/sage/ext'%SAGE_DEVEL]
63
64#####################################################   
65       
66ec =    Extension('sage.libs.ec.ec',
67              sources = ["sage/libs/ec/ec.pyx"] +  \
68                        ["sage/libs/ec/%s"%s for s in \
69                         ["analrank.c", "apcompute.c", "arderivs.c",
70                          "arintern.c", "arith.c", "artwists.c",
71                          "arutil.c", "checkit.c", "degphi.c", 
72                          "diskio.c", "docurve.c", "dodisk.c", 
73                          "equation.c", "exotic.c", "fixit.c", 
74                          "iisog2.c", "iisog3.c", "isog.c", "isog2.c",
75                          "isog23.c", "isog24.c", "isog3.c", "isog5.c",
76                          "isog52.c", "isog713.c", "isogNprime.c",
77                          "isoggen.c", "isogsort.c", "isogx0.c", 
78                          "isogx0branch.c", "isogx0branch1.c", 
79                          "isogx0branch2.c", "isogx0branch3.c",
80                          "isogx0branch4.c", "isogx0branch5.c", 
81                          "isogx0branch6.c", "isogx0getd.c", 
82                          "isogx0period.c", "readit.c",
83                          "special.c", "util.c"]], 
84              libraries = ["pari", "m"])
85
86hanke = Extension(name = "sage.libs.hanke.hanke",
87              sources = ["sage/libs/hanke/hanke.pyx",
88                         "sage/libs/hanke/wrap.cc",
89                         "sage/libs/hanke/Matrix_mpz/Matrix_mpz.cc",
90                         "sage/libs/hanke/Matrix_mpz/CountLocal2.cc",
91                         "sage/libs/hanke/Matrix_mpz/CountLocal.cc",
92                         "sage/libs/hanke/Matrix_mpz/Local_Constants.cc",
93                         "sage/libs/hanke/Matrix_mpz/Local_Density_Front.cc",
94                         "sage/libs/hanke/Matrix_mpz/Local_Density_Congruence.cc",
95                         "sage/libs/hanke/Matrix_mpz/Local_Normal.cc",
96                         "sage/libs/hanke/Matrix_mpz/Local_Invariants.cc",
97                         "sage/libs/hanke/Utilities/string_utils.cc",
98                         "sage/libs/hanke/GMP_class_extras/mpz_class_extras.cc",
99                         "sage/libs/hanke/GMP_class_extras/vectors.cc" ],
100                   libraries = ["gmp", "gmpxx", "stdc++"])
101
102ntl = Extension('sage.libs.ntl.ntl',
103                 sources = ["sage/libs/ntl/ntl.pyx", "sage/libs/ntl/ntl_wrap.cc"],
104                 libraries = ["ntl", "gmp", "gmpxx", "m", "stdc++"]
105                 )
106
107mwrank =  Extension("sage.libs.mwrank.mwrank",
108                    sources = ["sage/libs/mwrank/mwrank.pyx",
109                         "sage/libs/mwrank/wrap.cc"],
110                    define_macros = [("NTL_ALL",None)],
111                    libraries = ["mwrank", "ntl", "gmp", "gmpxx", "stdc++", "m", "pari"])
112
113pari = Extension('sage.libs.pari.gen',
114                 sources = ["sage/libs/pari/gen.pyx"],
115                 libraries = ['pari', 'gmp'])
116
117cf = Extension('sage.libs.cf.cf',
118               sources = ["sage/libs/cf/cf.pyxe", "sage/libs/cf/ftmpl_inst.cc"],
119               libraries = ['cf', 'cfmem', 'gmp', 'stdc++', 'm']
120               )
121
122
123givaro_gfq = Extension('sage.rings.finite_field_givaro',
124                       sources = ["sage/rings/finite_field_givaro.pyx"],
125                       libraries = ['givaro', 'gmpxx', 'gmp', 'm', 'stdc++', ],   # this order is needed to compile under windows.
126                       language='c++'
127                       )
128
129
130qd = Extension('sage.rings.real_qdrf',
131                       sources = ["sage/rings/real_qdrf.pyx"],
132                       libraries = ['qd', 'm', 'stdc++', ],
133                       language='c++'
134                       )
135
136matrix = Extension('sage.matrix.matrix', ['sage/matrix/matrix.pyx'])
137
138matrix_misc = Extension('sage.matrix.misc', ['sage/matrix/misc.pyx'],
139                        libraries=['gmp'])
140
141matrix_dense = Extension('sage.matrix.matrix_dense',
142                         ['sage/matrix/matrix_dense.pyx'])
143             
144matrix_sparse = Extension('sage.matrix.matrix_sparse',
145                          ['sage/matrix/matrix_sparse.pyx'])
146
147matrix_generic_dense = Extension('sage.matrix.matrix_generic_dense',
148                                 ['sage/matrix/matrix_generic_dense.pyx'])
149             
150matrix_generic_sparse = Extension('sage.matrix.matrix_generic_sparse',
151                                  ['sage/matrix/matrix_generic_sparse.pyx'])
152
153matrix_domain_dense = Extension('sage.matrix.matrix_domain_dense',
154                                ['sage/matrix/matrix_domain_dense.pyx'])
155
156matrix_domain_sparse = Extension('sage.matrix.matrix_domain_sparse',
157              ['sage/matrix/matrix_domain_sparse.pyx'])
158             
159matrix_pid_dense = Extension('sage.matrix.matrix_pid_dense',
160                       ['sage/matrix/matrix_pid_dense.pyx'])
161             
162matrix_pid_sparse = Extension('sage.matrix.matrix_pid_sparse',
163                       ['sage/matrix/matrix_pid_sparse.pyx'])
164
165
166matrix_integer_sparse = Extension('sage.matrix.matrix_integer_sparse',
167                                  ['sage/matrix/matrix_integer_sparse.pyx'],
168                                  libraries = ['gmp'])
169
170matrix_integer_2x2 = Extension('sage.matrix.matrix_integer_2x2',
171                                 ['sage/matrix/matrix_integer_2x2.pyx'],
172                                 libraries = ['gmp'])
173
174linbox = Extension('sage.libs.linbox.linbox',
175                   ['sage/libs/linbox/linbox.pyx',
176                    'sage/libs/linbox/linbox_wrap.cpp'],
177                   libraries = ['linbox', 'ntl', 'gmp', 'gmpxx', 'stdc++', 'givaro', CBLAS],
178                   language = 'c++')
179
180matrix_modn_dense = Extension('sage.matrix.matrix_modn_dense',
181                              ['sage/matrix/matrix_modn_dense.pyx'],
182                              libraries = ['gmp'])
183
184matrix_modn_sparse = Extension('sage.matrix.matrix_modn_sparse',
185                               ['sage/matrix/matrix_modn_sparse.pyx'])
186   
187matrix_field_dense = Extension('sage.matrix.matrix_field_dense',
188                       ['sage/matrix/matrix_field_dense.pyx'])
189   
190matrix_field_sparse = Extension('sage.matrix.matrix_field_sparse',
191                       ['sage/matrix/matrix_field_sparse.pyx'])
192
193matrix_rational_dense = Extension('sage.matrix.matrix_rational_dense',
194                                  ['sage/matrix/matrix_rational_dense.pyx'],
195                                 libraries = ['gmp'])
196
197matrix_integer_dense = Extension('sage.matrix.matrix_integer_dense',
198                                 ['sage/matrix/matrix_integer_dense.pyx'],
199                                  libraries = ['gmp'])
200
201matrix_real_double_dense=Extension('sage.matrix.matrix_real_double_dense',
202   ['sage/matrix/matrix_real_double_dense.pyx'],libraries=['gsl',CBLAS],
203   define_macros=[('GSL_DISABLE_DEPRECATED','1')],include_dirs=[SAGE_ROOT+'/local/lib/python2.5/site-packages/numpy/core/include/numpy'])
204
205matrix_complex_double_dense=Extension('sage.matrix.matrix_complex_double_dense',
206   ['sage/matrix/matrix_complex_double_dense.pyx'],libraries=['gsl',CBLAS],
207   define_macros=[('GSL_DISABLE_DEPRECATED','1')],include_dirs=[SAGE_ROOT+'/local/lib/python2.5/site-packages/numpy/core/include/numpy'])
208
209
210solve = Extension('sage.matrix.solve',['sage/matrix/solve.pyx'],libraries = ['gsl',CBLAS],define_macros = 
211   [('GSL_DISABLE_DEPRECATED','1')])
212
213matrix_cyclo_dense = Extension('sage.matrix.matrix_cyclo_dense',
214                               ['sage/matrix/matrix_cyclo_dense.pyx'])
215
216matrix_rational_sparse = Extension('sage.matrix.matrix_rational_sparse',
217                                   ['sage/matrix/matrix_rational_sparse.pyx'],
218                                   libraries = ['gmp'])
219
220matrix_cyclo_sparse = Extension('sage.matrix.matrix_cyclo_sparse',
221                                   ['sage/matrix/matrix_cyclo_sparse.pyx'])
222
223complex_number = Extension('sage.rings.complex_number',
224                            ['sage/rings/complex_number.pyx'],
225                            libraries = ['mpfr', 'gmp'])
226
227free_module_element = Extension('sage.modules.free_module_element',
228                                ['sage/modules/free_module_element.pyx'])
229
230################ GSL wrapping ######################
231gsl_probability=Extension('sage.gsl.probability_distribution',['sage/gsl/probability_distribution.pyx'],libraries=['gsl',CBLAS],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
232gsl_integration=Extension('sage.gsl.integration',['sage/gsl/integration.pyx'],define_macros=[('GSL_DISABLE_DEPRECATED','1')], libraries=['gsl',CBLAS])
233
234gsl_ode = Extension('sage.gsl.ode',['sage/gsl/ode.pyx'],libraries=['gsl',CBLAS],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
235
236gsl_fft = Extension('sage.gsl.fft',
237                ['sage/gsl/fft.pyx'],
238                libraries = ['gsl', CBLAS],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
239
240gsl_interpolation = Extension('sage.gsl.interpolation',
241                ['sage/gsl/interpolation.pyx'],
242                libraries = ['gsl', CBLAS], 
243define_macros=[('GSL_DISABLE_DEPRECATED','1')])
244
245gsl_callback = Extension('sage.gsl.callback',
246                ['sage/gsl/callback.pyx'],
247                libraries = ['gsl', CBLAS]
248,define_macros=[('GSL_DISABLE_DEPRECATED','1')])
249
250real_double = Extension('sage.rings.real_double',
251                ['sage/rings/real_double.pyx'],
252                libraries = ['gsl', CBLAS],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
253
254complex_double = Extension('sage.rings.complex_double',
255                           ['sage/rings/complex_double.pyx'],
256                           libraries = ['gsl', CBLAS, 'pari', 'gmp'])
257
258real_double_vector = Extension('sage.modules.real_double_vector',['sage/modules/real_double_vector.pyx'],
259                              libraries = ['gsl',CBLAS,'pari','gmp'],define_macros = [('GSL_DISABLE_DEPRECAED','1')])
260
261complex_double_vector = Extension('sage.modules.complex_double_vector',['sage/modules/complex_double_vector.pyx'],
262                           libraries = ['gsl', CBLAS, 'pari', 'gmp'],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
263
264
265gsl_array = Extension('sage.gsl.gsl_array',['sage/gsl/gsl_array.pyx'],
266                libraries=['gsl',CBLAS],define_macros=[('GSL_DISABLE_DEPRECATED','1')])
267
268gsl_ode = Extension('sage.gsl.ode',['sage/gsl/ode.pyx'],libraries=['gsl',CBLAS],
269                define_macros=[('GSL_DISABLE_DEPRECATED','1')])
270
271
272dwt = Extension('sage.gsl.dwt',['sage/gsl/dwt.pyx'],
273                 libraries=['gsl',CBLAS],
274                 define_macros=[('GSL_DISABLE_DEPRECATED','1')])
275
276
277sagex_ds = Extension('sage.misc.sagex_ds', ['sage/misc/sagex_ds.pyx'])
278
279
280#####################################################
281
282ext_modules = [ \
283
284    free_module_element, 
285   
286    complex_double_vector,
287    real_double_vector,
288    ec, 
289    pari, 
290
291    mwrank, 
292
293    ntl, 
294
295    matrix,
296   
297    matrix_misc,
298
299    #cf,
300
301    matrix_dense,
302    matrix_generic_dense,
303
304    matrix_sparse,
305    matrix_generic_sparse,
306
307##     matrix_domain_dense,
308##     matrix_domain_sparse,
309
310##     matrix_pid_dense,
311##     matrix_pid_sparse,
312
313##     matrix_field_dense,
314##     matrix_field_sparse,
315
316     matrix_integer_dense,
317     matrix_rational_dense,
318     matrix_integer_2x2,
319##     matrix_integer_sparse,   
320     matrix_real_double_dense,
321     matrix_complex_double_dense,
322     solve,
323     linbox,
324     matrix_modn_dense,
325     matrix_modn_sparse,
326     givaro_gfq, \
327
328##     matrix_rational_sparse,
329
330##     matrix_cyclo_dense,
331##     matrix_cyclo_sparse,
332   
333    dwt,
334
335    gsl_array,
336    gsl_ode,
337    gsl_fft,
338    gsl_interpolation,
339    gsl_callback,
340    gsl_probability,
341    gsl_integration,
342    real_double,
343    complex_double,
344    #qd,   
345
346    complex_number,
347
348    sagex_ds,
349
350    Extension('sage.ext.sig',
351              sources = ['sage/ext/sig.pyx']), \
352
353    Extension('sage.ext.arith',
354              sources = ['sage/ext/arith.pyx']), \
355
356    Extension('sage.ext.arith_gmp',
357              sources = ['sage/ext/arith_gmp.pyx'],
358              libraries=['gmp']), \
359
360    Extension('sage.ext.multi_modular',
361              sources = ['sage/ext/multi_modular.pyx'],
362              libraries=['gmp']), \
363
364    Extension('sage.structure.coerce',
365              sources = ['sage/structure/coerce.pyx']), \
366
367    Extension('sage.modular.congroup_pyx',
368              sources = ['sage/modular/congroup_pyx.pyx', \
369                         'sage/ext/arith.pyx']), \
370
371    Extension('sage.structure.element',
372              sources = ['sage/structure/element.pyx']), \
373
374    Extension('sage.modules.module',
375              sources = ['sage/modules/module.pyx']), \
376
377    Extension('sage.rings.ring',
378              sources = ['sage/rings/ring.pyx']), \
379
380    Extension('sage.groups.group',
381              sources = ['sage/groups/group.pyx']), \
382
383    Extension('sage.structure.sage_object',
384              sources = ['sage/structure/sage_object.pyx']), \
385
386    Extension('sage.structure.parent',
387              sources = ['sage/structure/parent.pyx']), \
388
389    Extension('sage.structure.parent_base',
390              sources = ['sage/structure/parent_base.pyx']), \
391   
392    Extension('sage.structure.parent_gens',
393              sources = ['sage/structure/parent_gens.pyx']), \
394
395    Extension('sage.ext.interactive_constructors_c',
396              sources = ['sage/ext/interactive_constructors_c.pyx']), \
397
398    Extension('sage.misc.sagex_c',
399              sources = ['sage/misc/sagex_c.pyx']), \
400
401    Extension('sage.rings.real_mpfr',
402              sources = ['sage/rings/real_mpfr.pyx', 'sage/rings/ring.pyx'],
403              libraries = ['mpfr', 'gmp']), \
404
405    Extension('sage.rings.real_mpfi',
406              sources = ['sage/rings/real_mpfi.pyx'],
407              libraries = ['mpfi', 'mpfr', 'gmp']), \
408
409    Extension('sage.rings.integer',
410              sources = ['sage/ext/arith.pyx', 'sage/rings/integer.pyx', \
411                         'sage/ext/mpn_pylong.c', 'sage/ext/mpz_pylong.c'],
412              libraries=['gmp']), \
413
414    Extension('sage.rings.integer_ring',
415              sources = ['sage/rings/integer_ring.pyx'],
416              libraries=['gmp']), \
417
418    Extension('sage.rings.memory', \
419              sources = ['sage/rings/memory.pyx'], \
420              libraries=['gmp']), \
421
422    Extension('sage.rings.bernoulli_mod_p',
423              sources = ['sage/rings/bernoulli_mod_p.pyx', 'sage/ext/arith.pyx'],
424              libraries=['ntl'],
425              include_dirs=['sage/libs/ntl/']), \
426
427    Extension('sage.rings.polynomial_element',
428              sources = ['sage/rings/polynomial_element.pyx']), \
429
430    Extension('sage.rings.polynomial_pyx',
431              sources = ['sage/rings/polynomial_pyx.pyx',
432                         'sage/ext/arith_gmp.pyx'],
433              libraries=['gmp']), \
434
435    Extension('sage.rings.rational',
436              sources = ['sage/rings/rational.pyx',
437                         'sage/ext/arith.pyx', \
438                         'sage/rings/integer.pyx', \
439                         'sage/ext/mpn_pylong.c', 'sage/ext/mpz_pylong.c'],
440              libraries=['gmp']), \
441
442    Extension('sage.rings.sparse_poly', 
443              sources = ['sage/rings/sparse_poly.pyx'],
444              libraries=['gmp']), \
445
446    Extension('sage.rings.polydict',
447              sources = ['sage/rings/polydict.pyx']), \
448
449    Extension('sage.misc.search',
450              ['sage/misc/search.pyx']), \
451
452    Extension('sage.modular.modsym.heilbronn',
453              ['sage/modular/modsym/heilbronn.pyx',
454               'sage/modular/modsym/p1list.pyx',
455               'sage/ext/arith.pyx'],
456              libraries = ['gmp', 'm']), \
457
458    Extension('sage.modular.modsym.p1list',
459              ['sage/modular/modsym/p1list.pyx',
460               'sage/ext/arith.pyx'],
461              libraries = ['gmp']), \
462
463    Extension('sage.structure.mutability',
464              ['sage/structure/mutability.pyx']
465              ), \
466
467    Extension('sage.matrix.matrix0',
468              ['sage/matrix/matrix0.pyx']
469              ), \
470
471    Extension('sage.matrix.matrix1',
472              ['sage/matrix/matrix1.pyx']
473              ), \
474
475    Extension('sage.matrix.matrix2',
476              ['sage/matrix/matrix2.pyx']
477              ), \
478   
479    Extension('sage.matrix.matrix',
480              ['sage/matrix/matrix.pyx']
481              ), \
482
483    Extension('sage.matrix.matrix_window',
484              ['sage/matrix/matrix_window.pyx']
485              ), \
486
487    Extension('sage.matrix.matrix_window_modn_dense',
488              ['sage/matrix/matrix_window_modn_dense.pyx']
489              ), \
490
491    Extension('sage.matrix.strassen',
492              ['sage/matrix/strassen.pyx']
493              ), \
494                           
495    Extension('sage.rings.integer_mod',
496              ['sage/rings/integer_mod.pyx'],
497              libraries = ['gmp']
498              ), \
499
500    Extension('sage.combinat.expnums',
501              ['sage/combinat/expnums.pyx'],
502              libraries = ['gmp']
503              ), \
504                           
505    Extension('sage.graphs.graph_fast',
506              ['sage/graphs/graph_fast.pyx'],
507              libraries = ['gmp']), \
508                           
509    ]
510   
511
512#mpc = Extension('sage.rings.mpc',
513#              sources = ['sage/rings/mpc.pyx', 'sage/rings/ring.pyx'],
514#              libraries = ['mpc', 'mpfr', 'gmp'])
515
516
517extra_compile_args = [ ]
518
519if NO_WARN and distutils.sysconfig.get_config_var('CC').startswith("gcc"):
520    extra_compile_args = ['-w']
521
522if DEVEL:
523    extra_compile_args.append('-ggdb')
524    ext_modules.append(hanke)
525    #ext_modules.append(mpc)
526
527for m in ext_modules:
528    m.libraries += ['csage']
529    m.library_dirs += ['%s/lib' % SAGE_LOCAL]
530
531
532######################################################################
533# CODE for generating C/C++ code from Pyrex and doing dependency
534# checking, etc.  In theory distutils would run Pyrex, but I don't
535# trust it at all, and it won't have the more sophisticated dependency
536# checking that we need.
537######################################################################
538
539def is_older(file1, file2):
540    """
541    Return True if either file2 does not exist or is older than file1.
542
543    If file1 does not exist, always return False.
544    """
545    if not os.path.exists(file1):
546        return False
547    if not os.path.exists(file2):
548        return True
549    if os.path.getctime(file2) < os.path.getctime(file1):
550        return True
551    return False
552
553
554def need_to_pyrex(filename, outfile):
555    """
556    INPUT:
557        filename -- The name of a pyrex file in the SAGE source tree.
558        outfile -- The name of the corresponding c or cpp file in the build directory.
559
560    OUTPUT:
561        bool -- whether or not outfile must be regenerated.
562    """
563    if is_older(filename, outfile):   # outfile is older than filename
564        return True
565    base =  os.path.splitext(filename)[0]
566    pxd = base+'.pxd'
567    if is_older(pxd, outfile):   # outfile is older than pxd file (if it exists)
568        return True
569
570    ## comment this out to turn on dependency checking!
571    # return False
572
573    # Now we look inside the file to see what it cimports or include.
574    # If any of these files are newer than outfile, we rebuild
575    # outfile.
576    S = open(filename).readlines()
577    if os.path.exists(pxd):
578        S += open(pxd).readlines()
579    # Take the lines that begin with cimport (it won't hurt to
580    # have extra lines)
581    C = [x.strip() for x in S if 'cimport' in x]
582    for A in C:
583        # Deduce the full module name.
584        # The only allowed forms of cimport are:
585        #        cimport a.b.c.d
586        #        from a.b.c.d cimport e
587        # Also, the cimport can be both have no dots (current directory) or absolute.
588        # The multiple imports with parens, e.g.,
589        #        import (a.b.c.d, e.f.g)
590        # of Python are not allowed in Pyrex.
591        # In both cases, the module name is the second word if we split on whitespace.
592        try:
593            A = A.strip().split()[1]
594        except IndexError:
595            # illegal statement or not really a cimport (e.g., cimport could
596            # be in a comment or something)
597            continue
598
599        # Now convert A to a filename, e.g., a/b/c/d
600        #
601        if '.' in A:
602            # It is an absolute cimport.
603            A = A.replace('.','/') + '.pxd'
604        else:
605            # It is a relative cimport.
606            A =  os.path.split(base)[0] + '/' + A + '.pxd'
607        # Check to see if a/b/c/d.pxd exists and is newer than filename.
608        # If so, we have to regenerate outfile.  If not, we're safe.
609        if os.path.exists(A) and is_older(A, outfile):
610            print "\nRegenerating %s because it depends on %s."%(outfile, A)
611            return True # yep we must rebuild
612
613    # OK, next we move on to include pxi files.
614    # If they change, we likewise must rebuild the pyx file.
615    I = [x for x in S if 'include' in x]
616    # The syntax for include is like this:
617    #       include "../a/b/c.pxi"
618    # I.e., it's a quoted *relative* path to a pxi file.
619    for A in I:
620        try:
621            A = A.strip().split()[1]
622        except IndexError:
623            # Illegal include statement or not really an include
624            # (e.g., include could easily be in a comment or
625            # something).  No reason to crash setup.py!
626            continue
627        # Strip the quotes from either side of the pxi filename.
628        A = A.strip('"').strip("'")
629        # Now take filename (the input argument to this function)
630        # and strip off the last part of the path and stick
631        # A onto it to get the filename of the pxi file relative
632        # where setup.py is being run.
633        A = os.path.split(filename)[0] + '/' + A
634        # Finally, check to see if filename is older than A
635        if os.path.exists(A) and is_older(A, outfile):
636            print "\nBuilding %s because it depends on %s."%(outfile, A)
637            return True
638
639    # We do not have to rebuild.
640    return False
641
642def process_pyrexembed_file(f, m):
643    # This is a pyrexembed file, so process accordingly.
644    dir, base = os.path.split(f[:-5])
645    tmp = '%s/.tmp_pyrexembed'%dir
646    if os.path.exists(tmp) and not os.path.isdir(tmp):
647        print "Please delete file '%s' in %s"%(tmp, dir)
648        sys.exit(1)
649    if not os.path.exists(tmp):
650        os.makedirs(tmp)
651    pyxe_file = "%s/%s.pyxe"%(tmp, base)
652
653    # The following files will be produced by pyrexembed.
654    cpp_file = "%s/%s_embed.cpp"%(dir, base)
655    c_file = "%s/%s.c"%(dir, base)
656    pyx_file = "%s/%s.pyx"%(dir,base)
657    pyx_embed_file = "%s/%s.pyx"%(tmp, base)
658    h_file = "%s/%s_embed.h"%(tmp, base)
659    if is_older(f, pyx_file) or is_older(f, cpp_file) or is_older(f, h_file):
660        os.system('cp -p %s %s'%(f, pyxe_file))
661        os.system('cp -p %s/*.pxi %s'%(dir, tmp))
662        os.system('cp -p %s/*.pxd %s'%(dir, tmp))
663        os.system('cp -p %s/*.h %s'%(dir, tmp))
664        cmd = "pyrexembed %s"%pyxe_file
665        print cmd
666        ret = os.system(cmd)
667        if ret != 0:
668            print "sage: Error running pyrexembed."
669            sys.exit(1)
670        process_pyrex_file(pyx_embed_file, m)
671        cmd = 'cp -p %s/*.pyx %s/; cp -p %s/*.c %s/; cp -p %s/*.h %s/; cp -p %s/*.cpp %s/'%(tmp, dir, tmp, dir, tmp, dir, tmp, dir)
672        print cmd
673        os.system(cmd)
674    return [cpp_file, c_file]
675
676def process_pyrex_file(f, m):
677    """
678    INPUT:
679        f -- file name
680        m -- Extension module description (i.e., object of type Extension).
681    """
682    # This is a pyrex file, so process accordingly.
683    pyx_inst_file = '%s/%s'%(SITE_PACKAGES, f)
684    if is_older(f, pyx_inst_file):
685        print "%s --> %s"%(f, pyx_inst_file)
686        os.system('cp %s %s 2>/dev/null'%(f, pyx_inst_file))
687    outfile = f[:-4] + ".c"
688    if m.language == 'c++':
689        outfile += 'pp'
690
691    if need_to_pyrex(f, outfile):
692        cmd = "pyrexc --embed-positions -I%s %s"%(os.getcwd(), f)
693        print cmd
694        ret = os.system(cmd)
695        if ret != 0:
696            print "sage: Error running pyrexc."
697            sys.exit(1)
698        # If the language for the extension is C++,
699        # then move the resulting output file to have the correct extension.
700        # (I don't know how to tell Pyrex to do this automatically.)
701        if m.language == 'c++':
702            os.system('mv %s.c %s'%(f[:-4], outfile))
703    return [outfile]
704   
705
706def pyrex(ext_modules):
707    for m in ext_modules:
708        m.extra_compile_args += extra_compile_args
709#        m.extra_link_args += extra_link_args
710        new_sources = []
711        for i in range(len(m.sources)):
712            f = m.sources[i]
713            s = open(f).read()
714            if f[-5:] == '.pyxe':# and s.find("#embed") != -1 and s.find('#}embed') != -1:
715                new_sources = process_pyrexembed_file(f, m)
716            elif f[-4:] == ".pyx":
717                new_sources += process_pyrex_file(f, m)
718            else:
719                new_sources.append(f)
720        m.sources = new_sources
721
722
723       
724
725if not sdist:
726    pyrex(ext_modules)
727
728setup(name        = 'sage',
729
730      version     =  SAGE_VERSION,
731     
732      description = 'SAGE: System for Algebra and Geometry Experimentation',
733
734      license     = 'GNU Public License (GPL)',
735     
736      author      = 'William Stein',
737
738      author_email= 'wstein@gmail.com',
739     
740      url         = 'http://modular.math.washington.edu/sage',
741     
742      packages    = ['sage',
743                     
744                     'sage.algebras',
745                     
746                     'sage.catalogue',
747                     
748                     'sage.categories',
749
750                     'sage.coding',
751
752                     'sage.combinat',
753                     
754                     'sage.crypto',
755                     
756                     'sage.databases',
757                     
758                     'sage.ext',
759                     
760                     'sage.calculus',
761
762                     'sage.functions',
763
764                     'sage.geometry',
765
766                     'sage.games',
767
768                     'sage.gsl',
769                     
770                     'sage.graphs',
771                     
772                     'sage.groups',
773                     'sage.groups.abelian_gps',
774                     'sage.groups.matrix_gps',
775                     'sage.groups.perm_gps',
776                     
777                     'sage.interfaces',
778
779                     'sage.lfunctions',
780                     
781                     'sage.libs',
782                     'sage.libs.hanke',
783                     'sage.libs.linbox',
784                     'sage.libs.mwrank',
785                     'sage.libs.ntl',
786                     'sage.libs.ec',
787                     'sage.libs.pari',
788                     'sage.libs.cf',
789                     
790                     'sage.matrix',
791                     
792                     'sage.misc',
793                     
794                     'sage.modules',
795                     
796                     'sage.modular',
797                     'sage.modular.abvar',
798                     'sage.modular.hecke',
799                     'sage.modular.modform',
800                     'sage.modular.modsym',
801                     'sage.modular.ssmod',
802                     
803                     'sage.monoids',
804                     
805                     'sage.plot',
806                     'sage.plot.mpl3d',
807                     
808                     'sage.probability',
809
810                     'sage.quadratic_forms',
811
812                     'sage.rings',
813                     'sage.rings.number_field',
814                     'sage.rings.padics',
815                     
816                     'sage.tests',
817                     
818                     'sage.sets',
819                     
820                     'sage.schemes',
821                     'sage.schemes.generic',
822                     'sage.schemes.jacobians',
823                     'sage.schemes.plane_curves',
824                     'sage.schemes.plane_quartics',
825                     'sage.schemes.elliptic_curves',
826                     'sage.schemes.hyperelliptic_curves',
827
828                     'sage.server',
829                     'sage.server.server1',
830                     'sage.server.notebook',
831                     'sage.server.wiki',
832                     'sage.server.trac',
833                     
834                     'sage.structure',
835                     
836                     'sage.dsage',
837                     'sage.dsage.database',
838                     'sage.dsage.server',
839                     'sage.dsage.errors',
840                     'sage.dsage.tests',
841                     'sage.dsage.pb',
842                     'sage.dsage.dist_functions',
843                     'sage.dsage.misc',
844                     'sage.dsage.interface',
845                     'sage.dsage.scripts'
846                     ],
847     
848      scripts = ['sage/dsage/scripts/dsage_server.py',
849                 'sage/dsage/scripts/dsage_worker.py',
850                 'sage/dsage/scripts/dsage_setup.py',
851                 'sage/dsage/scripts/dsage_console.py'
852                ],
853     
854      ext_modules = ext_modules,
855      include_dirs = include_dirs)
856
857 
858 
Note: See TracBrowser for help on using the repository browser.