diff --git a/SConstruct b/SConstruct index 0950fa05735dc8ce882c09428efbd1f25aa71669..41b467e976aa29985e80bab4ccf01c6f86236816 100644 --- a/SConstruct +++ b/SConstruct @@ -4,13 +4,13 @@ import os.path import platform import sys -default_install_dir="/usr/local" +default_install_dir='/usr/local' if platform.system() == 'Windows': - default_install_dir = "build" # no obvious place for installation on Windows + default_install_dir = 'build' # no obvious place for installation on Windows vars = Variables(None, ARGUMENTS) -vars.Add(PathVariable('DESTDIR', "Root directory to install in (useful for packaging scripts)", None, PathVariable.PathIsDirCreate)) -vars.Add(PathVariable('prefix', "Where to install in the FHS", default_install_dir, PathVariable.PathAccept)) +vars.Add(PathVariable('DESTDIR', 'Root directory to install in (useful for packaging scripts)', None, PathVariable.PathIsDirCreate)) +vars.Add(PathVariable('prefix', 'Where to install in the FHS', default_install_dir, PathVariable.PathAccept)) vars.Add(ListVariable('bindings', 'Language bindings to build', 'none', ['cpp', 'dotnet', 'perl', 'php', 'python', 'ruby'])) tools = ['default', 'scanreplace'] @@ -35,7 +35,7 @@ if not 'bindings' in env: def calcInstallPath(*elements): path = os.path.abspath(os.path.join(*map(env.subst, elements))) if 'DESTDIR' in env: - path = os.path.join(env['DESTDIR'], os.path.relpath(path, start="/")) + path = os.path.join(env['DESTDIR'], os.path.relpath(path, start='/')) return path rel_prefix = not os.path.isabs(env['prefix']) @@ -43,131 +43,131 @@ env['prefix'] = os.path.abspath(env['prefix']) if 'DESTDIR' in env: env['DESTDIR'] = os.path.abspath(env['DESTDIR']) if rel_prefix: - print >>sys.stderr, "--!!-- You used a relative prefix with a DESTDIR. This is probably not what you" - print >>sys.stderr, "--!!-- you want; files will be installed in" - print >>sys.stderr, "--!!-- %s" % (calcInstallPath("$prefix"),) + print >>sys.stderr, '--!!-- You used a relative prefix with a DESTDIR. This is probably not what you' + print >>sys.stderr, '--!!-- you want; files will be installed in' + print >>sys.stderr, '--!!-- %s' % (calcInstallPath('$prefix'),) -env['libpath'] = calcInstallPath("$prefix", "lib") -env['incpath'] = calcInstallPath("$prefix", "include", "hammer") -env['parsersincpath'] = calcInstallPath("$prefix", "include", "hammer", "parsers") -env['backendsincpath'] = calcInstallPath("$prefix", "include", "hammer", "backends") -env['pkgconfigpath'] = calcInstallPath("$prefix", "lib", "pkgconfig") +env['libpath'] = calcInstallPath('$prefix', 'lib') +env['incpath'] = calcInstallPath('$prefix', 'include', 'hammer') +env['parsersincpath'] = calcInstallPath('$prefix', 'include', 'hammer', 'parsers') +env['backendsincpath'] = calcInstallPath('$prefix', 'include', 'hammer', 'backends') +env['pkgconfigpath'] = calcInstallPath('$prefix', 'lib', 'pkgconfig') env.ScanReplace('libhammer.pc.in') -AddOption("--variant", - dest="variant", - nargs=1, type="choice", - choices=["debug", "opt"], - default="opt", - action="store", - help="Build variant (debug or opt)") +AddOption('--variant', + dest='variant', + nargs=1, type='choice', + choices=['debug', 'opt'], + default='opt', + action='store', + help='Build variant (debug or opt)') -AddOption("--coverage", - dest="coverage", +AddOption('--coverage', + dest='coverage', default=False, - action="store_true", - help="Build with coverage instrumentation") + action='store_true', + help='Build with coverage instrumentation') -AddOption("--in-place", - dest="in_place", +AddOption('--in-place', + dest='in_place', default=False, - action="store_true", - help="Build in-place, rather than in the build/<variant> tree") + action='store_true', + help='Build in-place, rather than in the build/<variant> tree') -AddOption("--tests", - dest="with_tests", +AddOption('--tests', + dest='with_tests', default=env['PLATFORM'] != 'win32', - action="store_true", - help="Build tests") + action='store_true', + help='Build tests') -env["CC"] = os.getenv("CC") or env["CC"] -env["CXX"] = os.getenv("CXX") or env["CXX"] +env['CC'] = os.getenv('CC') or env['CC'] +env['CXX'] = os.getenv('CXX') or env['CXX'] -if os.getenv("CC") == "clang" or env['PLATFORM'] == 'darwin': - env.Replace(CC="clang", - CXX="clang++") +if os.getenv('CC') == 'clang' or env['PLATFORM'] == 'darwin': + env.Replace(CC='clang', + CXX='clang++') # Language standard and warnings -if env["CC"] == "cl": - env.MergeFlags("-W3 -WX") +if env['CC'] == 'cl': + env.MergeFlags('-W3 -WX') env.Append( CPPDEFINES=[ - "_CRT_SECURE_NO_WARNINGS" # allow uses of sprintf + '_CRT_SECURE_NO_WARNINGS' # allow uses of sprintf ], CFLAGS=[ - "-wd4018", # 'expression' : signed/unsigned mismatch - "-wd4244", # 'argument' : conversion from 'type1' to 'type2', possible loss of data - "-wd4267", # 'var' : conversion from 'size_t' to 'type', possible loss of data + '-wd4018', # 'expression' : signed/unsigned mismatch + '-wd4244', # 'argument' : conversion from 'type1' to 'type2', possible loss of data + '-wd4267', # 'var' : conversion from 'size_t' to 'type', possible loss of data ] ) else: - env.MergeFlags("-std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes -Wno-unused-variable") + env.MergeFlags('-std=gnu99 -Wall -Wextra -Werror -Wno-unused-parameter -Wno-attributes -Wno-unused-variable') # Linker options if env['PLATFORM'] == 'darwin': - env.Append(SHLINKFLAGS = '-install_name ' + env["libpath"] + '/${TARGET.file}') -elif platform.system() == "OpenBSD": + env.Append(SHLINKFLAGS = '-install_name ' + env['libpath'] + '/${TARGET.file}') +elif platform.system() == 'OpenBSD': pass elif env['PLATFORM'] == 'win32': # no extra lib needed pass else: - env.MergeFlags("-lrt") + env.MergeFlags('-lrt') -if GetOption("coverage"): - env.Append(CFLAGS=["--coverage"], - CXXFLAGS=["--coverage"], - LDFLAGS=["--coverage"]) - if env["CC"] == "gcc": +if GetOption('coverage'): + env.Append(CFLAGS=['--coverage'], + CXXFLAGS=['--coverage'], + LDFLAGS=['--coverage']) + if env['CC'] == 'gcc': env.Append(LIBS=['gcov']) else: env.ParseConfig('llvm-config --ldflags') dbg = env.Clone(VARIANT='debug') -if env["CC"] == "cl": - dbg.Append(CCFLAGS=["/Z7"]) +if env['CC'] == 'cl': + dbg.Append(CCFLAGS=['/Z7']) else: dbg.Append(CCFLAGS=['-g']) opt = env.Clone(VARIANT='opt') -if env["CC"] == "cl": - opt.Append(CCFLAGS=["/O2"]) +if env['CC'] == 'cl': + opt.Append(CCFLAGS=['/O2']) else: - opt.Append(CCFLAGS=["-O3"]) + opt.Append(CCFLAGS=['-O3']) -if GetOption("variant") == 'debug': +if GetOption('variant') == 'debug': env = dbg else: env = opt -env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_")) +env['ENV'].update(x for x in os.environ.items() if x[0].startswith('CCC_')) #rootpath = env['ROOTPATH'] = os.path.abspath('.') -#env.Append(CPPPATH=os.path.join('#', "hammer")) +#env.Append(CPPPATH=os.path.join('#', 'hammer')) testruns = [] -targets = ["$libpath", - "$incpath", - "$parsersincpath", - "$backendsincpath", - "$pkgconfigpath"] +targets = ['$libpath', + '$incpath', + '$parsersincpath', + '$backendsincpath', + '$pkgconfigpath'] Export('env') Export('testruns') Export('targets') -if not GetOption("in_place"): +if not GetOption('in_place'): env['BUILD_BASE'] = 'build/$VARIANT' - lib = env.SConscript(["src/SConscript"], variant_dir='$BUILD_BASE/src') - env.Alias("examples", env.SConscript(["examples/SConscript"], variant_dir='$BUILD_BASE/examples')) + lib = env.SConscript(['src/SConscript'], variant_dir='$BUILD_BASE/src') + env.Alias('examples', env.SConscript(['examples/SConscript'], variant_dir='$BUILD_BASE/examples')) else: env['BUILD_BASE'] = '.' - lib = env.SConscript(["src/SConscript"]) - env.Alias(env.SConscript(["examples/SConscript"])) + lib = env.SConscript(['src/SConscript']) + env.Alias(env.SConscript(['examples/SConscript'])) for testrun in testruns: - env.Alias("test", testrun) + env.Alias('test', testrun) -env.Alias("install", targets) +env.Alias('install', targets) diff --git a/src/SConscript b/src/SConscript index 414f9f46fc3e3344627139a4e0900b76177f5914..fa843fca9750181d82cbf6f9adf8580eaa180386 100644 --- a/src/SConscript +++ b/src/SConscript @@ -4,21 +4,21 @@ import os.path Import('env testruns') dist_headers = [ - "hammer.h", - "allocator.h", - "compiler_specifics.h", - "glue.h", - "internal.h", - "platform.h" + 'hammer.h', + 'allocator.h', + 'compiler_specifics.h', + 'glue.h', + 'internal.h', + 'platform.h' ] parsers_headers = [ - "parsers/parser_internal.h" + 'parsers/parser_internal.h' ] backends_headers = [ - "backends/regex.h", - "backends/contextfree.h" + 'backends/regex.h', + 'backends/contextfree.h' ] parsers = ['parsers/%s.c'%s for s in @@ -95,27 +95,27 @@ libhammer_shared = env.SharedLibrary('hammer', parsers + backends + misc_hammer_ libhammer_static = env.StaticLibrary(static_library_name, parsers + backends + misc_hammer_parts) if build_shared_library: Default(libhammer_shared, libhammer_static) - env.Install("$libpath", [libhammer_static, libhammer_shared]) + env.Install('$libpath', [libhammer_static, libhammer_shared]) else: Default(libhammer_static) - env.Install("$libpath", [libhammer_static]) + env.Install('$libpath', [libhammer_static]) -env.Install("$incpath", dist_headers) -env.Install("$parsersincpath", parsers_headers) -env.Install("$backendsincpath", backends_headers) -env.Install("$pkgconfigpath", "../../../libhammer.pc") +env.Install('$incpath', dist_headers) +env.Install('$parsersincpath', parsers_headers) +env.Install('$backendsincpath', backends_headers) +env.Install('$pkgconfigpath', '../../../libhammer.pc') -if GetOption("with_tests"): +if GetOption('with_tests'): testenv = env.Clone() testenv.ParseConfig('pkg-config --cflags --libs glib-2.0') testenv.Append(LIBS=['hammer']) testenv.Prepend(LIBPATH=['.']) - ctestexec = testenv.Program('test_suite', ctests + ['test_suite.c'], LINKFLAGS="--coverage" if testenv.GetOption("coverage") else None) - ctest = Alias('testc', [ctestexec], "".join(["env LD_LIBRARY_PATH=", os.path.dirname(ctestexec[0].path), " ", ctestexec[0].path])) + ctestexec = testenv.Program('test_suite', ctests + ['test_suite.c'], LINKFLAGS='--coverage' if testenv.GetOption('coverage') else None) + ctest = Alias('testc', [ctestexec], ''.join(['env LD_LIBRARY_PATH=', os.path.dirname(ctestexec[0].path), ' ', ctestexec[0].path])) AlwaysBuild(ctest) testruns.append(ctest) -Export("libhammer_static libhammer_shared") +Export('libhammer_static libhammer_shared') for b in env['bindings']: - env.SConscript(["bindings/%s/SConscript" % b]) + env.SConscript(['bindings/%s/SConscript' % b])