| 1 | ## |
|---|
| 2 | ## c_lib SConstruct file |
|---|
| 3 | ## |
|---|
| 4 | ## Author: Joel Mohler (original file) |
|---|
| 5 | ## Craig Citro (minor edits) |
|---|
| 6 | ## |
|---|
| 7 | ## |
|---|
| 8 | ## 07 Sep 01: |
|---|
| 9 | ## I added a fix for trac ticket 555, which is to add the "install_lib" |
|---|
| 10 | ## and "install_includes" below. |
|---|
| 11 | ## This is not the most elegant approach, I think. The problem is this: |
|---|
| 12 | ## I (= Craig Citro) don't understand how to tell scons that it should |
|---|
| 13 | ## look at /sage/local/libcsage.dylib to see if *it* is up to date. So |
|---|
| 14 | ## what happens is that you change libcsage in branch foo, do a sage -b bar, |
|---|
| 15 | ## and since you haven't modified sage-bar/c_lib/libcsage.dylib, scons |
|---|
| 16 | ## doesn't think it needs to reinstall libcsage.dylib into |
|---|
| 17 | ## $SAGE_ROOT/local/lib. This is obviously problematic; the best solution |
|---|
| 18 | ## I could come up with is just always copying all the libraries and |
|---|
| 19 | ## headers into $SAGE_ROOT where they belong. |
|---|
| 20 | ## |
|---|
| 21 | ## I also edited a bunch of lines below so that they didn't go over 80 chars, |
|---|
| 22 | ## because I don't like seeing wrapped lines. |
|---|
| 23 | import os |
|---|
| 24 | |
|---|
| 25 | # Note that SCons's strong point is not the './configure' step of |
|---|
| 26 | # autotools. However, for this build we know that we are in a |
|---|
| 27 | # SAGE local filesystem. Once we have SAGE_LOCAL imported, we |
|---|
| 28 | # know where everything is. |
|---|
| 29 | env = Environment() |
|---|
| 30 | |
|---|
| 31 | # By default, SCons hashes the source file contents to determine |
|---|
| 32 | # if rebuilds are necessary. If you like the old way better, |
|---|
| 33 | # uncomment this to use timestamps. |
|---|
| 34 | #env.SourceSignatures('timestamp') |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | # Since the sage build of python is only a static library, |
|---|
| 38 | # we just suppress the undefined python symbols. I don't |
|---|
| 39 | # really understand the other options (-single_module and |
|---|
| 40 | # -flat_namespace). I can't find the documentation. |
|---|
| 41 | ## |
|---|
| 42 | ## These extra link flags make OS X play nice with building a dynamic |
|---|
| 43 | ## library. -undefined dynamic_lookup is being used instead of |
|---|
| 44 | ## -undefined suppress -- they should do basically the same thing ( |
|---|
| 45 | ## tell the linker it's okay to ignore undefined symbols at link time), |
|---|
| 46 | ## but there's a possibility that -undefined suppress will throw an |
|---|
| 47 | ## error, whereas -undefined dynamic_lookup will definitely try to find |
|---|
| 48 | ## missing symbols at runtime. |
|---|
| 49 | ## The other two options control the way the linker creates a namespace |
|---|
| 50 | ## for the dynamic library; check the man page for ld on a mac to see |
|---|
| 51 | ## the details. |
|---|
| 52 | if env['PLATFORM']=="darwin": |
|---|
| 53 | env.Append( LINKFLAGS="-single_module -flat_namespace -undefined dynamic_lookup" ) |
|---|
| 54 | |
|---|
| 55 | # SCons doesn't automatically pull in system environment variables |
|---|
| 56 | # However, we only need SAGE_LOCAL, so that's easy. |
|---|
| 57 | env['SAGE_LOCAL'] = os.environ['SAGE_LOCAL'] |
|---|
| 58 | |
|---|
| 59 | def copy_all_includes( target, source, env ): |
|---|
| 60 | path = os.environ['SAGE_LOCAL'] + "/include" |
|---|
| 61 | for f in source: |
|---|
| 62 | Copy( path, f ) |
|---|
| 63 | return None |
|---|
| 64 | |
|---|
| 65 | # The SCons convenience function Split is the only strange thing |
|---|
| 66 | # to python programmers. It just makes a list by splitting on |
|---|
| 67 | # whitespace without the syntax clutter of lists of strings. |
|---|
| 68 | includes = ['$SAGE_LOCAL/include/', '$SAGE_LOCAL/include/python2.5/', |
|---|
| 69 | '$SAGE_LOCAL/include/NTL/'] |
|---|
| 70 | cFiles = Split( "interrupt.c mpn_pylong.c mpz_pylong.c stdsage.c" ) |
|---|
| 71 | cppFiles = Split( "ZZ_pylong.cpp ntl_wrap.cpp" ) |
|---|
| 72 | |
|---|
| 73 | includes_to_install = Split( "ZZ_pylong.h ccobject.h interrupt.h") + \ |
|---|
| 74 | Split( "mpn_pylong.h mpz_pylong.h ntl_wrap.h stdsage.h" ) |
|---|
| 75 | lib = env.SharedLibrary( "csage", cFiles + cppFiles, |
|---|
| 76 | LIBS=['ntl', 'gmp'], LIBPATH=['$SAGE_LOCAL/lib'], |
|---|
| 77 | CPPPATH=includes ) |
|---|
| 78 | |
|---|
| 79 | env.Install( "$SAGE_LOCAL/include", includes_to_install ) |
|---|
| 80 | env.Install( "$SAGE_LOCAL/lib", lib ) |
|---|
| 81 | |
|---|
| 82 | Command( "install_includes", includes_to_install, copy_all_includes ) |
|---|
| 83 | Command( "install_lib", lib, Copy( env['SAGE_LOCAL'] + "/lib", lib ) ) |
|---|
| 84 | |
|---|
| 85 | env.Alias( "install", ["$SAGE_LOCAL/include", "$SAGE_LOCAL/lib", |
|---|
| 86 | "install_includes", "install_lib"] ) |
|---|