diff --git a/SConscript b/SConscript index 55b5c100..9ed2a719 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: @@ -106,7 +109,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') @@ -162,6 +165,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']]) @@ -221,6 +226,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 38d141c9..4fb31ac2 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: @@ -213,8 +218,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..7b578a75 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() diff --git a/src/compat.h b/src/compat.h index b92b54a7..b6c55a59 100644 --- a/src/compat.h +++ b/src/compat.h @@ -62,7 +62,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)