Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 1 | import os |
| 2 | import os.path |
| 3 | import sys |
| 4 | |
| 5 | JSONCPP_VERSION = '0.1' |
| 6 | DIST_DIR = '#dist' |
| 7 | |
| 8 | options = Options() |
| 9 | options.Add( EnumOption('platform', |
| 10 | 'Platform (compiler/stl) used to build the project', |
| 11 | 'msvc71', |
| 12 | allowed_values='suncc vacpp mingw msvc6 msvc7 msvc71 msvc80 linux-gcc'.split(), |
| 13 | ignorecase=2) ) |
| 14 | |
| 15 | try: |
| 16 | platform = ARGUMENTS['platform'] |
| 17 | except KeyError: |
| 18 | print 'You must specify a "platform"' |
| 19 | sys.exit(2) |
| 20 | |
| 21 | print "Building using PLATFORM =", platform |
| 22 | |
| 23 | rootbuild_dir = Dir('#buildscons') |
| 24 | build_dir = os.path.join( '#buildscons', platform ) |
| 25 | bin_dir = os.path.join( '#bin', platform ) |
| 26 | lib_dir = os.path.join( '#libs', platform ) |
| 27 | sconsign_dir_path = Dir(build_dir).abspath |
| 28 | sconsign_path = os.path.join( sconsign_dir_path, '.sconsign.dbm' ) |
| 29 | |
| 30 | # Ensure build directory exist (SConsignFile fail otherwise!) |
| 31 | if not os.path.exists( sconsign_dir_path ): |
| 32 | os.makedirs( sconsign_dir_path ) |
| 33 | |
| 34 | # Store all dependencies signature in a database |
| 35 | SConsignFile( sconsign_path ) |
| 36 | |
| 37 | env = Environment( ENV = {'PATH' : os.environ['PATH']}, |
| 38 | toolpath = ['scons-tools'], |
| 39 | tools=[] ) #, tools=['default'] ) |
| 40 | |
| 41 | if platform == 'suncc': |
| 42 | env.Tool( 'sunc++' ) |
| 43 | env.Tool( 'sunlink' ) |
| 44 | env.Tool( 'sunar' ) |
| 45 | env.Append( LIBS = ['pthreads'] ) |
| 46 | elif platform == 'vacpp': |
| 47 | env.Tool( 'default' ) |
| 48 | env.Tool( 'aixcc' ) |
| 49 | env['CXX'] = 'xlC_r' #scons does not pick-up the correct one ! |
| 50 | # using xlC_r ensure multi-threading is enabled: |
| 51 | # http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ibm.vacpp7a.doc/compiler/ref/cuselect.htm |
| 52 | env.Append( CCFLAGS = '-qrtti=all', |
| 53 | LINKFLAGS='-bh:5' ) # -bh:5 remove duplicate symbol warning |
| 54 | elif platform == 'msvc6': |
| 55 | env['MSVS_VERSION']='6.0' |
| 56 | for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']: |
| 57 | env.Tool( tool ) |
| 58 | env['CXXFLAGS']='-GR -GX /nologo /MT' |
| 59 | elif platform == 'msvc70': |
| 60 | env['MSVS_VERSION']='7.0' |
| 61 | for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']: |
| 62 | env.Tool( tool ) |
| 63 | env['CXXFLAGS']='-GR -GX /nologo /MT' |
| 64 | elif platform == 'msvc71': |
| 65 | env['MSVS_VERSION']='7.1' |
| 66 | for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']: |
| 67 | env.Tool( tool ) |
| 68 | env['CXXFLAGS']='-GR -GX /nologo /MT' |
| 69 | elif platform == 'msvc80': |
| 70 | env['MSVS_VERSION']='8.0' |
| 71 | for tool in ['msvc', 'msvs', 'mslink', 'masm', 'mslib']: |
| 72 | env.Tool( tool ) |
| 73 | env['CXXFLAGS']='-GR -EHsc /nologo /MT' |
| 74 | elif platform == 'mingw': |
| 75 | env.Tool( 'mingw' ) |
| 76 | env.Append( CPPDEFINES=[ "WIN32", "NDEBUG", "_MT" ] ) |
| 77 | elif platform == 'linux-gcc': |
| 78 | env.Tool( 'default' ) |
| 79 | env.Append( LIBS = ['pthread'], CCFLAGS = "-Wall" ) |
Christopher Dunn | d2fdeb3 | 2007-06-14 19:32:40 +0000 | [diff] [blame^] | 80 | LD_LIBRARY_PATH = os.environ.get('LD_LIBRARY_PATH', '') |
| 81 | os.environ['LD_LIBRARY_PATH'] = "%s:libs/linux-gcc" %LD_LIBRARY_PATH |
Christopher Dunn | e0d7224 | 2007-06-14 17:58:59 +0000 | [diff] [blame] | 82 | else: |
| 83 | print "UNSUPPORTED PLATFORM." |
| 84 | env.Exit(1) |
| 85 | |
| 86 | env.Tool('doxygen') |
| 87 | env.Tool('substinfile') |
| 88 | env.Tool('targz') |
| 89 | env.Tool('srcdist') |
| 90 | |
| 91 | env.Append( CPPPATH = ['#include'], |
| 92 | LIBPATH = lib_dir ) |
| 93 | short_platform = platform |
| 94 | if short_platform.startswith('msvc'): |
| 95 | short_platform = short_platform[2:] |
| 96 | env['LIB_PLATFORM'] = short_platform |
| 97 | env['LIB_LINK_TYPE'] = 'lib' # static |
| 98 | env['LIB_CRUNTIME'] = 'mt' |
| 99 | env['LIB_NAME_SUFFIX'] = '${LIB_PLATFORM}_${LIB_LINK_TYPE}${LIB_CRUNTIME}' # must match autolink naming convention |
| 100 | env['JSONCPP_VERSION'] = JSONCPP_VERSION |
| 101 | env['BUILD_DIR'] = env.Dir(build_dir) |
| 102 | env['ROOTBUILD_DIR'] = env.Dir(rootbuild_dir) |
| 103 | env['DIST_DIR'] = DIST_DIR |
| 104 | class SrcDistAdder: |
| 105 | def __init__( self, env ): |
| 106 | self.env = env |
| 107 | def __call__( self, *args, **kw ): |
| 108 | apply( self.env.SrcDist, (self.env['SRCDIST_TARGET'],) + args, kw ) |
| 109 | env['SRCDIST_ADD'] = SrcDistAdder( env ) |
| 110 | env['SRCDIST_TARGET'] = os.path.join( DIST_DIR, 'jsoncpp-src-%s.tar.gz' % env['JSONCPP_VERSION'] ) |
| 111 | env['SRCDIST_BUILDER'] = env.TarGz |
| 112 | |
| 113 | env_testing = env.Copy( ) |
| 114 | env_testing.Append( LIBS = ['json_${LIB_NAME_SUFFIX}'] ) |
| 115 | |
| 116 | def buildJSONExample( env, target_sources, target_name ): |
| 117 | env = env.Copy() |
| 118 | env.Append( CPPPATH = ['#'] ) |
| 119 | exe = env.Program( target=target_name, |
| 120 | source=target_sources ) |
| 121 | env['SRCDIST_ADD']( source=[target_sources] ) |
| 122 | global bin_dir |
| 123 | return env.Install( bin_dir, exe ) |
| 124 | |
| 125 | def buildJSONTests( env, target_sources, target_name ): |
| 126 | jsontests_node = buildJSONExample( env, target_sources, target_name ) |
| 127 | check_alias_target = env.Alias( 'check', jsontests_node, RunJSONTests( jsontests_node, jsontests_node ) ) |
| 128 | env.AlwaysBuild( check_alias_target ) |
| 129 | |
| 130 | def buildLibrary( env, target_sources, target_name ): |
| 131 | static_lib = env.StaticLibrary( target=target_name + '_${LIB_NAME_SUFFIX}', |
| 132 | source=target_sources ) |
| 133 | shared_lib = env.SharedLibrary( target=target_name + '_${LIB_NAME_SUFFIX}', |
| 134 | source=target_sources ) |
| 135 | global lib_dir |
| 136 | env.Install( lib_dir, static_lib ) |
| 137 | env.Install( lib_dir, shared_lib ) |
| 138 | env['SRCDIST_ADD']( source=[target_sources] ) |
| 139 | |
| 140 | Export( 'env env_testing buildJSONExample buildLibrary buildJSONTests' ) |
| 141 | |
| 142 | def buildProjectInDirectory( target_directory ): |
| 143 | global build_dir |
| 144 | target_build_dir = os.path.join( build_dir, target_directory ) |
| 145 | target = os.path.join( target_directory, 'sconscript' ) |
| 146 | SConscript( target, build_dir=target_build_dir, duplicate=0 ) |
| 147 | env['SRCDIST_ADD']( source=[target] ) |
| 148 | |
| 149 | |
| 150 | def runJSONTests_action( target, source = None, env = None ): |
| 151 | # Add test scripts to python path |
| 152 | jsontest_path = Dir( '#test' ).abspath |
| 153 | sys.path.insert( 0, jsontest_path ) |
| 154 | import runjsontests |
| 155 | return runjsontests.runAllTests( os.path.abspath(source), jsontest_path ) |
| 156 | |
| 157 | def runJSONTests_string( target, source = None, env = None ): |
| 158 | return 'RunJSONTests("%s")' % source |
| 159 | |
| 160 | ##def buildDoc( doxyfile_path ): |
| 161 | ## doc_cmd = env.Doxygen( doxyfile_path ) |
| 162 | |
| 163 | import SCons.Action |
| 164 | ActionFactory = SCons.Action.ActionFactory |
| 165 | RunJSONTests = ActionFactory(runJSONTests_action, runJSONTests_string ) |
| 166 | |
| 167 | env.Alias( 'check' ) |
| 168 | |
| 169 | srcdist_cmd = env['SRCDIST_ADD']( source = """ |
| 170 | AUTHORS README.txt SConstruct |
| 171 | """.split() ) |
| 172 | env.Alias( 'src-dist', srcdist_cmd ) |
| 173 | |
| 174 | buildProjectInDirectory( 'src/jsontestrunner' ) |
| 175 | buildProjectInDirectory( 'src/lib_json' ) |
| 176 | buildProjectInDirectory( 'doc' ) |