Author: Not specified Language: text
Description: Not specified Timestamp: 2015-05-15 13:08:03 -0400
View raw paste Reply
  1. debug = int( ARGUMENTS.get( 'debug', 0 ) )
  2. force32 = int( ARGUMENTS.get( 'force32', 0 ) )
  3.  
  4. def cmp_version( v1, v2 ):
  5.         def normalise( v ):
  6.                 import re
  7.                 return [int(x) for x in re.sub( r'(\.0+)*$', '', v ).split( '.' )]
  8.  
  9.         return cmp(
  10.                 normalise( v1 ),
  11.                 normalise( v2 )
  12.         )
  13.  
  14. import platform
  15. plat = platform.system() # Windows or Linux
  16. try:
  17.         bits = int( platform.architecture()[0][:2] ) # 32 or 64
  18. except( ValueError, TypeError ):
  19.         bits = None
  20. arch = None # platform-specific, set manually
  21.  
  22. # architecture settings, needed for binary names, also passed as a preprocessor definition
  23. if force32:
  24.         bits = 32
  25. if bits == 32:
  26.         if plat == 'Windows':
  27.                 arch = 'x86'
  28.         elif plat == 'Linux':
  29.                 if platform.machine()[:3] == 'arm':
  30.                         arch = 'arm'
  31.                 else:
  32.                         arch = 'i386'
  33.         elif plat == 'Darwin':
  34.                 arch = 'i386'
  35. elif bits == 64:
  36.         if plat == 'Windows':
  37.                 arch = 'x64'
  38.         else:
  39.                 arch = 'x86_64'
  40.  
  41. clangHack = plat == 'Darwin'
  42.  
  43. # fatal error if the cpu architecture can't be detected
  44. if arch is None:
  45.         raise Exception( 'could not determine architecture' )
  46. if bits is None:
  47.         raise Exception( 'could not determine architecture width' )
  48.  
  49. # create the build environment
  50. import os
  51. env = Environment( TARGET_ARCH = arch )
  52.  
  53. # ADDED FOR CHECKING LIBRARY AVAILABILITY REMOVE ME
  54. conf = Configure(env)
  55. if not conf.CheckLib('pthread'):
  56.     print 'Did not find libpthread.a or pthread.lib, exiting!'
  57.     Exit(1)
  58.  
  59. # END OF: ADDED FOR CHECKING LIBRARY AVAILABILITY REMOVE ME
  60.  
  61. env['CC'] = os.getenv( 'CC' ) or env[ 'CC' ]
  62. env['CXX'] = os.getenv( 'CXX' ) or env[ 'CXX' ]
  63. env['ENV'].update( x for x in os.environ.items() if x[0].startswith( 'CCC_' ) )
  64. if 'TERM' in os.environ:
  65.         env['ENV']['TERM'] = os.environ['TERM']
  66.  
  67. # prettify the compiler output
  68. import sys
  69. colours = {}
  70. colours['white'] = '\033[1;97m'
  71. colours['cyan'] = '\033[96m'
  72. colours['orange'] = '\033[33m'
  73. colours['green'] = '\033[92m'
  74. colours['end']  = '\033[0m'
  75.  
  76. # if the output is not a terminal, remove the colours
  77. if not sys.stdout.isatty():
  78.         for key in colours.keys():
  79.                 colours[key] = ''
  80.  
  81. env['SHCCCOMSTR'] = env['SHCXXCOMSTR'] = env['CCCOMSTR'] = env['CXXCOMSTR'] = \
  82.         '%s compiling: %s$SOURCE%s' % (colours['cyan'], colours['white'], colours['end'])
  83. env['ARCOMSTR'] = \
  84.         '%s archiving: %s$TARGET%s' % (colours['orange'], colours['white'], colours['end'])
  85. env['RANLIBCOMSTR'] = \
  86.         '%s  indexing: %s$TARGET%s' % (colours['orange'], colours['white'], colours['end'])
  87. env['ASCOMSTR'] = \
  88.         '%sassembling: %s$TARGET%s' % (colours['orange'], colours['white'], colours['end'])
  89. env['SHLINKCOMSTR'] = env['LINKCOMSTR'] = \
  90.         '%s   linking: %s$TARGET%s' % (colours['green'], colours['white'], colours['end'])
  91.  
  92. # obtain the compiler version
  93. import commands
  94. if plat == 'Windows':
  95.         ccversion = env['MSVC_VERSION']
  96. else:
  97.         status, ccrawversion = commands.getstatusoutput( env['CC'] + ' -dumpversion' )
  98.         ccversion = None if status else ccrawversion
  99.  
  100. # git revision
  101. status, rawrevision = commands.getstatusoutput( 'git rev-parse --short HEAD' )
  102. revision = None if status else rawrevision
  103.  
  104. # set job/thread count
  105. if plat == 'Linux' or plat == 'Darwin':
  106.         # works on recent mac/linux
  107.         status, num_cores = commands.getstatusoutput( 'getconf _NPROCESSORS_ONLN' )
  108.         if status != 0:
  109.                 # only works on linux
  110.                 status, num_cores = commands.getstatusoutput( 'cat /proc/cpuinfo | grep processor | wc -l' )
  111.         env.SetOption( 'num_jobs', int(num_cores) * 3 if status == 0 else 1 )
  112. elif plat == 'Windows':
  113.         num_cores = int( os.environ['NUMBER_OF_PROCESSORS'] )
  114.         env.SetOption( 'num_jobs', num_cores * 3 )
  115.  
  116. # notify the user of the build configuration
  117. if not env.GetOption( 'clean' ):
  118.         msg = 'Building for ' + plat + ' ' + str(bits) + ' bits (' + env['CC'] + ' ' + ccversion + ', python ' + platform.python_version() + ')'
  119.         if debug:
  120.                 msg += ', debug symbols'
  121.         if debug == 0 or debug == 2:
  122.                 msg += ', optimised'
  123.         msg += ', x87 fpu' if 'NO_SSE' in os.environ else ', SSE'
  124.         if force32:
  125.                 msg += ', forcing 32 bit build'
  126.         msg += ', ' + str(env.GetOption( 'num_jobs' )) + ' threads'
  127.         if revision:
  128.                 msg += '\ngit revision: ' + revision
  129.         print( msg )
  130.  
  131. # compiler switches
  132. if plat == 'Linux' or plat == 'Darwin':
  133.         env['CPPDEFINES'] = []
  134.         env['CFLAGS'] = []
  135.         env['CCFLAGS'] = []
  136.         env['CXXFLAGS'] = []
  137.  
  138.         # c warnings
  139.         env['CFLAGS'] += [ '-Wdeclaration-after-statement', '-Wnested-externs', '-Wold-style-definition',
  140.                 '-Wstrict-prototypes'
  141.         ]
  142.  
  143.         # c/cpp warnings
  144.         env['CCFLAGS'] += [ '-Wall', '-Wextra', '-Wno-missing-braces', '-Wno-missing-field-initializers',
  145.                 '-Wno-sign-compare', '-Wno-unused-parameter', '-Winit-self', '-Winline', '-Wmissing-include-dirs',
  146.                 '-Woverlength-strings', '-Wpointer-arith', '-Wredundant-decls', '-Wundef', '-Wuninitialized', '-Wwrite-strings'
  147.         ]
  148.  
  149.         # strict c/cpp warnings
  150.         if 'MORE_WARNINGS' in os.environ:
  151.                 env['CCFLAGS'] += [
  152.                         '-Waggregate-return',
  153.                         '-Wbad-function-cast',
  154.                         '-Wcast-qual',
  155.                         '-Wfloat-equal',
  156.                         '-Wlong-long',
  157.                         '-Wshadow',
  158.                         '-Wsign-conversion',
  159.                         '-Wswitch-default',
  160.                         '-Wunreachable-code'
  161.                 ]
  162.                 if not clangHack:
  163.                         env['CCFLAGS'] += [
  164.                                 '-Wdouble-promotion',
  165.                                 '-Wsuggest-attribute=const',
  166.                                 '-Wunsuffixed-float-constants'
  167.                         ]
  168.  
  169.         # gcc-specific warnings
  170.         if env['CC'] == 'gcc' and arch != 'arm' and not clangHack:
  171.                 env['CCFLAGS'] += [ '-Wlogical-op' ]
  172.  
  173.                 # requires gcc 4.7 or above
  174.                 if cmp_version( ccversion, '4.7' ) >= 0:
  175.                         env['CCFLAGS'] += [ '-Wstack-usage=32768' ]
  176.  
  177.         # disable warnings
  178.         env['CCFLAGS'] += [ '-Wno-char-subscripts' ]
  179.  
  180.         # c/cpp flags
  181.         if arch == 'arm':
  182.                 env['CCFLAGS'] += [ '-fsigned-char' ]
  183.         else:
  184.                 env['CCFLAGS'] += [ '-mstackrealign' ]
  185.                 if 'NO_SSE' in os.environ:
  186.                         env['CCFLAGS'] += [ '-mfpmath=387', '-mno-sse2', '-ffloat-store' ]
  187.                         if env['CC'] == 'gcc':
  188.                                 env['CCFLAGS'] += [ '-fexcess-precision=standard' ]
  189.                 else:
  190.                         env['CCFLAGS'] += [ '-mfpmath=sse', '-msse2' ]
  191.                 if arch == 'i386':
  192.                         env['CCFLAGS'] += [ '-m32', '-march=i686', '-pthread']
  193.                         env['LINKFLAGS'] += [ '-m32' ]
  194.                 elif arch == 'x86_64':
  195.                         env['CCFLAGS'] += [ '-mtune=generic' ]
  196.         env['CCFLAGS'] += [ '-fvisibility=default', '-fomit-frame-pointer' ]
  197.  
  198.         # c flags
  199.         env['CFLAGS'] += [ '-std=gnu99' ]
  200.  
  201.         # c++ flags
  202.         env['CXXFLAGS'] += [ '-fvisibility-inlines-hidden', '-std=c++11' ]
  203.  
  204. elif plat == 'Windows':
  205.         # assume msvc
  206.         env['CFLAGS'] = [ '/TC' ] # compile as c
  207.         env['CCFLAGS'] = [
  208.                 '/EHsc',                                # exception handling
  209.         #       '/errorReport:none',    # don't send error reports for internal compiler errors
  210.         #       '/FC',                                  # display full path of source code in error messages
  211.         #       '/Gd',                                  # use cdecl calling convention
  212.         #       '/GS',                                  # buffer security check
  213.                 '/nologo',                              # remove watermark
  214.         ]
  215.  
  216.         env['LINKFLAGS'] = [
  217.                 '/ERRORREPORT:none',    # don't send error reports for internal linker errors
  218.         #       '/MACHINE:' + arch,             # set the linker architecture
  219.                 '/NOLOGO',                              # remove watermark
  220.         ]
  221.         if bits == 64:
  222.                 env['LINKFLAGS'] += [ '/SUBSYSTEM:WINDOWS' ]    # graphical application
  223.         else:
  224.                 env['LINKFLAGS'] += [ '/SUBSYSTEM:WINDOWS,5.1' ]        # graphical application
  225.  
  226.         env['CPPDEFINES'] = [ '_WIN32' ]
  227.         if bits == 64:
  228.                 env['CPPDEFINES'] += [ '_WIN64' ]
  229.  
  230.         # multi-processor compilation
  231.         if num_cores > 1:
  232.                 env['CCFLAGS'] += [
  233.                 #       '/FS',                                                  # force synchronous writes to PDB file
  234.                 #       '/cgthreads' + str(num_cores),  # compiler threads to use for optimisation and code generation
  235.                 ]
  236.                 env['LINKFLAGS'] += [
  237.                 #       '/CGTHREADS:' + str(num_cores), # linker threads to use for optimisations and code generation
  238.                 ]
  239.  
  240.         # fpu control
  241.         if 'NO_SSE' in os.environ:
  242.                 env['CCFLAGS'] += [ '/fp:precise' ] # precise FP
  243.                 if bits == 32:
  244.                         env['CCFLAGS'] += [ '/arch:IA32' ] # no sse, x87 fpu
  245.         else:
  246.                 env['CCFLAGS'] += [ '/fp:strict' ] # strict FP
  247.                 if bits == 32:
  248.                         env['CCFLAGS'] += [ '/arch:SSE2' ] # sse2
  249.  
  250.         # strict c/cpp warnings
  251.         if 'LESS_WARNINGS' in os.environ:
  252.                 env['CPPDEFINES'] += [ '/W2' ]
  253.         else:
  254.                 env['CPPDEFINES'] += [
  255.                         '/W4',
  256.                         '/Wall',
  257.                         '/we 4013',
  258.                         '/we 4024',
  259.                         '/we 4026',
  260.                         '/we 4028',
  261.                         '/we 4029',
  262.                         '/we 4033',
  263.                         '/we 4047',
  264.                         '/we 4053',
  265.                         '/we 4087',
  266.                         '/we 4098',
  267.                         '/we 4245',
  268.                         '/we 4305',
  269.                         '/we 4700'
  270.                 ]
  271.         if 'MORE_WARNINGS' not in os.environ:
  272.                 env['CPPDEFINES'] += [
  273.                         '/wd 4100',
  274.                         '/wd 4127',
  275.                         '/wd 4244',
  276.                         '/wd 4706',
  277.                         '/wd 4131',
  278.                         '/wd 4996'
  279.                 ]
  280.  
  281.         env['LINKFLAGS'] += [
  282.                 '/NODEFAULTLIB:LIBCMTD',
  283.                 '/NODEFAULTLIB:MSVCRT',
  284.         ]
  285.  
  286. if plat == 'Darwin':
  287.         env['CPPDEFINES'] += [ 'MACOS_X' ]
  288.  
  289. # debug / release
  290. if debug == 0 or debug == 2:
  291.         if plat == 'Linux' or plat == 'Darwin':
  292.                 env['CCFLAGS'] += [ '-O3' ]
  293.                 if debug == 0 and not clangHack:
  294.                         env['LINKFLAGS'] += [ '-s' ]
  295.         elif plat == 'Windows':
  296.                 env['CCFLAGS'] += [
  297.                 #       '/c',   # compile without linking
  298.                 #       '/GL',  # whole program optimisation
  299.                 #       '/Gw',  # optimise global data
  300.                 #       '/MP',  # multiple process compilation
  301.                         '/O2',  # maximise speed
  302.                 ]
  303.                 env['LINKFLAGS'] += [
  304.                 #       '/INCREMENTAL:NO',      # don't incrementally link
  305.                 #       '/LTCG',                        # link-time code generation
  306.                         '/OPT:REF',                     # remove unreferenced functions/data
  307.                         '/STACK:32768',         # stack size
  308.                 ]
  309.  
  310.         if debug == 0:
  311.                 env['CPPDEFINES'] += [ 'NDEBUG' ]
  312.  
  313. if debug:
  314.         if plat == 'Linux' or plat == 'Darwin':
  315.                 env['CCFLAGS'] += [ '-g3' ]
  316.         elif plat == 'Windows':
  317.                 env['CCFLAGS'] += [
  318.                 #       '/GF',          # string pooling
  319.                 #       '/Gy',          # function level linking
  320.                         '/Od',          # disable optimisations
  321.                 #       '/Oy-',         # disable frame pointer omission
  322.                 #       '/RTC1',        # runtime checks
  323.                         '/Z7',          # emit debug information
  324.                     '/MDd',
  325.                 ]
  326.                 env['LINKFLAGS'] += [
  327.                         '/DEBUG',               # generate debug info
  328.                 #       '/INCREMENTAL', # incrementally link
  329.                 ]
  330.  
  331.         env['CPPDEFINES'] += [ '_DEBUG' ]
  332.  
  333. if revision:
  334.         env['CPPDEFINES'] += [ 'REVISION=\\"' + revision + '\\"' ]
  335.  
  336. env['CPPDEFINES'] += [ 'SCONS_BUILD' ]
  337. env['CPPPATH'] = [ '#', '../game' ]
  338. env['LIBPATH'] = [ '#/libs/' + plat + '/' + str(bits) + '/' ]
  339.  
  340. if debug == 1:
  341.         configuration = 'debug'
  342. elif debug == 2:
  343.         configuration = 'optimised-debug'
  344. else:
  345.         configuration = 'release'
  346.  
  347. # invoke the per-project scripts
  348. projects = [
  349.         'game',
  350.         'cgame',
  351.         'ui'
  352. ]
  353. for project in projects:
  354.         env.SConscript(
  355.                 os.path.join( project, 'SConscript' ),
  356.                 exports = [ 'arch', 'bits', 'configuration', 'env', 'plat' ]
  357.         )
View raw paste Reply