From 89516d5a6ee4e3c4682da7c9d94fd010a7089d68 Mon Sep 17 00:00:00 2001 From: Steve Osselton Date: Fri, 8 Jun 2018 12:09:59 -0700 Subject: [PATCH 1/2] Initial support added for building on MacOS with brew Signed-off-by: Steve Osselton --- SConscript | 9 ++++++++- SConstruct | 32 +++++++++++++++++++++++++++++++- ext/SConscript | 5 ++++- src/compat.h | 2 ++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/SConscript b/SConscript index 65797e43..06694179 100755 --- a/SConscript +++ b/SConscript @@ -22,6 +22,9 @@ if platform == 'win32': libenv.Append(LIBS = env['UV_LIBS']) elif platform == 'posix': libenv.Append(CCFLAGS = ['-Wall', '-Wno-format-extra-args']) +elif platform == 'darwin': + libenv.Append(CPPDEFINES = ['__STDC_WANT_LIB_EXT1__=0', 'DARWIN']) + libenv.Append(CCFLAGS = ['-Wall', '-Wno-format-extra-args']) # Include the fuzzing hooks when the sanitizer is enabled if platform == 'posix' and env['fsan'] == True: @@ -105,7 +108,7 @@ if platform == 'posix': libenv.Install('#/build/dist/lib', ns3shlib) swig_docs = [] -if env['python']: +if env['python'] and platform != 'darwin': # Using SWIG to build the python wrapper pyenv = libenv.Clone() pyenv.VariantDir('swig/py', 'swig') @@ -159,6 +162,8 @@ if env['nodejs'] and platform == 'posix': testenv = env.Clone() if testenv['PLATFORM'] == 'win32': testenv.Append(CPPDEFINES = ['_CRT_SECURE_NO_WARNINGS', '__STDC_WANT_SECURE_LIB__=0']) +elif platform == 'darwin': + testenv.Append(CPPDEFINES = ['__STDC_WANT_LIB_EXT1__=0', 'DARWIN']) testenv.Append(CPPPATH = ['#/ext/safestring/include', 'src']) testenv.Append(LIBS = [lib, env['UV_LIBS']]) @@ -212,6 +217,8 @@ if platform == 'posix' and env['fsan'] == True: exampleenv = env.Clone() if exampleenv['PLATFORM'] == 'win32': exampleenv.Append(CPPDEFINES = ['_CRT_SECURE_NO_WARNINGS']) +elif platform == 'darwin': + exampleenv.Append(CPPDEFINES = ['__STDC_WANT_LIB_EXT1__=0', 'DARWIN']) exampleenv.Append(LIBS = [lib, env['UV_LIBS']]) examplesrcs = ['examples/pub_many.c', diff --git a/SConstruct b/SConstruct index c41ef2d9..22b0d050 100755 --- a/SConstruct +++ b/SConstruct @@ -33,6 +33,11 @@ if platform.system() == 'Linux': BoolVariable('fsan', 'Enable fuzzer sanitizer?', False), BoolVariable('cov', 'Enable code coverage?', False)) +# Darwin-specific command line variables +if platform.system() == 'Darwin': + vars.AddVariables( + PathVariable('UV_PATH', 'Path where libuv is installed', '', PathVariable.PathAccept)) + tools=['default', 'textfile', DPS] # Doxygen is optional try: @@ -207,8 +212,33 @@ elif env['PLATFORM'] == 'posix': env.Prepend(LIBPATH = env['UV_PATH']) env.Prepend(CPPPATH = env['UV_PATH'] + '/include') +elif env['PLATFORM'] == 'darwin': + + # Treat warnings as errors + env.Append(CCFLAGS = ['-Werror']) + + if env['variant'] == 'debug': + env.Append(CCFLAGS = ['-O', '-DDPS_DEBUG']) + else: + env.Append(CCFLAGS = ['-O3', '-DNDEBUG']) + + # Where to find Python.h + if env['target'] == 'yocto': + env['PY_CPPPATH'] = [os.getenv('SYSROOT') + '/usr/include/python2.7'] + else: + env['PY_CPPPATH'] = ['/usr/include/python2.7'] + env['PY_LIBPATH'] = [] + + # Where to find libuv and the libraries it needs + env['UV_LIBS'] = ['uv', 'pthread'] + + if env['UV_PATH']: + env.Prepend(LIBPATH = env['UV_PATH']) + env.Prepend(CPPPATH = env['UV_PATH'] + '/include') + else: - print('Unsupported system') + + print('Unsupported system: ' + env['PLATFORM']) exit() env.Append(LIBPATH=['./ext']) diff --git a/ext/SConscript b/ext/SConscript index f2670029..73cdb4eb 100644 --- a/ext/SConscript +++ b/ext/SConscript @@ -97,6 +97,9 @@ if scEnv['PLATFORM'] == 'win32': elif scEnv['PLATFORM'] == 'posix': scEnv.Append(CPPDEFINES = ['_ISCO99_SOURCE']) scEnv.Append(CFLAGS = ['-Os', '-fPIC', '-std=c99', '-Wall', '-Wextra', '-Wno-unused-parameter', '-Wno-implicit-fallthrough', '-MMD']) +elif scEnv['PLATFORM'] == 'darwin': + scEnv.Append(CPPDEFINES = ['_ISCO99_SOURCE']) + scEnv.Append(CFLAGS = ['-Os', '-fPIC', '-std=c99', '-Wall', '-Wextra', '-Wno-unused-parameter', '-Wno-implicit-fallthrough', '-MMD']) else: print('Unsupported system') exit() @@ -106,7 +109,7 @@ scsrcs = ['./safestring/safeclib/ignore_handler_s.c', './safestring/safeclib/safe_str_constraint.c', './safestring/safeclib/memcpy_s.c', './safestring/safeclib/memmove_s.c', - './safestring/safeclib/memset_s.c', +# './safestring/safeclib/memset_s.c', './safestring/safeclib/memzero_s.c', './safestring/safeclib/strcmp_s.c', './safestring/safeclib/strncpy_s.c', diff --git a/src/compat.h b/src/compat.h index fbc9cf04..537a38bd 100644 --- a/src/compat.h +++ b/src/compat.h @@ -60,7 +60,9 @@ inline char* strndup(const char* str, size_t maxLen) #else // posix +#ifndef DARWIN #include +#endif #define BSWAP_32(n) __builtin_bswap32(n) #define BSWAP_64(n) __builtin_bswap64(n) From b4bd9bcf52b886746eeb44e7d90267fa18ff0c91 Mon Sep 17 00:00:00 2001 From: Steve Osselton Date: Fri, 8 Jun 2018 12:25:02 -0700 Subject: [PATCH 2/2] Accidental change backout Signed-off-by: Steve Osselton --- ext/SConscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/SConscript b/ext/SConscript index 73cdb4eb..7b578a75 100644 --- a/ext/SConscript +++ b/ext/SConscript @@ -109,7 +109,7 @@ scsrcs = ['./safestring/safeclib/ignore_handler_s.c', './safestring/safeclib/safe_str_constraint.c', './safestring/safeclib/memcpy_s.c', './safestring/safeclib/memmove_s.c', -# './safestring/safeclib/memset_s.c', + './safestring/safeclib/memset_s.c', './safestring/safeclib/memzero_s.c', './safestring/safeclib/strcmp_s.c', './safestring/safeclib/strncpy_s.c',