summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-12-24 15:27:38 +0800
committerruki <[email protected]>2022-12-24 15:27:38 +0800
commit62c09d19c04b66c0031c3e13b7769a7dde7cce72 (patch)
treec12b898aefe2056660c295ca3fce41c5ae76a162
parent2c8b93c27a637f6e475e28b900705b75095821ef (diff)
improve build
-rwxr-xr-xconfigure29
-rw-r--r--core/src/xmake/io/file_close.c10
-rw-r--r--core/src/xmake/io/file_flush.c6
-rw-r--r--core/src/xmake/io/file_open.c2
-rw-r--r--core/src/xmake/io/file_read.c26
-rw-r--r--core/src/xmake/io/file_readable.c4
-rw-r--r--core/src/xmake/io/file_seek.c8
-rw-r--r--core/src/xmake/io/file_write.c24
-rw-r--r--core/src/xmake/io/prefix.h2
-rw-r--r--core/src/xmake/io/stdfile.c2
10 files changed, 67 insertions, 46 deletions
diff --git a/configure b/configure
index c13adbd64..5f55bb2fa 100755
--- a/configure
+++ b/configure
@@ -1608,6 +1608,20 @@ _get_target_compiler_flags() {
result="${result} ${flags}"
fi
fi
+
+ # get flags from environments, e.g. $CFLAGS, $CXXFLAGS
+ if test_eq "${flagname}" "cflags" && test_nz "${CFLAGS}"; then
+ result="${result} ${CFLAGS}"
+ fi
+ if test_eq "${flagname}" "cxxflags" && test_nz "${CXXFLAGS}"; then
+ result="${result} ${CXXFLAGS}"
+ fi
+ if test_eq "${flagname}" "mflags" && test_nz "${MFLAGS}"; then
+ result="${result} ${MFLAGS}"
+ fi
+ if test_eq "${flagname}" "mxxflags" && test_nz "${MXXFLAGS}"; then
+ result="${result} ${MXXFLAGS}"
+ fi
_ret="${result}"
}
@@ -1676,6 +1690,13 @@ _get_target_linker_flags() {
result="${result} ${flags}"
fi
+ # get flags from environments, e.g. $LDFLAGS
+ if test_eq "${flagname}" "ldflags" && test_nz "${LDFLAGS}"; then
+ result="${result} ${LDFLAGS}"
+ fi
+ if test_eq "${flagname}" "shflags" && test_nz "${LDFLAGS}"; then
+ result="${result} ${LDFLAGS}"
+ fi
_ret="${result}"
}
@@ -3539,7 +3560,7 @@ _gmake_add_header() {
_gmake_add_switches() {
echo "ifneq (\$(VERBOSE),1)" >> "${xmake_sh_makefile}"
- echo "V=@" >> "${xmake_sh_makefile}"
+ echo "VV=@" >> "${xmake_sh_makefile}"
echo "endif" >> "${xmake_sh_makefile}"
echo "" >> "${xmake_sh_makefile}"
echo "ifeq (\$(PREFIX),)" >> "${xmake_sh_makefile}"
@@ -3578,7 +3599,7 @@ _gmake_add_build_object_for_gcc_clang() {
local flagname="${4}"
path_directory "${objectfile}"; local objectdir="${_ret}"
print "\t@mkdir -p ${objectdir}" >> "${xmake_sh_makefile}"
- print "\t\$(V)\$(${kind}) -c \$(${flagname}) -o ${objectfile} ${sourcefile}" >> "${xmake_sh_makefile}"
+ print "\t\$(VV)\$(${kind}) -c \$(${flagname}) -o ${objectfile} ${sourcefile}" >> "${xmake_sh_makefile}"
}
_gmake_add_build_object() {
@@ -3618,7 +3639,7 @@ _gmake_add_build_target_for_gcc_clang() {
local flagname="${4}"
path_directory "${targetfile}"; local targetdir="${_ret}"
print "\t@mkdir -p ${targetdir}" >> "${xmake_sh_makefile}"
- print "\t\$(V)\$(${kind}) -o ${targetfile} ${objectfiles} \$(${flagname})" >> "${xmake_sh_makefile}"
+ print "\t\$(VV)\$(${kind}) -o ${targetfile} ${objectfiles} \$(${flagname})" >> "${xmake_sh_makefile}"
}
_gmake_add_build_target_for_ar() {
@@ -3628,7 +3649,7 @@ _gmake_add_build_target_for_ar() {
local flagname="${4}"
path_directory "${targetfile}"; local targetdir="${_ret}"
print "\t@mkdir -p ${targetdir}" >> "${xmake_sh_makefile}"
- print "\t\$(V)\$(${kind}) \$(${flagname}) ${flags} ${targetfile} ${objectfiles}" >> "${xmake_sh_makefile}"
+ print "\t\$(VV)\$(${kind}) \$(${flagname}) ${flags} ${targetfile} ${objectfiles}" >> "${xmake_sh_makefile}"
}
_gmake_add_build_target() {
diff --git a/core/src/xmake/io/file_close.c b/core/src/xmake/io/file_close.c
index 2390b7fd4..52b4a45a7 100644
--- a/core/src/xmake/io/file_close.c
+++ b/core/src/xmake/io/file_close.c
@@ -52,7 +52,7 @@ tb_int_t xm_io_file_close(lua_State* lua)
if (xm_io_file_is_file(file))
{
// check
- tb_assert(file->file_ref);
+ tb_assert(file->u.file_ref);
#ifdef TB_CONFIG_OS_WINDOWS
// write cached data first
@@ -60,7 +60,7 @@ tb_int_t xm_io_file_close(lua_State* lua)
tb_size_t osize = tb_buffer_size(&file->wcache);
if (odata && osize)
{
- if (!tb_stream_bwrit(file->file_ref, odata, osize)) return tb_false;
+ if (!tb_stream_bwrit(file->u.file_ref, odata, osize)) return tb_false;
tb_buffer_clear(&file->wcache);
}
#endif
@@ -68,12 +68,12 @@ tb_int_t xm_io_file_close(lua_State* lua)
// flush filter stream cache, TODO we should fix it in tbox/stream
if ((file->mode & TB_FILE_MODE_RW) == TB_FILE_MODE_RW && file->fstream)
{
- if (!tb_stream_sync(file->file_ref, tb_false)) return tb_false;
+ if (!tb_stream_sync(file->u.file_ref, tb_false)) return tb_false;
}
// close file
- tb_stream_clos(file->file_ref);
- file->file_ref = tb_null;
+ tb_stream_clos(file->u.file_ref);
+ file->u.file_ref = tb_null;
// exit fstream
if (file->fstream) tb_stream_exit(file->fstream);
diff --git a/core/src/xmake/io/file_flush.c b/core/src/xmake/io/file_flush.c
index 6e2d86f34..81f2b415c 100644
--- a/core/src/xmake/io/file_flush.c
+++ b/core/src/xmake/io/file_flush.c
@@ -36,7 +36,7 @@
static tb_bool_t xm_io_std_flush_impl(xm_io_file_t* file)
{
tb_assert_and_check_return_val(xm_io_file_is_std(file), tb_false);
- return (file->std_ref != tb_stdfile_input())? tb_stdfile_flush(file->std_ref) : tb_false;
+ return (file->u.std_ref != tb_stdfile_input())? tb_stdfile_flush(file->u.std_ref) : tb_false;
}
static tb_bool_t xm_io_file_flush_impl(xm_io_file_t* file)
@@ -50,11 +50,11 @@ static tb_bool_t xm_io_file_flush_impl(xm_io_file_t* file)
tb_size_t osize = tb_buffer_size(&file->wcache);
if (odata && osize)
{
- if (!tb_stream_bwrit(file->file_ref, odata, osize)) return tb_false;
+ if (!tb_stream_bwrit(file->u.file_ref, odata, osize)) return tb_false;
tb_buffer_clear(&file->wcache);
}
#endif
- return tb_stream_sync(file->file_ref, tb_false);
+ return tb_stream_sync(file->u.file_ref, tb_false);
}
/* //////////////////////////////////////////////////////////////////////////////////////
diff --git a/core/src/xmake/io/file_open.c b/core/src/xmake/io/file_open.c
index 435e2aec0..ea5f36dda 100644
--- a/core/src/xmake/io/file_open.c
+++ b/core/src/xmake/io/file_open.c
@@ -292,7 +292,7 @@ tb_int_t xm_io_file_open(lua_State* lua)
tb_assert_and_check_return_val(file, 0);
// init file
- file->file_ref = file_ref;
+ file->u.file_ref = file_ref;
file->stream = stream;
file->fstream = fstream;
file->mode = mode;
diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c
index 7bba88e20..aefa8f774 100644
--- a/core/src/xmake/io/file_read.c
+++ b/core/src/xmake/io/file_read.c
@@ -98,7 +98,7 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re
static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t* file, tb_char_t const* continuation, tb_bool_t keep_crlf)
{
// check
- tb_assert(buf && file && continuation && xm_io_file_is_file(file) && file->file_ref);
+ tb_assert(buf && file && continuation && xm_io_file_is_file(file) && file->u.file_ref);
// is binary?
tb_bool_t is_binary = file->encoding == XM_IO_FILE_ENCODING_BINARY;
@@ -112,7 +112,7 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t* fi
tb_buffer_clear(&file->rcache);
// read line data
- tb_long_t size = xm_io_file_buffer_readline(file->file_ref, &file->rcache);
+ tb_long_t size = xm_io_file_buffer_readline(file->u.file_ref, &file->rcache);
// translate line data
tb_int_t result = PL_FAIL;
@@ -177,7 +177,7 @@ static tb_int_t xm_io_file_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_t* fi
static tb_int_t xm_io_file_read_all_directly(lua_State* lua, xm_io_file_t* file)
{
// check
- tb_assert(lua && file && xm_io_file_is_file(file) && file->file_ref);
+ tb_assert(lua && file && xm_io_file_is_file(file) && file->u.file_ref);
// init buffer
tb_buffer_t buf;
@@ -186,7 +186,7 @@ static tb_int_t xm_io_file_read_all_directly(lua_State* lua, xm_io_file_t* file)
// read all
tb_byte_t data[TB_STREAM_BLOCK_MAXN];
- tb_stream_ref_t stream = file->file_ref;
+ tb_stream_ref_t stream = file->u.file_ref;
while (!tb_stream_beof(stream))
{
tb_long_t real = tb_stream_read(stream, data, sizeof(data));
@@ -209,7 +209,7 @@ static tb_int_t xm_io_file_read_all_directly(lua_State* lua, xm_io_file_t* file)
static tb_int_t xm_io_file_read_all(lua_State* lua, xm_io_file_t* file, tb_char_t const* continuation)
{
// check
- tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->file_ref);
+ tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref);
// is binary? read all directly
tb_bool_t is_binary = file->encoding == XM_IO_FILE_ENCODING_BINARY;
@@ -248,7 +248,7 @@ static tb_int_t xm_io_file_read_all(lua_State* lua, xm_io_file_t* file, tb_char_
static tb_int_t xm_io_file_read_line(lua_State* lua, xm_io_file_t* file, tb_char_t const* continuation, tb_bool_t keep_crlf)
{
// check
- tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->file_ref);
+ tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref);
// init buffer
tb_buffer_t buf;
@@ -285,7 +285,7 @@ static tb_int_t xm_io_file_read_line(lua_State* lua, xm_io_file_t* file, tb_char
static tb_int_t xm_io_file_read_n(lua_State* lua, xm_io_file_t* file, tb_char_t const* continuation, tb_long_t n)
{
// check
- tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->file_ref);
+ tb_assert(lua && file && continuation && xm_io_file_is_file(file) && file->u.file_ref);
// check continuation
if (*continuation != '\0')
@@ -299,7 +299,7 @@ static tb_int_t xm_io_file_read_n(lua_State* lua, xm_io_file_t* file, tb_char_t
if (n == 0)
{
tb_byte_t* data = tb_null;
- if (tb_stream_need(file->file_ref, &data, 1))
+ if (tb_stream_need(file->u.file_ref, &data, 1))
{
lua_pushliteral(lua, "");
ok = tb_true;
@@ -310,7 +310,7 @@ static tb_int_t xm_io_file_read_n(lua_State* lua, xm_io_file_t* file, tb_char_t
tb_byte_t* bufptr = tb_buffer_resize(&file->rcache, n + 1);
if (bufptr)
{
- if (tb_stream_bread(file->file_ref, bufptr, n))
+ if (tb_stream_bread(file->u.file_ref, bufptr, n))
{
lua_pushlstring(lua, (tb_char_t const*)bufptr, n);
ok = tb_true;
@@ -330,7 +330,7 @@ static tb_size_t xm_io_file_std_buffer_pushline(tb_buffer_ref_t buf, xm_io_file_
tb_char_t strbuf[8192];
tb_size_t buflen = 0;
tb_size_t result = PL_FAIL;
- if (tb_stdfile_gets(file->std_ref, strbuf, tb_arrayn(strbuf) - 1))
+ if (tb_stdfile_gets(file->u.std_ref, strbuf, tb_arrayn(strbuf) - 1))
buflen = tb_strlen(strbuf);
else return PL_EOF;
@@ -457,7 +457,7 @@ static tb_int_t xm_io_file_std_read_n(lua_State* lua, xm_io_file_t* file, tb_cha
if (n == 0)
{
tb_char_t ch;
- if (!tb_stdfile_peek(file->std_ref, &ch))
+ if (!tb_stdfile_peek(file->u.std_ref, &ch))
lua_pushnil(lua);
else
lua_pushliteral(lua, "");
@@ -469,7 +469,7 @@ static tb_int_t xm_io_file_std_read_n(lua_State* lua, xm_io_file_t* file, tb_cha
tb_assert(buf_ptr);
// io.read(n)
- if (tb_stdfile_read(file->std_ref, buf_ptr, (tb_size_t)n))
+ if (tb_stdfile_read(file->u.std_ref, buf_ptr, (tb_size_t)n))
lua_pushlstring(lua, (tb_char_t const*)buf_ptr, (size_t)n);
else lua_pushnil(lua);
return 1;
@@ -486,7 +486,7 @@ static tb_int_t xm_io_file_std_read_num(lua_State* lua, xm_io_file_t* file, tb_c
// read number
tb_char_t strbuf[512];
- if (tb_stdfile_gets(file->std_ref, strbuf, tb_arrayn(strbuf)))
+ if (tb_stdfile_gets(file->u.std_ref, strbuf, tb_arrayn(strbuf)))
lua_pushnumber(lua, tb_s10tod(strbuf)); // TODO check invalid float number string and push nil
else lua_pushnil(lua);
return 1;
diff --git a/core/src/xmake/io/file_readable.c b/core/src/xmake/io/file_readable.c
index 154e2e188..f3043919b 100644
--- a/core/src/xmake/io/file_readable.c
+++ b/core/src/xmake/io/file_readable.c
@@ -49,8 +49,8 @@ tb_int_t xm_io_file_readable(lua_State* lua)
// has readable data?
tb_bool_t ok = tb_false;
- if (xm_io_file_is_file(file)) ok = tb_stream_left(file->file_ref) > 0;
- else ok = tb_stdfile_readable(file->std_ref);
+ if (xm_io_file_is_file(file)) ok = tb_stream_left(file->u.file_ref) > 0;
+ else ok = tb_stdfile_readable(file->u.std_ref);
lua_pushboolean(lua, ok);
return 1;
}
diff --git a/core/src/xmake/io/file_seek.c b/core/src/xmake/io/file_seek.c
index 32448c9bd..5f98560f4 100644
--- a/core/src/xmake/io/file_seek.c
+++ b/core/src/xmake/io/file_seek.c
@@ -56,25 +56,25 @@ tb_int_t xm_io_file_seek(lua_State* lua)
// seek file
if (xm_io_file_is_file(file))
{
- tb_assert(file->file_ref);
+ tb_assert(file->u.file_ref);
switch (*whence)
{
case 's': // "set"
break;
case 'e': // "end"
{
- tb_hong_t size = tb_stream_size(file->file_ref);
+ tb_hong_t size = tb_stream_size(file->u.file_ref);
if (size > 0 && size + offset <= size)
offset = size + offset;
else xm_io_return_error(lua, "seek failed, invalid offset!");
}
break;
default: // "cur"
- offset = tb_stream_offset(file->file_ref) + offset;
+ offset = tb_stream_offset(file->u.file_ref) + offset;
break;
}
- if (tb_stream_seek(file->file_ref, offset))
+ if (tb_stream_seek(file->u.file_ref, offset))
{
lua_pushnumber(lua, (lua_Number)offset);
return 1;
diff --git a/core/src/xmake/io/file_write.c b/core/src/xmake/io/file_write.c
index a374057a4..97285dca7 100644
--- a/core/src/xmake/io/file_write.c
+++ b/core/src/xmake/io/file_write.c
@@ -36,7 +36,7 @@
static tb_void_t xm_io_file_write_file_utfbom(xm_io_file_t* file)
{
// check
- tb_assert(file && xm_io_file_is_file(file) && file->file_ref);
+ tb_assert(file && xm_io_file_is_file(file) && file->u.file_ref);
// write bom
switch (file->encoding)
@@ -44,19 +44,19 @@ static tb_void_t xm_io_file_write_file_utfbom(xm_io_file_t* file)
case TB_CHARSET_TYPE_UTF8:
{
static tb_byte_t bom[] = {0xef, 0xbb, 0xbf};
- tb_stream_bwrit(file->file_ref, bom, sizeof(bom));
+ tb_stream_bwrit(file->u.file_ref, bom, sizeof(bom));
}
break;
case TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_LE:
{
static tb_byte_t bom[] = {0xff, 0xfe};
- tb_stream_bwrit(file->file_ref, bom, sizeof(bom));
+ tb_stream_bwrit(file->u.file_ref, bom, sizeof(bom));
}
break;
case TB_CHARSET_TYPE_UTF16 | TB_CHARSET_TYPE_BE:
{
static tb_byte_t bom[] = {0xfe, 0xff};
- tb_stream_bwrit(file->file_ref, bom, sizeof(bom));
+ tb_stream_bwrit(file->u.file_ref, bom, sizeof(bom));
}
break;
default:
@@ -65,13 +65,13 @@ static tb_void_t xm_io_file_write_file_utfbom(xm_io_file_t* file)
}
static tb_void_t xm_io_file_write_file_directly(xm_io_file_t* file, tb_byte_t const* data, tb_size_t size)
{
- tb_assert(file && data && xm_io_file_is_file(file) && file->file_ref);
- tb_stream_bwrit(file->file_ref, data, size);
+ tb_assert(file && data && xm_io_file_is_file(file) && file->u.file_ref);
+ tb_stream_bwrit(file->u.file_ref, data, size);
}
static tb_void_t xm_io_file_write_file_transcrlf(xm_io_file_t* file, tb_byte_t const* data, tb_size_t size)
{
// check
- tb_assert(file && data && xm_io_file_is_file(file) && file->file_ref);
+ tb_assert(file && data && xm_io_file_is_file(file) && file->u.file_ref);
#ifdef TB_CONFIG_OS_WINDOWS
@@ -80,7 +80,7 @@ static tb_void_t xm_io_file_write_file_transcrlf(xm_io_file_t* file, tb_byte_t c
tb_size_t osize = tb_buffer_size(&file->wcache);
if (odata && osize)
{
- if (!tb_stream_bwrit(file->file_ref, odata, osize)) return ;
+ if (!tb_stream_bwrit(file->u.file_ref, odata, osize)) return ;
tb_buffer_clear(&file->wcache);
}
@@ -95,12 +95,12 @@ static tb_void_t xm_io_file_write_file_transcrlf(xm_io_file_t* file, tb_byte_t c
{
if (lf > p && lf[-1] == '\r')
{
- if (!tb_stream_bwrit(file->file_ref, (tb_byte_t const*)p, lf + 1 - p)) break;
+ if (!tb_stream_bwrit(file->u.file_ref, (tb_byte_t const*)p, lf + 1 - p)) break;
}
else
{
- if (lf > p && !tb_stream_bwrit(file->file_ref, (tb_byte_t const*)p, lf - p)) break;
- if (!tb_stream_bwrit(file->file_ref, (tb_byte_t const*)"\r\n", 2)) break;
+ if (lf > p && !tb_stream_bwrit(file->u.file_ref, (tb_byte_t const*)p, lf - p)) break;
+ if (!tb_stream_bwrit(file->u.file_ref, (tb_byte_t const*)"\r\n", 2)) break;
}
// next line
@@ -128,7 +128,7 @@ static tb_void_t xm_io_file_write_std(xm_io_file_t* file, tb_byte_t const* data,
tb_check_return(type != XM_IO_FILE_TYPE_STDIN);
// write data to stdout/stderr
- tb_stdfile_writ(file->std_ref, data, size);
+ tb_stdfile_writ(file->u.std_ref, data, size);
}
/* //////////////////////////////////////////////////////////////////////////////////////
diff --git a/core/src/xmake/io/prefix.h b/core/src/xmake/io/prefix.h
index bec186a92..2f4705e70 100644
--- a/core/src/xmake/io/prefix.h
+++ b/core/src/xmake/io/prefix.h
@@ -81,7 +81,7 @@ typedef struct __xm_io_file_t
// the standard io file
tb_stdfile_ref_t std_ref;
- };
+ }u;
tb_stream_ref_t stream; // the file stream for XM_IO_FILE_TYPE_FILE
tb_stream_ref_t fstream; // the file charset stream filter
diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c
index 06d6fc579..13edbfc79 100644
--- a/core/src/xmake/io/stdfile.c
+++ b/core/src/xmake/io/stdfile.c
@@ -116,7 +116,7 @@ static xm_io_file_t* xm_io_stdfile_new(lua_State* lua, tb_size_t type)
tb_assert_and_check_return_val(file, tb_null);
// init file
- file->std_ref = fp;
+ file->u.std_ref = fp;
file->stream = tb_null;
file->fstream = tb_null;
file->type = xm_io_stdfile_isatty(type);