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