X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=scons%2Fgeneric.py;h=7592222fd6a4c3bf7169580adb6e4009bc168cf0;hb=1a693e90b5594651a3b17f47c7f5f094088c502f;hp=f0bb3de9fcd43ac410b3b9b20408d6c3e21bbda0;hpb=374cf77b2f0f13f9380fb0c9d804222a83bdc2e0;p=mesa.git diff --git a/scons/generic.py b/scons/generic.py index f0bb3de9fcd..7592222fd6a 100644 --- a/scons/generic.py +++ b/scons/generic.py @@ -206,6 +206,25 @@ _bool_map = { } +def num_jobs(): + try: + return int(os.environ['NUMBER_OF_PROCESSORS']) + except (ValueError, KeyError): + pass + + try: + return os.sysconf('SC_NPROCESSORS_ONLN') + except (ValueError, OSError, AttributeError): + pass + + try: + return int(os.popen2("sysctl -n hw.ncpu")[1].read()) + except ValueError: + pass + + return 1 + + def generate(env): """Common environment generation code""" @@ -239,6 +258,11 @@ def generate(env): if env['toolchain'] == 'crossmingw' and env['machine'] not in ('generic', 'x86'): env['machine'] = 'x86' + try: + env['MSVS_VERSION'] = ARGUMENTS['MSVS_VERSION'] + except KeyError: + pass + # Build type env['debug'] = _bool_map[ARGUMENTS.get('debug', 'no')] env['profile'] = _bool_map[ARGUMENTS.get('profile', 'no')] @@ -246,7 +270,7 @@ def generate(env): # Put build output in a separate dir, which depends on the current # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample try: - env['variant_dir'] = ARGUMENTS['variant_dir'] + env['build'] = ARGUMENTS['build'] except KeyError: build_topdir = 'build' build_subdir = env['platform'] @@ -256,11 +280,14 @@ def generate(env): build_subdir += "-debug" if env['profile']: build_subdir += "-profile" - env['variant_dir'] = os.path.join(build_topdir, build_subdir) + env['build'] = os.path.join(build_topdir, build_subdir) # Place the .sconsign file in the build dir too, to avoid issues with # different scons versions building the same source file - #env.VariantDir(env['variant_dir'] - #env.SConsignFile(os.path.join(env['variant_dir'], '.sconsign')) + env.SConsignFile(os.path.join(env['build'], '.sconsign')) + + # Parallel build + if env.GetOption('num_jobs') <= 1: + env.SetOption('num_jobs', num_jobs()) # Summary print @@ -269,7 +296,8 @@ def generate(env): print ' toolchain=%s' % env['toolchain'] print ' debug=%s' % ['no', 'yes'][env['debug']] print ' profile=%s' % ['no', 'yes'][env['profile']] - #print ' variant_dir=%s' % env['variant_dir'] + print ' build=%s' % env['build'] + print ' %s jobs' % env.GetOption('num_jobs') print # Load tool chain @@ -299,7 +327,7 @@ def generate(env): #'_UNICODE', #'UNICODE', # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx, - 'WIN32_LEAN_AND_MEAN', + #'WIN32_LEAN_AND_MEAN', 'VC_EXTRALEAN', '_CRT_SECURE_NO_DEPRECATE', ] @@ -358,24 +386,26 @@ def generate(env): ]) # C compiler options - cflags = [] + cflags = [] # C + cxxflags = [] # C++ + ccflags = [] # C & C++ if gcc: if debug: - cflags += ['-O0', '-g3'] + ccflags += ['-O0', '-g3'] else: - cflags += ['-O3', '-g0'] + ccflags += ['-O3', '-g0'] if env['profile']: - cflags += ['-pg'] + ccflags += ['-pg'] if env['machine'] == 'x86': - cflags += [ + ccflags += [ '-m32', #'-march=pentium4', '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics #'-mfpmath=sse', ] if env['machine'] == 'x86_64': - cflags += ['-m64'] - cflags += [ + ccflags += ['-m64'] + ccflags += [ '-Wall', '-Wmissing-prototypes', '-Wno-long-long', @@ -383,43 +413,47 @@ def generate(env): '-pedantic', '-fmessage-length=0', # be nice to Eclipse ] + cflags += [ + '-Wmissing-prototypes', + ] if msvc: # See also: # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx # - cl /? if debug: - cflags += [ + ccflags += [ '/Od', # disable optimizations '/Oi', # enable intrinsic functions '/Oy-', # disable frame pointer omission + '/GL-', # disable whole program optimization ] else: - cflags += [ + ccflags += [ '/Ox', # maximum optimizations '/Oi', # enable intrinsic functions '/Ot', # favor code speed #'/fp:fast', # fast floating point ] if env['profile']: - cflags += [ + ccflags += [ '/Gh', # enable _penter hook function '/GH', # enable _pexit hook function ] - cflags += [ + ccflags += [ '/W3', # warning level #'/Wp64', # enable 64 bit porting warnings ] if env['machine'] == 'x86': - cflags += [ + ccflags += [ #'/QIfist', # Suppress _ftol #'/arch:SSE2', # use the SSE2 instructions ] if platform == 'windows': - cflags += [ + ccflags += [ # TODO ] if platform == 'winddk': - cflags += [ + ccflags += [ '/Zl', # omit default library name in .OBJ '/Zp8', # 8bytes struct member alignment '/Gy', # separate functions for linker @@ -438,7 +472,7 @@ def generate(env): ] if platform == 'wince': # See also C:\WINCE600\public\common\oak\misc\makefile.def - cflags += [ + ccflags += [ '/Zl', # omit default library name in .OBJ '/GF', # enable read-only string pooling '/GR-', # disable C++ RTTI @@ -455,9 +489,20 @@ def generate(env): # See http://scons.tigris.org/issues/show_bug.cgi?id=1656 env.EnsureSConsVersion(0, 98, 0) env['PDB'] = '${TARGET.base}.pdb' + env.Append(CCFLAGS = ccflags) env.Append(CFLAGS = cflags) - env.Append(CXXFLAGS = cflags) + env.Append(CXXFLAGS = cxxflags) + if env['platform'] == 'windows' and msvc: + # Choose the appropriate MSVC CRT + # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx + if env['debug']: + env.Append(CCFLAGS = ['/MTd']) + env.Append(SHCCFLAGS = ['/LDd']) + else: + env.Append(CCFLAGS = ['/MT']) + env.Append(SHCCFLAGS = ['/LD']) + # Assembler options if gcc: if env['machine'] == 'x86': @@ -472,9 +517,14 @@ def generate(env): linkflags += ['-m32'] if env['machine'] == 'x86_64': linkflags += ['-m64'] - if platform == 'winddk': + if platform == 'windows' and msvc: # See also: # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx + linkflags += [ + '/fixed:no', + '/incremental:no', + ] + if platform == 'winddk': linkflags += [ '/merge:_PAGE=PAGE', '/merge:_TEXT=.text',