123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- Help('''
- Type 'scons' to build and run all the available test cases.
- It will automatically detect your platform and C compiler and
- build appropriately.
- You can modify the behaviour using following options:
- BUILDDIR Directory to build into (default "build")
- CC Name of C compiler
- CXX Name of C++ compiler
- CCFLAGS Flags to pass to the C compiler
- CXXFLAGS Flags to pass to the C++ compiler
- LINK Name of linker (usually same as CC)
- LINKFLAGS Flags to pass to linker
- LINKLIBS Flags to pass to linker after object files
- PROTOC Path to protoc binary
- PROTOCFLAGS Arguments to pass protoc
- NODEFARGS Do not add the default CCFLAGS
- NOVALGRIND Do not use valgrind for memory checks
- For example, for a clang build, use:
- scons CC=clang CXX=clang++
- ''')
- import os
- import platform
- env = Environment(ENV = os.environ)
- list_vars = ['CCFLAGS', 'CXXFLAGS', 'LINKFLAGS', 'LINKLIBS', 'PROTOCFLAGS']
- for var,val in ARGUMENTS.items():
- if var in list_vars:
- env.Append(**{var: val})
- else:
- env.Replace(**{var: val})
- env.SetDefault(BUILDDIR = "build")
- env.SConsignFile(env['BUILDDIR'] + "/sconsign")
- env.Replace(CONFIGUREDIR = env['BUILDDIR'] + "/config")
- if ARGUMENTS.get('PLATFORM'):
- platform_func = platforms.get(ARGUMENTS.get('PLATFORM'))
- if not platform_func:
- print("Supported platforms: " + str(platforms.keys()))
- raise Exception("Unsupported platform: " + ARGUMENTS.get('PLATFORM'))
- else:
- platform_func(env)
- env.Tool("nanopb")
- try:
- import resource
- soft, hard = resource.getrlimit(resourse.RLIMIT_AS)
- resource.setrlimit(resource.RLIMIT_AS, (100*1024*1024, hard))
- except:
- pass
- if platform.system() == "Darwin" and 'CC' not in ARGUMENTS:
- env.Replace(CC = "clang", CXX = "clang++")
- add_nanopb_builders(env)
- env.Append(CPPPATH = ["#../", "$COMMON"])
- env.Append(PROTOCPATH = '#../generator')
- if not env.GetOption('clean'):
- def check_ccflags(context, flags, linkflags = ''):
- '''Check if given CCFLAGS are supported'''
- context.Message('Checking support for CCFLAGS="%s"... ' % flags)
- oldflags = context.env['CCFLAGS']
- oldlinkflags = context.env['LINKFLAGS']
- context.env.Append(CCFLAGS = flags)
- context.env.Append(LINKFLAGS = linkflags)
- result = context.TryCompile("int main() {return 0;}", '.c')
- context.env.Replace(CCFLAGS = oldflags)
- context.env.Replace(LINKFLAGS = oldlinkflags)
- context.Result(result)
- return result
-
- def check_protocversion(context):
- context.Display("Checking protoc version... ")
- status, output = context.TryAction('$PROTOC --version > $TARGET')
- if status:
- context.Result(str(output.strip()))
- return str(output.strip())
- else:
- context.Display("error: %s\n" % output.strip())
- context.did_show_result = 1
- context.Result("unknown, assuming 3.6.1")
- return "3.6.1"
- conf = Configure(env, custom_tests =
- {'CheckCCFLAGS': check_ccflags,
- 'CheckProtocVersion': check_protocversion})
-
- stdbool = conf.CheckCHeader('stdbool.h')
- stdint = conf.CheckCHeader('stdint.h')
- stddef = conf.CheckCHeader('stddef.h')
- string = conf.CheckCHeader('string.h')
- stdlib = conf.CheckCHeader('stdlib.h')
- limits = conf.CheckCHeader('limits.h')
- if not stdbool or not stdint or not stddef or not string or not limits:
- conf.env.Append(CPPDEFINES = {'PB_SYSTEM_HEADER': '\\"pb_syshdr.h\\"'})
- conf.env.Append(CPPPATH = "#../extra")
- conf.env.Append(SYSHDR = '\\"pb_syshdr.h\\"')
-
- if stdbool: conf.env.Append(CPPDEFINES = {'HAVE_STDBOOL_H': 1})
- if stdint: conf.env.Append(CPPDEFINES = {'HAVE_STDINT_H': 1})
- if stddef: conf.env.Append(CPPDEFINES = {'HAVE_STDDEF_H': 1})
- if string: conf.env.Append(CPPDEFINES = {'HAVE_STRING_H': 1})
- if stdlib: conf.env.Append(CPPDEFINES = {'HAVE_STDLIB_H': 1})
- if limits: conf.env.Append(CPPDEFINES = {'HAVE_LIMITS_H': 1})
-
-
- conf.env['PROTOC_VERSION'] = conf.CheckProtocVersion()
-
-
- if not env.get('NODEFARGS'):
-
- if 'gcc' in env['CC']:
- if conf.CheckLib('mudflap'):
- conf.env.Append(CCFLAGS = '-fmudflap')
- conf.env.Append(LINKFLAGS = '-fmudflap')
-
- extra = '-Wcast-qual -Wlogical-op -Wconversion'
- extra += ' -fstrict-aliasing -Wstrict-aliasing=1'
- extra += ' -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls'
- extra += ' -Wstack-protector '
- if 'gcc' in env['CC']:
- if conf.CheckCCFLAGS(extra):
- conf.env.Append(CORECFLAGS = extra)
-
-
-
- extra = '-fsanitize=undefined,integer -fno-sanitize-recover=undefined,integer '
- if 'clang' in env['CC']:
- if conf.CheckCCFLAGS(extra, linkflags = extra):
- conf.env.Append(CORECFLAGS = extra)
- conf.env.Append(LINKFLAGS = extra)
-
-
- env = conf.Finish()
- if not env.get('NODEFARGS'):
-
- if 'gcc' in env['CC']:
-
-
-
- env.Append(CFLAGS = '-g -Wall -Werror ')
- env.Append(CORECFLAGS = '-Wextra')
-
-
- if env.get("EMBEDDED") != "AVR":
- env.Append(CFLAGS = '-ansi -pedantic')
-
- if not env.get("EMBEDDED"):
- env.Append(CFLAGS = '-fprofile-arcs -ftest-coverage ')
- env.Append(LINKFLAGS = '-g --coverage')
-
- env.Append(CFLAGS = '-Wno-long-long')
- elif 'clang' in env['CC']:
-
- env.Append(CFLAGS = '-ansi -g -Wall -Werror')
- env.Append(CORECFLAGS = ' -Wextra -Wcast-qual -Wconversion')
- elif 'cl' in env['CC']:
-
-
- env.Append(CFLAGS = '/Zi /W2 /WX')
- env.Append(LINKFLAGS = '/DEBUG')
-
- env.Append(CORECFLAGS = '/W4')
-
-
-
-
- env.Append(CFLAGS = '/wd4116')
- elif 'tcc' in env['CC']:
-
- env.Append(CFLAGS = '-Wall -Werror -g')
- if 'clang' in env['CXX']:
- env.Append(CXXFLAGS = '-g -Wall -Werror -Wextra -Wno-missing-field-initializers')
- elif 'g++' in env['CXX'] or 'gcc' in env['CXX']:
- env.Append(CXXFLAGS = '-g -Wall -Werror -Wextra -Wno-missing-field-initializers')
- elif 'cl' in env['CXX']:
- env.Append(CXXFLAGS = '/Zi /W2 /WX /wd4116 /wd4127')
- env.SetDefault(CORECFLAGS = '')
- if not env.get("EMBEDDED") and not env.get("NOVALGRIND"):
- valgrind = env.WhereIs('valgrind')
- if valgrind:
- env.SetDefault(VALGRIND = valgrind)
- env.SetDefault(LINKLIBS = '')
- env.Replace(LINKCOM = env['LINKCOM'] + " $LINKLIBS")
- import os.path
- env['VARIANT_DIR'] = env['BUILDDIR']
- env['BUILD'] = '#' + env['VARIANT_DIR']
- env['COMMON'] = '#' + env['VARIANT_DIR'] + '/common'
- SConscript("common/SConscript", exports = 'env', variant_dir = env['VARIANT_DIR'] + '/common')
- for subdir in Glob('*/SConscript') + Glob('regression/*/SConscript'):
- if str(subdir).startswith("common/"): continue
- if str(subdir).startswith("common\\"): continue
- SConscript(subdir, exports = 'env', variant_dir = env['VARIANT_DIR'] + '/' + os.path.dirname(str(subdir)))
|