1 Star 0 Fork 121

blog/kbengine

forked from likecg/kbengine 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
SConstruct 9.98 KB
一键复制 编辑 原始数据 按行查看 历史
kbengine 提交于 2012-09-05 14:27 +08:00 .
import os, sys, platform
def bitscanrev(x, c=-1):
return bitscanrev(x/2, c+1) if x else c
architectures = ["generic", "x86", "x64"]
env = Environment()
#print env['TOOLS']
AddOption('--postfix', dest='postfix', nargs=1, default='_d', help='appends a string to the DLL name')
AddOption('--debugbuild', dest='debug', nargs='?', const=True, help='enable debug build')
AddOption('--static', dest='static', nargs='?', const=True, help='build a static library rather than shared library')
AddOption('--pgo', dest='pgo', nargs='?', const=True, help='build PGO instrumentation')
AddOption('--debugprint', dest='debugprint', nargs='?', const=True, help='enable lots of debug printing (windows only)')
AddOption('--fullsanitychecks', dest='fullsanitychecks', nargs='?', const=True, help='enable full sanity checking on every memory op')
AddOption('--force32', dest='force32', help='force 32 bit build on 64 bit machine')
AddOption('--sse', dest='sse', nargs=1, type='int', default=1, help='set SSE used (0-4) on 32 bit x86. Defaults to 1 (SSE1).')
AddOption('--replacesystemallocator', dest='replacesystemallocator', nargs='?', const=True, help='replace all usage of the system allocator in the process when loaded')
AddOption('--tolerant', dest='tolerant', nargs=1, default=1, help='enable tolerance of the system allocator (not guaranteed). On by default.')
AddOption('--magicheaders', dest='magicheaders', nargs='?', const=True, help='enable magic headers (guaranteed tolerance of the system allocator)')
AddOption('--useallocator', dest='useallocator', nargs=1, type='int', default=1, help='which allocator to use')
AddOption('--uselocks', dest='uselocks', nargs=1, type='int', default=1, help='which form of locking to use')
AddOption('--nospinlocks', dest='nospinlocks', nargs='?', const=True, help='use system mutexs rather than CPU spinlocks')
AddOption('--largepages', dest='largepages', nargs='?', const=True, help='enable large page support')
AddOption('--fastheapdetection', dest='fastheapdetection', nargs='?', const=True, help='enable fast system-specific heap detection')
AddOption('--maxthreadsinpool', dest='maxthreadsinpool', nargs=1, type='int', help='sets how much memory bloating to cause for more performance')
AddOption('--defaultgranularity', dest='defaultgranularity', nargs=1, type='int', help='sets how much memory to claim or release from the system at one time')
AddOption('--threadcachemax', dest='threadcachemax', nargs=1, type='string', help='sets what allocations should use the threadcache')
AddOption('--threadcachemaxbins', dest='threadcachemaxbins', nargs=1, type='int', help='sets the threadcache binning')
AddOption('--threadcachemaxfreespace', dest='threadcachemaxfreespace', nargs=1, type='int', help='sets when the threadcache should be garbage collected')
AddOption('--adminuac', dest='adminuac', nargs='?', const=True, help='Windows only. Link with UAC:requireAdmin to force all test apps to run as Administrator')
# Force scons to always use absolute paths in everything (helps debuggers to find source files)
env['CCCOM'] = env['CCCOM'].replace('$CHANGED_SOURCES','$SOURCES.abspath')
env['SHCCCOM'] = env['SHCCCOM'].replace('$CHANGED_SOURCES','$SOURCES.abspath')
env['CXXCOM'] = env['CXXCOM'].replace('$CHANGED_SOURCES','$SOURCES.abspath')
env['SHCXXCOM']= env['SHCXXCOM'].replace('$CHANGED_SOURCES','$SOURCES.abspath')
architecture="generic"
env['CPPDEFINES']=[]
env['CCFLAGS']=[]
env['CXXFLAGS']=[]
env['LIBS']=[]
env['LINKFLAGS']=[]
env['CCFLAGSFORNEDMALLOC']=[]
env['NEDMALLOCLIBRARYNAME']="nedmalloc"+('_ptchg' if env.GetOption('replacesystemallocator') else '')+env.GetOption('postfix')
env['UMPALIBRARYNAME']="nedumpa"+('_ptchg' if env.GetOption('replacesystemallocator') else '')+env.GetOption('postfix')
if env.GetOption('debugprint'): env['CPPDEFINES']+=["USE_DEBUGGER_OUTPUT"]
if env.GetOption('fullsanitychecks'): env['CPPDEFINES']+=["FULLSANITYCHECKS"]
if env.GetOption('replacesystemallocator'): env['CPPDEFINES']+=["REPLACE_SYSTEM_ALLOCATOR"]
if env.GetOption('tolerant'): env['CPPDEFINES']+=["ENABLE_TOLERANT_NEDMALLOC"]
if env.GetOption('magicheaders'): env['CPPDEFINES']+=["USE_MAGIC_HEADERS"]
env['CPPDEFINES']+=[("USE_ALLOCATOR",env.GetOption('useallocator'))]
env['CPPDEFINES']+=[("USE_LOCKS",env.GetOption('uselocks'))]
if env.GetOption('nospinlocks'): env['CPPDEFINES']+=[("USE_SPIN_LOCKS",0)]
if env.GetOption('largepages'): env['CPPDEFINES']+=["ENABLE_LARGE_PAGES"]
if env.GetOption('fastheapdetection'): env['CPPDEFINES']+=["ENABLE_FAST_HEAP_DETECTION"]
if env.GetOption('maxthreadsinpool'): env['CPPDEFINES']+=[("MAXTHREADSINPOOL",env.GetOption('maxthreadsinpool'))]
if env.GetOption('defaultgranularity'): env['CPPDEFINES']+=[("DEFAULT_GRANULARITY",env.GetOption('defaultgranularity'))]
if env.GetOption('threadcachemax'):
threadcachemax=int(env.GetOption('threadcachemax'))
if threadcachemax<=32: threadcachemax=0
env['CPPDEFINES']+=[("THREADCACHEMAX",threadcachemax)]
if not env.GetOption('threadcachemaxbins') and threadcachemax:
maxbins=bitscanrev(threadcachemax)-4;
print "THREADCACHEMAX set but not THREADCACHEMAXBINS, so auto-setting THREADCACHEMAXBINS =", maxbins
env['CPPDEFINES']+=[("THREADCACHEMAXBINS",maxbins)]
if env.GetOption('threadcachemaxbins'): env['CPPDEFINES']+=[("THREADCACHEMAXBINS",env.GetOption('threadcachemaxbins'))]
if env.GetOption('threadcachemaxfreespace'): env['CPPDEFINES']+=[("THREADCACHEMAXFREESPACE",env.GetOption('threadcachemaxfreespace'))]
env['CPPDEFINES']+=[("NEDMALLOCDEPRECATED", "")]
# Am I in a 32 or 64 bit environment? Note that not specifying --sse doesn't set any x86 or x64 specific options
# so it's good to go for ANY platform
if sys.platform=="win32":
# Even the very latest scons still screws this up :(
env['ENV']['INCLUDE']=os.environ['INCLUDE']
env['ENV']['LIB']=os.environ['LIB']
env['ENV']['PATH']=os.environ['PATH']
else:
# Test the build environment
def CheckGCCHasVisibility(cc):
cc.Message("Checking for GCC global symbol visibility support...")
try:
temp=cc.env['CPPFLAGS']
except:
temp=[]
cc.env['CPPFLAGS']=temp+["-fvisibility=hidden"]
result=cc.TryCompile('struct __attribute__ ((visibility("default"))) Foo { int foo; };\nint main(void) { Foo foo; return 0; }\n', '.cpp')
cc.env['CPPFLAGS']=temp
cc.Result(result)
return result
def CheckGCCHasCPP0xFeatures(cc):
cc.Message("Checking if GCC can enable C++0x features ...")
try:
temp=cc.env['CPPFLAGS']
except:
temp=[]
cc.env['CPPFLAGS']=temp+["-std=c++0x"]
result=cc.TryCompile('struct Foo { static const int gee=5; Foo(const char *) { } Foo(Foo &&a) { } };\nint main(void) { Foo foo(__func__); static_assert(Foo::gee==5, "Death!"); return 0; }\n', '.cpp')
cc.env['CPPFLAGS']=temp
cc.Result(result)
return result
conf=Configure(env, { "CheckGCCHasVisibility" : CheckGCCHasVisibility, "CheckGCCHasCPP0xFeatures" : CheckGCCHasCPP0xFeatures } )
assert conf.CheckCHeader("pthread.h")
if not conf.CheckLib("rt", "clock_gettime") and not conf.CheckLib("c", "clock_gettime"):
print "WARNING: Can't find clock_gettime() in librt or libc, code may not fully compile if your system headers say that this function is available"
if conf.CheckGCCHasVisibility():
env['CPPFLAGS']+=["-fvisibility=hidden"] # All symbols are hidden unless marked otherwise
env['CXXFLAGS']+=["-fvisibility-inlines-hidden" # All inlines are always hidden
]
else:
print "Disabling -fvisibility support"
if conf.CheckGCCHasCPP0xFeatures():
env['CXXFLAGS']+=["-std=c++0x"]
else:
print "Disabling C++0x support"
env=conf.Finish()
# Build
nedmalloclib=None
buildvariants={}
for architecture in architectures:
for buildtype in ["Debug", "Release"]:
env['VARIANT']=architecture+"/"+buildtype
nedmalloclibvariant=SConscript("SConscript", variant_dir=env['VARIANT'], duplicate=False, exports="env")
buildvariants[(buildtype, architecture)]=nedmalloclibvariant
# What architecture am I on?
architecture="generic"
if sys.platform=="win32":
# We're on windows
if not env.GetOption('force32') and os.environ.has_key('LIBPATH') and -1!=os.environ['LIBPATH'].find("\\amd64"):
architecture="x64"
else:
architecture="x86"
else:
# We're on POSIX
if not env.GetOption('force32') and ('x64' in platform.machine() or 'x86_64' in platform.machine()):
architecture="x64"
elif platform.machine() in ['i386', 'i486', 'i586', 'i686']:
architecture="x86"
print "*** Build variant preferred by environment is", "Debug" if env.GetOption("debug") else "Release", architecture
nedmalloclib=buildvariants[("Debug" if env.GetOption("debug") else "Release", architecture)]
Default([x[0] for x in nedmalloclib.values()])
nedmalloclib=nedmalloclib['nedmalloclib'][0]
# Set up the MSVC project files
if 'win32'==sys.platform:
includes = [ "nedmalloc.h", "malloc.c.h", "nedmalloc.c", "usermodepageallocator.c"]
variants = []
projs = {}
for buildvariant, output in buildvariants.items():
variant = buildvariant[0]+'|'+("Win32" if buildvariant[1]=="x86" else buildvariant[1])
variants+=[variant]
for program, builditems in output.items():
if not program in projs: projs[program]={}
projs[program][variant]=builditems
variants.sort()
msvsprojs = []
for program, items in projs.items():
buildtargets = items.items()
buildtargets.sort()
#print buildtargets
#print [str(x[1][0][0]) for x in buildtargets]
msvsprojs+=env.MSVSProject(program+env['MSVSPROJECTSUFFIX'], srcs=items.values()[0][1], incs=includes, misc="Readme.html", buildtarget=[x[1][0][0] for x in buildtargets], runfile=[str(x[1][0][0]) for x in buildtargets], variant=[x[0] for x in buildtargets], auto_build_solution=0)
msvssolution = env.MSVSSolution("nedmalloc.sln", projects=msvsprojs, variant=variants)
Depends(msvssolution, msvsprojs)
Alias("msvcproj", msvssolution)
Return("nedmalloclib")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/blog/kbengine.git
git@gitee.com:blog/kbengine.git
blog
kbengine
kbengine
0.1.3

搜索帮助