Skip to content

Commit

Permalink
improve compile mode
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jul 31, 2018
1 parent e941f54 commit 5b33798
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
11 changes: 6 additions & 5 deletions src/demo/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,14 @@ tb_int_t main(tb_int_t argc, tb_char_t** argv)
{
// init tbox
#if 0
if (!tb_init(tb_null, tb_default_allocator((tb_byte_t*)malloc(300 * 1024 * 1024), 300 * 1024 * 1024))) return 0;
if (!tb_init(tb_null, tb_default_allocator((tb_byte_t*)malloc(300 * 1024 * 1024), 300 * 1024 * 1024))) return -1;
#elif 0
if (!tb_init(tb_null, tb_static_allocator((tb_byte_t*)malloc(300 * 1024 * 1024), 300 * 1024 * 1024))) return 0;
#elif defined(__tb_valgrind__) && defined(TB_CONFIG_VALGRIND_HAVE_VALGRIND_STACK_REGISTER)
if (!tb_init(tb_null, tb_native_allocator())) return 0;
if (!tb_init(tb_null, tb_static_allocator((tb_byte_t*)malloc(300 * 1024 * 1024), 300 * 1024 * 1024))) return -1;
#elif (defined(__tb_valgrind__) && defined(TB_CONFIG_VALGRIND_HAVE_VALGRIND_STACK_REGISTER)) \
|| defined(__tb_sanitize_address__) || defined(__tb_sanitize_thread__)
if (!tb_init(tb_null, tb_native_allocator())) return -1;
#else
if (!tb_init(tb_null, tb_null)) return 0;
if (!tb_init(tb_null, tb_null)) return -1;
#endif

// find the main func from the first argument
Expand Down
7 changes: 4 additions & 3 deletions src/demo/micro.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ static tb_demo_t g_demo[] =
tb_int_t main(tb_int_t argc, tb_char_t** argv)
{
// init tbox
#if 1
if (!tb_init(tb_null, tb_static_allocator((tb_byte_t*)malloc(1024 * 1024), 1024 * 1024))) return 0;
#if (defined(__tb_valgrind__) && defined(TB_CONFIG_VALGRIND_HAVE_VALGRIND_STACK_REGISTER)) \
|| defined(__tb_sanitize_address__) || defined(__tb_sanitize_thread__)
if (!tb_init(tb_null, tb_native_allocator())) return -1;
#else
if (!tb_init(tb_null, tb_native_allocator())) return 0;
if (!tb_init(tb_null, tb_static_allocator((tb_byte_t*)malloc(1024 * 1024), 1024 * 1024))) return -1;
#endif

// find the main func from the first argument
Expand Down
37 changes: 24 additions & 13 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ add_mxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing")
set_objectdir("$(buildir)/$(mode)/$(arch)/.objs")
set_targetdir("$(buildir)/$(mode)/$(arch)")

-- the debug, sanitize or coverage mode
if is_mode("debug", "sanitize", "coverage") then
-- the debug, coverage, valgrind or sanitize-address/thread mode
if is_mode("debug", "coverage", "valgrind", "asan", "tsan") then

-- enable the debug symbols
set_symbols("debug")
Expand All @@ -33,13 +33,29 @@ if is_mode("debug", "sanitize", "coverage") then
set_optimize("none")

-- add defines for debug
add_defines("__tb_debug__")
if is_mode("debug") then
add_defines("__tb_debug__")
end

-- add defines for valgrind
if is_mode("valgrind") then
add_defines("__tb_valgrind__")
end

-- attempt to enable sanitize-address for pc
if is_mode("sanitize") and is_arch("i386", "x86_64") then
-- attempt to enable sanitize-address
if is_mode("asan") then
add_cxflags("-fsanitize=address", "-ftrapv")
add_mxflags("-fsanitize=address", "-ftrapv")
add_ldflags("-fsanitize=address")
add_defines("__tb_sanitize_address__")
end

-- attempt to enable sanitize-thread
if is_mode("tsan") then
add_cxflags("-fsanitize=thread")
add_mxflags("-fsanitize=thread")
add_ldflags("-fsanitize=thread")
add_defines("__tb_sanitize_thread__")
end

-- enable coverage
Expand All @@ -50,8 +66,8 @@ if is_mode("debug", "sanitize", "coverage") then
end
end

-- the release, profile or valgrind mode
if is_mode("release", "profile", "valgrind") then
-- the release, profile mode
if is_mode("release", "profile") then

-- the release mode
if is_mode("release") then
Expand All @@ -62,7 +78,7 @@ if is_mode("release", "profile", "valgrind") then
-- strip all symbols
set_strip("all")

-- the profile/valgrind mode
-- the profile mode
else

-- enable the debug symbols
Expand All @@ -71,11 +87,6 @@ if is_mode("release", "profile", "valgrind") then
-- enable gprof
add_cxflags("-pg")
add_ldflags("-pg")

-- add defines for valgrind
if is_mode("valgrind") then
add_defines("__tb_valgrind__")
end
end

-- small or micro?
Expand Down

0 comments on commit 5b33798

Please sign in to comment.