https://bitbucket.org/edgimar/sage-main
Raw File
Tip revision: a61b23da71d37a8cdf89a3d860228b06e06c6151 authored by Minh Van Nguyen on 04 August 2009, 08:15:40 UTC
trac 6674: only use ASCII characters in patches
Tip revision: a61b23d
SConstruct
##
## c_lib SConstruct file
##
## Author: Joel Mohler (original file)
##         Craig Citro (minor edits)
##
##
## 2007 Sep 01:
## I added a fix for trac ticket 555, which is to add the "install_lib"
## and "install_includes" below. 
## This is not the most elegant approach, I think. The problem is this:
## I (= Craig Citro) don't understand how to tell scons that it should
## look at /sage/local/libcsage.dylib to see if *it* is up to date. So
## what happens is that you change libcsage in branch foo, do a sage -b bar,
## and since you haven't modified sage-bar/c_lib/libcsage.dylib, scons
## doesn't think it needs to reinstall libcsage.dylib into
## $SAGE_ROOT/local/lib. (If it's not an OSX machine, then the target
## would be libcsage.so, but the point is the same.) This is obviously 
## problematic; the best solution I could come up with is just always 
## copying all the libraries and headers into $SAGE_ROOT where they belong.
## Actually, having discussed this with William, we came up with a better
## plan: we have two targets, install and branch_switch. With install, it's
## what you'd get with a sage -b. With branch_switch, it rebuilds the
## libraries, and then forces the copy regardless to exactly deal with
## the problem above.
##
## I also edited a bunch of lines below so that they didn't go over 80 chars,
## because I don't like seeing wrapped lines.
##
## 2007 Oct 01:
## After discussion with Gonzalo Tornaria and William Stein, we 
## decided that there's a much better solution to the above 
## problem: make $SAGE_ROOT/local/lib/libcsage.dylib. Also, we're
## reorganizing the directory tree to have src/ and include/
## subdirectories, and $SAGE_ROOT/local/include has a link into
## this directory.
##
import os

# Note that SCons's strong point is not the './configure' step of 
# autotools.  However, for this build we know that we are in a 
# SAGE local filesystem.  Once we have SAGE_LOCAL imported, we 
# know where everything is.
env = Environment(ENV = os.environ)

# By default, SCons hashes the source file contents to determine 
# if rebuilds are necessary. If you like the old way better, 
# uncomment this to use timestamps.
#env.SourceSignatures('timestamp')


# Since the sage build of python is only a static library,
# we just suppress the undefined python symbols. I don't 
# really understand the other options (-single_module and 
# -flat_namespace).  I can't find the documentation.
##
## These extra link flags make OS X play nice with building a dynamic
## library. -undefined dynamic_lookup is being used instead of
## -undefined suppress -- they should do basically the same thing (
## tell the linker it's okay to ignore undefined symbols at link time),
## but there's a possibility that -undefined suppress will throw an
## error, whereas -undefined dynamic_lookup will definitely try to find
## missing symbols at runtime.
## The other two options control the way the linker creates a namespace
## for the dynamic library; check the man page for ld on a mac to see
## the details.
if env['PLATFORM']=="darwin":
    if os.environ['SAGE64']=="yes":
        # We want the debug and optimization flags, since debug symbols are so useful, etc.
        print "MacIntel in 64 bit mode"
        env.Append( CFLAGS="-O2 -g -m64" )
        env.Append( CXXFLAGS="-O2 -g -m64" )
        env.Append( LINKFLAGS="-m64 -single_module -flat_namespace -undefined dynamic_lookup" )
    else:
        env.Append( LINKFLAGS="-single_module -flat_namespace -undefined dynamic_lookup" )

# SCons doesn't automatically pull in system environment variables
# However, we only need SAGE_LOCAL, so that's easy.
env['SAGE_LOCAL'] = os.environ['SAGE_LOCAL']
if os.environ.has_key('SAGE_DEBIAN'):
    env['SAGE_LOCAL'] = '/usr'

# The SCons convenience function Split is the only strange thing 
# to python programmers. It just makes a list by splitting on 
# whitespace without the syntax clutter of lists of strings.
includes = ['$SAGE_LOCAL/include/', '$SAGE_LOCAL/include/python2.6/',
            '$SAGE_LOCAL/include/NTL/', 'include']
cFiles = Split( "convert.c  interrupt.c  mpn_pylong.c  mpz_pylong.c") + \
         Split( "mpz_longlong.c stdsage.c  gmp_globals.c" )
cppFiles = Split( "ZZ_pylong.cpp  ntl_wrap.cpp" )
srcFiles = cFiles + cppFiles

lib = env.SharedLibrary( "csage", [ "src/" + x for x in srcFiles ],
                         LIBS=['ntl', 'gmp', 'pari'], LIBPATH=['$SAGE_LOCAL/lib'],
                         CPPPATH=includes )

env.Alias( "install", [ lib ] )

back to top