Compare commits
2 Commits
fb0efd9cbb
...
66dfd956da
| Author | SHA1 | Date | |
|---|---|---|---|
| 66dfd956da | |||
| c7d175d90f |
-177
@@ -1,177 +0,0 @@
|
|||||||
import os
|
|
||||||
import platform
|
|
||||||
|
|
||||||
#version info of the library, we use 5 chars from the git hash
|
|
||||||
revision = os.popen('git describe --abbrev=5 --dirty --always').read()[:-1]
|
|
||||||
|
|
||||||
version_info = {
|
|
||||||
'version_major': 1 ,
|
|
||||||
'version_minor': 0 ,
|
|
||||||
'version_patch': 0 ,
|
|
||||||
'version_revision': revision,
|
|
||||||
#version_abi is the abi version of the shared library. Only bump it when
|
|
||||||
#backwards compatibility breaks. Strive to not break the ABI.
|
|
||||||
'version_abi': '1.0.0'
|
|
||||||
}
|
|
||||||
version_info['version_str'] = "%d.%d.%d.%s" % (
|
|
||||||
version_info['version_major'],
|
|
||||||
version_info['version_minor'],
|
|
||||||
version_info['version_patch'],
|
|
||||||
version_info['version_revision'])
|
|
||||||
|
|
||||||
|
|
||||||
AddOption('--build_type',
|
|
||||||
dest = 'build_type',
|
|
||||||
type = 'choice',
|
|
||||||
nargs = 1,
|
|
||||||
action='store',
|
|
||||||
default='debug',
|
|
||||||
metavar='TYPE',
|
|
||||||
choices = ['debug', 'release'],
|
|
||||||
help = 'debug|release - Build a Debug (default) or Release variant'
|
|
||||||
)
|
|
||||||
AddOption('--prefix',
|
|
||||||
dest='prefix',
|
|
||||||
type='string',
|
|
||||||
nargs=1,
|
|
||||||
action='store',
|
|
||||||
metavar='DIR',
|
|
||||||
default='/usr',
|
|
||||||
help='installation prefix'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--test_xml',
|
|
||||||
dest='test_xml',
|
|
||||||
action='store_true',
|
|
||||||
help='Create a result.xml when running the testsuite'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--coverage',
|
|
||||||
dest='coverage',
|
|
||||||
action='store_true',
|
|
||||||
help='Build with coverage (gcov) support'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--without-assertions',
|
|
||||||
dest='assertions',
|
|
||||||
action='store_false',
|
|
||||||
default=True,
|
|
||||||
help='Build without assertions enabled'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--stack-protection',
|
|
||||||
dest = 'stack_protection',
|
|
||||||
action='store_true',
|
|
||||||
default=False,
|
|
||||||
help = 'Build with stack protection support'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--sanitizer',
|
|
||||||
dest = 'sanitizer',
|
|
||||||
action='store_true',
|
|
||||||
default=False,
|
|
||||||
help = 'Build with gcc sanitizer'
|
|
||||||
)
|
|
||||||
|
|
||||||
AddOption('--32',
|
|
||||||
dest='force32bit',
|
|
||||||
action='store_true',
|
|
||||||
default=False,
|
|
||||||
help='Force building for 32 bit architecture'
|
|
||||||
)
|
|
||||||
|
|
||||||
build_type = GetOption('build_type')
|
|
||||||
assertions = GetOption('assertions')
|
|
||||||
stack_protection = GetOption('stack_protection')
|
|
||||||
test_xml = GetOption('test_xml')
|
|
||||||
prefix = GetOption('prefix')
|
|
||||||
lib_suffix = ''
|
|
||||||
if not (build_type in ['debug', 'release']):
|
|
||||||
print("Error: expected 'debug' or 'release', found: " + build_type)
|
|
||||||
Exit(1)
|
|
||||||
|
|
||||||
def InstallPerm(env, dest, files, perm):
|
|
||||||
obj = env.Install(dest, files)
|
|
||||||
for i in obj:
|
|
||||||
env.AddPostAction(i, Chmod(str(i), perm))
|
|
||||||
return obj
|
|
||||||
|
|
||||||
|
|
||||||
env = Environment(tools = ['default', 'textfile', 'packaging'])
|
|
||||||
|
|
||||||
#allow shell environment to override compiler
|
|
||||||
if os.environ.get('CC'):
|
|
||||||
env['CC'] = os.environ['CC']
|
|
||||||
|
|
||||||
env.AddMethod(InstallPerm)
|
|
||||||
|
|
||||||
env.Append(CFLAGS = ['-std=gnu99','-Wall', '-Wextra', '-Wundef', '-Wcast-qual','-Wshadow' ,'-Wcast-align','-pipe', '-ggdb', '-pthread'])
|
|
||||||
env.Append(CFLAGS = ['-Wno-unused-parameter', '-Werror=implicit-function-declaration', '-Winit-self'])
|
|
||||||
env.Append(LINKFLAGS = ['-O2', '-pthread'])
|
|
||||||
env.Append(CPPDEFINES = ['_FILE_OFFSET_BITS=64'])
|
|
||||||
env.Append(CPPPATH = ['#include'])
|
|
||||||
env.Append(SHLIBVERSION = version_info['version_abi'])
|
|
||||||
|
|
||||||
if GetOption('force32bit'):
|
|
||||||
env.Append(CFLAGS = ['-m32'])
|
|
||||||
env.Append(LINKFLAGS = ['-m32'])
|
|
||||||
|
|
||||||
if build_type == 'release':
|
|
||||||
env.Append(CFLAGS = ['-O2'])
|
|
||||||
elif build_type == 'debug':
|
|
||||||
lib_suffix = 'D'
|
|
||||||
env.Append(CPPDEFINES = ['DEBUG'])
|
|
||||||
|
|
||||||
if stack_protection:
|
|
||||||
env.Append(CFLAGS = ['-fstack-protector', '--param=ssp-buffer-size=4'])
|
|
||||||
env.Append(CPPDEFINES = ['_FORTIFY_SOURCE=2'])
|
|
||||||
if not assertions:
|
|
||||||
#this will turn off assert()
|
|
||||||
env.Append(CPPDEFINES = ['NDEBUG'])
|
|
||||||
|
|
||||||
if GetOption('coverage'):
|
|
||||||
env.Append(CFLAGS = ['--coverage'])
|
|
||||||
env.Append(LINKFLAGS = ['--coverage'])
|
|
||||||
|
|
||||||
if GetOption('sanitizer'):
|
|
||||||
env.Append(CFLAGS = ['-fsanitize=undefined', '-fsanitize=address'])
|
|
||||||
env.Append(LINKFLAGS = ['-fsanitize=undefined', '-fsanitize=address'])
|
|
||||||
|
|
||||||
# Generate substitute dictionary
|
|
||||||
subst_info = dict(('@' + key + '@', version_info[key]) for key in version_info)
|
|
||||||
subst_info['@prefix@'] = prefix
|
|
||||||
subst_info['@build_type@'] = build_type
|
|
||||||
|
|
||||||
if assertions:
|
|
||||||
subst_info['@build_type@'] += '_A'
|
|
||||||
if stack_protection:
|
|
||||||
subst_info['@build_type@'] += '_SP'
|
|
||||||
|
|
||||||
subst_info['@build_host@'] = platform.node()
|
|
||||||
|
|
||||||
Export('env', 'build_type', 'prefix', 'lib_suffix', 'version_info', 'test_xml', 'subst_info')
|
|
||||||
|
|
||||||
#put all .sconsign files in one place
|
|
||||||
env.SConsignFile()
|
|
||||||
|
|
||||||
subdirs = [
|
|
||||||
'src',
|
|
||||||
'include',
|
|
||||||
'test',
|
|
||||||
]
|
|
||||||
|
|
||||||
for subdir in subdirs:
|
|
||||||
env.SConscript(subdir + '/SConscript', variant_dir='#build/' + subdir, src_dir='#'+subdir, duplicate=0)
|
|
||||||
|
|
||||||
env.Package(target = 'libucore-' + version_info['version_str'] + '.tar.gz',
|
|
||||||
source = env.FindInstalledFiles(),
|
|
||||||
NAME = 'libucore',
|
|
||||||
VERSION = version_info['version_str'],
|
|
||||||
PACKAGEVERSION = 0,
|
|
||||||
PACKAGETYPE = 'targz',
|
|
||||||
LICENSE = 'BSD',
|
|
||||||
SUMMARY = 'libucore is a C library of misc useful stuff including an eventloop, timer support and various data-structures.',
|
|
||||||
DESCRIPTION = 'libucore is a C library of misc useful stuff including an eventloop, timer support and various data-structures.',
|
|
||||||
X_RPM_GROUP = 'Development/Libraries'
|
|
||||||
)
|
|
||||||
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
Import('env', 'build_type', 'prefix', 'version_info')
|
|
||||||
|
|
||||||
ucore_env = env.Clone()
|
|
||||||
|
|
||||||
headers = ucore_env.Glob('ucore/*.h')
|
|
||||||
|
|
||||||
#install targets
|
|
||||||
|
|
||||||
ucore_env.Alias('install',
|
|
||||||
ucore_env.InstallPerm(os.path.join(prefix, 'include', 'ucore'), headers, 0o0644))
|
|
||||||
|
|
||||||
@@ -25,6 +25,10 @@ uc_phi_64(uint64_t N);
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Note: the nextpow2 functions have undefined behavior if
|
||||||
|
// x > 2^(n-1) for n of the 32 or 64 bit variants
|
||||||
|
|
||||||
#if HAVE_BUILTIN_CLZ
|
#if HAVE_BUILTIN_CLZ
|
||||||
|
|
||||||
static inline uint32_t
|
static inline uint32_t
|
||||||
@@ -39,7 +43,7 @@ static inline uint64_t
|
|||||||
uc_nextpow2_64(uint64_t x)
|
uc_nextpow2_64(uint64_t x)
|
||||||
{
|
{
|
||||||
if (x <= 1) return 1;
|
if (x <= 1) return 1;
|
||||||
return 1u << (64 - __builtin_clzll(x - 1));
|
return (uint64_t)1 << (64 - __builtin_clzll(x - 1));
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -61,7 +65,7 @@ uc_nextpow2(uint32_t x)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline uint64_t
|
static inline uint64_t
|
||||||
uc_nextpow2(uint64_t x)
|
uc_nextpow2_64(uint64_t x)
|
||||||
{
|
{
|
||||||
if (x == 0) {
|
if (x == 0) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
Import('env', 'build_type', 'prefix', 'lib_suffix', 'subst_info')
|
|
||||||
|
|
||||||
ucore_env = env.Clone()
|
|
||||||
|
|
||||||
ucore_env.Substfile('version.c.in', SUBST_DICT = subst_info)
|
|
||||||
|
|
||||||
sources = ucore_env.Glob('*.c')
|
|
||||||
|
|
||||||
#print 'ucore_env', dir(ucore_env)
|
|
||||||
#print ucore_env.Dump()
|
|
||||||
#print 'sources:', sources[len(sources)-2]
|
|
||||||
|
|
||||||
#Build library
|
|
||||||
ucore_staticlib = ucore_env.StaticLibrary(target='ucore' + lib_suffix , source=sources)
|
|
||||||
ucore_sharedlib = ucore_env.SharedLibrary(target='ucore' + lib_suffix , source=sources)
|
|
||||||
|
|
||||||
#install targets
|
|
||||||
ucore_env.Alias('install',
|
|
||||||
ucore_env.Install(os.path.join(prefix, 'lib'), [ucore_staticlib]))
|
|
||||||
ucore_env.Alias('install',
|
|
||||||
ucore_env.InstallVersionedLib(os.path.join(prefix, 'lib'), [ucore_sharedlib]))
|
|
||||||
|
|
||||||
ucore_env.Default([ucore_staticlib, ucore_sharedlib])
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import platform
|
|
||||||
|
|
||||||
Import('env', 'build_type', 'prefix', 'lib_suffix', 'version_info', 'test_xml')
|
|
||||||
|
|
||||||
test_env = env.Clone()
|
|
||||||
test_env.Append(LIBPATH = ['#build/src']);
|
|
||||||
test_env.Append(LIBS = ['ucore' + lib_suffix, 'check','m'])
|
|
||||||
|
|
||||||
system = platform.system()
|
|
||||||
|
|
||||||
#NetBSD needs /usr/pkg/...
|
|
||||||
if 'netbsd' in system.lower():
|
|
||||||
test_env.Append(LIBPATH = ['/usr/pkg/lib'])
|
|
||||||
test_env.Append(LINKFLAGS = ['-Wl,-rpath,/usr/pkg/lib'])
|
|
||||||
test_env.Append(CPPPATH = ['/usr/pkg/include'])
|
|
||||||
|
|
||||||
if 'darwin' in system.lower():
|
|
||||||
test_env.Append(LIBPATH = ['/opt/homebrew/lib'])
|
|
||||||
test_env.Append(LINKFLAGS = ['-Wl,-rpath,/opt/homebrew/lib'])
|
|
||||||
test_env.Append(CPPPATH = ['/opt/homebrew/include'])
|
|
||||||
|
|
||||||
if 'darwin' not in system.lower():
|
|
||||||
test_env.Append(LIBS = ['rt'])
|
|
||||||
|
|
||||||
|
|
||||||
tests = test_env.Glob('test_*.c')
|
|
||||||
|
|
||||||
test_executable = 'test_runner'
|
|
||||||
#run test_runner --xml to produce an xml result file
|
|
||||||
if test_xml:
|
|
||||||
test_executable += ' -x'
|
|
||||||
|
|
||||||
#rpath to shared lib, so test_runner can actually be executed
|
|
||||||
test_env.Append(LINKFLAGS = ['-Wl,-rpath,\\$$ORIGIN/../src'])
|
|
||||||
|
|
||||||
prog = test_env.Program('test_runner', tests)
|
|
||||||
cmd = test_env.Command(target='test_phony' ,
|
|
||||||
source = None,
|
|
||||||
action= test_env.Dir('.').abspath + '/' + test_executable)
|
|
||||||
test_env.Depends(cmd, prog)
|
|
||||||
test_env.AlwaysBuild(cmd)
|
|
||||||
test_env.Default(test_executable)
|
|
||||||
Reference in New Issue
Block a user