wscript_user_sample.py (5509B)
1 import os 2 compilers = ['gcc', 'clang', 'clang-msvc', 'clang-msvc64'] 3 configs = ['debug', 'rel-test', 'rel'] 4 5 import itertools 6 variants = list(map(lambda x: '%s-%s' % x, itertools.product(compilers, configs))) 7 8 def my_configure(cfg): 9 bdir = cfg.path.abspath() 10 11 gcc = 'gcc' 12 gxx = 'g++' 13 clang_bin = os.path.expanduser('~/llvm/prefix/bin/') 14 clang_flags = [ 15 '-stdlib=libc++', '-ferror-limit=5', '-ftemplate-backtrace-limit=0', 16 '-march=native' 17 ] 18 clang_linkflags = [ 19 '-stdlib=libc++', '-fuse-ld=lld', '-march=native' 20 ] 21 22 vcdir = '/mnt/msvc/vc12' 23 # i386 and x86_64 24 clang_win32_tgt = [ '-target', 'i386-pc-windows-msvc18' ] 25 clang_win64_tgt = [ '-target', 'x86_64-pc-windows-msvc18' ] 26 clang_win_cxxflags = [ 27 '-march=x86-64', 28 '-fms-compatibility-version=18', 29 '-Xclang', '-internal-isystem', '-Xclang', vcdir+'/include', 30 '-Xclang', '-internal-isystem', '-Xclang', vcdir+'/win_sdk/include/um', 31 '-Xclang', '-internal-isystem', '-Xclang', vcdir+'/win_sdk/include/shared', 32 '-DDOCTEST_CONFIG_COLORS_ANSI', 33 '-ferror-limit=5', 34 ] 35 clang_win32_linkflags = clang_win32_tgt + [ 36 '-fuse-ld=lld', 37 '-L%s/lib' % vcdir, 38 '-L%s/win_sdk/lib/winv6.3/um/x86' % vcdir, 39 ] 40 clang_win64_linkflags = clang_win64_tgt + [ 41 '-fuse-ld=lld', 42 '-L%s/lib/amd64' % vcdir, 43 '-L%s/win_sdk/lib/winv6.3/um/x64' % vcdir, 44 ] 45 46 cfg.options.host_lua = 'luajit' 47 cfg.options.lua_dll = True 48 49 for comp in compilers: 50 for conf in configs: 51 var = '%s-%s' % (comp, conf) 52 if var not in variants: continue 53 54 cfg.setenv(var) 55 if comp == 'gcc': 56 cfg.env.AR = 'gcc-ar' 57 cfg.env.CC = gcc 58 cfg.env.CXX = gxx 59 cfg.env.CXXFLAGS = ['-march=native'] 60 cfg.env.LINKFLAGS = ['-march=native'] 61 cfg.environ.pop('HOST_CC', None) 62 cfg.environ.pop('HOST_CXX', None) 63 cfg.options.all_system = None 64 elif comp == 'clang': 65 cfg.env.AR = clang_bin+'llvm-ar' 66 cfg.env.CC = clang_bin+'clang' 67 cfg.env.CXX = clang_bin+'clang++' 68 cfg.env.CXXFLAGS = clang_flags 69 cfg.env.LINKFLAGS = clang_linkflags 70 cfg.environ.pop('HOST_CC', None) 71 cfg.environ.pop('HOST_CXX', None) 72 cfg.options.all_system = 'bundle' 73 else: # clang-msvc* 74 cfg.env.AR = clang_bin+'llvm-ar' 75 cfg.env.CC = clang_bin+'clang' 76 cfg.env.CXX = clang_bin+'clang++' 77 cfg.environ['HOST_CC'] = 'gcc' 78 cfg.environ['HOST_CXX'] = 'g++' 79 cfg.options.all_system = 'bundle' 80 81 if comp == 'clang-msvc': 82 cfg.environ['WINRC'] = 'i686-w64-mingw32-windres' 83 cfg.env.CXXFLAGS = cfg.env.CFLAGS = \ 84 clang_win32_tgt + clang_win_cxxflags 85 cfg.env.LINKFLAGS = clang_win32_linkflags 86 elif comp == 'clang-msvc64': 87 cfg.environ['WINRC'] = 'x86_64-w64-mingw32-windres' 88 cfg.env.CXXFLAGS = cfg.env.CFLAGS = \ 89 clang_win64_tgt + clang_win_cxxflags 90 cfg.env.LINKFLAGS = clang_win64_linkflags 91 else: 92 error() 93 94 cfg.options.optimize_ext = True 95 if conf == 'debug': 96 cfg.options.optimize = False 97 cfg.options.release = False 98 cfg.options.with_tests = True 99 elif conf == 'rel-test': 100 cfg.options.optimize = True 101 cfg.options.release = True 102 cfg.options.with_tests = True 103 elif conf == 'rel': 104 cfg.options.optimize = True 105 cfg.options.release = True 106 cfg.options.with_tests = False 107 else: 108 error() 109 configure(cfg) 110 111 from waflib.Configure import ConfigurationContext 112 class my_configure_cls(ConfigurationContext): 113 cmd = 'my_configure' 114 fun = 'my_configure' 115 116 from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext 117 118 def init(ctx): 119 for x in variants: 120 for y in (BuildContext, CleanContext, InstallContext, UninstallContext): 121 name = y.__name__.replace('Context','').lower() 122 class tmp(y): 123 cmd = '%s-%s' % (name, x) 124 variant = x 125 126 127 from waflib import Utils, Build 128 class buildall_ctx(Build.BuildContext): 129 cmd = fun = 'buildall' 130 def compile(self): 131 pass 132 133 def buildall(ctx): 134 _build_many(ctx, variants) 135 136 def _build_many(ctx, variants): 137 from waflib import Options, Task 138 sem = Utils.threading.Semaphore(Options.options.jobs) 139 def with_sem(f): 140 def f2(self): 141 sem.acquire() 142 f(self) 143 sem.release() 144 return f2 145 Task.TaskBase.process = with_sem(Task.TaskBase.process) 146 147 threads = [] 148 for var in variants: 149 cls = type(Build.BuildContext)(var, (Build.BuildContext,), {'cmd': var, 'variant': var}) 150 bld = cls(top_dir=ctx.top_dir, out_dir=ctx.out_dir) 151 bld.targets = ctx.targets 152 t = Utils.threading.Thread() 153 t.run = bld.execute 154 threads.append(t) 155 156 for t in threads: t.start() 157 for t in threads: t.join()