package An official xmake package repository
https://xrepo.xmake.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
177 lines
6.1 KiB
177 lines
6.1 KiB
5 years ago
|
set_policy("build.across_targets_in_parallel", false)
|
||
|
|
||
|
add_rules("mode.debug", "mode.release")
|
||
|
if is_mode("release") then
|
||
|
add_cflags("-fomit-frame-pointer")
|
||
|
add_cflags("-fno-stack-protector")
|
||
|
end
|
||
|
|
||
|
option("nojit")
|
||
|
set_default(false)
|
||
|
set_showmenu(true)
|
||
|
add_defines("LUAJIT_DISABLE_JIT", "LUAJIT_DISABLE_FFI")
|
||
|
|
||
|
option("fpu")
|
||
|
set_default(true)
|
||
|
set_showmenu(true)
|
||
|
add_defines("LJ_ARCH_HASFPU=1", "LJ_ABI_SOFTFP=0")
|
||
|
|
||
|
rule("dasc")
|
||
|
set_extensions(".dasc")
|
||
|
before_build_file(function(target, sourcefile)
|
||
|
|
||
|
local outputdir = target:objectdir()
|
||
|
if not os.isdir(outputdir) then
|
||
|
os.mkdir(outputdir)
|
||
|
end
|
||
|
|
||
|
local argv = {"dynasm/dynasm.lua", "-LN"}
|
||
|
if is_arch("x64", "x86_64", "arm64", "mips64") then
|
||
|
-- 64bits pointer
|
||
|
table.insert(argv, "-D")
|
||
|
table.insert(argv, "P64")
|
||
|
end
|
||
|
if target:opt("fpu") then
|
||
|
table.insert(argv, "-D")
|
||
|
table.insert(argv, "FPU")
|
||
|
table.insert(argv, "-D")
|
||
|
table.insert(argv, "HFABI")
|
||
|
end
|
||
|
if not target:opt("nojit") then
|
||
|
table.insert(argv, "-D")
|
||
|
table.insert(argv, "JIT")
|
||
|
table.insert(argv, "-D")
|
||
|
table.insert(argv, "FFI")
|
||
|
end
|
||
|
if is_plat("windows", "mingw") then
|
||
|
table.insert(argv, "-D")
|
||
|
table.insert(argv, "WIN")
|
||
|
end
|
||
|
table.insert(argv, "-o")
|
||
|
table.insert(argv, path.join(outputdir, "buildvm_arch.h"))
|
||
|
table.insert(argv, sourcefile)
|
||
|
os.vrunv(target:dep("minilua"):targetfile(), argv)
|
||
|
target:add("includedirs", outputdir, {public = true})
|
||
|
end)
|
||
|
|
||
|
rule("buildvm")
|
||
|
before_build_files(function (target, sourcebatch)
|
||
|
|
||
|
local buildvm = target:dep("buildvm")
|
||
|
local outputdir = buildvm:objectdir()
|
||
|
if not os.isdir(outputdir) then
|
||
|
os.mkdir(outputdir)
|
||
|
end
|
||
|
|
||
|
local buildvm_bin = buildvm:targetfile()
|
||
|
local sourcefiles = sourcebatch.sourcefiles
|
||
|
os.vrunv(buildvm_bin, {"-m", "bcdef", "-o", "src/lj_bcdef.h", unpack(sourcefiles)})
|
||
|
os.vrunv(buildvm_bin, {"-m", "ffdef", "-o", "src/lj_ffdef.h", unpack(sourcefiles)})
|
||
|
os.vrunv(buildvm_bin, {"-m", "libdef", "-o", "src/lj_libdef.h", unpack(sourcefiles)})
|
||
|
os.vrunv(buildvm_bin, {"-m", "recdef", "-o", "src/lj_recdef.h", unpack(sourcefiles)})
|
||
|
os.vrunv(buildvm_bin, {"-m", "vmdef", "-o", "src/lj_vmdef.h", unpack(sourcefiles)})
|
||
|
os.vrunv(buildvm_bin, {"-m", "folddef", "-o", "src/lj_folddef.h", "src/lj_opt_fold.c"})
|
||
|
if is_plat("windows", "mingw") then
|
||
|
local lj_vm_obj = path.join(outputdir, "lj_vm.obj")
|
||
|
os.vrunv(buildvm_bin, {"-m", "peobj", "-o", lj_vm_obj})
|
||
|
table.join2(target:objectfiles(), lj_vm_obj)
|
||
|
else
|
||
|
import("core.tool.compiler")
|
||
|
local lj_vm_asm = path.join(outputdir, "lj_vm.S")
|
||
|
local lj_vm_obj = path.join(outputdir, "lj_vm.o")
|
||
|
local march
|
||
|
if is_plat("macosx", "iphoneos", "watchos") then
|
||
|
march = "machasm"
|
||
|
else
|
||
|
march = "elfasm"
|
||
|
end
|
||
|
os.vrunv(buildvm_bin, {"-m", march, "-o", lj_vm_asm})
|
||
|
compiler.compile(lj_vm_asm, lj_vm_obj, {target = target})
|
||
|
table.join2(target:objectfiles(), lj_vm_obj)
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
target("minilua")
|
||
|
set_kind("binary")
|
||
|
add_files("src/host/minilua.c")
|
||
|
|
||
|
target("buildvm")
|
||
|
set_kind("binary")
|
||
|
add_deps("minilua")
|
||
|
add_rules("dasc")
|
||
|
add_options("nojit", "fpu")
|
||
|
add_includedirs("src")
|
||
|
add_files("src/host/buildvm*.c")
|
||
|
if is_arch("x86", "i386") then
|
||
|
add_files("src/vm_x86.dasc")
|
||
|
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X86")
|
||
|
elseif is_arch("x64", "x86_64") then
|
||
|
--FIXME will crash
|
||
|
--add_files("src/vm_x64.dasc")
|
||
|
add_files("src/vm_x86.dasc")
|
||
|
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_X64")
|
||
|
elseif is_arch("arm64", "arm64-v8a") then
|
||
|
add_files("src/vm_arm64.dasc")
|
||
|
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM64")
|
||
|
elseif is_arch("arm*") then
|
||
|
add_files("src/vm_arm.dasc")
|
||
|
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_ARM")
|
||
|
elseif is_arch("mips64") then
|
||
|
add_files("src/vm_mips64.dasc")
|
||
|
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS64")
|
||
|
elseif is_arch("mips") then
|
||
|
add_files("src/vm_mips.dasc")
|
||
|
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_MIPS")
|
||
|
elseif is_arch("ppc") then
|
||
|
add_files("src/vm_ppc.dasc")
|
||
|
add_defines("LUAJIT_TARGET=LUAJIT_ARCH_PPC")
|
||
|
end
|
||
|
|
||
|
target("luajit")
|
||
|
set_kind("$(kind)")
|
||
|
add_deps("buildvm")
|
||
|
add_options("nojit", "fpu")
|
||
|
if is_mode("debug") then
|
||
|
add_defines("LUA_USE_ASSERT")
|
||
|
end
|
||
|
add_defines("LUAJIT_ENABLE_LUA52COMPAT", {public = true})
|
||
|
add_defines("_FILE_OFFSET_BITS=64", "LARGEFILE_SOURCE", {public = true})
|
||
|
add_undefines("_FORTIFY_SOURCE", {public = true})
|
||
|
add_headerfiles("src/*.h", {prefixdir = "luajit"})
|
||
|
add_files("src/ljamalg.c")
|
||
|
add_files("src/lib_base.c",
|
||
|
"src/lib_math.c",
|
||
|
"src/lib_bit.c",
|
||
|
"src/lib_string.c",
|
||
|
"src/lib_table.c",
|
||
|
"src/lib_io.c",
|
||
|
"src/lib_os.c",
|
||
|
"src/lib_package.c",
|
||
|
"src/lib_debug.c",
|
||
|
"src/lib_jit.c",
|
||
|
"src/lib_ffi.c", {rules = {"buildvm", override = true}})
|
||
|
|
||
|
target("luajit_bin")
|
||
|
set_kind("binary")
|
||
|
add_deps("luajit")
|
||
|
set_basename("luajit")
|
||
|
add_files("src/luajit.c")
|
||
|
add_options("nojit", "fpu")
|
||
|
if is_plat("windows") then
|
||
|
add_links("advapi32", "shell32")
|
||
|
if is_arch("x86") then
|
||
|
add_ldflags("/subsystem:console,5.01")
|
||
|
else
|
||
|
add_ldflags("/subsystem:console,5.02")
|
||
|
end
|
||
|
elseif is_plat("android") then
|
||
|
add_links("m", "c")
|
||
|
elseif is_plat("macosx") then
|
||
|
add_ldflags("-all_load", "-pagezero_size 10000", "-image_base 100000000")
|
||
|
elseif is_plat("mingw") then
|
||
|
add_ldflags("-static-libgcc", {force = true})
|
||
|
else
|
||
|
add_links("pthread", "dl", "m", "c")
|
||
|
end
|
||
|
|