summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-12-18 17:24:55 +0800
committerGitHub <[email protected]>2022-12-18 17:24:55 +0800
commit68425b26424dbe2aead586a0e28fc76b640a3d57 (patch)
treef9e77acb0f55bfaeb62ca86826402449cd982391
parent4e4f010e7fd1123dcbc272549f3d45f5261bc8a9 (diff)
parent6cebe3979a67dbbc778692571f8dbdeb33a8fecb (diff)
Merge pull request #3175 from xmake-io/xmake.sh
improve xmake.sh
-rwxr-xr-xconfigure242
-rwxr-xr-xcore/src/lua-cjson/xmake.sh8
m---------core/src/tbox/tbox0
-rwxr-xr-xcore/src/tbox/xmake.sh1
-rwxr-xr-xcore/src/xmake/xmake.sh30
-rwxr-xr-xcore/xmake.sh130
6 files changed, 278 insertions, 133 deletions
diff --git a/configure b/configure
index af44f5dde..62b3b9d8f 100755
--- a/configure
+++ b/configure
@@ -974,11 +974,12 @@ _get_option_item() {
_set_option_item() {
local name=${1}
local key=${2}
- local value=${3}
+ shift
+ shift
if test_nz "${name}"; then
- _map_set "options" "${name}_${key}" "${value}"
+ _map_set "options" "${name}_${key}" "${@}"
else
- raise "please call set_${key}(${value}) in the option scope!"
+ raise "please call set_${key}(${@}) in the option scope!"
fi
}
@@ -986,13 +987,14 @@ _set_option_item() {
_add_option_item() {
local name=${1}
local key=${2}
- local value=${3}
+ shift
+ shift
if test_nz "${name}"; then
_map_get "options" "${name}_${key}"; local values="${_ret}"
- values="${values} ${value}"
+ values="${values} ${@}"
_map_set "options" "${name}_${key}" "${values}"
else
- raise "please call add_${key}(${value}) in the option scope!"
+ raise "please call add_${key}(${@}) in the option scope!"
fi
}
@@ -1137,8 +1139,7 @@ add_cfuncs() {
if ! ${_loading_options}; then
return
fi
- local cfuncs="${1}"
- _add_option_item "${_xmake_sh_option_current}" "cfuncs" "${cfuncs}"
+ _add_option_item "${_xmake_sh_option_current}" "cfuncs" "${@}"
}
# add cxxfuncs in option
@@ -1146,8 +1147,7 @@ add_cxxfuncs() {
if ! ${_loading_options}; then
return
fi
- local cxxfuncs="${1}"
- _add_option_item "${_xmake_sh_option_current}" "cxxfuncs" "${cxxfuncs}"
+ _add_option_item "${_xmake_sh_option_current}" "cxxfuncs" "${@}"
}
# add cincludes in option
@@ -1155,8 +1155,7 @@ add_cincludes() {
if ! ${_loading_options}; then
return
fi
- local cincludes="${1}"
- _add_option_item "${_xmake_sh_option_current}" "cincludes" "${cincludes}"
+ _add_option_item "${_xmake_sh_option_current}" "cincludes" "${@}"
}
# add cxxincludes in option
@@ -1164,8 +1163,7 @@ add_cxxincludes() {
if ! ${_loading_options}; then
return
fi
- local cxxincludes="${1}"
- _add_option_item "${_xmake_sh_option_current}" "cxxincludes" "${cxxincludes}"
+ _add_option_item "${_xmake_sh_option_current}" "cxxincludes" "${@}"
}
# add ctypes in option
@@ -1173,8 +1171,7 @@ add_ctypes() {
if ! ${_loading_options}; then
return
fi
- local ctypes="${1}"
- _add_option_item "${_xmake_sh_option_current}" "ctypes" "${ctypes}"
+ _add_option_item "${_xmake_sh_option_current}" "ctypes" "${@}"
}
# add cxxtypes in option
@@ -1182,8 +1179,7 @@ add_cxxtypes() {
if ! ${_loading_options}; then
return
fi
- local cxxtypes="${1}"
- _add_option_item "${_xmake_sh_option_current}" "cxxtypes" "${cxxtypes}"
+ _add_option_item "${_xmake_sh_option_current}" "cxxtypes" "${@}"
}
# add csnippets in option
@@ -1204,6 +1200,15 @@ add_cxxsnippets() {
_add_option_item "${_xmake_sh_option_current}" "cxxsnippets" "${cxxsnippets}"
}
+# before_check in option
+before_check() {
+ if ! ${_loading_options}; then
+ return
+ fi
+ local funcname="${1}"
+ _add_option_item "${_xmake_sh_option_current}" "before_check" "${funcname}"
+}
+
#-----------------------------------------------------------------------------
# target configuration apis
#
@@ -1268,11 +1273,12 @@ _get_target_item() {
_set_target_item() {
local name=${1}
local key=${2}
- local value=${3}
+ shift
+ shift
if test_nz "${name}"; then
- _map_set "targets" "${name}_${key}" "${value}"
+ _map_set "targets" "${name}_${key}" "${@}"
else
- _map_set "targets" "__root_${key}" "${value}"
+ _map_set "targets" "__root_${key}" "${@}"
fi
}
@@ -1280,14 +1286,15 @@ _set_target_item() {
_add_target_item() {
local name=${1}
local key=${2}
- local value=${3}
+ shift
+ shift
if test_nz "${name}"; then
_map_get "targets" "${name}_${key}"; local values="${_ret}"
- values="${values} ${value}"
+ values="${values} ${@}"
_map_set "targets" "${name}_${key}" "${values}"
else
_map_get "targets" "__root_${key}"; local values="${_ret}"
- values="${values} ${value}"
+ values="${values} ${@}"
_map_set "targets" "__root_${key}" "${values}"
fi
}
@@ -1583,6 +1590,18 @@ _get_target_compiler_flags() {
# get raw flags, e.g. add_cflags, add_cxxflags
_get_flagname "${toolkind}"; local flagname="${_ret}"
_get_target_item "${name}" "${flagname}"; local flags="${_ret}"
+ # get flags from target deps
+ _get_target_librarydeps "${name}"; local deps="${_ret}"
+ local dep=""
+ for dep in ${deps}; do
+ _get_target_item "${dep}" "kind"; local dep_kind="${_ret}"
+ if test_eq "${dep_kind}" "static" || test_eq "${dep_kind}" "shared"; then
+ _get_target_item "${dep}" "${flagname}_public"; local depflags="${_ret}"
+ if test_nz "${depflags}"; then
+ flags="${flags} ${depflags}"
+ fi
+ fi
+ done
if test_nz "${flags}"; then
result="${result} ${flags}"
fi
@@ -1651,6 +1670,16 @@ _get_target_linker_flags() {
# get raw flags, e.g. add_ldflags, add_shflags
_get_flagname "${toolkind}"; local flagname="${_ret}"
_get_target_item "${name}" "${flagname}"; local flags="${_ret}"
+ # get flags from target deps
+ for dep in ${deps}; do
+ _get_target_item "${dep}" "kind"; local dep_kind="${_ret}"
+ if test_eq "${dep_kind}" "static" || test_eq "${dep_kind}" "shared"; then
+ _get_target_item "${dep}" "${flagname}_public"; local depflags="${_ret}"
+ if test_nz "${depflags}"; then
+ flags="${flags} ${depflags}"
+ fi
+ fi
+ done
if test_nz "${flags}"; then
result="${result} ${flags}"
fi
@@ -1912,10 +1941,7 @@ add_deps() {
if ! ${_loading_targets}; then
return
fi
- local dep=""
- for dep in $@; do
- _add_target_item "${_xmake_sh_target_current}" "deps" "${dep}"
- done
+ _add_target_item "${_xmake_sh_target_current}" "deps" "${@}"
}
# add files in target
@@ -1970,9 +1996,7 @@ add_defines() {
done
fi
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
- for define in $@; do
- _add_option_item "${_xmake_sh_option_current}" "defines" "${define}"
- done
+ _add_option_item "${_xmake_sh_option_current}" "defines" "${@}"
fi
}
@@ -1996,9 +2020,7 @@ add_udefines() {
done
fi
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
- for udefine in $@; do
- _add_option_item "${_xmake_sh_option_current}" "udefines" "${udefine}"
- done
+ _add_option_item "${_xmake_sh_option_current}" "udefines" "${@}"
fi
}
@@ -2011,7 +2033,9 @@ add_includedirs() {
if ! path_is_absolute "${dir}"; then
dir="${xmake_sh_scriptdir}/${dir}"
fi
- path_relative ${xmake_sh_projectdir} "${dir}"; dir="${_ret}"
+ if string_startswith "${dir}" "${xmake_sh_projectdir}"; then
+ path_relative ${xmake_sh_projectdir} "${dir}"; dir="${_ret}"
+ fi
if ${_loading_targets} && test_z "${_xmake_sh_option_current}"; then
_add_target_item "${_xmake_sh_target_current}" "includedirs" "${dir}"
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
@@ -2027,7 +2051,9 @@ add_includedirs() {
if ! path_is_absolute "${dir}"; then
dir="${xmake_sh_scriptdir}/${dir}"
fi
- path_relative ${xmake_sh_projectdir} "${dir}"; dir="${_ret}"
+ if string_startswith "${dir}" "${xmake_sh_projectdir}"; then
+ path_relative ${xmake_sh_projectdir} "${dir}"; dir="${_ret}"
+ fi
if ${_loading_targets} && test_z "${_xmake_sh_option_current}"; then
_add_target_item "${_xmake_sh_target_current}" "includedirs_public" "${dir}"
fi
@@ -2056,9 +2082,7 @@ add_links() {
done
fi
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
- for link in $@; do
- _add_option_item "${_xmake_sh_option_current}" "links" "${link}"
- done
+ _add_option_item "${_xmake_sh_option_current}" "links" "${@}"
fi
}
@@ -2082,9 +2106,7 @@ add_syslinks() {
done
fi
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
- for syslink in $@; do
- _add_option_item "${_xmake_sh_option_current}" "syslinks" "${syslink}"
- done
+ _add_option_item "${_xmake_sh_option_current}" "syslinks" "${@}"
fi
}
@@ -2097,7 +2119,9 @@ add_linkdirs() {
if ! path_is_absolute "${dir}"; then
dir="${xmake_sh_scriptdir}/${dir}"
fi
- path_relative ${xmake_sh_projectdir} "${dir}"; dir="${_ret}"
+ if string_startswith "${dir}" "${xmake_sh_projectdir}"; then
+ path_relative ${xmake_sh_projectdir} "${dir}"; dir="${_ret}"
+ fi
if ${_loading_targets} && test_z "${_xmake_sh_option_current}"; then
_add_target_item "${_xmake_sh_target_current}" "linkdirs" "${dir}"
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
@@ -2113,7 +2137,9 @@ add_linkdirs() {
if ! path_is_absolute "${dir}"; then
dir="${xmake_sh_scriptdir}/${dir}"
fi
- path_relative ${xmake_sh_projectdir} "${dir}"; dir="${_ret}"
+ if string_startswith "${dir}" "${xmake_sh_projectdir}"; then
+ path_relative ${xmake_sh_projectdir} "${dir}"; dir="${_ret}"
+ fi
if ${_loading_targets} && test_z "${_xmake_sh_option_current}"; then
_add_target_item "${_xmake_sh_target_current}" "linkdirs_public" "${dir}"
fi
@@ -2157,9 +2183,7 @@ add_frameworks() {
done
fi
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
- for framework in $@; do
- _add_option_item "${_xmake_sh_option_current}" "frameworks" "${framework}"
- done
+ _add_option_item "${_xmake_sh_option_current}" "frameworks" "${@}"
fi
}
@@ -2209,63 +2233,46 @@ set_languages() {
# set warnings in target
set_warnings() {
- local warnings="${@}"
if ${_loading_targets} && test_z "${_xmake_sh_option_current}"; then
- _set_target_item "${_xmake_sh_target_current}" "warnings" "${warnings}"
+ _set_target_item "${_xmake_sh_target_current}" "warnings" "${@}"
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
- _set_option_item "${_xmake_sh_option_current}" "warnings" "${warnings}"
+ _set_option_item "${_xmake_sh_option_current}" "warnings" "${@}"
fi
}
# set optimizes in target
set_optimizes() {
- local optimizes="${@}"
if ${_loading_targets} && test_z "${_xmake_sh_option_current}"; then
- _set_target_item "${_xmake_sh_target_current}" "optimizes" "${optimizes}"
+ _set_target_item "${_xmake_sh_target_current}" "optimizes" "${@}"
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
- _set_option_item "${_xmake_sh_option_current}" "optimizes" "${optimizes}"
+ _set_option_item "${_xmake_sh_option_current}" "optimizes" "${@}"
fi
}
# add cflags in target
add_cflags() {
- local flag=""
if ${_loading_targets} && test_z "${_xmake_sh_option_current}"; then
- for flag in $@; do
- _add_target_item "${_xmake_sh_target_current}" "cflags" "${flag}"
- done
+ _add_target_item "${_xmake_sh_target_current}" "cflags" "${@}"
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
- for flag in $@; do
- _add_option_item "${_xmake_sh_option_current}" "cflags" "${flag}"
- done
+ _add_option_item "${_xmake_sh_option_current}" "cflags" "${@}"
fi
}
# add cxflags in target
add_cxflags() {
- local flag=""
if ${_loading_targets} && test_z "${_xmake_sh_option_current}"; then
- for flag in $@; do
- _add_target_item "${_xmake_sh_target_current}" "cxflags" "${flag}"
- done
+ _add_target_item "${_xmake_sh_target_current}" "cxflags" "${@}"
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
- for flag in $@; do
- _add_option_item "${_xmake_sh_option_current}" "cxflags" "${flag}"
- done
+ _add_option_item "${_xmake_sh_option_current}" "cxflags" "${@}"
fi
}
# add cxxflags in target
add_cxxflags() {
- local flag=""
if ${_loading_targets} && test_z "${_xmake_sh_option_current}"; then
- for flag in $@; do
- _add_target_item "${_xmake_sh_target_current}" "cxxflags" "${flag}"
- done
+ _add_target_item "${_xmake_sh_target_current}" "cxxflags" "${@}"
elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
- for flag in $@; do
- _add_option_item "${_xmake_sh_option_current}" "cxxflags" "${flag}"
- done
+ _add_option_item "${_xmake_sh_option_current}" "cxxflags" "${@}"
fi
}
@@ -2274,10 +2281,7 @@ add_asflags() {
if ! ${_loading_targets}; then
return
fi
- local flag=""
- for flag in $@; do
- _add_target_item "${_xmake_sh_target_current}" "asflags" "${flag}"
- done
+ _add_target_item "${_xmake_sh_target_current}" "asflags" "${@}"
}
# add mflags in target
@@ -2285,10 +2289,7 @@ add_mflags() {
if ! ${_loading_targets}; then
return
fi
- local flag=""
- for flag in $@; do
- _add_target_item "${_xmake_sh_target_current}" "mflags" "${flag}"
- done
+ _add_target_item "${_xmake_sh_target_current}" "mflags" "${@}"
}
# add mxflags in target
@@ -2296,10 +2297,7 @@ add_mxflags() {
if ! ${_loading_targets}; then
return
fi
- local flag=""
- for flag in $@; do
- _add_target_item "${_xmake_sh_target_current}" "mxflags" "${flag}"
- done
+ _add_target_item "${_xmake_sh_target_current}" "mxflags" "${@}"
}
# add mxxflags in target
@@ -2307,21 +2305,16 @@ add_mxxflags() {
if ! ${_loading_targets}; then
return
fi
- local flag=""
- for flag in $@; do
- _add_target_item "${_xmake_sh_target_current}" "mxxflags" "${flag}"
- done
+ _add_target_item "${_xmake_sh_target_current}" "mxxflags" "${@}"
}
# add ldflags in target
add_ldflags() {
- if ! ${_loading_targets}; then
- return
+ if ${_loading_targets} && test_z "${_xmake_sh_option_current}"; then
+ _add_target_item "${_xmake_sh_target_current}" "ldflags" "${@}"
+ elif ${_loading_options} && test_nz "${_xmake_sh_option_current}"; then
+ _add_option_item "${_xmake_sh_option_current}" "ldflags" "${@}"
fi
- local flag=""
- for flag in $@; do
- _add_target_item "${_xmake_sh_target_current}" "ldflags" "${flag}"
- done
}
# add shflags in target
@@ -2329,10 +2322,7 @@ add_shflags() {
if ! ${_loading_targets}; then
return
fi
- local flag=""
- for flag in $@; do
- _add_target_item "${_xmake_sh_target_current}" "shflags" "${flag}"
- done
+ _add_target_item "${_xmake_sh_target_current}" "shflags" "${@}"
}
# add arflags in target
@@ -2340,9 +2330,36 @@ add_arflags() {
if ! ${_loading_targets}; then
return
fi
- local flag=""
- for flag in $@; do
- _add_target_item "${_xmake_sh_target_current}" "arflags" "${flag}"
+ _add_target_item "${_xmake_sh_target_current}" "arflags" "${@}"
+}
+
+# add options in target
+add_options() {
+ if ! ${_loading_targets}; then
+ return
+ fi
+ local name=""
+ local public=false
+ for name in $@; do
+ if test_nq "${name}" "{public}"; then
+ public=true
+ break
+ fi
+ done
+ for name in $@; do
+ if has_config "${name}"; then
+ local itemname=""
+ local itemnames="includedirs linkdirs links defines cflags cxflags cxxflags ldflags"
+ for itemname in ${itemnames}; do
+ _get_option_item "${name}" "${itemname}"; local values="${_ret}"
+ if test_nz "${values}"; then
+ _add_target_item "${_xmake_sh_target_current}" "${itemname}" "${values}"
+ if $public; then
+ _add_target_item "${_xmake_sh_target_current}" "${itemname}_public" "${values}"
+ fi
+ fi
+ done
+ fi
done
}
@@ -3104,15 +3121,10 @@ _check_cxsnippets() {
_get_option_item "${name}" "${kind}includes"; local includes="${_ret}"
_get_option_item "${name}" "${kind}types"; local types="${_ret}"
_get_option_item "${name}" "${kind}snippets"; local snippets="${_ret}"
- _get_option_item "${name}" "links"; local links="${_ret}"
- _get_option_item "${name}" "syslinks"; local syslinks="${_ret}"
if test_z "${funcs}" && test_z "${includes}" &&
test_z "${types}" && test_z "${snippets}"; then
return 0
fi
- if test_nz "${syslinks}"; then
- links="${links} ${syslinks}"
- fi
# get c/c++ extension
local extension=".c"
@@ -3140,7 +3152,7 @@ _check_cxsnippets() {
local compflags=""
_get_toolchain_toolset "${_target_toolchain}" "${sourcekind}"; local program="${_ret}"
path_toolname "${program}"; local toolname="${_ret}"
- local itemnames="languages warnings optimizes defines undefines"
+ local itemnames="languages warnings optimizes defines undefines includedirs"
for itemname in ${itemnames}; do
_get_option_abstract_flags "${name}" "${sourcekind}" "${toolname}" "${itemname}"; local flags="${_ret}"
if test_nz "${flags}"; then
@@ -3170,7 +3182,13 @@ _check_cxsnippets() {
fi
# try linking it
- if ${ok} && test_nz "${links}"; then
+ _get_option_item "${name}" "links"; local links="${_ret}"
+ _get_option_item "${name}" "syslinks"; local syslinks="${_ret}"
+ _get_option_item "${name}" "ldflags"; local ldflags="${_ret}"
+ if test_nz "${syslinks}"; then
+ links="${links} ${syslinks}"
+ fi
+ if ${ok} && (test_nz "${links}" || test_nz "${ldflags}"); then
local toolkind="ld"
_get_toolchain_toolset "${_target_toolchain}" "${toolkind}"; local program="${_ret}"
path_toolname "${program}"; local toolname="${_ret}"
@@ -3245,6 +3263,10 @@ _check_cxxsnippets() {
# check option
_check_option() {
local name="${1}"
+ _get_option_item "${name}" "before_check"; local before_check="${_ret}"
+ if test_nz "${before_check}"; then
+ eval ${before_check}
+ fi
if _check_csnippets "${name}" && _check_cxxsnippets "${name}"; then
return 0
fi
diff --git a/core/src/lua-cjson/xmake.sh b/core/src/lua-cjson/xmake.sh
index 7ee38cc10..134173051 100755
--- a/core/src/lua-cjson/xmake.sh
+++ b/core/src/lua-cjson/xmake.sh
@@ -4,7 +4,13 @@ target "lua_cjson"
set_kind "static"
set_default false
set_warnings "all"
- add_deps "lua"
+ if is_config "runtime" "luajit" && has_config "luajit"; then
+ add_options "luajit" "{public}"
+ elif has_config "lua"; then
+ add_options "lua" "{public}"
+ else
+ add_deps "lua"
+ fi
add_files "lua-cjson/dtoa.c"
add_files "lua-cjson/lua_cjson.c"
add_files "lua-cjson/strbuf.c"
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox
-Subproject 592d19f5efd42204a2bfcf9ac3fef05e9fe251c
+Subproject 09f715aabf543981544112b929f105a77bc90f1
diff --git a/core/src/tbox/xmake.sh b/core/src/tbox/xmake.sh
index ed5d59d2a..9bd760793 100755
--- a/core/src/tbox/xmake.sh
+++ b/core/src/tbox/xmake.sh
@@ -14,6 +14,7 @@ hide_options() {
for name in $options; do
option "${name}"
set_showmenu false
+ option_end
done
}
hide_options
diff --git a/core/src/xmake/xmake.sh b/core/src/xmake/xmake.sh
index 983dc95ea..f3fe92aa1 100755
--- a/core/src/xmake/xmake.sh
+++ b/core/src/xmake/xmake.sh
@@ -5,7 +5,24 @@ target "xmake"
set_default false
# add deps
- add_deps "sv" "lua_cjson" "lua" "lz4" "tbox"
+ local libs="lua_cjson lz4 sv tbox"
+ for lib in $libs; do
+ if has_config "$lib"; then
+ add_options "$lib" "{public}"
+ else
+ add_deps "$lib"
+ fi
+ done
+ if is_config "runtime" "luajit" && has_config "luajit"; then
+ add_options "luajit" "{public}"
+ elif has_config "lua"; then
+ add_options "lua" "{public}"
+ else
+ add_deps "lua"
+ fi
+
+ # add options
+ add_options "readline" "curses" "{public}"
# add defines
add_defines "__tb_prefix__=\"xmake\""
@@ -44,14 +61,3 @@ target "xmake"
add_files "winos/*.c"
fi
- # enable readline
- if has_config "readline"; then
- add_defines "XM_CONFIG_API_HAVE_READLINE" "{public}"
- add_links "readline" "{public}"
- fi
-
- # enable curses
- if has_config "curses"; then
- add_defines "XM_CONFIG_API_HAVE_CURSES" "{public}"
- add_links "curses" "{public}"
- fi
diff --git a/core/xmake.sh b/core/xmake.sh
index 21c7db319..819525b9b 100755
--- a/core/xmake.sh
+++ b/core/xmake.sh
@@ -35,24 +35,134 @@ option "readline"
add_links "readline"
add_cincludes "readline/readline.h"
add_cfuncs "readline"
+ add_defines "XM_CONFIG_API_HAVE_READLINE"
+option_end
# the curses option
option "curses"
add_links "curses"
+ add_cfuncs "initscr"
add_cincludes "curses.h"
+ add_defines "XM_CONFIG_API_HAVE_CURSES"
+option_end
+
+# the lua-cjson option
+option "lua_cjson"
+ add_links "lua5.1-cjson"
+ add_csnippets "
+int luaopen_cjson(void *l);\n
+void test() {\n
+ luaopen_cjson(0);\n
+}
+"
+option_end
+
+# the lua option
+option "lua"
+ add_cfuncs "lua_pushstring"
+ add_cincludes "lua.h" "lualib.h" "lauxlib.h"
+ add_defines "LUA_COMPAT_5_1" "LUA_COMPAT_5_2" "LUA_COMPAT_5_3"
+ before_check "option_find_lua"
+option_end
+
+option_find_lua() {
+ option "lua"
+ add_cflags `pkg-config --cflags lua5.4 2>/dev/null`
+ add_ldflags `pkg-config --libs lua5.4 2>/dev/null`
+ option_end
+}
+
+# the luajit option
+option "luajit"
+ add_cfuncs "lua_pushstring"
+ add_cincludes "lua.h" "lualib.h" "lauxlib.h"
+ add_defines "USE_LUAJIT"
+ before_check "option_find_luajit"
+option_end
+
+option_find_luajit() {
+ option "luajit"
+ add_cflags `pkg-config --cflags luajit 2>/dev/null`
+ add_ldflags `pkg-config --libs luajit 2>/dev/null`
+ option_end
+}
+
+# the lz4 option
+option "lz4"
+ add_cfuncs "LZ4F_compressFrame"
+ add_cincludes "lz4.h" "lz4frame.h"
+ before_check "option_find_lz4"
+option_end
+
+option_find_lz4() {
+ option "lz4"
+ add_cflags `pkg-config --cflags liblz4 2>/dev/null`
+ add_ldflags `pkg-config --libs liblz4 2>/dev/null`
+ option_end
+}
+
+# the sv option
+option "sv"
+ add_cfuncs "semver_tryn"
+ add_cincludes "semver.h"
+ add_links "sv"
+ before_check "option_find_sv"
+option_end
+
+option_find_sv() {
+ option "sv"
+ local dirs="/usr/local /usr"
+ for dir in $dirs; do
+ if test -f "${dir}/lib/libsv.a"; then
+ add_linkdirs "${dir}/lib"
+ add_includedirs "${dir}/include/sv"
+ break
+ fi
+ done
+ option_end
+}
+
+# the tbox option
+option "tbox"
+ add_cfuncs "tb_exit" "tb_md5_init" "tb_charset_conv_data"
+ add_cincludes "tbox/tbox.h"
+ add_links "tbox"
+ before_check "option_find_tbox"
option_end
+option_find_tbox() {
+ option "tbox"
+ local dirs="/usr/local /usr"
+ for dir in $dirs; do
+ if test -f "${dir}/lib/libtbox.a"; then
+ add_linkdirs "${dir}/lib"
+ add_includedirs "${dir}/include"
+ break
+ fi
+ done
+ option_end
+}
+
# add projects
-includes "src/lua-cjson"
-includes "src/sv"
-includes "src/lz4"
-includes "src/tbox"
+if ! has_config "lua"; then
+ if is_config "runtime" "luajit"; then
+ includes "src/luajit"
+ else
+ includes "src/lua"
+ fi
+fi
+if ! has_config "lua_cjson"; then
+ includes "src/lua-cjson"
+fi
+if ! has_config "lz4"; then
+ includes "src/lz4"
+fi
+if ! has_config "sv"; then
+ includes "src/sv"
+fi
+if ! has_config "tbox"; then
+ includes "src/tbox"
+fi
includes "src/xmake"
includes "src/demo"
-if is_config "runtime" "luajit"; then
- includes "src/luajit"
-else
- includes "src/lua"
-fi
-