Skip to content

Commit

Permalink
Merge pull request #3172 from xmake-io/xmake.sh
Browse files Browse the repository at this point in the history
add xmake.sh
  • Loading branch information
waruqi authored Dec 14, 2022
2 parents 4e1325a + 52c919d commit 47add86
Show file tree
Hide file tree
Showing 18 changed files with 4,154 additions and 16 deletions.
3,836 changes: 3,836 additions & 0 deletions configure

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion core/src/demo/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ target("demo")
add_ldflags("/export:malloc", "/export:free", "/export:memmove")
elseif is_plat("android") then
add_links("m", "c")
elseif is_plat("macosx") then
elseif is_plat("macosx") and is_config("runtime", "luajit") then
add_ldflags("-all_load", "-pagezero_size 10000", "-image_base 100000000")
elseif is_plat("mingw") then
add_ldflags("-static-libgcc", {force = true})
Expand Down
25 changes: 25 additions & 0 deletions core/src/demo/xmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

target "demo"
add_deps "xmake"
set_kind "binary"
set_basename "xmake"
set_targetdir "${buildir}"

# add defines
add_defines "__tb_prefix__=\"xmake\""

# add includes directory
add_includedirs "${projectdir}/core" "${projectdir}/core/src"

# add the common source files
add_files "**.c"

# add links
if is_plat "macosx" && is_config "runtime" "luajit"; then
add_ldflags "-all_load" "-pagezero_size 10000" "-image_base 100000000"
elif is_plat "mingw"; then
add_ldflags "-static-libgcc"
fi


2 changes: 1 addition & 1 deletion core/src/lua-cjson/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
target("lua-cjson")
set_kind("static")
set_warnings("all")
add_deps(get_config("runtime"))
add_deps("lua")
if is_plat("windows") then
set_languages("c89")
end
Expand Down
13 changes: 13 additions & 0 deletions core/src/lua-cjson/xmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

target "lua_cjson"
set_kind "static"
set_warnings "all"
add_deps "lua"
add_files "lua-cjson/dtoa.c"
add_files "lua-cjson/lua_cjson.c"
add_files "lua-cjson/strbuf.c"
add_files "lua-cjson/g_fmt.c"
# Use internal strtod() / g_fmt() code for performance and disable multi-thread
add_defines "NDEBUG" "USE_INTERNAL_FPCONV"

3 changes: 0 additions & 3 deletions core/src/lua/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
target("lua")
if not is_config("runtime", "lua") then
set_default(false)
end
set_kind("static")
set_warnings("all")

Expand Down
53 changes: 53 additions & 0 deletions core/src/lua/xmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/sh

target "lua"
set_kind "static"
set_warnings "all"

# add include directories
add_includedirs "lua" "{public}"

# add the common source files
add_files "lua/lapi.c"
add_files "lua/lauxlib.c"
add_files "lua/lbaselib.c"
add_files "lua/lcode.c"
add_files "lua/lcorolib.c"
add_files "lua/lctype.c"
add_files "lua/ldblib.c"
add_files "lua/ldebug.c"
add_files "lua/ldo.c"
add_files "lua/ldump.c"
add_files "lua/lfunc.c"
add_files "lua/lgc.c"
add_files "lua/linit.c"
add_files "lua/liolib.c"
add_files "lua/llex.c"
add_files "lua/lmathlib.c"
add_files "lua/lmem.c"
add_files "lua/loadlib.c"
add_files "lua/lobject.c"
add_files "lua/lopcodes.c"
add_files "lua/loslib.c"
add_files "lua/lparser.c"
add_files "lua/lstate.c"
add_files "lua/lstring.c"
add_files "lua/lstrlib.c"
add_files "lua/ltable.c"
add_files "lua/ltablib.c"
add_files "lua/ltm.c"
add_files "lua/lundump.c"
add_files "lua/lutf8lib.c"
add_files "lua/lvm.c"
add_files "lua/lzio.c"

# add defines
add_defines "LUA_COMPAT_5_1" "LUA_COMPAT_5_2" "LUA_COMPAT_5_3" "{public}"
if is_plat "mingw"; then
add_defines "LUA_USE_WINDOWS"
elif is_plat "macosx"; then
add_defines "LUA_USE_MACOSX"
else
add_defines "LUA_USE_LINUX"
fi

5 changes: 1 addition & 4 deletions core/src/luajit/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ end
local autogendir = path.join("luajit", "autogen", plat, jit and "jit" or "nojit", arch)

-- add target
target("luajit")
if not is_config("runtime", "luajit") then
set_default(false)
end
target("lua")

-- make as a static library
set_kind("static")
Expand Down
67 changes: 67 additions & 0 deletions core/src/luajit/xmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/sh

# disable jit compiler for redhat and centos
jit=true
jit_plat="${plat}"
jit_arch="${arch}"
if is_plat "mingw"; then
jit_plat="windows"
if is_arch "x86_64"; then
jit_arch="x64"
else
jit_arch="x86"
fi
fi
if is_arch "arm64" "arm64-v8a"; then
jit_arch="arm64"
elif is_arch "arm" "armv7"; then
jit_arch="arm"
elif is_arch "mips64"; then
jit_arch="mips64"
jit=false
fi
if test -f "/etc/redhat-release"; then
jit=false
fi
if $jit; then
jit_dir="jit"
else
jit_dir="nojit"
fi
jit_autogendir="luajit/autogen/${jit_plat}/${jit_dir}/${jit_arch}"

target "lua"
set_kind "static"
set_warnings "all"

# add include directories
add_includedirs "${jit_autogendir}"
add_includedirs "luajit/src" "{public}"

# add the common source files
add_files "luajit/src/lj_*.c"
add_files "luajit/src/lib_*.c"
if is_plat "mingw"; then
add_files "${jit_autogendir}/lj_vm.o"
else
add_files "${jit_autogendir}/*.S"
fi

add_defines "USE_LUAJIT" "{public}"

# disable jit compiler?
if ! $jit; then
add_defines "LUAJIT_DISABLE_JIT"
fi

# using internal memory management under armv7 gc will cause a crash when free strings in lua_close
if test_eq "${jit_arch}" "arm"; then
add_defines "LUAJIT_USE_SYSMALLOC"
fi

# fix call math.sin/log crash for fedora/i386/lj_vm.S with `LDFLAGS = -specs=/usr/lib/rpm/redhat/redhat-hardened-ld` in xmake.spec/%set_build_flags
if is_plat "linux" && is_arch "i386"; then
add_asflags "-fPIE"
add_ldflags "-fPIE"
fi

13 changes: 13 additions & 0 deletions core/src/lz4/xmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

target "lz4"
set_kind "static"
set_warnings "all"
add_includedirs "lz4/lib" "{public}"
add_files "lz4/lib/lz4.c"
add_files "lz4/lib/lz4frame.c"
add_files "lz4/lib/lz4hc.c"
add_files "lz4/lib/xxhash.c"
add_defines "XXH_NAMESPACE=LZ4_"


8 changes: 8 additions & 0 deletions core/src/sv/xmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

target "sv"
set_languages "c99"
set_kind "static"
add_includedirs "sv/include" "{public}"
add_files "sv/src/*.c"

2 changes: 1 addition & 1 deletion core/src/tbox/tbox
Submodule tbox updated 1 files
+3 −5 src/xmake.sh
15 changes: 15 additions & 0 deletions core/src/tbox/xmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

set_config "hash" true
set_config "charset" true
set_config "force_utf8" true
set_config "float" true
set_config "demo" false

includes "tbox/src"
target_end

set_configvar "TB_CONFIG_MODULE_HAVE_HASH" 1
set_configvar "TB_CONFIG_MODULE_HAVE_CHARSET" 1
set_configvar "TB_CONFIG_FORCE_UTF8" 1
set_configvar "TB_CONFIG_TYPE_HAVE_FLOAT" 1
1 change: 0 additions & 1 deletion core/src/xmake/os/cpuinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ static tb_float_t xm_os_cpuinfo_usagerate()
tb_float_t usagerate = 0;
if (tb_file_info("/proc/stat", tb_null))
{
tb_bool_t ok = tb_false;
FILE* fp = fopen("/proc/stat", "r");
if (fp)
{
Expand Down
5 changes: 1 addition & 4 deletions core/src/xmake/xmake.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
target("xmake")

-- make as a static library
set_kind("static")

-- add deps
add_deps("sv", "lua-cjson", "lz4", "tbox")
add_deps(get_config("runtime"))
add_deps("sv", "lua-cjson", "lua", "lz4", "tbox")
if is_plat("windows") and has_config("pdcurses") then
add_deps("pdcurses")
end
Expand Down
56 changes: 56 additions & 0 deletions core/src/xmake/xmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

target "xmake"
set_kind "static"

# add deps
add_deps "sv" "lua_cjson" "lua" "lz4" "tbox"

# add defines
add_defines "__tb_prefix__=\"xmake\""
if is_mode "debug"; then
add_defines "__tb_debug__" "{public}"
fi

# set the auto-generated config.h
set_configdir "${buildir}/${plat}/${arch}/${mode}"
add_configfiles "xmake.config.h.in"

# add includes directory
add_includedirs ".." "{public}"
add_includedirs "${buildir}/${plat}/${arch}/${mode}" "{public}"
add_includedirs "../xxhash"

# add the common source files
add_files "*.c"
add_files "base64/*.c"
add_files "bloom_filter/*.c"
add_files "curses/*.c"
add_files "fwatcher/*.c"
add_files "hash/*.c"
add_files "io/*.c"
add_files "libc/*.c"
add_files "lz4/*.c"
add_files "os/*.c"
add_files "path/*.c"
add_files "process/*.c"
add_files "readline/*.c"
add_files "sandbox/*.c"
add_files "semver/*.c"
add_files "string/*.c"
add_files "tty/*.c"
if is_plat "mingw"; then
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
4 changes: 3 additions & 1 deletion core/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ if is_plat("windows") then
end

-- add projects
includes("src/lua-cjson", "src/sv", "src/lua", "src/lz4", "src/tbox", "src/xmake", "src/demo")
includes("src/lua-cjson", "src/sv", "src/lz4", "src/tbox", "src/xmake", "src/demo")
if is_config("runtime", "luajit") then
includes("src/luajit")
else
includes("src/lua")
end
if is_plat("windows") then
includes("src/pdcurses")
Expand Down
60 changes: 60 additions & 0 deletions core/xmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

set_project "xmake"
set_version "2.7.3" "%Y%m%d%H%M"

# set warning all
set_warnings "all"

# set language: c99
set_languages "c99"

# add defines
add_defines "_GNU_SOURCE=1" "_FILE_OFFSET_BITS=64" "_LARGEFILE_SOURCE"

# disable some compiler errors
if is_plat "macosx"; then
add_cxflags "-Wno-error=deprecated-declarations" "-fno-strict-aliasing" "-Wno-error=nullability-completeness" "-Wno-error=parentheses-equality"
fi

# add build modes
if is_mode "debug"; then
set_symbols "debug"
set_optimizes "none"
else
set_strip "all"
set_symbols "hidden"
set_optimizes "smallest"
fi

# the runtime option, lua or luajit
option "runtime" "Use luajit or lua runtime" "lua"

# the readline option
option "readline"
set_description "Enable or disable readline library"
add_links "readline"
add_cincludes "readline/readline.h"
add_cfuncs "readline"

# the curses option
option "curses"
set_description "Enable or disable curses library"
add_links "curses"
add_cincludes "curses.h"
option_end

# add projects
includes "src/lua-cjson"
includes "src/sv"
includes "src/lz4"
includes "src/tbox"
includes "src/xmake"
includes "src/demo"
if is_config "runtime" "luajit"; then
includes "src/luajit"
else
includes "src/lua"
fi


0 comments on commit 47add86

Please sign in to comment.