Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos/xmake/xmake/rules/go
repos/xmake/xmake/rules/go/env/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("go.env") on_load(function (target) -- imports import("private.tools.go.goenv") import("async.runjobs") import("core.base.tty") import("core.base.option") import("core.project.config") -- check and install go packages for other platform local goroot = goenv.GOROOT() local goos = goenv.GOOS(target:plat()) local goarch = goenv.GOARCH(target:arch()) if goroot and goos and goarch then local goroot_local = path.join(config.buildir(), ".goenv", path.filename(goroot)) local gopkgdir = path.join(os.isdir(goroot_local) and goroot_local or goroot, "pkg", goos .. "_" .. goarch) if not os.isdir(gopkgdir) or os.emptydir(gopkgdir) then local gosrcdir = path.join(goroot, "src") local confirm = utils.confirm({default = true, description = ("we need to build go for %s_%s only once first!"):format(goos, goarch)}) if confirm then local build_task = function () tty.erase_line_to_start().cr() printf("building go for %s_%s .. ", goos, goarch) io.flush() if is_host("windows") then os.vrunv(path.join(gosrcdir, "make.bat"), {"--no-clean"}, {envs = {GOOS = goos, GOARCH = goarch, GOROOT_BOOTSTRAP = goroot}, curdir = gosrcdir}) else -- we need to copy goroot to the local directory to solving permission problem if is_host("linux") then os.vcp(goroot, goroot_local) goroot = path.absolute(goroot_local) gosrcdir = path.absolute(path.join(goroot_local, "src")) end -- we patch '/' to GOROOT_BOOTSTRAP to solve the following issue -- -- in make.bash -- ERROR: $GOROOT_BOOTSTRAP must not be set to $GOROOT -- Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4. -- os.vrunv(path.join(gosrcdir, "make.bash"), {"--no-clean"}, {envs = {GOOS = goos, GOARCH = goarch, GOROOT_BOOTSTRAP = goroot .. "/"}, curdir = gosrcdir}) end tty.erase_line_to_start().cr() cprint("building go for %s_%s .. ${color.success}${text.success}", goos, goarch) end if option.get("verbose") then build_task() else runjobs("build/goenv", build_task, {progress = true}) end end end -- switch to the local go root directory if os.isdir(goroot_local) and os.isdir(gopkgdir) and not os.emptydir(gopkgdir) then config.set("gc", path.join(goroot_local, "bin", "go"), {readonly = true, force = true}) config.set("gcld", path.join(goroot_local, "bin", "go"), {readonly = true, force = true}) config.set("gcar", path.join(goroot_local, "bin", "go"), {readonly = true, force = true}) end end end)
0
repos/xmake/xmake/rules/go
repos/xmake/xmake/rules/go/build/object.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file object.lua -- -- imports import("core.base.option") import("core.base.hashset") import("core.tool.compiler") import("core.project.depend") import("utils.progress") -- build the source files function main(target, sourcebatch, opt) -- get source files and kind local sourcefiles = sourcebatch.sourcefiles local sourcekind = sourcebatch.sourcekind -- get object file local objectfile = target:objectfile(path.join(path.directory(sourcefiles[1]), "__go__")) -- get depend file local dependfile = target:dependfile(objectfile) -- remove the object files in sourcebatch local objectfiles_set = hashset.from(sourcebatch.objectfiles) for idx, file in irpairs(target:objectfiles()) do if objectfiles_set:has(file) then table.remove(target:objectfiles(), idx) end end -- add object file table.insert(target:objectfiles(), objectfile) -- load compiler local compinst = compiler.load(sourcekind, {target = target}) -- get compile flags local compflags = compinst:compflags({target = target}) -- load dependent info local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {}) -- need build this object? local depvalues = {compinst:program(), compflags} if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile), values = depvalues}) then return end -- trace progress info for index, sourcefile in ipairs(sourcefiles) do progress.show(opt.progress, "${color.build.object}compiling.$(mode) %s", sourcefile) end -- trace verbose info vprint(compinst:compcmd(sourcefiles, objectfile, {compflags = compflags})) -- compile it dependinfo.files = {} assert(compinst:compile(sourcefiles, objectfile, {dependinfo = dependinfo, compflags = compflags})) -- update files and values to the dependent file dependinfo.values = depvalues table.join2(dependinfo.files, sourcefiles) depend.save(dependinfo, dependfile) end
0
repos/xmake/xmake/rules
repos/xmake/xmake/rules/cppfront/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("cppfront.build.h2") set_extensions(".h2") on_buildcmd_file(function (target, batchcmds, sourcefile_h2, opt) -- get cppfront import("lib.detect.find_tool") local cppfront = assert(find_tool("cppfront", {check = "-h"}), "cppfront not found!") -- get h header file for h2 local sourcefile_h = target:autogenfile((sourcefile_h2:gsub(".h2$", ".h"))) local basedir = path.directory(sourcefile_h) -- add commands local argv = {"-o", path(sourcefile_h), path(sourcefile_h2)} batchcmds:show_progress(opt.progress, "${color.build.object}compiling.h2 %s", sourcefile_h2) batchcmds:mkdir(basedir) batchcmds:vrunv(cppfront.program, argv) -- add deps batchcmds:add_depfiles(sourcefile_h2) batchcmds:set_depmtime(os.mtime(sourcefile_h)) batchcmds:set_depcache(target:dependfile(sourcefile_h)) end) -- define rule: cppfront.build rule("cppfront.build.cpp2") set_extensions(".cpp2") -- .h2 must compile before .cpp2 add_deps("cppfront.build.h2", {order = true}) on_load(function (target) -- only cppfront source files? we need to patch cxx source kind for linker local sourcekinds = target:sourcekinds() if #sourcekinds == 0 then table.insert(sourcekinds, "cxx") end local cppfront = target:pkg("cppfront") if cppfront and cppfront:installdir() then local includedir = path.join(cppfront:installdir(), "include") if os.isdir(includedir) then target:add("includedirs", includedir) end end end) on_buildcmd_file(function (target, batchcmds, sourcefile_cpp2, opt) -- get cppfront import("lib.detect.find_tool") local cppfront = assert(find_tool("cppfront", {check = "-h"}), "cppfront not found!") -- get c++ source file for cpp2 local sourcefile_cpp = target:autogenfile((sourcefile_cpp2:gsub(".cpp2$", ".cpp"))) local basedir = path.directory(sourcefile_cpp) -- add objectfile local objectfile = target:objectfile(sourcefile_cpp) table.insert(target:objectfiles(), objectfile) -- add_depfiles for #include "xxxx/xxxx/xxx.h2" ,exclude // #include "xxxx.h2" local root_dir = path.directory(sourcefile_cpp2) for line in io.lines(sourcefile_cpp2) do local match_h2 = line:match("^ -#include *\"([%w%p]+.h2)\"") if match_h2 ~= nil then batchcmds:add_depfiles(path.join(root_dir, match_h2)) end end -- add commands local argv = {"-o", path(sourcefile_cpp), path(sourcefile_cpp2)} batchcmds:show_progress(opt.progress, "${color.build.object}compiling.cpp2 %s", sourcefile_cpp2) batchcmds:mkdir(basedir) batchcmds:vrunv(cppfront.program, argv) batchcmds:compile(sourcefile_cpp, objectfile, {configs = {languages = "c++20"}}) -- add deps batchcmds:add_depfiles(sourcefile_cpp2) batchcmds:set_depmtime(os.mtime(objectfile)) batchcmds:set_depcache(target:dependfile(objectfile)) end) -- define rule: cppfront rule("cppfront") -- add_build.h2 rules add_deps("cppfront.build.h2") -- add build rules add_deps("cppfront.build.cpp2") -- set compiler runtime, e.g. vs runtime add_deps("utils.compiler.runtime") -- inherit links and linkdirs of all dependent targets by default add_deps("utils.inherit.links") -- support `add_files("src/*.o")` and `add_files("src/*.a")` to merge object and archive files to target add_deps("utils.merge.object", "utils.merge.archive") -- we attempt to extract symbols to the independent file and -- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled add_deps("utils.symbols.extract")
0
repos/xmake/xmake/rules
repos/xmake/xmake/rules/platform/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("platform.wasm") add_deps("platform.wasm.preloadfiles") add_deps("platform.wasm.installfiles") rule("platform.windows") add_deps("platform.windows.def") if is_host("windows") then add_deps("platform.windows.manifest") end
0
repos/xmake/xmake/rules/platform/linux
repos/xmake/xmake/rules/platform/linux/bpf/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- add *.bpf.c for linux bpf program -- @see https://github.com/xmake-io/xmake/issues/1274 rule("platform.linux.bpf") set_extensions(".bpf.c") on_config(function (target) assert(is_host("linux"), 'rule("platform.linux.bpf"): only supported on linux!') local headerdir = path.join(target:autogendir(), "rules", "bpf") if not os.isdir(headerdir) then os.mkdir(headerdir) end target:add("includedirs", headerdir) end) before_buildcmd_file(function (target, batchcmds, sourcefile, opt) local headerfile = path.join(target:autogendir(), "rules", "bpf", (path.filename(sourcefile):gsub("%.bpf%.c", ".skel.h"))) local objectfile = path.join(target:autogendir(), "rules", "bpf", (path.filename(sourcefile):gsub("%.bpf%.c", ".bpf.o"))) local targetarch if target:is_arch("x86_64", "i386") then targetarch = "__TARGET_ARCH_x86" elseif target:is_arch("arm64", "arm64-v8a") then targetarch = "__TARGET_ARCH_arm64" elseif target:is_arch("arm.*") then targetarch = "__TARGET_ARCH_arm" elseif target:is_arch("mips64", "mips") then targetarch = "__TARGET_ARCH_mips" elseif target:is_arch("ppc64", "ppc") then targetarch = "__TARGET_ARCH_powerpc" end target:add("includedirs", path.directory(headerfile)) batchcmds:show_progress(opt.progress, "${color.build.object}compiling.bpf %s", sourcefile) batchcmds:mkdir(path.directory(objectfile)) batchcmds:compile(sourcefile, objectfile, {configs = {force = {cxflags = {"-target bpf", "-g", "-O2"}}, defines = targetarch}}) batchcmds:mkdir(path.directory(headerfile)) batchcmds:execv("bpftool", {"gen", "skeleton", path(objectfile)}, {stdout = headerfile}) batchcmds:add_depfiles(sourcefile) batchcmds:set_depmtime(os.mtime(headerfile)) batchcmds:set_depcache(target:dependfile(headerfile)) end)
0
repos/xmake/xmake/rules/platform/linux
repos/xmake/xmake/rules/platform/linux/driver/driver_modules.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file driver_modules.lua -- -- imports import("core.base.option") import("core.project.depend") import("core.cache.memcache") import("lib.detect.find_tool") import("utils.progress") import("private.tools.ccache") -- get linux-headers sdk function _get_linux_headers_sdk(target) local linux_headersdir = target:values("linux.driver.linux-headers") if linux_headersdir then return {sdkdir = linux_headersdir, includedir = path.join(linux_headersdir, "include")} end local linux_headers = assert(target:pkg("linux-headers"), "please add `add_requires(\"linux-headers\", {configs = {driver_modules = true}})` and `add_packages(\"linux-headers\")` to the given target!") local includedirs = linux_headers:get("includedirs") or linux_headers:get("sysincludedirs") local version = linux_headers:version() local includedir for _, dir in ipairs(includedirs) do if dir:find("linux-headers", 1, true) then includedir = dir linux_headersdir = path.directory(dir) break end end assert(linux_headersdir, "linux-headers not found!") if not os.isfile(path.join(includedir, "generated/autoconf.h")) and not os.isfile(path.join(includedir, "config/auto.conf")) then raise("kernel configuration is invalid. include/generated/autoconf.h or include/config/auto.conf are missing.") end return {version = version, sdkdir = linux_headersdir, includedir = includedir} end -- get cflags from make function _get_cflags_from_make(target, sdkdir) local key = sdkdir .. target:arch() local cflags = memcache.get2("linux.driver", key, "cflags") local ldflags_o = memcache.get2("linux.driver", key, "ldflags_o") local ldflags_ko = memcache.get2("linux.driver", key, "ldflags_ko") if cflags == nil then local make = assert(find_tool("make"), "make not found!") local tmpdir = os.tmpfile() .. ".dir" local makefile = path.join(tmpdir, "Makefile") local stubfile = path.join(tmpdir, "src/stub.c") local foofile = path.join(tmpdir, "src/foo.c") io.writefile(makefile, [[obj-m := stub.o stub-objs := src/stub.o src/foo.o]]) io.writefile(foofile, "") io.writefile(stubfile, [[ #include <linux/init.h> #include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); MODULE_AUTHOR("Ruki"); MODULE_DESCRIPTION("A simple Hello World Module"); MODULE_ALIAS("a simplest module"); int hello_init(void) { printk(KERN_INFO "Hello World\n"); return 0; } void hello_exit(void) { printk(KERN_INFO "Goodbye World\n"); } module_init(hello_init); module_exit(hello_exit); ]]) local argv = {"-C", sdkdir, "V=1", "M=" .. tmpdir, "modules"} if not target:is_plat(os.subhost()) then -- e.g. $(MAKE) -C $(KERN_DIR) V=1 ARCH=arm64 CROSS_COMPILE=/mnt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu- M=$(PWD) modules local arch if target:is_arch("arm", "armv7") then arch = "arm" elseif target:is_arch("arm64", "arm64-v8a") then arch = "arm64" elseif target:is_arch("mips") then arch = "mips" elseif target:is_arch("ppc", "ppc64", "powerpc", "powerpc64") then arch = "powerpc" end assert(arch, "unknown arch(%s)!", target:arch()) local cc = target:tool("cc") local cross = cc:gsub("%-gcc$", "-") table.insert(argv, "ARCH=" .. arch) table.insert(argv, "CROSS_COMPILE=" .. cross) end local result, errors = try {function () return os.iorunv(make.program, argv, {curdir = tmpdir}) end} if result then -- we can also split ';' for the muliple commands for _, line in ipairs(result:split("[\n;]")) do line = line:trim() if line:endswith("stub.c") then local include_cflag = false for _, cflag in ipairs(line:split("%s+")) do local has_cflag = false if cflag:startswith("-fplugin=") then -- @see https://github.com/xmake-io/xmake/issues/3279 local plugindir = cflag:sub(10) if not path.is_absolute(plugindir) then plugindir = path.absolute(plugindir, sdkdir) end cflag = "-fplugin=" .. plugindir has_cflag = true elseif cflag:startswith("-f") or cflag:startswith("-m") or (cflag:startswith("-W") and not cflag:startswith("-Wp,-MMD,") and not cflag:startswith("-Wp,-MD,")) or (cflag:startswith("-D") and not cflag:find("KBUILD_MODNAME=") and not cflag:find("KBUILD_BASENAME=")) then has_cflag = true local macro = cflag:match("%-D\"(.+)\"") -- -D"KBUILD_XXX=xxx" if macro then cflag = "-D" .. macro end elseif cflag == "-I" or cflag == "-isystem" or cflag == "-include" then include_cflag = cflag elseif cflag:startswith("-I") or include_cflag then local includedir = cflag if cflag:startswith("-I") then includedir = cflag:sub(3) end if not path.is_absolute(includedir) then includedir = path.absolute(includedir, sdkdir) end if cflag:startswith("-I") then cflag = "-I" .. includedir else cflag = include_cflag .. " " .. includedir end has_cflag = true include_cflag = nil end if has_cflag then cflags = cflags or {} table.insert(cflags, cflag) end end end local ldflags = line:match("%-ld (.+) %-o ") or line:match("ld (.+) %-o ") if ldflags then local ko = ldflags:find("-T ", 1, true) for _, ldflag in ipairs(os.argv(ldflags)) do if ldflag:endswith(".lds") then if not path.is_absolute(ldflag) then ldflag = path.absolute(ldflag, sdkdir) end end if ko then -- e.g. aarch64-linux-gnu-ld -r -EL -maarch64elf --build-id=sha1 -T scripts/module.lds -o hello.ko hello.o hello.mod.o ldflags_ko = ldflags_ko or {} table.insert(ldflags_ko, ldflag) else -- e.g. aarch64-linux-gnu-ld -EL -maarch64elf -r -o hello.o xxx.o ldflags_o = ldflags_o or {} table.insert(ldflags_o, ldflag) end end end if cflags and ldflags_o and ldflags_ko then break end end else if option.get("diagnosis") then print("rule(platform.linux.driver): cannot get cflags from make!") print(errors) end end os.tryrm(tmpdir) memcache.set2("linux.driver", key, "cflags", cflags or false) memcache.set2("linux.driver", key, "ldflags_o", ldflags_o or false) memcache.set2("linux.driver", key, "ldflags_ko", ldflags_ko or false) end return cflags or nil, ldflags_o or nil, ldflags_ko or nil end function load(target) -- we only need binary kind, because we will rewrite on_link target:set("kind", "binary") target:set("extension", ".ko") end function config(target) -- get and save linux-headers sdk local linux_headers = _get_linux_headers_sdk(target) target:data_set("linux.driver.linux_headers", linux_headers) -- check compiler, we must use gcc assert(target:has_tool("cc", "gcc"), "we must use gcc compiler!") -- check rules for _, rulename in ipairs({"mode.release", "mode.debug", "mode.releasedbg", "mode.minsizerel", "mode.asan", "mode.tsan"}) do assert(not target:rule(rulename), "target(%s) is linux driver module, it need not rule(%s)!", target:name(), rulename) end -- we need to disable includedirs from add_packages("linux-headers") if target:pkg("linux-headers") then target:pkg("linux-headers"):set("includedirs", nil) target:pkg("linux-headers"):set("sysincludedirs", nil) end -- add compilation flags target:add("defines", "KBUILD_MODNAME=\"" .. target:name() .. "\"") for _, sourcefile in ipairs(target:sourcefiles()) do target:fileconfig_set(sourcefile, {defines = "KBUILD_BASENAME=\"" .. path.basename(sourcefile) .. "\""}) end local cflags, ldflags_o, ldflags_ko = _get_cflags_from_make(target, linux_headers.sdkdir) if cflags then target:add("cflags", cflags, {force = true}) target:data_set("linux.driver.ldflags_o", ldflags_o) target:data_set("linux.driver.ldflags_ko", ldflags_ko) end end function link(target, opt) local targetfile = target:targetfile() local dependfile = target:dependfile(targetfile) local objectfiles = target:objectfiles() depend.on_changed(function () -- trace progress.show(opt.progress, "${color.build.object}linking.$(mode) %s", targetfile) -- get module scripts local modpost local linux_headers = target:data("linux.driver.linux_headers") if linux_headers then modpost = path.join(linux_headers.sdkdir, "scripts", "mod", "modpost") end assert(modpost and os.isfile(modpost), "scripts/mod/modpost not found!") -- get ld local ld = target:tool("ld") assert(ld, "ld not found!") ld = ld:gsub("gcc$", "ld") ld = ld:gsub("g%+%+$", "ld") -- link target.o local argv = {} local ldflags_o = target:data("linux.driver.ldflags_o") if ldflags_o then table.join2(argv, ldflags_o) end local targetfile_o = target:objectfile(targetfile) table.join2(argv, "-o", targetfile_o) table.join2(argv, objectfiles) os.mkdir(path.directory(targetfile_o)) os.vrunv(ld, argv) -- generate target.mod local targetfile_mod = targetfile_o:gsub("%.o$", ".mod") io.writefile(targetfile_mod, table.concat(objectfiles, "\n") .. "\n\n") -- generate .sourcename.o.cmd -- we only need to touch an empty file, otherwise modpost command will raise error. for _, objectfile in ipairs(objectfiles) do local objectdir = path.directory(objectfile) local objectname = path.filename(objectfile) local cmdfile = path.join(objectdir, "." .. objectname .. ".cmd") io.writefile(cmdfile, "") end -- generate target.mod.c local orderfile = path.join(path.directory(targetfile_o), "modules.order") local symversfile = path.join(path.directory(targetfile_o), "Module.symvers") argv = {"-m", "-a", "-o", symversfile, "-e", "-N", "-w", "-T", orderfile} io.writefile(orderfile, targetfile_o .. "\n") os.vrunv(modpost, argv) -- compile target.mod.c local targetfile_mod_c = targetfile_o:gsub("%.o$", ".mod.c") local targetfile_mod_o = targetfile_o:gsub("%.o$", ".mod.o") local compinst = target:compiler("cc") if option.get("verbose") then print(compinst:compcmd(targetfile_mod_c, targetfile_mod_o, {target = target, rawargs = true})) end assert(compinst:compile(targetfile_mod_c, targetfile_mod_o, {target = target})) -- link target.ko argv = {} local ldflags_ko = target:data("linux.driver.ldflags_ko") if ldflags_ko then table.join2(argv, ldflags_ko) end local targetfile_o = target:objectfile(targetfile) table.join2(argv, "-o", targetfile, targetfile_o, targetfile_mod_o) os.mkdir(path.directory(targetfile)) os.vrunv(ld, argv) end, {dependfile = dependfile, lastmtime = os.mtime(target:targetfile()), files = objectfiles, changed = target:is_rebuilt()}) end function install(target) os.vrunv("insmod", {target:targetfile()}) end function uninstall(target) os.vrunv("rmmod", {target:targetfile()}) end
0
repos/xmake/xmake/rules/platform/linux
repos/xmake/xmake/rules/platform/linux/driver/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- build linux driver module rule("platform.linux.driver") set_sourcekinds("cc") on_load(function (target) import("driver_modules").load(target) end) on_config(function (target) import("driver_modules").config(target) end) on_link(function (target, opt) import("driver_modules").link(target, opt) end) on_install(function (target) import("driver_modules").install(target) end) on_uninstall(function (target) import("driver_modules").uninstall(target) end)
0
repos/xmake/xmake/rules/platform/wasm
repos/xmake/xmake/rules/platform/wasm/preloadfiles/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- @see https://github.com/xmake-io/xmake/issues/3613 rule("platform.wasm.preloadfiles") on_load("wasm", function (target) if not target:is_binary() then return end local preloadfiles = target:values("wasm.preloadfiles") if preloadfiles then for _, preloadfile in ipairs(preloadfiles) do target:add("ldflags", {"--preload-file", preloadfile}, {force = true, expand = false}) end end end)
0
repos/xmake/xmake/rules/platform/wasm
repos/xmake/xmake/rules/platform/wasm/installfiles/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author SirLynix, ruki -- @file xmake.lua -- -- copy other files generated by emcc (see https://emscripten.org/docs/tools_reference/emcc.html#emcc-o-target) rule("platform.wasm.installfiles") on_load("wasm", function (target) if not target:is_binary() then return end local targetfile = target:targetfile() target:add("installfiles", targetfile:gsub("%.html", ".js"), { prefixdir = "bin" }) target:add("installfiles", targetfile:gsub("%.html", ".mem"), { prefixdir = "bin" }) target:add("installfiles", targetfile:gsub("%.html", ".mjs"), { prefixdir = "bin" }) target:add("installfiles", targetfile:gsub("%.html", ".wasm"), { prefixdir = "bin" }) end)
0
repos/xmake/xmake/rules/platform/windows
repos/xmake/xmake/rules/platform/windows/def/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- add *.def for windows/dll rule("platform.windows.def") set_extensions(".def") on_config("windows", "mingw", function (target) if not target:is_shared() then return end if target:is_plat("windows") and (not target:has_tool("sh", "link")) then return end local sourcebatch = target:sourcebatches()["platform.windows.def"] if sourcebatch then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local flag = path.translate(sourcefile) if target:is_plat("windows") then flag = "/def:" .. flag end -- https://github.com/xmake-io/xmake/pull/4901 target:add("shflags", flag, {force = true}) target:data_add("linkdepfiles", sourcefile) break; end end end)
0
repos/xmake/xmake/rules/platform/windows
repos/xmake/xmake/rules/platform/windows/manifest/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- add *.manifest for windows -- https://github.com/xmake-io/xmake/issues/1241 rule("platform.windows.manifest") set_extensions(".manifest") on_config("windows", function (target) if not target:is_binary() and not target:is_shared() then return end if target:has_tool("ld", "link") or target:has_tool("sh", "link") then local manifest = false local uac = false local sourcebatch = target:sourcebatches()["platform.windows.manifest"] if sourcebatch then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do target:add("ldflags", "/manifestinput:" .. path.translate(sourcefile), {force = true}) target:add("shflags", "/manifestinput:" .. path.translate(sourcefile), {force = true}) target:data_add("linkdepfiles", sourcefile) manifest = true local content = io.readfile(sourcefile) if content then content = content:gsub("<!%-%-.-%-%->", "") if content:find("requestedPrivileges", 1, true) then uac = true end end break end end if manifest then -- if manifest file is provided, we need disable default UAC manifest -- @see https://github.com/xmake-io/xmake/pull/4362 if uac then target:add("ldflags", "/manifestuac:no", {force = true}) end target:add("shflags", "/manifestuac:no", {force = true}) target:add("ldflags", "/manifest:embed", {force = true}) target:add("shflags", "/manifest:embed", {force = true}) else local level = target:policy("windows.manifest.uac") if level then local level_maps = { invoker = "asInvoker", admin = "requireAdministrator", highest = "highestAvailable" } assert(level_maps[level], "unknown uac level %s, please set invoker, admin or highest", level) local ui = target:policy("windows.manifest.uac.ui") or false target:add("ldflags", "/manifest:embed", {("/manifestuac:level='%s' uiAccess='%s'"):format(level_maps[level], ui)}, {force = true, expand = false}) end end end end)
0
repos/xmake/xmake/rules
repos/xmake/xmake/rules/winsdk/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- define rule: win.sdk.resource rule("win.sdk.resource") set_sourcekinds("mrc") on_build_files("private.action.build.object", {batch = true}) -- define rule: application rule("win.sdk.application") -- before load on_load(function (target) target:set("kind", "binary") end) -- after load after_load(function (target) -- set subsystem: windows if is_plat("mingw") then target:add("ldflags", "-mwindows", {force = true}) else local subsystem = false for _, ldflag in ipairs(target:get("ldflags")) do if type(ldflag) == "string" then ldflag = ldflag:lower() if ldflag:find("[/%-]subsystem:") then subsystem = true break end end end if not subsystem then target:add("ldflags", "-subsystem:windows", {force = true}) end end -- add links target:add("syslinks", "kernel32", "user32", "gdi32", "winspool", "comdlg32", "advapi32") target:add("syslinks", "shell32", "ole32", "oleaut32", "uuid", "odbc32", "odbccp32", "comctl32") target:add("syslinks", "comdlg32", "setupapi", "shlwapi") if not is_plat("mingw") then target:add("syslinks", "strsafe") end end)
0
repos/xmake/xmake/rules/winsdk
repos/xmake/xmake/rules/winsdk/mfc/mfc.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author xigal, ruki -- @file xmake.lua -- -- remove exists md or mt function _remove_mt_md_flags(target, flagsname) local flags = table.wrap(target:get(flagsname)) for i = #flags, 1, -1 do flag = flags[i]:lower():trim() if flag:find("^[/%-]?mt[d]?$") or flag:find("^[/%-]?md[d]?$") then table.remove(flags, i) end end target:set(flagsname, flags) end -- remove exists settings function _remove_flags(target) local ldflags = table.wrap(target:get("ldflags")) for i = #ldflags, 1, -1 do ldflag = ldflags[i]:lower():trim() if ldflag:find("[/%-]subsystem:") then table.remove(ldflags, i) break end end target:set("ldflags", ldflags) -- remove defines MT MTd MD MDd local defines = table.wrap(target:get("defines")) for i = #defines, 1, -1 do define = defines[i]:lower():trim() if define:find("^[/%-]?mt[d]?$") or define:find("^[/%-]?md[d]?$") then table.remove(defines, i) end end target:set("defines", defines) -- remove c /MD,/MT _remove_mt_md_flags(target, "cflags") -- remove c,cpp /MD,/MT _remove_mt_md_flags(target, "cxflags") -- remove cpp /MD,/MT _remove_mt_md_flags(target, "cxxflags") end -- apply mfc library settings function library(target, kind) -- set kind: static/shared target:set("kind", kind) -- set runtime library if kind == "static" then target:add("cxflags", is_mode("debug") and "-MTd" or "-MT") else target:add("cxflags", is_mode("debug") and "-MDd" or "-MD") target:add("defines", "AFX", "_AFXDLL") end end -- apply mfc application settings function application(target, mfc_kind) -- set kind: binary target:set("kind", "binary") -- remove some exists flags _remove_flags(target) -- set windows subsystem target:add("ldflags", "-subsystem:windows", {force = true}) -- forces a link to complete even with unresolved symbols if mfc_kind == "static" then target:add("ldflags", "-force", {force = true}) end -- set runtime library if mfc_kind == "static" then target:add("cxflags", is_mode("debug") and "-MTd" or "-MT") else target:add("cxflags", is_mode("debug") and "-MDd" or "-MD") target:add("defines", "AFX", "_AFXDLL") end -- set startup entry local unicode = false for _, define in ipairs(target:get("defines")) do define = define:lower():trim() if define:find("^[_]?unicode$") then unicode = true break end end target:add("ldflags", unicode and "-entry:wWinMainCRTStartup" or "-entry:WinMainCRTStartup", {force = true}) end
0
repos/xmake/xmake/rules/winsdk
repos/xmake/xmake/rules/winsdk/mfc/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author xigal, ruki -- @file xmake.lua -- -- define rule: the mfc shared library rule("win.sdk.mfc.shared") -- add mfc base rule add_deps("win.sdk.mfc.env") -- after load after_load(function (target) import("mfc").library(target, "shared") end) -- define rule: the mfc static library rule("win.sdk.mfc.static") -- add mfc base rule add_deps("win.sdk.mfc.env") -- after load after_load(function (target) import("mfc").library(target, "static") end) -- define rule: the application with shared mfc libraries rule("win.sdk.mfc.shared_app") -- add mfc base rule add_deps("win.sdk.mfc.env") -- after load after_load(function (target) import("mfc").application(target, "shared") end) -- define rule: the application with static mfc libraries rule("win.sdk.mfc.static_app") -- add mfc base rule add_deps("win.sdk.mfc.env") -- after load after_load(function (target) import("mfc").application(target, "static") end)
0
repos/xmake/xmake/rules/winsdk/mfc
repos/xmake/xmake/rules/winsdk/mfc/env/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author xigal, ruki -- @file xmake.lua -- -- define rule: mfc.env rule("win.sdk.mfc.env") -- TODO: before load need check of vs's minverion, if defined on_load(function (target) end)
0
repos/xmake/xmake/rules/winsdk
repos/xmake/xmake/rules/winsdk/dotnet/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- define rule: dotnet rule("win.sdk.dotnet") -- before load on_load(function (target) -- imports import("core.project.config") import("detect.sdks.find_dotnet") -- load dotnet environment if not target:data("win.sdk.dotnet") then -- find dotnet local dotnet = assert(find_dotnet(nil, {verbose = true}), "dotnet not found!") -- add link directory target:add("linkdirs", path.join(dotnet.libdir, "um", config.arch())) -- save dotnet target:data_set("win.sdk.dotnet", dotnet) end end) -- before build file before_build_file(function (target, sourcefile, opt) -- get dotnet local dotnet = target:data("win.sdk.dotnet") if not dotnet then -- imports import("core.project.config") import("detect.sdks.find_dotnet") -- find dotnet dotnet = assert(find_dotnet(nil, {verbose = true}), "dotnet not found!") -- add link directory target:add("linkdirs", path.join(dotnet.libdir, "um", config.arch())) -- save dotnet target:data_set("win.sdk.dotnet", dotnet) end -- get file config local fileconfig = target:fileconfig(sourcefile) or {} -- add cxflags to the given source file -- -- add_files(sourcefile, {force = {cxflags = "/clr"}}) -- fileconfig.force = fileconfig.force or {} fileconfig.force.cxflags = fileconfig.force.cxflags or {} table.insert(fileconfig.force.cxflags, "/clr") -- add include directory to given source file fileconfig.includedirs = fileconfig.includedirs or {} table.insert(fileconfig.includedirs, path.join(dotnet.includedir, "um")) -- update file config target:fileconfig_set(sourcefile, fileconfig) end)
0
repos/xmake/xmake/rules/luarocks
repos/xmake/xmake/rules/luarocks/module/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("luarocks.module") on_load(function (target) -- imports import("core.cache.detectcache") import("core.project.target", {alias = "project_target"}) -- set kind if target:is_plat("macosx") then target:set("kind", "binary") target:add("ldflags", "-bundle", "-undefined dynamic_lookup", {force = true}) else target:set("kind", "shared") end -- set library name local modulename = target:name():split('.', {plain = true}) modulename = modulename[#modulename] if target:is_plat("windows", "mingw") then target:set("basename", modulename) else target:set("filename", modulename .. ".so") end -- export symbols if target:is_plat("windows") then local exported_name = target:name():gsub("%.", "_") exported_name = exported_name:match('^[^%-]+%-(.+)$') or exported_name target:add("shflags", "/export:luaopen_" .. exported_name, {force = true}) else target:set("symbols", "none") end -- add lua library local has_lua = false local includedirs = get_config("includedirs") -- pass lua library from luarocks-build-xmake/xmake.lua if includedirs and includedirs:find("lua", 1, true) then has_lua = true end if not has_lua then -- user use `add_requires/add_packages` to add lua/luajit package for _, pkg in ipairs(target:get("packages")) do if pkg == "lua" or pkg == "luajit" then has_lua = true break end end end if not has_lua then target:add(find_package("lua")) end end) on_install(function (target) local moduledir = path.directory((target:name():gsub('%.', '/'))) import('target.action.install')(target, {libdir = path.join('lib', moduledir), bindir = path.join('lib', moduledir)}) end)
0
repos/xmake/xmake/rules
repos/xmake/xmake/rules/linker/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("linker") add_deps("linker.link_scripts") add_deps("linker.version_scripts") add_deps("linker.soname")
0
repos/xmake/xmake/rules/linker
repos/xmake/xmake/rules/linker/soname/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("linker.soname") on_config(function (target) local soname = target:soname() if target:is_shared() and soname then if target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then if target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then target:add("shflags", "-Wl,-install_name,@rpath/" .. soname, {force = true}) else target:add("shflags", "-Wl,-soname," .. soname, {force = true}) end target:data_set("soname.enabled", true) end end end) after_link(function (target) import("core.project.depend") local soname = target:soname() if target:is_shared() and soname and target:data("soname.enabled") then local version = target:version() local filename = target:filename() local extension = path.extension(filename) local targetfile_with_version = path.join(target:targetdir(), filename .. "." .. version) if extension == ".dylib" then targetfile_with_version = path.join(target:targetdir(), path.basename(filename) .. "." .. version .. extension) end local targetfile_with_soname = path.join(target:targetdir(), soname) local targetfile = target:targetfile() if soname ~= filename and soname ~= path.filename(targetfile_with_version) then depend.on_changed(function () os.cp(target:targetfile(), targetfile_with_version) os.rm(target:targetfile()) local oldir = os.cd(target:targetdir()) os.ln(path.filename(targetfile_with_version), soname, {force = true}) os.ln(soname, path.filename(targetfile), {force = true}) os.cd(oldir) end, {dependfile = target:dependfile(targetfile_with_version), files = {target:targetfile()}, values = {soname, version}, changed = target:is_rebuilt()}) end end end) after_clean(function (target) import("private.action.clean.remove_files") local soname = target:soname() if target:is_shared() and soname then local version = target:version() local filename = target:filename() local extension = path.extension(filename) local targetfile_with_version = path.join(target:targetdir(), filename .. "." .. version) if extension == ".dylib" then targetfile_with_version = path.join(target:targetdir(), path.basename(filename) .. "." .. version .. extension) end local targetfile_with_soname = path.join(target:targetdir(), soname) remove_files(targetfile_with_soname) remove_files(targetfile_with_version) end end)
0
repos/xmake/xmake/rules/linker
repos/xmake/xmake/rules/linker/version_scripts/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("linker.version_scripts") set_extensions(".ver", ".map") on_config(function (target) if not target:is_binary() and not target:is_shared() then return end local scriptfile local sourcebatch = target:sourcebatches()["linker.version_scripts"] if sourcebatch then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do scriptfile = sourcefile break end end if not scriptfile then return end -- @note apple's linker does not support it if target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then return end if target:has_tool("ld", "gcc", "gxx", "clang", "clangxx") or target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then target:add(target:is_shared() and "shflags" or "ldflags", "-Wl,--version-script=" .. scriptfile, {force = true}) elseif target:has_tool("ld", "dmd") or target:has_tool("sh", "dmd") then target:add(target:is_shared() and "shflags" or "ldflags", "-L--version-script=" .. scriptfile, {force = true}) elseif target:has_tool("ld", "ld") or target:has_tool("sh", "ld") then target:add(target:is_shared() and "shflags" or "ldflags", "--version-script=" .. scriptfile, {force = true}) end end)
0
repos/xmake/xmake/rules/linker
repos/xmake/xmake/rules/linker/link_scripts/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("linker.link_scripts") set_extensions(".ld", ".lds") on_config(function (target) if not target:is_binary() and not target:is_shared() then return end local scriptfile local sourcebatch = target:sourcebatches()["linker.link_scripts"] if sourcebatch then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do scriptfile = sourcefile break end end if not scriptfile then return end -- @note apple's linker does not support it if target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then return end if target:has_tool("ld", "gcc", "gxx", "clang", "clangxx") or target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then target:add(target:is_shared() and "shflags" or "ldflags", "-T " .. scriptfile, {force = true}) target:data_add("linkdepfiles", scriptfile) elseif target:has_tool("ld", "ld") or target:has_tool("sh", "ld") then target:add(target:is_shared() and "shflags" or "ldflags", "-T " .. scriptfile, {force = true}) target:data_add("linkdepfiles", scriptfile) end end)
0
repos/xmake/xmake/rules
repos/xmake/xmake/rules/python/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- @see https://github.com/xmake-io/xmake/issues/1896 rule("python.library") on_config(function (target) target:set("kind", "shared") target:set("prefixname", "") target:add("runenvs", "PYTHONPATH", target:targetdir()) local soabi = target:extraconf("rules", "python.library", "soabi") if soabi then import("lib.detect.find_tool") local python = assert(find_tool("python3"), "python not found!") local result = try { function() return os.iorunv(python.program, {"-c", "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"}) end} if result then result = result:trim() if result ~= "None" then target:set("extension", result) end end else if target:is_plat("windows", "mingw") then target:set("extension", ".pyd") else target:set("extension", ".so") end end -- fix segmentation fault for macosx -- @see https://github.com/xmake-io/xmake/issues/2177#issuecomment-1209398292 if target:is_plat("macosx", "linux") then if target:is_plat("macosx") then target:add("shflags", "-undefined dynamic_lookup", {force = true}) end for _, pkg in pairs(target:pkgs()) do local links = pkg:get("links") if links then local with_python = false for _, link in ipairs(links) do if link:startswith("python") then with_python = true break end end if with_python then pkg:set("links", nil) pkg:set("linkdirs", nil) end end end end end)
0
repos/xmake/xmake/rules
repos/xmake/xmake/rules/mdk/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("mdk.binary") on_load(function (target) -- we disable checking flags for cross toolchain automatically target:set("policy", "check.auto_ignore_flags", false) target:set("policy", "check.auto_map_flags", false) -- set default output binary target:set("kind", "binary") if not target:get("extension") then target:set("extension", ".axf") end end) rule("mdk.static") on_load(function (target) -- we disable checking flags for cross toolchain automatically target:set("policy", "check.auto_ignore_flags", false) target:set("policy", "check.auto_map_flags", false) -- set default output binary target:set("kind", "static") end) rule("mdk.console") add_deps("mdk.binary")
0
repos/xmake/xmake/rules/utils
repos/xmake/xmake/rules/utils/merge_archive/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("utils.merge.archive") set_extensions(".a", ".lib") after_load(function (target) -- we need to disable inherit links if all static deps have been merged -- and we must disable it in after_load, because it will be called before rule(utils.inherit.links).on_config -- -- @see https://github.com/xmake-io/xmake/issues/3404 if target:policy("build.merge_archive") then for _, dep in ipairs(target:orderdeps()) do if dep:is_static() then dep:data_set("inherit.links.deplink", false) end end end end) on_build_files(function (target, sourcebatch, opt) if sourcebatch.sourcefiles then target:data_set("merge_archive.sourcefiles", sourcebatch.sourcefiles) end end) after_link(function (target, opt) if not target:is_static() then return end local sourcefiles = target:data("merge_archive.sourcefiles") if target:policy("build.merge_archive") or sourcefiles then import("utils.archive.merge_staticlib") import("core.project.depend") import("utils.progress") local libraryfiles = {} if sourcefiles then table.join2(libraryfiles, sourcefiles) else for _, dep in ipairs(target:orderdeps()) do if dep:is_static() then table.insert(libraryfiles, dep:targetfile()) end end end if #libraryfiles > 0 then table.insert(libraryfiles, target:targetfile()) end depend.on_changed(function () progress.show(opt.progress, "${color.build.target}merging.$(mode) %s", path.filename(target:targetfile())) if #libraryfiles > 0 then local tmpfile = os.tmpfile() .. path.extension(target:targetfile()) merge_staticlib(target, tmpfile, libraryfiles) os.cp(tmpfile, target:targetfile()) os.rm(tmpfile) end end, {dependfile = target:dependfile(target:targetfile() .. ".merge_archive"), files = libraryfiles, changed = target:is_rebuilt()}) end end)
0
repos/xmake/xmake/rules/utils
repos/xmake/xmake/rules/utils/inherit_links/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- define rule: utils.inherit.links rule("utils.inherit.links") on_config("inherit_links")
0
repos/xmake/xmake/rules/utils
repos/xmake/xmake/rules/utils/inherit_links/inherit_links.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file inherit_links.lua -- -- get values from target function _get_values_from_target(target, name) local values = table.clone(table.wrap(target:get(name))) for _, value in ipairs((target:get_from(name, "option::*"))) do table.join2(values, value) end for _, value in ipairs((target:get_from(name, "package::*"))) do table.join2(values, value) end return values end -- @note we cannot directly set `{interface = true}`, because it will overwrite the previous configuration -- https://github.com/xmake-io/xmake/issues/1465 function _add_export_value(target, name, value) local has_private = false local private_values = target:get(name) if private_values then for _, v in ipairs(private_values) do if v == value then has_private = true break end end end local extraconf = target:extraconf(name, value) if has_private then target:add(name, value, table.join(extraconf or {}, {public = true})) else target:add(name, value, table.join(extraconf or {}, {interface = true})) end end -- export values as public/interface in target function _add_export_values(target, name, values) for _, value in ipairs(values) do _add_export_value(target, name, value) end end function main(target) -- disable inherit.links for `add_deps()`? if target:data("inherit.links") == false then return end -- export target links and linkdirs if target:is_shared() or target:is_static() then local targetfile = target:targetfile() -- rust maybe will disable inherit links, only inherit linkdirs if target:data("inherit.links.deplink") ~= false then -- we need to move target link to head _add_export_value(target, "links", target:linkname()) local links = target:get("links", {rawref = true}) if links and type(links) == "table" and #links > 1 then table.insert(links, 1, links[#links]) table.remove(links, #links) end end _add_export_value(target, "linkdirs", path.directory(targetfile)) if target:rule("go") then -- we need to add includedirs to support import modules for golang _add_export_value(target, "includedirs", path.directory(targetfile)) end end -- we export all links and linkdirs in self/packages/options to the parent target by default -- -- @note we only export links for static target, -- and we need to pass `{public = true}` to add_packages/add_links/... to export it if want to export links for shared target -- if target:data("inherit.links.exportlinks") ~= false then if target:is_static() or target:is_object() then for _, name in ipairs({"rpathdirs", "frameworkdirs", "frameworks", "linkdirs", "links", "syslinks", "ldflags", "shflags"}) do local values = _get_values_from_target(target, name) if values and #values > 0 then _add_export_values(target, name, values) end end end end -- export rpathdirs for all shared library if target:is_binary() and target:policy("build.rpath") then local targetdir = target:targetdir() for _, dep in ipairs(target:orderdeps({inherit = true})) do if dep:kind() == "shared" then local rpathdir = "@loader_path" local subdir = path.relative(path.directory(dep:targetfile()), targetdir) if subdir and subdir ~= '.' then rpathdir = path.join(rpathdir, subdir) end target:add("rpathdirs", rpathdir) end end end end
0
repos/xmake/xmake/rules/utils
repos/xmake/xmake/rules/utils/install_importfiles/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- install pkg-config/*.pc import files rule("utils.install.pkgconfig_importfiles") after_install(function (target, opt) opt = opt or {} local configs = target:extraconf("rules", "utils.install.pkgconfig_importfiles") import("target.action.install.pkgconfig_importfiles")(target, table.join(opt, configs)) end) -- install *.cmake import files rule("utils.install.cmake_importfiles") after_install(function (target, opt) opt = opt or {} local configs = target:extraconf("rules", "utils.install.cmake_importfiles") import("target.action.install.cmake_importfiles")(target, table.join(opt, configs)) end)
0
repos/xmake/xmake/rules/utils
repos/xmake/xmake/rules/utils/compiler_runtime/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- define rule: utils.compiler.runtime rule("utils.compiler.runtime") on_config(function (target) local runtimes = get_config("runtimes") if not runtimes and target:is_plat("windows") then runtimes = get_config("vs_runtime") if runtimes then wprint("--vs_runtime=%s is deprecated, please use --runtimes=%s", runtimes, runtimes) end end if not runtimes and target:is_plat("android") then runtimes = get_config("ndk_cxxstl") if runtimes then wprint("--ndk_cxxstl=%s is deprecated, please use --runtimes=%s", runtimes, runtimes) end end if runtimes and not target:get("runtimes") then if type(runtimes) == "string" then runtimes = runtimes:split(",", {plain = true}) end target:set("runtimes", runtimes) end end)
0
repos/xmake/xmake/rules/utils
repos/xmake/xmake/rules/utils/ispc/xmake.lua
rule("utils.ispc") set_extensions(".ispc") on_config(function (target) local headersdir = path.join(target:autogendir(), "rules", "utils", "ispc", "headers") os.mkdir(headersdir) target:add("includedirs", headersdir, {public = true}) end) before_buildcmd_file(function (target, batchcmds, sourcefile_ispc, opt) import("lib.detect.find_tool") local ispc = assert(find_tool("ispc"), "ispc not found!") local flags = {} if target:values("ispc.flags") then table.join2(flags, target:values("ispc.flags")) end if target:get("symbols") == "debug" then table.insert(flags, "-g") end if target:get("optimize") == "none" then table.insert(flags, "-O0") elseif target:get("optimize") == "fast" then table.insert(flags, "-O2") elseif target:get("optimize") == "faster" or target:get("optimize") == "fastest" then table.insert(flags, "-O3") elseif target:get("optimize") == "smallest" then table.insert(flags, "-O1") end if target:get("warnings") == "none" then table.insert(flags, "--woff") elseif target:get("warnings") == "error" then table.insert(flags, "--werror") end if not target:is_plat("windows") then table.insert(flags, "--pic") end local headersdir = path.join(target:autogendir(), "rules", "utils", "ispc", "headers") local objectfile = target:objectfile(sourcefile_ispc) local objectdir = path.directory(objectfile) local headersfile local header_extension = target:extraconf("rules", "utils.ispc", "header_extension") if header_extension then headersfile = path.join(headersdir, path.basename(sourcefile_ispc) .. header_extension) else headersfile = path.join(headersdir, path.filename(sourcefile_ispc) .. ".h") end table.insert(flags, "-o") table.insert(flags, path(objectfile)) table.insert(flags, "-h") table.insert(flags, path(headersfile)) table.insert(flags, path(sourcefile_ispc)) batchcmds:show_progress(opt.progress, "${color.build.object}compiling.ispc %s", sourcefile_ispc) batchcmds:mkdir(objectdir) batchcmds:vrunv(ispc.program, flags) table.insert(target:objectfiles(), objectfile) batchcmds:add_depfiles(sourcefile_ispc, headersfile) batchcmds:set_depmtime(os.mtime(objectfile)) batchcmds:set_depcache(target:dependfile(objectfile)) end)
0
repos/xmake/xmake/rules/utils
repos/xmake/xmake/rules/utils/hlsl2spv/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- compile glsl shader to spirv file, .spv -- -- e.g. -- compile *.hlsl/*.hlsl to *.spv/*.spv files -- add_rules("utils.hlsl2spv", {outputdir = "build"}) -- -- compile *.vert/*.frag and generate binary c header files -- add_rules("utils.hlsl2spv", {bin2c = true}) -- -- in c code: -- static unsigned char g_test_frag_spv_data[] = { -- #include "test.spv.h" -- }; -- -- rule("utils.hlsl2spv") set_extensions(".hlsl") on_load(function (target) local is_bin2c = target:extraconf("rules", "utils.hlsl2spv", "bin2c") if is_bin2c then local headerdir = path.join(target:autogendir(), "rules", "utils", "hlsl2spv") if not os.isdir(headerdir) then os.mkdir(headerdir) end target:add("includedirs", headerdir) end end) before_buildcmd_file(function (target, batchcmds, sourcefile_hlsl, opt) import("lib.detect.find_tool") local dxc = assert(find_tool("dxc"), "dxc not found!") -- hlsl to spv local basename_with_type = path.basename(sourcefile_hlsl) local shadertype = path.extension(basename_with_type):sub(2) if shadertype == "" then -- if not specify shader type, considered it a header, skip wprint("hlsl2spv: shader type not specified, skip %s", sourcefile_hlsl) return end local targetenv = target:extraconf("rules", "utils.hlsl2spv", "targetenv") or "vulkan1.0" local outputdir = target:extraconf("rules", "utils.hlsl2spv", "outputdir") or path.join(target:autogendir(), "rules", "utils", "hlsl2spv") local hlslversion = target:extraconf("rules", "utils.hlsl2spv", "hlslversion") or "2018" local spvfilepath = path.join(outputdir, basename_with_type .. ".spv") local shadermodel = target:extraconf("rules", "utils.hlsl2spv", "shadermodel") or "6.0" local sm = shadermodel:gsub("%.", "_") local dxc_profile = shadertype .. "_" .. sm batchcmds:show_progress(opt.progress, "${color.build.object}compiling.hlsl %s", sourcefile_hlsl) batchcmds:mkdir(outputdir) batchcmds:vrunv(dxc.program, {path(sourcefile_hlsl), "-spirv", "-HV", hlslversion, "-fspv-target-env=" .. targetenv, "-E", "main", "-T", dxc_profile, "-Fo", path(spvfilepath)}) -- bin2c local outputfile = spvfilepath local is_bin2c = target:extraconf("rules", "utils.hlsl2spv", "bin2c") if is_bin2c then -- get header file local headerdir = outputdir local headerfile = path.join(headerdir, path.filename(spvfilepath) .. ".h") target:add("includedirs", headerdir) outputfile = headerfile -- add commands local argv = {"lua", "private.utils.bin2c", "--nozeroend", "-i", path(spvfilepath), "-o", path(headerfile)} batchcmds:vrunv(os.programfile(), argv, {envs = {XMAKE_SKIP_HISTORY = "y"}}) end batchcmds:add_depfiles(sourcefile_hlsl) batchcmds:set_depmtime(os.mtime(outputfile)) batchcmds:set_depcache(target:dependfile(outputfile)) end) after_clean(function (target, batchcmds, sourcefile_hlsl) import("private.action.clean.remove_files") local outputdir = target:extraconf("rules", "utils.hlsl2spv", "outputdir") or path.join(target:targetdir(), "shader") remove_files(path.join(outputdir, "*.spv")) remove_files(path.join(outputdir, "*.spv.h")) end)
0
repos/xmake/xmake/rules/utils/symbols
repos/xmake/xmake/rules/utils/symbols/export_list/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- export the given symbols list -- --@code -- target("foo") -- set_kind("shared") -- add_files("src/foo.c") -- add_rules("utils.symbols.export_list", {symbols = { -- "add", -- "sub"}}) -- -- target("foo2") -- set_kind("shared") -- add_files("src/foo.c") -- add_files("src/foo.export.txt") -- add_rules("utils.symbols.export_list") -- rule("utils.symbols.export_list") set_extensions(".export.txt") on_config(function (target) assert(target:is_shared(), 'rule("utils.symbols.export_list"): only for shared target(%s)!', target:name()) local exportfile local exportkind local exportsymbols = target:extraconf("rules", "utils.symbols.export_list", "symbols") if not exportsymbols then local sourcebatch = target:sourcebatches()["utils.symbols.export_list"] if sourcebatch then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local list = io.readfile(sourcefile) if list then exportsymbols = list:split("\n") end break end end end assert(exportsymbols and #exportsymbols > 0, 'rule("utils.symbols.export_list"): no exported symbols!') local linkername = target:linker():name() if linkername == "dmd" then if target:is_plat("windows") then exportkind = "def" exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.def") target:add("shflags", "-L/def:" .. exportfile, {force = true}) elseif target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then exportkind = "apple" exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.exp") target:add("shflags", {"-L-exported_symbols_list", "-L" .. exportfile}, {force = true, expand = false}) else exportkind = "ver" exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.map") target:add("shflags", "-L--version-script=" .. exportfile, {force = true}) end elseif target:has_tool("ld", "link") then exportkind = "def" exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.def") target:add("shflags", "/def:" .. exportfile, {force = true}) elseif target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then exportkind = "apple" exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.exp") target:add("shflags", {"-Wl,-exported_symbols_list", exportfile}, {force = true, expand = false}) elseif target:has_tool("ld", "gcc", "gxx", "clang", "clangxx") or target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then exportkind = "ver" exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.map") target:add("shflags", "-Wl,--version-script=" .. exportfile, {force = true}) elseif target:has_tool("ld", "ld") or target:has_tool("sh", "ld") then exportkind = "ver" exportfile = path.join(target:autogendir(), "rules", "symbols", "export_list.map") target:add("shflags", "--version-script=" .. exportfile, {force = true}) end if exportfile and exportkind then if exportkind == "ver" then io.writefile(exportfile, ([[{ global: %s local: *; };]]):format(table.concat(exportsymbols, ";\n ") .. ";")) elseif exportkind == "apple" then local file = io.open(exportfile, 'w') for _, symbol in ipairs(exportsymbols) do if not symbol:startswith("_") then symbol = "_" .. symbol end file:print("%s", symbol) end file:close() elseif exportkind == "def" then local file = io.open(exportfile, 'w') file:print("EXPORTS") for _, symbol in ipairs(exportsymbols) do file:print("%s", symbol) end file:close() end end end)
0
repos/xmake/xmake/rules/utils/symbols
repos/xmake/xmake/rules/utils/symbols/export_all/export_all.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file export_all.lua -- -- imports import("lib.detect.find_tool") import("core.tool.toolchain") import("core.base.option") import("core.base.hashset") import("core.project.depend") import("utils.progress") -- use dumpbin to get all symbols from object files function _get_allsymbols_by_dumpbin(target, dumpbin, opt) opt = opt or {} local allsymbols = hashset.new() local export_classes = opt.export_classes local export_filter = opt.export_filter for _, objectfile in ipairs(target:objectfiles()) do local objectsymbols = try { function () return os.iorunv(dumpbin, {"/symbols", "/nologo", objectfile}) end } if objectsymbols then for _, line in ipairs(objectsymbols:split('\n', {plain = true})) do -- https://docs.microsoft.com/en-us/cpp/build/reference/symbols -- 008 00000000 SECT3 notype () External | add if line:find("External") and not line:find("UNDEF") then local symbol = line:match(".*External%s+| (.*)") if symbol then symbol = symbol:split('%s')[1] -- we need ignore DllMain, https://github.com/xmake-io/xmake/issues/3992 if target:is_arch("x86") and symbol:startswith("_") and not symbol:startswith("__") and not symbol:startswith("_DllMain@") then symbol = symbol:sub(2) end if export_filter then if export_filter(symbol) then allsymbols:insert(symbol) end elseif not symbol:startswith("__") then if export_classes or not symbol:startswith("?") then if export_classes then if not symbol:startswith("??_G") and not symbol:startswith("??_E") then allsymbols:insert(symbol) end else allsymbols:insert(symbol) end end end end end end end end return allsymbols end -- use objdump to get all symbols from object files function _get_allsymbols_by_objdump(target, objdump, opt) opt = opt or {} local allsymbols = hashset.new() local export_classes = opt.export_classes local export_filter = opt.export_filter for _, objectfile in ipairs(target:objectfiles()) do local objectsymbols = try { function () return os.iorunv(objdump, {"--syms", objectfile}) end } if objectsymbols then for _, line in ipairs(objectsymbols:split('\n', {plain = true})) do if line:find("(scl 2)", 1, true) then local splitinfo = line:split("%s") local symbol = splitinfo[#splitinfo] if symbol then -- we need ignore DllMain, https://github.com/xmake-io/xmake/issues/3992 if target:is_arch("x86") and symbol:startswith("_") and not symbol:startswith("__") and not symbol:startswith("_DllMain@") then symbol = symbol:sub(2) end if export_filter then if export_filter(symbol) then allsymbols:insert(symbol) end elseif not symbol:startswith("__") then if export_classes or not symbol:startswith("?") then if export_classes then if not symbol:startswith("??_G") and not symbol:startswith("??_E") then allsymbols:insert(symbol) end else allsymbols:insert(symbol) end end end end end end end end return allsymbols end -- export all symbols for dynamic library function main(target, opt) -- @note it only supports windows/dll now assert(target:is_shared(), 'rule("utils.symbols.export_all"): only for shared target(%s)!', target:name()) if not target:is_plat("windows") or option.get("dry-run") then return end -- export all symbols local allsymbols_filepath = path.join(target:autogendir(), "rules", "symbols", "export_all.def") local dependfile = allsymbols_filepath .. ".d" depend.on_changed(function () -- trace progress info progress.show(opt.progress, "${color.build.target}exporting.$(mode) %s", path.filename(target:targetfile())) -- export c++ class? local export_classes = target:extraconf("rules", "utils.symbols.export_all", "export_classes") -- the export filter local export_filter = target:extraconf("rules", "utils.symbols.export_all", "export_filter") -- get all symbols local allsymbols if target:has_tool("cc", "clang", "clang_cl", "clangxx", "gcc", "gxx") then local objdump = assert(find_tool("llvm-objdump") or find_tool("objdump"), "objdump not found!") allsymbols = _get_allsymbols_by_objdump(target, objdump.program, { export_classes = export_classes, export_filter = export_filter}) end if not allsymbols then local msvc = toolchain.load("msvc", {plat = target:plat(), arch = target:arch()}) if msvc:check() then local dumpbin = assert(find_tool("dumpbin", {envs = msvc:runenvs()}), "dumpbin not found!") allsymbols = _get_allsymbols_by_dumpbin(target, dumpbin.program, { export_classes = export_classes, export_filter = export_filter}) end end -- export all symbols if allsymbols and allsymbols:size() > 0 then local allsymbols_file = io.open(allsymbols_filepath, 'w') allsymbols_file:print("EXPORTS") for _, symbol in allsymbols:keys() do allsymbols_file:print("%s", symbol) end allsymbols_file:close() else wprint('rule("utils.symbols.export_all"): no symbols are exported for target(%s)!', target:name()) end end, {dependfile = dependfile, files = target:objectfiles(), changed = target:is_rebuilt()}) end
0
repos/xmake/xmake/rules/utils/symbols
repos/xmake/xmake/rules/utils/symbols/export_all/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- export all symbols for windows/dll -- -- @note: we don't need any export macros to a classes or functions! -- and we can't use /GL (Whole Program Optimization) when use this approach! -- -- @see https://github.com/xmake-io/xmake/issues/1123 -- rule("utils.symbols.export_all") on_config(function (target) -- @note it only supports windows/dll now assert(target:is_shared(), 'rule("utils.symbols.export_all"): only for shared target(%s)!', target:name()) if target:is_plat("windows") then assert(target:get("optimize") ~= "smallest", 'rule("utils.symbols.export_all"): does not support set_optimize("smallest") for target(%s)!', target:name()) local allsymbols_filepath = path.join(target:autogendir(), "rules", "symbols", "export_all.def") if target:has_tool("sh", "link") then target:add("shflags", "/def:" .. allsymbols_filepath, {force = true}) elseif target:has_tool("sh", "clang", "clangxx") then target:add("shflags", "-Wl,/def:" .. allsymbols_filepath, {force = true}) end end end) before_link("export_all")
0
repos/xmake/xmake/rules/utils/symbols
repos/xmake/xmake/rules/utils/symbols/extract/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- define rule: utils.symbols.extract rule("utils.symbols.extract") before_link(function(target) -- imports import("core.platform.platform") -- need generate symbols? local strip = target:get("strip") if target:get("symbols") == "debug" and (strip == "all" or strip == "debug") and (target:is_binary() or target:is_shared()) and target:tool("strip") then -- only for strip command target:data_set("utils.symbols.extract", true) target:set("strip", "none") -- disable strip in link stage, because we need to run separate strip commands target:data_set("strip.origin", strip) end end) after_link(function (target, opt) -- need generate symbols? if not target:data("utils.symbols.extract") then return end -- imports import("core.base.option") import("core.theme.theme") import("core.project.depend") import("core.platform.platform") import("utils.progress") -- get strip local strip = target:tool("strip") if not strip then return end -- get dsymutil and objcopy local dsymutil, objcopy if target:is_plat("macosx", "iphoneos", "watchos") then dsymutil = target:tool("dsymutil") if not dsymutil then return end else objcopy = target:tool("objcopy") end -- @note we use dependfile(targetfile) as sourcefile/mtime instead of targetfile to ensure it's mtime less than mtime(symbolfile), because targetfile will be changed after stripping local targetfile = target:targetfile() local symbolfile = target:symbolfile() local dryrun = option.get("dry-run") depend.on_changed(function () -- trace progress info progress.show(opt.progress, "${color.build.target}generating.$(mode) %s", path.filename(symbolfile)) -- we remove the previous symbol file to ensure that it will be re-generated and it's mtime will be changed. if not dryrun then os.tryrm(symbolfile) end -- generate symbols file if dsymutil then local dsymutil_argv = {} local arch = target:arch() if arch then table.insert(dsymutil_argv, "-arch") table.insert(dsymutil_argv, arch) end table.insert(dsymutil_argv, targetfile) table.insert(dsymutil_argv, "-o") table.insert(dsymutil_argv, symbolfile) os.vrunv(dsymutil, dsymutil_argv, {dryrun = dryrun}) else -- @see https://github.com/xmake-io/xmake/issues/4684 if objcopy then os.vrunv(objcopy, {"--only-keep-debug", targetfile, symbolfile}, {dryrun = dryrun}) elseif not dryrun then os.vcp(targetfile, symbolfile) end end -- strip it local strip_argv = {} if target:is_plat("macosx", "iphoneos", "watchos") then -- do not support `-s`, we can only strip debug symbols local arch = target:arch() if arch then table.insert(strip_argv, "-arch") table.insert(strip_argv, arch) end table.insert(strip_argv, "-S") else -- -s/--strip-all for gnu strip local strip = target:data("strip.origin") if strip == "debug" then table.insert(strip_argv, "-S") else table.insert(strip_argv, "-s") end end table.insert(strip_argv, targetfile) os.vrunv(strip, strip_argv, {dryrun = dryrun}) -- attach symbolfile to targetfile if not target:is_plat("macosx", "iphoneos", "watchos") and objcopy then -- @see https://github.com/xmake-io/xmake/issues/4684 os.vrunv(objcopy, {"--add-gnu-debuglink=" .. symbolfile, targetfile}, {dryrun = dryrun}) end end, {dependfile = target:dependfile(symbolfile), files = target:dependfile(targetfile), changed = target:is_rebuilt(), dryrun = dryrun}) end)
0
repos/xmake/xmake/rules/utils
repos/xmake/xmake/rules/utils/bin2c/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("utils.bin2c") set_extensions(".bin") on_load(function (target) local headerdir = path.join(target:autogendir(), "rules", "utils", "bin2c") if not os.isdir(headerdir) then os.mkdir(headerdir) end target:add("includedirs", headerdir) end) before_buildcmd_file(function (target, batchcmds, sourcefile_bin, opt) -- get header file local headerdir = path.join(target:autogendir(), "rules", "utils", "bin2c") local headerfile = path.join(headerdir, path.filename(sourcefile_bin) .. ".h") target:add("includedirs", headerdir) -- add commands batchcmds:show_progress(opt.progress, "${color.build.object}generating.bin2c %s", sourcefile_bin) batchcmds:mkdir(headerdir) local argv = {"lua", "private.utils.bin2c", "-i", path(sourcefile_bin), "-o", path(headerfile)} local linewidth = target:extraconf("rules", "utils.bin2c", "linewidth") if linewidth then table.insert(argv, "-w") table.insert(argv, tostring(linewidth)) end local nozeroend = target:extraconf("rules", "utils.bin2c", "nozeroend") if nozeroend then table.insert(argv, "--nozeroend") end batchcmds:vrunv(os.programfile(), argv, {envs = {XMAKE_SKIP_HISTORY = "y"}}) -- add deps batchcmds:add_depfiles(sourcefile_bin) batchcmds:set_depmtime(os.mtime(headerfile)) batchcmds:set_depcache(target:dependfile(headerfile)) end)
0
repos/xmake/xmake/rules/utils
repos/xmake/xmake/rules/utils/glsl2spv/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- compile glsl shader to spirv file, .spv -- -- e.g. -- compile *.vert/*.frag to *.vert.spv/*.frag.spv files -- add_rules("utils.glsl2spv", {outputdir = "build"}) -- -- compile *.vert/*.frag and generate binary c header files -- add_rules("utils.glsl2spv", {bin2c = true}) -- -- in c code: -- static unsigned char g_test_frag_spv_data[] = { -- #include "test.frag.spv.h" -- }; -- -- rule("utils.glsl2spv") set_extensions(".vert", ".tesc", ".tese", ".geom", ".comp", ".frag", ".comp", ".mesh", ".task", ".rgen", ".rint", ".rahit", ".rchit", ".rmiss", ".rcall", ".glsl") on_load(function (target) local is_bin2c = target:extraconf("rules", "utils.glsl2spv", "bin2c") if is_bin2c then local headerdir = path.join(target:autogendir(), "rules", "utils", "glsl2spv") if not os.isdir(headerdir) then os.mkdir(headerdir) end target:add("includedirs", headerdir) end end) before_buildcmd_file(function (target, batchcmds, sourcefile_glsl, opt) import("lib.detect.find_tool") -- get glslangValidator local glslc local glslangValidator = find_tool("glslangValidator") if not glslangValidator then glslc = find_tool("glslc") end assert(glslangValidator or glslc, "glslangValidator or glslc not found!") -- glsl to spv local targetenv = target:extraconf("rules", "utils.glsl2spv", "targetenv") or "vulkan1.0" local client = target:extraconf("rules", "utils.glsl2spv", "client") or "vulkan100" local outputdir = target:extraconf("rules", "utils.glsl2spv", "outputdir") or path.join(target:autogendir(), "rules", "utils", "glsl2spv") local spvfilepath = path.join(outputdir, path.filename(sourcefile_glsl) .. ".spv") batchcmds:show_progress(opt.progress, "${color.build.object}generating.glsl2spv %s", sourcefile_glsl) batchcmds:mkdir(outputdir) if glslangValidator then batchcmds:vrunv(glslangValidator.program, {"--target-env", targetenv, "--client", client, "-o", path(spvfilepath), path(sourcefile_glsl)}) else batchcmds:vrunv(glslc.program, {"--target-env", targetenv, "-o", path(spvfilepath), path(sourcefile_glsl)}) end -- do bin2c local outputfile = spvfilepath local is_bin2c = target:extraconf("rules", "utils.glsl2spv", "bin2c") if is_bin2c then -- get header file local headerdir = outputdir local headerfile = path.join(headerdir, path.filename(spvfilepath) .. ".h") target:add("includedirs", headerdir) outputfile = headerfile -- add commands local argv = {"lua", "private.utils.bin2c", "--nozeroend", "-i", path(spvfilepath), "-o", path(headerfile)} batchcmds:vrunv(os.programfile(), argv, {envs = {XMAKE_SKIP_HISTORY = "y"}}) end -- add deps batchcmds:add_depfiles(sourcefile_glsl) batchcmds:set_depmtime(os.mtime(outputfile)) batchcmds:set_depcache(target:dependfile(outputfile)) end)
0
repos/xmake/xmake/rules/utils
repos/xmake/xmake/rules/utils/merge_object/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- define rule: utils.merge.object rule("utils.merge.object") -- set extensions set_extensions(".o", ".obj") -- on build file on_build_file(function (target, sourcefile_obj, opt) -- imports import("core.base.option") import("core.theme.theme") import("core.project.depend") import("utils.progress") -- get object file local objectfile = target:objectfile(sourcefile_obj) -- add objectfile table.insert(target:objectfiles(), objectfile) -- load dependent info local dependfile = target:dependfile(objectfile) local dependinfo = target:is_rebuilt() and {} or (depend.load(dependfile) or {}) -- need build this object? if not depend.is_changed(dependinfo, {lastmtime = os.mtime(objectfile)}) then return end -- trace progress info progress.show(opt.progress, "${color.build.object}inserting.$(mode) %s", sourcefile_obj) -- insert this object file os.vcp(sourcefile_obj, objectfile) -- update files to the dependent file dependinfo.files = {} table.insert(dependinfo.files, sourcefile_obj) depend.save(dependinfo, dependfile) end)
0
repos/xmake/xmake/rules
repos/xmake/xmake/rules/asn1c/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("asn1c") set_extensions(".asn1") before_buildcmd_file(function (target, batchcmds, sourcefile_asn1, opt) -- get asn1c import("lib.detect.find_tool") local asn1c = assert(find_tool("asn1c"), "asn1c not found!") -- asn1 to *.c sourcefiles local sourcefile_dir = path.join(target:autogendir(), "rules", "asn1c") batchcmds:show_progress(opt.progress, "${color.build.object}compiling.asn1c %s", sourcefile_asn1) batchcmds:mkdir(sourcefile_dir) batchcmds:vrunv(asn1c.program, {path(sourcefile_asn1):absolute()}, {curdir = sourcefile_dir}) batchcmds:add_depfiles(sourcefile_asn1) batchcmds:set_depcache(target:dependfile(sourcefile_asn1)) -- add includedirs target:add("includedirs", sourcefile_dir) end) on_buildcmd_file(function (target, batchcmds, sourcefile_asn1, opt) -- compile *.c local sourcefile_dir = path.join(target:autogendir(), "rules", "asn1c") for _, sourcefile in ipairs(os.files(path.join(sourcefile_dir, "*.c|converter-*.c"))) do local objectfile = target:objectfile(sourcefile) batchcmds:compile(sourcefile, objectfile, {configs = {includedirs = sourcefile_dir}}) table.insert(target:objectfiles(), objectfile) batchcmds:add_depfiles(sourcefile) end batchcmds:set_depcache(target:dependfile(sourcefile_asn1 .. ".c")) end)
0
repos/xmake/xmake/rules
repos/xmake/xmake/rules/c51/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- rule("c51.binary") on_load(function (target) -- we disable checking flags for cross toolchain automatically target:set("policy", "check.auto_ignore_flags", false) target:set("policy", "check.auto_map_flags", false) -- set default output binary target:set("kind", "binary") if not target:get("extension") then target:set("extension", "") end end) after_link(function(target, opt) import("core.project.depend") import("lib.detect.find_tool") import("utils.progress") depend.on_changed(function() local oh = assert(find_tool("oh51"), "oh51 not found") os.iorunv(oh.program, {target:targetfile()}) progress.show(opt.progress, "${color.build.target}generating.$(mode) %s", target:targetfile() .. ".hex") end, {files = {target:targetfile()}, changed = target:is_rebuilt()}) end)
0
repos/xmake/xmake/rules/lex_yacc
repos/xmake/xmake/rules/lex_yacc/lex/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- define rule: lex rule("lex") add_deps("c++") add_deps("yacc", {order = true}) set_extensions(".l", ".ll") before_buildcmd_file(function (target, batchcmds, sourcefile_lex, opt) -- get lex import("lib.detect.find_tool") local lex = assert(find_tool("flex") or find_tool("lex"), "lex not found!") -- get c/c++ source file for lex local extension = path.extension(sourcefile_lex) local sourcefile_cx = path.join(target:autogendir(), "rules", "lex_yacc", path.basename(sourcefile_lex) .. (extension == ".ll" and ".cpp" or ".c")) -- add objectfile local objectfile = target:objectfile(sourcefile_cx) table.insert(target:objectfiles(), objectfile) -- add commands batchcmds:show_progress(opt.progress, "${color.build.object}compiling.lex %s", sourcefile_lex) batchcmds:mkdir(path.directory(sourcefile_cx)) batchcmds:vrunv(lex.program, {"-o", path(sourcefile_cx), path(sourcefile_lex)}) batchcmds:compile(sourcefile_cx, objectfile) -- add deps batchcmds:add_depfiles(sourcefile_lex) batchcmds:set_depmtime(os.mtime(objectfile)) batchcmds:set_depcache(target:dependfile(objectfile)) end)
0
repos/xmake/xmake/rules/lex_yacc
repos/xmake/xmake/rules/lex_yacc/yacc/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- define rule: yacc rule("yacc") add_deps("c++") set_extensions(".y", ".yy") on_load(function (target) -- add yacc includedirs if there are yacc files -- @see https://github.com/xmake-io/xmake/issues/4820 if target:sourcebatches()["yacc"] then local sourcefile_dir = path.join(target:autogendir(), "rules", "yacc_yacc") target:add("includedirs", sourcefile_dir) end end) before_buildcmd_file(function (target, batchcmds, sourcefile_yacc, opt) -- get yacc import("lib.detect.find_tool") local yacc = assert(find_tool("bison") or find_tool("yacc"), "yacc/bison not found!") -- get c/c++ source file for yacc local extension = path.extension(sourcefile_yacc) local sourcefile_cx = path.join(target:autogendir(), "rules", "yacc_yacc", path.basename(sourcefile_yacc) .. ".tab" .. (extension == ".yy" and ".cpp" or ".c")) -- add objectfile local objectfile = target:objectfile(sourcefile_cx) table.insert(target:objectfiles(), objectfile) -- add includedirs local sourcefile_dir = path.directory(sourcefile_cx) -- add commands batchcmds:show_progress(opt.progress, "${color.build.object}compiling.yacc %s", sourcefile_yacc) batchcmds:mkdir(sourcefile_dir) batchcmds:vrunv(yacc.program, {"-d", "-o", path(sourcefile_cx), path(sourcefile_yacc)}) batchcmds:compile(sourcefile_cx, objectfile) -- add deps batchcmds:add_depfiles(sourcefile_yacc) batchcmds:set_depmtime(os.mtime(objectfile)) batchcmds:set_depcache(target:dependfile(objectfile)) end)
0
repos/xmake/xmake/rules
repos/xmake/xmake/rules/fortran/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- define rule: fortran.build.modules rule("fortran.build.modules") before_build(function (target) if target:has_tool("fc", "gfortran") then local modulesdir = target:values("fortran.moduledir") or path.join(target:objectdir(), ".modules") os.mkdir(modulesdir) target:add("fcflags", "-J" .. modulesdir) target:add("includedirs", modulesdir, {public = true}) end end) -- define rule: fortran.build rule("fortran.build") set_sourcekinds("fc") add_deps("fortran.build.modules") on_load(function (target) -- we disable to build across targets in parallel, because the source files may depend on other target modules target:set("policy", "build.across_targets_in_parallel", false) end) on_build_files(function (target, sourcebatch, opt) import("private.action.build.object").build(target, sourcebatch, opt) end) -- define rule: fortran rule("fortran") -- add build rules add_deps("fortran.build") -- inherit links and linkdirs of all dependent targets by default add_deps("utils.inherit.links") -- support `add_files("src/*.o")` and `add_files("src/*.a")` to merge object and archive files to target add_deps("utils.merge.object", "utils.merge.archive") -- we attempt to extract symbols to the independent file and -- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled add_deps("utils.symbols.extract")
0
repos/xmake/xmake/rules
repos/xmake/xmake/rules/swig/build_module_file.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file build_module_file.lua -- -- imports import("lib.detect.find_tool") function main(target, batchcmds, sourcefile, opt) -- get swig opt = opt or {} local swig = assert(find_tool("swig"), "swig not found!") local sourcefile_cx = path.join(target:autogendir(), "rules", "swig", path.basename(sourcefile) .. (opt.sourcekind == "cxx" and ".cpp" or ".c")) -- add objectfile local objectfile = target:objectfile(sourcefile_cx) table.insert(target:objectfiles(), objectfile) -- add commands local moduletype = assert(target:data("swig.moduletype"), "swig.moduletype not found!") local argv = { "-" .. moduletype, "-o", sourcefile_cx } if opt.sourcekind == "cxx" then table.insert(argv, "-c++") end local fileconfig = target:fileconfig(sourcefile) if fileconfig and fileconfig.swigflags then table.join2(argv, fileconfig.swigflags) end -- add includedirs local function _get_values_from_target(target, name) local values = {} for _, value in ipairs((target:get_from(name, "*"))) do table.join2(values, value) end return table.unique(values) end local pathmaps = { { "includedirs", "includedir" }, { "sysincludedirs", "includedir" }, { "frameworkdirs", "frameworkdir" } } for _, pathmap in ipairs(pathmaps) do for _, item in ipairs(_get_values_from_target(target, pathmap[1])) do table.join2(argv, "-I" .. item) end end table.insert(argv, sourcefile) batchcmds:show_progress(opt.progress, "${color.build.object}compiling.swig.%s %s", moduletype, sourcefile) batchcmds:mkdir(path.directory(sourcefile_cx)) batchcmds:vrunv(swig.program, argv) batchcmds:compile(sourcefile_cx, objectfile) -- add deps batchcmds:add_depfiles(sourcefile) batchcmds:set_depmtime(os.mtime(objectfile)) batchcmds:set_depcache(target:dependfile(objectfile)) end
0
repos/xmake/xmake/rules
repos/xmake/xmake/rules/swig/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- -- references: -- -- https://github.com/xmake-io/xmake/issues/1622 -- http://www.swig.org/Doc4.0/SWIGDocumentation.html#Introduction_nn4 -- rule("swig.base") on_load(function (target) target:set("kind", "shared") local moduletype = target:extraconf("rules", "swig.c", "moduletype") or target:extraconf("rules", "swig.cpp", "moduletype") if moduletype == "python" then target:set("prefixname", "_") local soabi = target:extraconf("rules", "swig.c", "soabi") or target:extraconf("rules", "swig.cpp", "soabi") if soabi then import("lib.detect.find_tool") local python = assert(find_tool("python3"), "python not found!") local result = try { function() return os.iorunv(python.program, {"-c", "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"}) end} if result then result = result:trim() if result ~= "None" then target:set("extension", result) end end else if target:is_plat("windows", "mingw") then target:set("extension", ".pyd") end end elseif moduletype == "lua" then target:set("prefixname", "") if not target:is_plat("windows", "mingw") then target:set("extension", ".so") end elseif moduletype == "java" then if target:is_plat("windows", "mingw") then target:set("prefixname", "") target:set("extension", ".dll") elseif target:is_plat("macosx") then target:set("prefixname", "lib") target:set("extension", ".dylib") elseif target:is_plat("linux") then target:set("prefixname", "lib") target:set("extension", ".so") end else raise("unknown swig module type, please use `add_rules(\"swig.c\", {moduletype = \"python\"})` to set it!") end local scriptfiles = {} for _, sourcebatch in pairs(target:sourcebatches()) do if sourcebatch.rulename:startswith("swig.") then for _, sourcefile in ipairs(sourcebatch.sourcefiles) do local scriptdir local fileconfig = target:fileconfig(sourcefile) if fileconfig then scriptdir = fileconfig.scriptdir end local autogenfiles local autogendir = path.join(target:autogendir(), "rules", "swig") if moduletype == "python" then autogenfiles = os.files(path.join(autogendir, "*.py")) elseif moduletype == "lua" then autogenfiles = os.files(path.join(autogendir, "*.lua")) elseif moduletype == "java" then autogenfiles = os.files(path.join(autogendir, "*.java")) end if autogenfiles then table.join2(scriptfiles, autogenfiles) if scriptdir then target:add("installfiles", autogenfiles, {prefixdir = scriptdir}) end end end end end -- for custom on_install/after_install, user can use it to install them target:data_set("swig.scriptfiles", scriptfiles) target:data_set("swig.moduletype", moduletype) end) rule("swig.c") set_extensions(".i") add_deps("swig.base", "c.build") on_buildcmd_file(function (target, batchcmds, sourcefile, opt) import("build_module_file")(target, batchcmds, sourcefile, table.join({sourcekind = "cc"}, opt)) end) rule("swig.cpp") set_extensions(".i") add_deps("swig.base", "c++.build") on_buildcmd_file(function (target, batchcmds, sourcefile, opt) import("build_module_file")(target, batchcmds, sourcefile, table.join({sourcekind = "cxx"}, opt)) end)
0
repos/xmake/xmake
repos/xmake/xmake/scripts/update-script.sh
#!/bin/sh cd "$1" rm -rf actions core includes languages modules platforms plugins repository rules scripts templates themes cp -rf "$2" "$1/.."
0
repos/xmake/xmake
repos/xmake/xmake/scripts/update-script.bat
@echo off echo Removing old files cd /d "%~1" del actions core includes languages modules platforms plugins repository rules scripts templates themes /S /Q /F >nul echo Copying from temp directory to "%~1" if exist "%WINDIR%\System32\Robocopy.exe" ( robocopy "%~2" "%~1" /S /IS /NFL /NDL /NJH /NJS >nul ) else ( if exist "%WINDIR%\SysWOW64\Robocopy.exe" ( robocopy "%~2" "%~1" /S /IS /NFL /NDL /NJH /NJS >nul ) else ( xcopy "%~2" "%~1" /S /Y /Q >nul ) )
0
repos/xmake/xmake
repos/xmake/xmake/scripts/find_cudadevices.cpp
#include <cuda_runtime.h> #include <stdio.h> #include <stdlib.h> #ifndef PRINT_SUFFIX #define PRINT_SUFFIX "<find_cudadevices>" #endif #define MY_CUDA_VER (__CUDACC_VER_MAJOR__ * 100 + __CUDACC_VER_MINOR__) inline void check(cudaError_t result) { if (result) { fprintf(stderr, PRINT_SUFFIX "%s (%s)", cudaGetErrorName(result), cudaGetErrorString(result)); cudaDeviceReset(); // Make sure we call CUDA Device Reset before exiting exit(0); } } inline void print_value(unsigned long long value) { printf("%llu", value); } inline void print_value(unsigned long value) { printf("%lu", value); } inline void print_value(unsigned int value) { printf("%u", value); } inline void print_value(bool value) { printf(value ? "true" : "false"); } inline void print_value(int value) { printf("%d", value); } template <typename T, size_t len> inline void print_value(const T (&value)[len]) { printf("("); for (size_t i = 0; i < len - 1; i++) { print_value(value[i]); printf(", "); } print_value(value[len - 1]); printf(")"); } inline void print_value(const void *value) { printf("\"%s\"", (const char *)value); } template <size_t len> inline void print_value(const char (&value)[len]) { printf("\""); for (size_t i = 0; i < len; i++) printf("%02hhx", value[i]); printf("\""); } template <> inline void print_value<16>(const char (&value)[16]) { // speicalized for uuid printf("\"%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx\"", value[0], value[1], value[2], value[3], value[4], value[5], value[6], value[7], value[8], value[9], value[10], value[11], value[12], value[13], value[14], value[15]); } #if MY_CUDA_VER >= 1000 inline void print_value(const cudaUUID_t &value) { print_value(value.bytes); } #endif template <typename T> inline void print_property(const char *name, const T &value) { printf(PRINT_SUFFIX " %s = ", name); print_value(value); printf("\n"); } inline void print_device(int id) { cudaDeviceProp deviceProp; check(cudaGetDeviceProperties(&deviceProp, id)); #define PRINT_PROPERTY(name) print_property(#name, deviceProp.name) #define PRINT_BOOL_PROPERTY(name) print_property(#name, static_cast<bool>(deviceProp.name)) #define PRINT_STR_PROPERTY(name) print_property(#name, static_cast<const void *>(deviceProp.name)) // cuda 8.0 PRINT_STR_PROPERTY(name); PRINT_PROPERTY(totalGlobalMem); PRINT_PROPERTY(sharedMemPerBlock); PRINT_PROPERTY(regsPerBlock); PRINT_PROPERTY(warpSize); PRINT_PROPERTY(memPitch); PRINT_PROPERTY(maxThreadsPerBlock); PRINT_PROPERTY(maxThreadsDim); PRINT_PROPERTY(maxGridSize); PRINT_PROPERTY(clockRate); PRINT_PROPERTY(totalConstMem); PRINT_PROPERTY(major); PRINT_PROPERTY(minor); PRINT_PROPERTY(textureAlignment); PRINT_PROPERTY(texturePitchAlignment); PRINT_BOOL_PROPERTY(deviceOverlap); PRINT_PROPERTY(multiProcessorCount); PRINT_BOOL_PROPERTY(kernelExecTimeoutEnabled); PRINT_BOOL_PROPERTY(integrated); PRINT_BOOL_PROPERTY(canMapHostMemory); PRINT_PROPERTY(computeMode); PRINT_PROPERTY(maxTexture1D); PRINT_PROPERTY(maxTexture1DMipmap); PRINT_PROPERTY(maxTexture1DLinear); PRINT_PROPERTY(maxTexture2D); PRINT_PROPERTY(maxTexture2DMipmap); PRINT_PROPERTY(maxTexture2DLinear); PRINT_PROPERTY(maxTexture2DGather); PRINT_PROPERTY(maxTexture3D); PRINT_PROPERTY(maxTexture3DAlt); PRINT_PROPERTY(maxTextureCubemap); PRINT_PROPERTY(maxTexture1DLayered); PRINT_PROPERTY(maxTexture2DLayered); PRINT_PROPERTY(maxTextureCubemapLayered); PRINT_PROPERTY(maxSurface1D); PRINT_PROPERTY(maxSurface2D); PRINT_PROPERTY(maxSurface3D); PRINT_PROPERTY(maxSurface1DLayered); PRINT_PROPERTY(maxSurface2DLayered); PRINT_PROPERTY(maxSurfaceCubemap); PRINT_PROPERTY(maxSurfaceCubemapLayered); PRINT_PROPERTY(surfaceAlignment); PRINT_BOOL_PROPERTY(concurrentKernels); PRINT_BOOL_PROPERTY(ECCEnabled); PRINT_PROPERTY(pciBusID); PRINT_PROPERTY(pciDeviceID); PRINT_PROPERTY(pciDomainID); PRINT_BOOL_PROPERTY(tccDriver); PRINT_PROPERTY(asyncEngineCount); PRINT_BOOL_PROPERTY(unifiedAddressing); PRINT_PROPERTY(memoryClockRate); PRINT_PROPERTY(memoryBusWidth); PRINT_PROPERTY(l2CacheSize); PRINT_PROPERTY(maxThreadsPerMultiProcessor); PRINT_BOOL_PROPERTY(streamPrioritiesSupported); PRINT_BOOL_PROPERTY(globalL1CacheSupported); PRINT_BOOL_PROPERTY(localL1CacheSupported); PRINT_PROPERTY(sharedMemPerMultiprocessor); PRINT_PROPERTY(regsPerMultiprocessor); PRINT_BOOL_PROPERTY(isMultiGpuBoard); PRINT_PROPERTY(multiGpuBoardGroupID); PRINT_PROPERTY(singleToDoublePrecisionPerfRatio); PRINT_BOOL_PROPERTY(pageableMemoryAccess); PRINT_BOOL_PROPERTY(concurrentManagedAccess); PRINT_BOOL_PROPERTY(managedMemory); #if MY_CUDA_VER >= 900 // Added in cuda 9.0 PRINT_BOOL_PROPERTY(computePreemptionSupported); PRINT_BOOL_PROPERTY(canUseHostPointerForRegisteredMem); PRINT_BOOL_PROPERTY(cooperativeLaunch); PRINT_BOOL_PROPERTY(cooperativeMultiDeviceLaunch); PRINT_PROPERTY(sharedMemPerBlockOptin); #endif #if MY_CUDA_VER >= 902 // Added in cuda 9.2 PRINT_BOOL_PROPERTY(pageableMemoryAccessUsesHostPageTables); PRINT_BOOL_PROPERTY(directManagedMemAccessFromHost); #endif #if MY_CUDA_VER >= 1000 // Added in cuda 10.0 PRINT_PROPERTY(uuid); PRINT_PROPERTY(luid); PRINT_PROPERTY(luidDeviceNodeMask); #endif } int main(int argc, char *argv[]) { printf("\n"); fprintf(stderr, "\n"); int count = 0; check(cudaGetDeviceCount(&count)); for (int i = 0; i < count; i++) { printf(PRINT_SUFFIX "DEVICE #%d\n", i); print_device(i); } return 0; }
0
repos/xmake/xmake
repos/xmake/xmake/scripts/profile-win.ps1
# PowerShell parameter completion for xmake Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock { param($commandName, $wordToComplete, $cursorPosition) $complete = "$wordToComplete" if (-not $commandName) { $complete = $complete + " " } $oldenv = $env:XMAKE_SKIP_HISTORY $env:XMAKE_SKIP_HISTORY = 1 $results = xmake lua "private.utils.complete" $cursorPosition "nospace-json" "$complete" | ConvertFrom-Json | Sort-Object -Property value $results | ForEach-Object { $hasdesc = [bool] $_.psobject.Properties['description'] if ($hasdesc) { $desc = " - $($_.description)" } else { $desc = "" } [System.Management.Automation.CompletionResult]::new($_.value, "$($_.value)$desc", 'ParameterValue', $_.value) } $env:XMAKE_SKIP_HISTORY = $oldenv } # PowerShell parameter completion for xrepo Register-ArgumentCompleter -Native -CommandName xrepo -ScriptBlock { param($commandName, $wordToComplete, $cursorPosition) $complete = "$wordToComplete" if (-not $commandName) { $complete = $complete + " " } $oldenv = $env:XMAKE_SKIP_HISTORY $env:XMAKE_SKIP_HISTORY = 1 $results = xmake lua "private.xrepo.complete" $cursorPosition "nospace-json" "$complete" | ConvertFrom-Json | Sort-Object -Property value $results | ForEach-Object { $hasdesc = [bool] $_.psobject.Properties['description'] if ($hasdesc) { $desc = " - $($_.description)" } else { $desc = "" } [System.Management.Automation.CompletionResult]::new($_.value, "$($_.value)$desc", 'ParameterValue', $_.value) } $env:XMAKE_SKIP_HISTORY = $oldenv }
0
repos/xmake/xmake
repos/xmake/xmake/scripts/profile-unix.fish
# A cross-platform build utility based on Lua # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http:##www.apache.org#licenses#LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Copyright (C) 2022-present, TBOOX Open Source Group. # # @author ruki # @homepage profile-unix.fish # # register PATH string match --regex --quiet "(^|:)$XMAKE_ROOTDIR(:|\$)" "$PATH" || \ export PATH="$XMAKE_ROOTDIR:$PATH" # register environments export XMAKE_SHELL=fish # register completions . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.fish"
0
repos/xmake/xmake
repos/xmake/xmake/scripts/profile-unix.sh
# A cross-platform build utility based on Lua # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http:##www.apache.org#licenses#LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Copyright (C) 2022-present, TBOOX Open Source Group. # # @author ruki # @homepage profile-unix.sh # # register PATH [[ "$PATH" =~ (^|:)"$XMAKE_ROOTDIR"(:|$) ]] || export PATH="$XMAKE_ROOTDIR:$PATH" # register completions if [[ -n "$ZSH_VERSION" ]]; then export XMAKE_SHELL=zsh . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.zsh" elif [[ -n "$BASH_VERSION" ]]; then export XMAKE_SHELL=bash . "$XMAKE_PROGRAM_DIR/scripts/completions/register-completions.bash" fi # register virtualenvs . "$XMAKE_PROGRAM_DIR/scripts/virtualenvs/register-virtualenvs.sh"
0
repos/xmake/xmake
repos/xmake/xmake/scripts/gas-preprocessor.pl
#!/usr/bin/env perl # by David Conrad # This code is licensed under GPLv2 or later; go to gnu.org to read it # (not that it much matters for an asm preprocessor) # usage: set your assembler to be something like "perl gas-preprocessor.pl gcc" use strict; # Apple's gas is ancient and doesn't support modern preprocessing features like # .rept and has ugly macro syntax, among other things. Thus, this script # implements the subset of the gas preprocessor used by x264 and ffmpeg # that isn't supported by Apple's gas. my %canonical_arch = ("aarch64" => "aarch64", "arm64" => "aarch64", "arm" => "arm", "powerpc" => "powerpc", "ppc" => "powerpc"); my %comments = ("aarch64" => '//', "arm" => '@', "ppc" => '#', "powerpc" => '#'); my @gcc_cmd; my @preprocess_c_cmd; my $comm; my $arch; my $as_type = "apple-gas"; my $fix_unreq = $^O eq "darwin"; my $force_thumb = 0; my $verbose = 0; my $arm_cond_codes = "eq|ne|cs|cc|mi|pl|vs|vc|hi|ls|ge|lt|gt|le|al|hs|lo"; my $usage_str = " $0\n Gas-preprocessor.pl converts assembler files using modern GNU as syntax for Apple's ancient gas version or clang's incompatible integrated assembler. The conversion is regularly tested for FFmpeg, Libav, x264 and vlc. Other projects might use different features which are not correctly handled. Options for this program needs to be separated with ' -- ' from the assembler command. Following options are currently supported: -help - this usage text -arch - target architecture -as-type - one value out of {{,apple-}{gas,clang},armasm} -fix-unreq -no-fix-unreq -force-thumb - assemble as thumb regardless of the input source (note, this is incomplete and only works for sources it explicitly was tested with) -verbose - print executed commands "; sub usage() { print $usage_str; } while (@ARGV) { my $opt = shift; if ($opt =~ /^-(no-)?fix-unreq$/) { $fix_unreq = $1 ne "no-"; } elsif ($opt eq "-force-thumb") { $force_thumb = 1; } elsif ($opt eq "-verbose") { $verbose = 1; } elsif ($opt eq "-arch") { $arch = shift; die "unknown arch: '$arch'\n" if not exists $canonical_arch{$arch}; } elsif ($opt eq "-as-type") { $as_type = shift; die "unknown as type: '$as_type'\n" if $as_type !~ /^((apple-)?(gas|clang|llvm_gcc)|armasm)$/; } elsif ($opt eq "-help") { usage(); exit 0; } elsif ($opt eq "--" ) { @gcc_cmd = @ARGV; } elsif ($opt =~ /^-/) { die "option '$opt' is not known. See '$0 -help' for usage information\n"; } else { push @gcc_cmd, $opt, @ARGV; } last if (@gcc_cmd); } if (grep /\.c$/, @gcc_cmd) { # C file (inline asm?) - compile @preprocess_c_cmd = (@gcc_cmd, "-S"); } elsif (grep /\.[sS]$/, @gcc_cmd) { # asm file, just do C preprocessor @preprocess_c_cmd = (@gcc_cmd, "-E"); } elsif (grep /-(v|h|-version|dumpversion)/, @gcc_cmd) { # pass -v/--version along, used during probing. Matching '-v' might have # uninteded results but it doesn't matter much if gas-preprocessor or # the compiler fails. print STDERR join(" ", @gcc_cmd)."\n" if $verbose; exec(@gcc_cmd); } else { die "Unrecognized input filetype"; } if ($as_type eq "armasm") { $preprocess_c_cmd[0] = "cpp"; # Remove -ignore XX parameter pairs from preprocess_c_cmd my $index = 1; while ($index < $#preprocess_c_cmd) { if ($preprocess_c_cmd[$index] eq "-ignore" and $index + 1 < $#preprocess_c_cmd) { splice(@preprocess_c_cmd, $index, 2); next; } $index++; } if (grep /^-MM$/, @preprocess_c_cmd) { push(@preprocess_c_cmd, "-D_WIN32"); # Normally a preprocessor for windows would predefine _WIN32, # but we're using any generic system-agnostic preprocessor "cpp" # with -undef (to avoid getting predefined variables from the host # system in cross compilation cases), so manually define it here. # We only use this generic preprocessor for generating dependencies, # if the build system runs preprocessing with -M/-MM without -MF. push(@preprocess_c_cmd, "-undef"); @preprocess_c_cmd = grep ! /^-nologo$/, @preprocess_c_cmd; print STDERR join(" ", @preprocess_c_cmd)."\n" if $verbose; system(@preprocess_c_cmd) == 0 or die "Error running preprocessor"; exit 0; } # If not preprocessing for getting a dependency list, use cl.exe # instead. $preprocess_c_cmd[0] = "cl"; } # if compiling, avoid creating an output file named '-.o' if ((grep /^-c$/, @gcc_cmd) && !(grep /^-o/, @gcc_cmd)) { foreach my $i (@gcc_cmd) { if ($i =~ /\.[csS]$/) { my $outputfile = $i; $outputfile =~ s/\.[csS]$/.o/; push(@gcc_cmd, "-o"); push(@gcc_cmd, $outputfile); last; } } } # Remove the -o argument; if omitted, we by default preprocess to stdout. my $index = 1; while ($index < $#preprocess_c_cmd) { if ($preprocess_c_cmd[$index] eq "-o") { splice(@preprocess_c_cmd, $index, 2); last; } $index++; } my $tempfile; if ($as_type ne "armasm") { @gcc_cmd = map { /\.[csS]$/ ? qw(-x assembler -) : $_ } @gcc_cmd; # Filter out options that can cause warnings due to unused arguments, # Clang warns about unused -D parameters when invoked with "-x assembler". @gcc_cmd = grep ! /^-D/, @gcc_cmd; } else { @preprocess_c_cmd = grep ! /^-c$/, @preprocess_c_cmd; @preprocess_c_cmd = grep ! /^-m/, @preprocess_c_cmd; @preprocess_c_cmd = grep ! /^-G/, @preprocess_c_cmd; @preprocess_c_cmd = grep ! /^-W/, @preprocess_c_cmd; @preprocess_c_cmd = grep ! /^-Z/, @preprocess_c_cmd; @preprocess_c_cmd = grep ! /^-fp/, @preprocess_c_cmd; @preprocess_c_cmd = grep ! /^-EHsc$/, @preprocess_c_cmd; @preprocess_c_cmd = grep ! /^-O/, @preprocess_c_cmd; @preprocess_c_cmd = grep ! /^-oldit/, @preprocess_c_cmd; @preprocess_c_cmd = grep ! /^-FS/, @preprocess_c_cmd; @preprocess_c_cmd = grep ! /^-w/, @preprocess_c_cmd; @preprocess_c_cmd = grep ! /^-M/, @preprocess_c_cmd; @gcc_cmd = grep ! /^-G/, @gcc_cmd; @gcc_cmd = grep ! /^-W/, @gcc_cmd; @gcc_cmd = grep ! /^-Z/, @gcc_cmd; @gcc_cmd = grep ! /^-fp/, @gcc_cmd; @gcc_cmd = grep ! /^-EHsc$/, @gcc_cmd; @gcc_cmd = grep ! /^-O/, @gcc_cmd; @gcc_cmd = grep ! /^-FS/, @gcc_cmd; @gcc_cmd = grep ! /^-w/, @gcc_cmd; my @outfiles = grep /\.(o|obj)$/, @gcc_cmd; $tempfile = $outfiles[0].".asm"; # Remove most parameters from gcc_cmd, which actually is the armasm command, # which doesn't support any of the common compiler/preprocessor options. @gcc_cmd = grep ! /^-D/, @gcc_cmd; @gcc_cmd = grep ! /^-U/, @gcc_cmd; @gcc_cmd = grep ! /^-m/, @gcc_cmd; @gcc_cmd = grep ! /^-M/, @gcc_cmd; @gcc_cmd = grep ! /^-c$/, @gcc_cmd; @gcc_cmd = grep ! /^-I/, @gcc_cmd; @gcc_cmd = map { /\.S$/ ? $tempfile : $_ } @gcc_cmd; } # detect architecture from gcc binary name if (!$arch) { if ($gcc_cmd[0] =~ /(arm64|aarch64|arm|powerpc|ppc)/) { $arch = $1; } else { # look for -arch flag foreach my $i (1 .. $#gcc_cmd-1) { if ($gcc_cmd[$i] eq "-arch" and $gcc_cmd[$i+1] =~ /(arm64|aarch64|arm|powerpc|ppc)/) { $arch = $1; } } } } # assume we're not cross-compiling if no -arch or the binary doesn't have the arch name $arch = qx/arch/ if (!$arch); die "Unknown target architecture '$arch'" if not exists $canonical_arch{$arch}; $arch = $canonical_arch{$arch}; $comm = $comments{$arch}; my $inputcomm = $comm; $comm = ";" if $as_type =~ /armasm/; my %ppc_spr = (ctr => 9, vrsave => 256); print STDERR join(" ", @preprocess_c_cmd)."\n" if $verbose; open(INPUT, "-|", @preprocess_c_cmd) || die "Error running preprocessor"; if ($ENV{GASPP_DEBUG}) { open(ASMFILE, ">&STDOUT"); } else { if ($as_type ne "armasm") { print STDERR join(" ", @gcc_cmd)."\n" if $verbose; open(ASMFILE, "|-", @gcc_cmd) or die "Error running assembler"; } else { open(ASMFILE, ">", $tempfile); } } my $current_macro = ''; my $macro_level = 0; my $rept_level = 0; my %macro_lines; my %macro_args; my %macro_args_default; my $macro_count = 0; my $altmacro = 0; my $in_irp = 0; my $num_repts; my @rept_lines; my @irp_args; my $irp_param; my @ifstack; my %symbols; my @sections; my %literal_labels; # for ldr <reg>, =<expr> my $literal_num = 0; my $literal_expr = ".word"; $literal_expr = ".quad" if $arch eq "aarch64"; my $thumb = 0; my %thumb_labels; my %call_targets; my %import_symbols; my %neon_alias_reg; my %neon_alias_type; my $temp_label_next = 0; my %last_temp_labels; my %next_temp_labels; my %labels_seen; my %aarch64_req_alias; if ($force_thumb) { parse_line(".thumb\n"); } # pass 1: parse .macro # note that the handling of arguments is probably overly permissive vs. gas # but it should be the same for valid cases while (<INPUT>) { # remove lines starting with '#', preprocessing is done, '#' at start of # the line indicates a comment for all supported archs (aarch64, arm, ppc # and x86). Also strips line number comments but since they are off anyway # it is no loss. s/^\s*#.*$//; # remove all comments (to avoid interfering with evaluating directives) s/(?<!\\)$inputcomm.*//x; # Strip out windows linefeeds s/\r$//; foreach my $subline (split(";", $_)) { chomp $subline; parse_line_continued($subline); } } parse_line_continued(""); sub eval_expr { my $expr = $_[0]; while ($expr =~ /([A-Za-z._][A-Za-z0-9._]*)/g) { my $sym = $1; $expr =~ s/$sym/($symbols{$sym})/ if defined $symbols{$sym}; } eval $expr; } sub handle_if { my $line = $_[0]; # handle .if directives; apple's assembler doesn't support important non-basic ones # evaluating them is also needed to handle recursive macros if ($line =~ /\.if(n?)([a-z]*)\s+(.*)/) { my $result = $1 eq "n"; my $type = $2; my $expr = $3; if ($type eq "b") { $expr =~ s/\s//g; $result ^= $expr eq ""; } elsif ($type eq "c") { if ($expr =~ /(\S*)\s*,\s*(\S*)/) { $result ^= $1 eq $2; } else { die "argument to .ifc not recognized"; } } elsif ($type eq "") { $result ^= eval_expr($expr) != 0; } elsif ($type eq "eq") { $result = eval_expr($expr) == 0; } elsif ($type eq "lt") { $result = eval_expr($expr) < 0; } else { chomp($line); die "unhandled .if varient. \"$line\""; } push (@ifstack, $result); return 1; } else { return 0; } } sub parse_if_line { my $line = $_[0]; # evaluate .if blocks if (scalar(@ifstack)) { # Don't evaluate any new if statements if we're within # a repetition or macro - they will be evaluated once # the repetition is unrolled or the macro is expanded. if (scalar(@rept_lines) == 0 and $macro_level == 0) { if ($line =~ /\.endif/) { pop(@ifstack); return 1; } elsif ($line =~ /\.elseif\s+(.*)/) { if ($ifstack[-1] == 0) { $ifstack[-1] = !!eval_expr($1); } elsif ($ifstack[-1] > 0) { $ifstack[-1] = -$ifstack[-1]; } return 1; } elsif ($line =~ /\.else/) { $ifstack[-1] = !$ifstack[-1]; return 1; } elsif (handle_if($line)) { return 1; } } # discard lines in false .if blocks foreach my $i (0 .. $#ifstack) { if ($ifstack[$i] <= 0) { return 1; } } } return 0; } my $last_line = ""; sub parse_line_continued { my $line = $_[0]; $last_line .= $line; if ($last_line =~ /\\$/) { $last_line =~ s/\\$//; } else { # Add newlines at the end of lines after concatenation. $last_line .= "\n"; parse_line($last_line); $last_line = ""; } } sub parse_line { my $line = $_[0]; return if (parse_if_line($line)); if (scalar(@rept_lines) == 0) { if ($line =~ /\.macro/) { $macro_level++; if ($macro_level > 1 && !$current_macro) { die "nested macros but we don't have master macro"; } } elsif ($line =~ /\.endm/) { $macro_level--; if ($macro_level < 0) { die "unmatched .endm"; } elsif ($macro_level == 0) { $current_macro = ''; return; } } } if ($macro_level == 0) { if ($line =~ /\.(rept|irp)/) { $rept_level++; } elsif ($line =~ /.endr/) { $rept_level--; } } if ($macro_level > 1) { push(@{$macro_lines{$current_macro}}, $line); } elsif (scalar(@rept_lines) and $rept_level >= 1) { push(@rept_lines, $line); } elsif ($macro_level == 0) { expand_macros($line); } else { if ($line =~ /\.macro\s+([\d\w\.]+)\s*,?\s*(.*)/) { $current_macro = $1; # commas in the argument list are optional, so only use whitespace as the separator my $arglist = $2; $arglist =~ s/,/ /g; my @args = split(/\s+/, $arglist); foreach my $i (0 .. $#args) { my @argpair = split(/=/, $args[$i]); $macro_args{$current_macro}[$i] = $argpair[0]; $argpair[0] =~ s/:vararg$//; $macro_args_default{$current_macro}{$argpair[0]} = $argpair[1]; } # ensure %macro_lines has the macro name added as a key $macro_lines{$current_macro} = []; } elsif ($current_macro) { push(@{$macro_lines{$current_macro}}, $line); } else { die "macro level without a macro name"; } } } sub handle_set { my $line = $_[0]; if ($line =~ /\.(?:set|equ)\s+(\S*)\s*,\s*(.*)/) { $symbols{$1} = eval_expr($2); return 1; } return 0; } sub expand_macros { my $line = $_[0]; # handle .if directives; apple's assembler doesn't support important non-basic ones # evaluating them is also needed to handle recursive macros if (handle_if($line)) { return; } if (/\.purgem\s+([\d\w\.]+)/) { delete $macro_lines{$1}; delete $macro_args{$1}; delete $macro_args_default{$1}; return; } if ($line =~ /\.altmacro/) { $altmacro = 1; return; } if ($line =~ /\.noaltmacro/) { $altmacro = 0; return; } $line =~ s/\%([^,]*)/eval_expr($1)/eg if $altmacro; # Strip out the .set lines from the armasm output return if (handle_set($line) and $as_type eq "armasm"); if ($line =~ /\.rept\s+(.*)/) { $num_repts = $1; @rept_lines = ("\n"); # handle the possibility of repeating another directive on the same line # .endr on the same line is not valid, I don't know if a non-directive is if ($num_repts =~ s/(\.\w+.*)//) { push(@rept_lines, "$1\n"); } $num_repts = eval_expr($num_repts); } elsif ($line =~ /\.irp\s+([\d\w\.]+)\s*(.*)/) { $in_irp = 1; $num_repts = 1; @rept_lines = ("\n"); $irp_param = $1; # only use whitespace as the separator my $irp_arglist = $2; $irp_arglist =~ s/,/ /g; $irp_arglist =~ s/^\s+//; @irp_args = split(/\s+/, $irp_arglist); } elsif ($line =~ /\.irpc\s+([\d\w\.]+)\s*(.*)/) { $in_irp = 1; $num_repts = 1; @rept_lines = ("\n"); $irp_param = $1; my $irp_arglist = $2; $irp_arglist =~ s/,/ /g; $irp_arglist =~ s/^\s+//; @irp_args = split(//, $irp_arglist); } elsif ($line =~ /\.endr/) { my @prev_rept_lines = @rept_lines; my $prev_in_irp = $in_irp; my @prev_irp_args = @irp_args; my $prev_irp_param = $irp_param; my $prev_num_repts = $num_repts; @rept_lines = (); $in_irp = 0; @irp_args = ''; if ($prev_in_irp != 0) { foreach my $i (@prev_irp_args) { foreach my $origline (@prev_rept_lines) { my $line = $origline; $line =~ s/\\$prev_irp_param/$i/g; $line =~ s/\\\(\)//g; # remove \() parse_line($line); } } } else { for (1 .. $prev_num_repts) { foreach my $origline (@prev_rept_lines) { my $line = $origline; parse_line($line); } } } } elsif ($line =~ /(\S+:|)\s*([\w\d\.]+)\s*(.*)/ && exists $macro_lines{$2}) { handle_serialized_line($1); my $macro = $2; # commas are optional here too, but are syntactically important because # parameters can be blank my @arglist = split(/,/, $3); my @args; my @args_seperator; my $comma_sep_required = 0; foreach (@arglist) { # allow arithmetic/shift operators in macro arguments $_ =~ s/\s*(\+|-|\*|\/|<<|>>|<|>)\s*/$1/g; my @whitespace_split = split(/\s+/, $_); if (!@whitespace_split) { push(@args, ''); push(@args_seperator, ''); } else { foreach (@whitespace_split) { #print ("arglist = \"$_\"\n"); if (length($_)) { push(@args, $_); my $sep = $comma_sep_required ? "," : " "; push(@args_seperator, $sep); #print ("sep = \"$sep\", arg = \"$_\"\n"); $comma_sep_required = 0; } } } $comma_sep_required = 1; } my %replacements; if ($macro_args_default{$macro}){ %replacements = %{$macro_args_default{$macro}}; } # construct hashtable of text to replace foreach my $i (0 .. $#args) { my $argname = $macro_args{$macro}[$i]; my @macro_args = @{ $macro_args{$macro} }; if ($args[$i] =~ m/=/) { # arg=val references the argument name # XXX: I'm not sure what the expected behaviour if a lot of # these are mixed with unnamed args my @named_arg = split(/=/, $args[$i]); $replacements{$named_arg[0]} = $named_arg[1]; } elsif ($i > $#{$macro_args{$macro}}) { # more args given than the macro has named args # XXX: is vararg allowed on arguments before the last? $argname = $macro_args{$macro}[-1]; if ($argname =~ s/:vararg$//) { #print "macro = $macro, args[$i] = $args[$i], args_seperator=@args_seperator, argname = $argname, arglist[$i] = $arglist[$i], arglist = @arglist, args=@args, macro_args=@macro_args\n"; #$replacements{$argname} .= ", $args[$i]"; $replacements{$argname} .= "$args_seperator[$i] $args[$i]"; } else { die "Too many arguments to macro $macro"; } } else { $argname =~ s/:vararg$//; $replacements{$argname} = $args[$i]; } } my $count = $macro_count++; # apply replacements as regex foreach (@{$macro_lines{$macro}}) { my $macro_line = $_; # do replacements by longest first, this avoids wrong replacement # when argument names are subsets of each other foreach (reverse sort {length $a <=> length $b} keys %replacements) { $macro_line =~ s/\\$_/$replacements{$_}/g; } if ($altmacro) { foreach (reverse sort {length $a <=> length $b} keys %replacements) { $macro_line =~ s/\b$_\b/$replacements{$_}/g; } } $macro_line =~ s/\\\@/$count/g; $macro_line =~ s/\\\(\)//g; # remove \() parse_line($macro_line); } } else { handle_serialized_line($line); } } sub is_arm_register { my $name = $_[0]; if ($name eq "lr" or $name eq "ip" or $name =~ /^[rav]\d+$/) { return 1; } return 0; } sub is_aarch64_register { my $name = $_[0]; if ($name =~ /^[xw]\d+$/) { return 1; } return 0; } sub handle_local_label { my $line = $_[0]; my $num = $_[1]; my $dir = $_[2]; my $target = "$num$dir"; if ($dir eq "b") { $line =~ s/\b$target\b/$last_temp_labels{$num}/g; } else { my $name = "temp_label_$temp_label_next"; $temp_label_next++; push(@{$next_temp_labels{$num}}, $name); $line =~ s/\b$target\b/$name/g; } return $line; } sub handle_serialized_line { my $line = $_[0]; # handle .previous (only with regard to .section not .subsection) if ($line =~ /\.(section|text|const_data)/) { push(@sections, $line); } elsif ($line =~ /\.previous/) { if (!$sections[-2]) { die ".previous without a previous section"; } $line = $sections[-2]; push(@sections, $line); } $thumb = 1 if $line =~ /\.code\s+16|\.thumb/; $thumb = 0 if $line =~ /\.code\s+32|\.arm/; # handle ldr <reg>, =<expr> if ($line =~ /(.*)\s*ldr([\w\s\d]+)\s*,\s*=(.*)/ and $as_type ne "armasm") { my $label = $literal_labels{$3}; if (!$label) { $label = "Literal_$literal_num"; $literal_num++; $literal_labels{$3} = $label; } $line = "$1 ldr$2, $label\n"; } elsif ($line =~ /\.ltorg/ and $as_type ne "armasm") { $line .= ".align 2\n"; foreach my $literal (keys %literal_labels) { $line .= "$literal_labels{$literal}:\n $literal_expr $literal\n"; } %literal_labels = (); } # handle GNU as pc-relative relocations for adrp/add if ($line =~ /(.*)\s*adrp([\w\s\d]+)\s*,\s*#?:pg_hi21:([^\s]+)/ and $as_type =~ /^apple-/) { $line = "$1 adrp$2, ${3}\@PAGE\n"; } elsif ($line =~ /(.*)\s*add([\w\s\d]+)\s*,([\w\s\d]+)\s*,\s*#?:lo12:([^\s]+)/ and $as_type =~ /^apple-/) { $line = "$1 add$2, $3, ${4}\@PAGEOFF\n"; } # thumb add with large immediate needs explicit add.w if ($thumb and $line =~ /add\s+.*#([^@]+)/) { $line =~ s/add/add.w/ if eval_expr($1) > 255; } # mach-o local symbol names start with L (no dot) $line =~ s/(?<!\w)\.(L\w+)/$1/g; # recycle the '.func' directive for '.thumb_func' if ($thumb and $as_type =~ /^apple-/) { $line =~ s/\.func/.thumb_func/x; } if ($thumb and $line =~ /^\s*(\w+)\s*:/) { $thumb_labels{$1}++; } if ($as_type =~ /^apple-/ and $line =~ /^\s*((\w+\s*:\s*)?bl?x?(..)?(?:\.w)?|\.global)\s+(\w+)/) { my $cond = $3; my $label = $4; # Don't interpret e.g. bic as b<cc> with ic as conditional code if ($cond =~ /^(|$arm_cond_codes)$/) { if (exists $thumb_labels{$label}) { print ASMFILE ".thumb_func $label\n"; } else { $call_targets{$label}++; } } } # @l -> lo16() @ha -> ha16() $line =~ s/,\s+([^,]+)\@l\b/, lo16($1)/g; $line =~ s/,\s+([^,]+)\@ha\b/, ha16($1)/g; # move to/from SPR if ($line =~ /(\s+)(m[ft])([a-z]+)\s+(\w+)/ and exists $ppc_spr{$3}) { if ($2 eq 'mt') { $line = "$1${2}spr $ppc_spr{$3}, $4\n"; } else { $line = "$1${2}spr $4, $ppc_spr{$3}\n"; } } if ($line =~ /\.unreq\s+(.*)/) { if (defined $neon_alias_reg{$1}) { delete $neon_alias_reg{$1}; delete $neon_alias_type{$1}; return; } elsif (defined $aarch64_req_alias{$1}) { delete $aarch64_req_alias{$1}; return; } } # old gas versions store upper and lower case names on .req, # but they remove only one on .unreq if ($fix_unreq) { if ($line =~ /\.unreq\s+(.*)/) { $line = ".unreq " . lc($1) . "\n"; $line .= ".unreq " . uc($1) . "\n"; } } if ($line =~ /(\w+)\s+\.(dn|qn)\s+(\w+)(?:\.(\w+))?(\[\d+\])?/) { $neon_alias_reg{$1} = "$3$5"; $neon_alias_type{$1} = $4; return; } if (scalar keys %neon_alias_reg > 0 && $line =~ /^\s+v\w+/) { # This line seems to possibly have a neon instruction foreach (keys %neon_alias_reg) { my $alias = $_; # Require the register alias to match as an invididual word, not as a substring # of a larger word-token. if ($line =~ /\b$alias\b/) { $line =~ s/\b$alias\b/$neon_alias_reg{$alias}/g; # Add the type suffix. If multiple aliases match on the same line, # only do this replacement the first time (a vfoo.bar string won't match v\w+). $line =~ s/^(\s+)(v\w+)(\s+)/$1$2.$neon_alias_type{$alias}$3/; } } } if ($arch eq "aarch64" or $as_type eq "armasm") { # clang's integrated aarch64 assembler in Xcode 5 does not support .req/.unreq if ($line =~ /\b(\w+)\s+\.req\s+(\w+)\b/) { $aarch64_req_alias{$1} = $2; return; } foreach (keys %aarch64_req_alias) { my $alias = $_; # recursively resolve aliases my $resolved = $aarch64_req_alias{$alias}; while (defined $aarch64_req_alias{$resolved}) { $resolved = $aarch64_req_alias{$resolved}; } $line =~ s/\b$alias\b/$resolved/g; } } if ($arch eq "aarch64") { # fix missing aarch64 instructions in Xcode 5.1 (beta3) # mov with vector arguments is not supported, use alias orr instead if ($line =~ /^(\d+:)?\s*mov\s+(v\d[\.{}\[\]\w]+),\s*(v\d[\.{}\[\]\w]+)\b\s*$/) { $line = "$1 orr $2, $3, $3\n"; } # movi 16, 32 bit shifted variant, shift is optional if ($line =~ /^(\d+:)?\s*movi\s+(v[0-3]?\d\.(?:2|4|8)[hsHS])\s*,\s*(#\w+)\b\s*$/) { $line = "$1 movi $2, $3, lsl #0\n"; } # Xcode 5 misses the alias uxtl. Replace it with the more general ushll. # Clang 3.4 misses the alias sxtl too. Replace it with the more general sshll. # armasm64 also misses these instructions. if ($line =~ /^(\d+:)?\s*(s|u)xtl(2)?\s+(v[0-3]?\d\.[248][hsdHSD])\s*,\s*(v[0-3]?\d\.(?:2|4|8|16)[bhsBHS])\b\s*$/) { $line = "$1 $2shll$3 $4, $5, #0\n"; } # clang 3.4 and armasm64 do not automatically use shifted immediates in add/sub if (($as_type eq "clang" or $as_type eq "armasm") and $line =~ /^(\d+:)?(\s*(?:add|sub)s?) ([^#l]+)#([\d\+\-\*\/ <>]+)\s*$/) { my $imm = eval $4; if ($imm > 4095 and not ($imm & 4095)) { $line = "$1 $2 $3#" . ($imm >> 12) . ", lsl #12\n"; } } if ($ENV{GASPP_FIX_XCODE5}) { if ($line =~ /^\s*bsl\b/) { $line =~ s/\b(bsl)(\s+v[0-3]?\d\.(\w+))\b/$1.$3$2/; $line =~ s/\b(v[0-3]?\d)\.$3\b/$1/g; } if ($line =~ /^\s*saddl2?\b/) { $line =~ s/\b(saddl2?)(\s+v[0-3]?\d\.(\w+))\b/$1.$3$2/; $line =~ s/\b(v[0-3]?\d)\.\w+\b/$1/g; } if ($line =~ /^\s*dup\b.*\]$/) { $line =~ s/\bdup(\s+v[0-3]?\d)\.(\w+)\b/dup.$2$1/g; $line =~ s/\b(v[0-3]?\d)\.[bhsdBHSD](\[\d\])$/$1$2/g; } } } if ($as_type eq "armasm") { # Also replace variables set by .set foreach (keys %symbols) { my $sym = $_; $line =~ s/\b$sym\b/$symbols{$sym}/g; } # Handle function declarations and keep track of the declared labels if ($line =~ s/^\s*\.func\s+(\w+)/$1 PROC/) { $labels_seen{$1} = 1; } if ($line =~ s/^\s*(\d+)://) { # Convert local labels into unique labels. armasm (at least in # RVCT) has something similar, but still different enough. # By converting to unique labels we avoid any possible # incompatibilities. my $num = $1; foreach (@{$next_temp_labels{$num}}) { $line = "$_\n" . $line; } @next_temp_labels{$num} = (); my $name = "temp_label_$temp_label_next"; $temp_label_next++; # The matching regexp above removes the label from the start of # the line (which might contain an instruction as well), readd # it on a separate line above it. $line = "$name:\n" . $line; $last_temp_labels{$num} = $name; } if ($line =~ s/^\s*(\w+):/$1/) { # Skip labels that have already been declared with a PROC, # labels must not be declared multiple times. return if (defined $labels_seen{$1}); $labels_seen{$1} = 1; } elsif ($line !~ /(\w+) PROC/) { # If not a label, make sure the line starts with whitespace, # otherwise ms armasm interprets it incorrectly. $line =~ s/^[\.\w]/\t$&/; } # Check branch instructions if ($line =~ /(?:^|\n)\s*(\w+\s*:\s*)?(bl?x?\.?([^\s]{2})?(\.w)?)\s+(\w+)/) { my $instr = $2; my $cond = $3; my $width = $4; my $target = $5; # Don't interpret e.g. bic as b<cc> with ic as conditional code if ($cond !~ /^(|$arm_cond_codes)$/) { # Not actually a branch } elsif ($target =~ /^(\d+)([bf])$/) { # The target is a local label $line = handle_local_label($line, $1, $2); $line =~ s/\b$instr\b/$&.w/ if $width eq "" and $arch eq "arm"; } elsif (($arch eq "arm" and !is_arm_register($target)) or ($arch eq "aarch64" and !is_aarch64_register($target))) { $call_targets{$target}++; } } elsif ($line =~ /(?:^|\n)\s*(\w+\s*:\s*)?(cbn?z|adr|tbn?z)\s+(\w+)\s*,(\s*#\d+\s*,)?\s*(\w+)/) { my $instr = $2; my $reg = $3; my $bit = $4; my $target = $5; if ($target =~ /^(\d+)([bf])$/) { # The target is a local label $line = handle_local_label($line, $1, $2); } else { $call_targets{$target}++; } # Convert tbz with a wX register into an xX register, # due to armasm64 bugs/limitations. if (($instr eq "tbz" or $instr eq "tbnz") and $reg =~ /w\d+/) { my $xreg = $reg; $xreg =~ s/w/x/; $line =~ s/\b$reg\b/$xreg/; } } elsif ($line =~ /^\s*.h?word.*\b\d+[bf]\b/) { while ($line =~ /\b(\d+)([bf])\b/g) { $line = handle_local_label($line, $1, $2); } } # ALIGN in armasm syntax is the actual number of bytes if ($line =~ /\.(?:p2)?align\s+(\d+)/) { my $align = 1 << $1; $line =~ s/\.(?:p2)?align\s+(\d+)/ALIGN $align/; } # Convert gas style [r0, :128] into armasm [r0@128] alignment specification $line =~ s/\[([^\[,]+),?\s*:(\d+)\]/[$1\@$2]/g; # armasm treats logical values {TRUE} and {FALSE} separately from # numeric values - logical operators and values can't be intermixed # with numerical values. Evaluate !<number> and (a <> b) into numbers, # let the assembler evaluate the rest of the expressions. This current # only works for cases when ! and <> are used with actual constant numbers, # we don't evaluate subexpressions here. # Evaluate !<number> while ($line =~ /!\s*(\d+)/g) { my $val = ($1 != 0) ? 0 : 1; $line =~ s/!(\d+)/$val/; } # Evaluate (a > b) while ($line =~ /\(\s*(\d+)\s*([<>])\s*(\d+)\s*\)/) { my $val; if ($2 eq "<") { $val = ($1 < $3) ? 1 : 0; } else { $val = ($1 > $3) ? 1 : 0; } $line =~ s/\(\s*(\d+)\s*([<>])\s*(\d+)\s*\)/$val/; } if ($arch eq "arm") { # Change a movw... #:lower16: into a mov32 pseudoinstruction $line =~ s/^(\s*)movw(\s+\w+\s*,\s*)\#:lower16:(.*)$/$1mov32$2$3/; # and remove the following, matching movt completely $line =~ s/^\s*movt\s+\w+\s*,\s*\#:upper16:.*$//; if ($line =~ /^\s*mov32\s+\w+,\s*([a-zA-Z]\w*)/) { $import_symbols{$1}++; } # Misc bugs/deficiencies: # armasm seems unable to parse e.g. "vmov s0, s1" without a type # qualifier, thus add .f32. $line =~ s/^(\s+(?:vmov|vadd))(\s+s\d+\s*,\s*s\d+)/$1.f32$2/; } elsif ($arch eq "aarch64") { # Convert ext into ext8; armasm64 seems to require it named as ext8. $line =~ s/^(\s+)ext(\s+)/$1ext8$2/; # Pick up targets from ldr x0, =sym+offset if ($line =~ /^\s*ldr\s+(\w+)\s*,\s*=([a-zA-Z]\w*)(.*)$/) { my $reg = $1; my $sym = $2; my $offset = eval_expr($3); if ($offset < 0 and $ENV{GASPP_ARMASM64_SKIP_NEG_OFFSET}) { # armasm64 in VS < 15.6 is buggy with ldr x0, =sym+offset where the # offset is a negative value; it does write a negative # offset into the literal pool as it should, but the # negative offset only covers the lower 32 bit of the 64 # bit literal/relocation. # Thus remove the offset and apply it manually with a sub # afterwards. $offset = -$offset; $line = "\tldr $reg, =$sym\n\tsub $reg, $reg, #$offset\n"; } $import_symbols{$sym}++; } # armasm64 (currently) doesn't support offsets on adrp targets, # even though the COFF format relocations (and the linker) # supports it. Therefore strip out the offsets from adrp and # add :lo12: (in case future armasm64 would start handling it) # and add an extra explicit add instruction for the offset. if ($line =~ s/(adrp\s+\w+\s*,\s*(\w+))([\d\+\-\*\/\(\) <>]+)?/\1/) { $import_symbols{$2}++; } if ($line =~ s/(add\s+(\w+)\s*,\s*\w+\s*,\s*):lo12:(\w+)([\d\+\-\*\/\(\) <>]+)?/\1\3/) { my $reg = $2; my $sym = $3; my $offset = eval_expr($4); $line .= "\tadd $reg, $reg, #$offset\n" if $offset > 0; $import_symbols{$sym}++; } # Convert e.g. "add x0, x0, w0, uxtw" into "add x0, x0, w0, uxtw #0", # or "ldr x0, [x0, w0, uxtw]" into "ldr x0, [x0, w0, uxtw #0]". $line =~ s/(uxt[whb]|sxt[whb])(\s*\]?\s*)$/\1 #0\2/i; # Convert "mov x0, v0.d[0]" into "umov x0, v0.d[0]" $line =~ s/\bmov\s+[xw]\d+\s*,\s*v\d+\.[ds]/u$&/i; # Convert "ccmp w0, #0, #0, ne" into "ccmpne w0, #0, #0", # and "csel w0, w0, w0, ne" into "cselne w0, w0, w0". $line =~ s/(ccmp|csel)\s+([xw]\w+)\s*,\s*([xw#]\w+)\s*,\s*([xw#]\w+)\s*,\s*($arm_cond_codes)/\1\5 \2, \3, \4/; # Convert "cinc w0, w0, ne" into "cincne w0, w0". $line =~ s/(cinc)\s+([xw]\w+)\s*,\s*([xw]\w+)\s*,\s*($arm_cond_codes)/\1\4 \2, \3/; # Convert "cset w0, lo" into "csetlo w0" $line =~ s/(cset)\s+([xw]\w+)\s*,\s*($arm_cond_codes)/\1\3 \2/; if ($ENV{GASPP_ARMASM64_SKIP_PRFUM}) { # Strip out prfum; armasm64 (VS < 15.5) fails to assemble any # variant/combination of prfum tested so far, but since it is # a prefetch instruction it can be skipped without changing # results. $line =~ s/prfum.*\]//; } # Convert "ldrb w0, [x0, #-1]" into "ldurb w0, [x0, #-1]". # Don't do this for forms with writeback though. if ($line =~ /(ld|st)(r[bh]?)\s+(\w+)\s*,\s*\[\s*(\w+)\s*,\s*#([^\]]+)\s*\][^!]/) { my $instr = $1; my $suffix = $2; my $target = $3; my $base = $4; my $offset = eval_expr($5); if ($offset < 0) { $line =~ s/$instr$suffix/${instr}u$suffix/; } } if ($ENV{GASPP_ARMASM64_INVERT_SCALE}) { # Instructions like fcvtzs and scvtf store the scale value # inverted in the opcode (stored as 64 - scale), but armasm64 # in VS < 15.5 stores it as-is. Thus convert from # "fcvtzs w0, s0, #8" into "fcvtzs w0, s0, #56". if ($line =~ /(?:fcvtzs|scvtf)\s+(\w+)\s*,\s*(\w+)\s*,\s*#(\d+)/) { my $scale = $3; my $inverted_scale = 64 - $3; $line =~ s/#$scale/#$inverted_scale/; } } # Convert "ld1 {v0.4h-v3.4h}" into "ld1 {v0.4h,v1.4h,v2.4h,v3.4h}" if ($line =~ /(\{\s*v(\d+)\.(\d+[bhsdBHSD])\s*-\s*v(\d+)\.(\d+[bhsdBHSD])\s*\})/) { my $regspec = $1; my $reg1 = $2; my $layout1 = $3; my $reg2 = $4; my $layout2 = $5; if ($layout1 eq $layout2) { my $new_regspec = "{"; foreach my $i ($reg1 .. $reg2) { $new_regspec .= "," if ($i > $reg1); $new_regspec .= "v$i.$layout1"; } $new_regspec .= "}"; $line =~ s/$regspec/$new_regspec/; } } } # armasm is unable to parse &0x - add spacing $line =~ s/&0x/& 0x/g; } if ($force_thumb) { # Convert register post indexing to a separate add instruction. # This converts e.g. "ldr r0, [r1], r2" into "ldr r0, [r1]", # "add r1, r1, r2". $line =~ s/((?:ldr|str)[bh]?)\s+(\w+),\s*\[(\w+)\],\s*(\w+)/$1 $2, [$3]\n\tadd $3, $3, $4/g; # Convert "mov pc, lr" into "bx lr", since the former only works # for switching from arm to thumb (and only in armv7), but not # from thumb to arm. $line =~ s/mov\s*pc\s*,\s*lr/bx lr/g; # Convert stmdb/ldmia/stmfd/ldmfd/ldm with only one register into a plain str/ldr with post-increment/decrement. # Wide thumb2 encoding requires at least two registers in register list while all other encodings support one register too. $line =~ s/stm(?:db|fd)\s+sp!\s*,\s*\{([^,-]+)\}/str $1, [sp, #-4]!/g; $line =~ s/ldm(?:ia|fd)?\s+sp!\s*,\s*\{([^,-]+)\}/ldr $1, [sp], #4/g; # Convert muls into mul+cmp $line =~ s/muls\s+(\w+),\s*(\w+)\,\s*(\w+)/mul $1, $2, $3\n\tcmp $1, #0/g; # Convert "and r0, sp, #xx" into "mov r0, sp", "and r0, r0, #xx" $line =~ s/and\s+(\w+),\s*(sp|r13)\,\s*#(\w+)/mov $1, $2\n\tand $1, $1, #$3/g; # Convert "ldr r0, [r0, r1, lsl #6]" where the shift is >3 (which # can't be handled in thumb) into "add r0, r0, r1, lsl #6", # "ldr r0, [r0]", for the special case where the same address is # used as base and target for the ldr. if ($line =~ /(ldr[bh]?)\s+(\w+),\s*\[\2,\s*(\w+),\s*lsl\s*#(\w+)\]/ and $4 > 3) { $line =~ s/(ldr[bh]?)\s+(\w+),\s*\[\2,\s*(\w+),\s*lsl\s*#(\w+)\]/add $2, $2, $3, lsl #$4\n\t$1 $2, [$2]/; } $line =~ s/\.arm/.thumb/x; } # comment out unsupported directives $line =~ s/\.type/$comm$&/x if $as_type =~ /^(apple-|armasm)/; $line =~ s/\.func/$comm$&/x if $as_type =~ /^(apple-|clang)/; $line =~ s/\.endfunc/$comm$&/x if $as_type =~ /^(apple-|clang)/; $line =~ s/\.endfunc/ENDP/x if $as_type =~ /armasm/; $line =~ s/\.ltorg/$comm$&/x if $as_type =~ /^(apple-|clang)/; $line =~ s/\.ltorg/LTORG/x if $as_type eq "armasm"; $line =~ s/\.size/$comm$&/x if $as_type =~ /^(apple-|armasm)/; $line =~ s/\.fpu/$comm$&/x if $as_type =~ /^(apple-|armasm)/; $line =~ s/\.arch/$comm$&/x if $as_type =~ /^(apple-|clang|armasm)/; $line =~ s/\.object_arch/$comm$&/x if $as_type =~ /^(apple-|armasm)/; $line =~ s/.section\s+.note.GNU-stack.*/$comm$&/x if $as_type =~ /^(apple-|armasm)/; $line =~ s/\.syntax/$comm$&/x if $as_type =~ /armasm/; $line =~ s/\.hword/.short/x; if ($as_type =~ /^apple-/) { # the syntax for these is a little different $line =~ s/\.global/.globl/x; # also catch .section .rodata since the equivalent to .const_data is .section __DATA,__const $line =~ s/(.*)\.rodata/.const_data/x; $line =~ s/\.int/.long/x; $line =~ s/\.float/.single/x; } if ($as_type eq "apple-gas") { $line =~ s/vmrs\s+APSR_nzcv/fmrx r15/x; } if ($as_type eq "armasm") { $line =~ s/\.global/EXPORT/x; $line =~ s/\.extern/IMPORT/x; $line =~ s/\.int/dcd/x; $line =~ s/\.long/dcd/x; $line =~ s/\.float/dcfs/x; $line =~ s/\.word/dcd/x; $line =~ s/\.short/dcw/x; $line =~ s/\.byte/dcb/x; $line =~ s/\.quad/dcq/x; $line =~ s/\.ascii/dcb/x; $line =~ s/\.asciz(.*)$/dcb\1,0/x; $line =~ s/\.thumb/THUMB/x; $line =~ s/\.arm/ARM/x; # The alignment in AREA is the power of two, just as .align in gas $line =~ s/\.text/AREA |.text|, CODE, READONLY, ALIGN=4, CODEALIGN/; $line =~ s/(\s*)(.*)\.ro?data(\s*,\s*"\w+")?/$1AREA |.rdata|, DATA, READONLY, ALIGN=5/; $line =~ s/\.data/AREA |.data|, DATA, ALIGN=5/; } if ($as_type eq "armasm" and $arch eq "arm") { $line =~ s/fmxr/vmsr/; $line =~ s/fmrx/vmrs/; $line =~ s/fadds/vadd.f32/; # Armasm in VS 2019 16.3 errors out on "it" instructions. But # armasm implicitly adds the necessary it instructions anyway, so we # can just filter them out. $line =~ s/^\s*it[te]*\s+/$comm$&/; } if ($as_type eq "armasm" and $arch eq "aarch64") { # Convert "b.eq" into "beq" $line =~ s/\bb\.($arm_cond_codes)\b/b\1/; } # catch unknown section names that aren't mach-o style (with a comma) if ($as_type =~ /apple-/ and $line =~ /.section ([^,]*)$/) { die ".section $1 unsupported; figure out the mach-o section name and add it"; } print ASMFILE $line; } if ($as_type ne "armasm") { print ASMFILE ".text\n"; print ASMFILE ".align 2\n"; foreach my $literal (keys %literal_labels) { print ASMFILE "$literal_labels{$literal}:\n $literal_expr $literal\n"; } map print(ASMFILE ".thumb_func $_\n"), grep exists $thumb_labels{$_}, keys %call_targets; } else { map print(ASMFILE "\tIMPORT $_\n"), grep ! exists $labels_seen{$_}, (keys %call_targets, keys %import_symbols); print ASMFILE "\tEND\n"; } close(INPUT) or exit 1; close(ASMFILE) or exit 1; if ($as_type eq "armasm" and ! defined $ENV{GASPP_DEBUG}) { print STDERR join(" ", @gcc_cmd)."\n" if $verbose; system(@gcc_cmd) == 0 or die "Error running assembler"; } END { unlink($tempfile) if defined $tempfile; } #exit 1
0
repos/xmake/xmake
repos/xmake/xmake/scripts/faq.lua
-- -- If you want to known more usage about xmake, please see https://xmake.io -- -- ## FAQ -- -- You can enter the project directory firstly before building project. -- -- $ cd projectdir -- -- 1. How to build project? -- -- $ xmake -- -- 2. How to configure project? -- -- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] -- -- 3. Where is the build output directory? -- -- The default output directory is `./build` and you can configure the output directory. -- -- $ xmake f -o outputdir -- $ xmake -- -- 4. How to run and debug target after building project? -- -- $ xmake run [targetname] -- $ xmake run -d [targetname] -- -- 5. How to install target to the system directory or other output directory? -- -- $ xmake install -- $ xmake install -o installdir -- -- 6. Add some frequently-used compilation flags in xmake.lua -- -- @code -- -- add debug and release modes -- add_rules("mode.debug", "mode.release") -- -- -- add macro definition -- add_defines("NDEBUG", "_GNU_SOURCE=1") -- -- -- set warning all as error -- set_warnings("all", "error") -- -- -- set language: c99, c++11 -- set_languages("c99", "c++11") -- -- -- set optimization: none, faster, fastest, smallest -- set_optimize("fastest") -- -- -- add include search directories -- add_includedirs("/usr/include", "/usr/local/include") -- -- -- add link libraries and search directories -- add_links("tbox") -- add_linkdirs("/usr/local/lib", "/usr/lib") -- -- -- add system link libraries -- add_syslinks("z", "pthread") -- -- -- add compilation and link flags -- add_cxflags("-stdnolib", "-fno-strict-aliasing") -- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) -- -- @endcode --
0
repos/xmake/xmake/scripts
repos/xmake/xmake/scripts/virtualenvs/register-virtualenvs.sh
# A cross-platform build utility based on Lua # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http:##www.apache.org#licenses#LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Copyright (C) 2022-present, TBOOX Open Source Group. # # @author ruki, xq114 # @homepage register-virtualenvs.sh # if test "${XMAKE_ROOTDIR}"; then export XMAKE_PROGRAM_FILE=${XMAKE_ROOTDIR}/xmake else local -i XMAKE_ROOTDIR=~/.local/bin export XMAKE_PROGRAM_FILE=xmake fi function xrepo { if [ $# -ge 2 ] && [ "$1" = "env" ]; then local cmd="${2-x}" case "$cmd" in shell) if test "${XMAKE_PROMPT_BACKUP}"; then PS1="${XMAKE_PROMPT_BACKUP}" source "${XMAKE_ENV_BACKUP}" || return 1 unset XMAKE_PROMPT_BACKUP unset XMAKE_ENV_BACKUP fi "$XMAKE_PROGRAM_FILE" lua private.xrepo.action.env.info config || return 1 local currentTest="$("$XMAKE_PROGRAM_FILE" lua --quiet private.xrepo.action.env)" || return 1 if [ ! -z "$currentTest" ]; then echo "error: corrupt xmake.lua detected in the current directory!" return 1 fi local prompt="$("$XMAKE_PROGRAM_FILE" lua --quiet private.xrepo.action.env.info prompt)" || return 1 if [ -z "${prompt+x}" ]; then return 1 fi local activateCommand="$("$XMAKE_PROGRAM_FILE" lua private.xrepo.action.env.info script.bash)" || return 1 export XMAKE_ENV_BACKUP="$("$XMAKE_PROGRAM_FILE" lua private.xrepo.action.env.info envfile)" export XMAKE_PROMPT_BACKUP="${PS1}" "$XMAKE_PROGRAM_FILE" lua private.xrepo.action.env.info backup.bash 1>"$XMAKE_ENV_BACKUP" eval "$activateCommand" PS1="${prompt} $PS1" ;; quit) if test "${XMAKE_PROMPT_BACKUP}"; then PS1="${XMAKE_PROMPT_BACKUP}" source "${XMAKE_ENV_BACKUP}" || return 1 unset XMAKE_PROMPT_BACKUP unset XMAKE_ENV_BACKUP fi ;; -b|--bind) if [ "$4" = "shell" ]; then local bnd="${3-x}" if test "${XMAKE_PROMPT_BACKUP}"; then PS1="${XMAKE_PROMPT_BACKUP}" source "${XMAKE_ENV_BACKUP}" || return 1 unset XMAKE_PROMPT_BACKUP unset XMAKE_ENV_BACKUP fi pushd ${XMAKE_ROOTDIR} 1>/dev/null "$XMAKE_PROGRAM_FILE" lua private.xrepo.action.env.info config $bnd || popd 1>/dev/null && return 1 local prompt="$("$XMAKE_PROGRAM_FILE" lua --quiet private.xrepo.action.env.info prompt $bnd)" || popd 1>/dev/null && return 1 if [ -z "${prompt+x}" ]; then popd 1>/dev/null echo "error: invalid environment!" return 1 fi local activateCommand="$("$XMAKE_PROGRAM_FILE" lua --quiet private.xrepo.action.env.info script.bash $bnd)" || popd 1>/dev/null && return 1 export XMAKE_ENV_BACKUP="$("$XMAKE_PROGRAM_FILE" lua private.xrepo.action.env.info envfile $bnd)" export XMAKE_PROMPT_BACKUP="${PS1}" "$XMAKE_PROGRAM_FILE" lua --quiet private.xrepo.action.env.info backup.bash $bnd 1>"$XMAKE_ENV_BACKUP" eval "$activateCommand" popd 1>/dev/null PS1="${prompt} $PS1" else "$XMAKE_PROGRAM_FILE" lua private.xrepo "$@" fi ;; *) "$XMAKE_PROGRAM_FILE" lua private.xrepo "$@" ;; esac else "$XMAKE_PROGRAM_FILE" lua private.xrepo "$@" fi }
0
repos/xmake/xmake/scripts/vsxmake
repos/xmake/xmake/scripts/vsxmake/vsproj/Xmake.props
<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup Label="XmakePropsInit"> <!-- initialize this first to allow `Condition="'$(XmakeMode)|$(XmakeArch)' == 'release|x86'"` in custom props file --> <XmakeMode Condition="'$(XmakeMode)' == ''">$(Configuration)</XmakeMode> <XmakeMode Condition="'$(XmakeMode)' == ''">release</XmakeMode> <XmakeArch Condition="'$(XmakeArch)' == '' And '$(Platform.ToLower())' == 'win32'">x86</XmakeArch> <XmakeArch Condition="'$(XmakeArch)' == '' And '$(Platform.ToLower())' != 'win32'">$(Platform)</XmakeArch> <XmakeArch Condition="'$(XmakeArch)' == ''">x86</XmakeArch> </PropertyGroup> <ImportGroup Label="CustomSettings"> <!--only search 2 levels to avoid accidentally import--> <Import Condition="Exists('$(MSBuildProjectDirectory)\Xmake.Custom.props')" Project="$(MSBuildProjectDirectory)\Xmake.Custom.props" /> <Import Condition="!Exists('$(MSBuildProjectDirectory)\Xmake.Custom.props') And Exists('$(MSBuildProjectDirectory)\..\Xmake.Custom.props')" Project="$(MSBuildProjectDirectory)\..\Xmake.Custom.props" /> </ImportGroup> <PropertyGroup Label="XmakePropsFallback"> <XmakeBasename Condition="'$(XmakeBasename)' == ''">$(XmakeTarget)</XmakeBasename> <XmakeBasename Condition="'$(XmakeBasename)' == ''">$(TargetName)</XmakeBasename> <XmakeBasename Condition="'$(XmakeBasename)' == ''">$(MSBuildProjectName)</XmakeBasename> <XmakeKind Condition="'$(XmakeKind)' == ''">binary</XmakeKind> <XmakePlat Condition="'$(XmakePlat)' == ''">windows</XmakePlat> </PropertyGroup> <PropertyGroup Label="XmakePathsFallback"> <XmakeBuilDir Condition="'$(XmakeBuilDir)' == ''">$(XmakeProjectDir)\build</XmakeBuilDir> <XmakeTargetDir Condition="'$(XmakeTargetDir)' == ''">$(XmakeBuilDir)\$(XmakePlat)\$(XmakeArch)\$(XmakeMode)</XmakeTargetDir> <XmakeConfigFileDir Condition="'$(XmakeConfigFileDir)' == ''">$(XmakeBuilDir)\$(XmakePlat)\$(XmakeArch)\$(XmakeMode)</XmakeConfigFileDir> <XmakeConfigDir Condition="'$(XmakeConfigDir)' == ''">$(XMAKE_CONFIGDIR)</XmakeConfigDir> <XmakeConfigDir Condition="'$(XmakeConfigDir)' == ''">$(XmakeProjectDir)</XmakeConfigDir> <XmakeRunDir Condition="'$(XmakeRunDir)' == ''">$(XmakeTargetDir)</XmakeRunDir> </PropertyGroup> <PropertyGroup Label="XmakeFlagsFallback"> <XmakeCleanAll Condition="'$(XmakeCleanAll)' == ''">true</XmakeCleanAll> <XmakeVerbose Condition="'$(XmakeVerbose)' == ''">false</XmakeVerbose> <XmakeDiagnosis Condition="'$(XmakeDiagnosis)' == ''">false</XmakeDiagnosis> <XmakeRebuildFile Condition="'$(XmakeRebuildFile)' == ''">false</XmakeRebuildFile> </PropertyGroup> <PropertyGroup Condition="'$(WindowsTargetPlatformVersion)' == '' And '$(XmakeWindowsSdkVersion)' != ''"> <WindowsTargetPlatformVersion>$(XmakeWindowsSdkVersion)</WindowsTargetPlatformVersion> </PropertyGroup> <PropertyGroup Condition="'$(PlatformToolset)' == ''"> <PlatformToolset Condition="'$(VisualStudioVersion)' == '10.0'">v100</PlatformToolset> <PlatformToolset Condition="'$(VisualStudioVersion)' == '11.0'">v110</PlatformToolset> <PlatformToolset Condition="'$(VisualStudioVersion)' == '12.0'">v120</PlatformToolset> <PlatformToolset Condition="'$(VisualStudioVersion)' == '14.0'">v140</PlatformToolset> <PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset> <PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset> <PlatformToolset Condition="'$(VisualStudioVersion)' == '17.0'">v143</PlatformToolset> </PropertyGroup> <PropertyGroup Label="AdditionalProps"> <UseOfMfc Condition="'$(XmakeMfcKind)' != ''">$(XmakeMfcKind)</UseOfMfc> <CharacterSet Condition="'$(CharacterSet)' == '' And ($(XmakeDefines.Contains(';UNICODE;')) Or $(XmakeDefines.EndsWith(';UNICODE')) Or $(XmakeDefines.StartsWith('UNICODE;')) Or $(XmakeDefines.Equals('UNICODE')))">Unicode</CharacterSet> <CharacterSet Condition="'$(CharacterSet)' == ''">MultiByte</CharacterSet> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Choose> <When Condition="'$(XmakeKind)' == 'binary'"> <PropertyGroup> <ConfigurationType>Application</ConfigurationType> </PropertyGroup> </When> <When Condition="'$(XmakeKind)' == 'shared'"> <PropertyGroup> <ConfigurationType>DynamicLibrary</ConfigurationType> </PropertyGroup> </When> <When Condition="'$(XmakeKind)' == 'static'"> <PropertyGroup> <ConfigurationType>StaticLibrary</ConfigurationType> </PropertyGroup> </When> <When Condition="'$(XmakeKind)' == 'phony'"> <PropertyGroup> <ConfigurationType>Unknown</ConfigurationType> </PropertyGroup> </When> <When Condition="'$(XmakeKind)' == 'headeronly'"> <PropertyGroup> <ConfigurationType>Unknown</ConfigurationType> </PropertyGroup> </When> <When Condition="'$(XmakeKind)' == 'moduleonly'"> <PropertyGroup> <ConfigurationType>Unknown</ConfigurationType> </PropertyGroup> </When> </Choose> <ItemDefinitionGroup> <ClCompile> <PreprocessorDefinitions>%(PreprocessorDefinitions);$(XmakeDefines)</PreprocessorDefinitions> <AdditionalIncludeDirectories>$(XmakeIncludeDirs)</AdditionalIncludeDirectories> <ForcedIncludeFiles>$(XmakeForceIncludes)</ForcedIncludeFiles> <AdditionalOptions>%(AdditionalOptions) $(XmakeCFlags) $(XmakeCXFlags) $(XmakeCXXFlags)</AdditionalOptions> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxx11'))">stdcpp11</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxx14'))">stdcpp14</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxx17'))">stdcpp17</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxx1z'))">stdcpp17</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxx20'))">stdcpplatest</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxx2a'))">stdcpplatest</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxx23'))">stdcpplatest</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxx2b'))">stdcpplatest</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('cxxlatest'))">stdcpplatest</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('gnuxx11'))">stdcpp11</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('gnuxx14'))">stdcpp14</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('gnuxx17'))">stdcpp17</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('gnuxx1z'))">stdcpp17</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('gnuxx20'))">stdcpplatest</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('gnuxx2a'))">stdcpplatest</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('gnuxx23'))">stdcpplatest</LanguageStandard> <LanguageStandard Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('gnuxx2b'))">stdcpplatest</LanguageStandard> <LanguageStandard_C Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('c11'))">stdc11</LanguageStandard_C> <LanguageStandard_C Condition="'%(LanguageStandard)' == '' And $(XmakeLanguages.Contains('c17'))">stdc17</LanguageStandard_C> <LanguageStandard_C Condition="'%(LanguageStandard_C)' == '' And $(XmakeLanguages.Contains('gnu11'))">stdc11</LanguageStandard_C> <LanguageStandard_C Condition="'%(LanguageStandard_C)' == '' And $(XmakeLanguages.Contains('gnu17'))">stdc17</LanguageStandard_C> <PrecompiledHeader Condition="'%(PrecompiledHeader)' == '' And $(XmakePrecompiledHeader.Contains('.h'))">Use</PrecompiledHeader> <PrecompiledHeaderFile Condition="'%(PrecompiledHeaderFile)' == '' And $(XmakePrecompiledHeader.Contains('.h'))">$(XmakeProjectDir)\$(XmakePrecompiledHeader)</PrecompiledHeaderFile> <ForcedIncludeFiles Condition="'%(ForcedIncludeFiles)' == '' And $(XmakePrecompiledHeader.Contains('.h'))">$(XmakeProjectDir)\$(XmakePrecompiledHeader);%(ForcedIncludeFiles)</ForcedIncludeFiles> </ClCompile> <Link> <SubSystem Condition="'%(SubSystem)' == '' And $(XmakeSubSystem.Contains('console'))">Console</SubSystem> <SubSystem Condition="'%(SubSystem)' == '' And $(XmakeSubSystem.Contains('windows'))">Windows</SubSystem> </Link> <ResourceCompile> <PreprocessorDefinitions>%(PreprocessorDefinitions);$(XmakeDefines)</PreprocessorDefinitions> <AdditionalIncludeDirectories>$(XmakeIncludeDirs)</AdditionalIncludeDirectories> </ResourceCompile> </ItemDefinitionGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <ItemGroup> <PropertyPageSchema Include="$(MSBuildThisFileDirectory)$(MSBuildThisFileName).xml"> <Context>Project</Context> </PropertyPageSchema> </ItemGroup> <ImportGroup Label="ExtensionSettings"> <Import Condition="'$(XmakeCudaVersion)' != '' And Exists('$(VCTargetsPath)\BuildCustomizations\CUDA $(XmakeCudaVersion).props')" Project="$(VCTargetsPath)\BuildCustomizations\CUDA $(XmakeCudaVersion).props" /> </ImportGroup> <ImportGroup Label="PropertySheets"> <Import Condition="Exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" /> </ImportGroup> <PropertyGroup Label="GlobalsFallback"> <TargetName Condition="'$(XmakeFilename)' == ''">$(XmakeBasename)</TargetName> <TargetName Condition="'$(XmakeFilename)' != ''">$([System.IO.Path]::GetFileNameWithoutExtension('$(XmakeFilename)'))</TargetName> <TargetExt Condition="'$(XmakeFilename)' != ''">$([System.IO.Path]::GetExtension('$(XmakeFilename)'))</TargetExt> </PropertyGroup> <PropertyGroup Label="Path"> <LibraryPath>$(XmakeLinkDirs);$(LibraryPath)</LibraryPath> <OutDir>$(XmakeTargetDir)\</OutDir> <IntDir>$(XmakeBuilDir)\.vs\$(TargetName)\$(XmakeArch)\$(XmakeMode)\</IntDir> <SourcePath>$(XmakeSourceDirs);$(SourcePath)</SourcePath> </PropertyGroup> <PropertyGroup Label="Debugger"> <LocalDebuggerWorkingDirectory>$(XmakeRunDir)</LocalDebuggerWorkingDirectory> <LocalDebuggerEnvironment>$(XmakeRunEnvs) $(LocalDebuggerEnvironment)</LocalDebuggerEnvironment> <LocalDebuggerCommandArguments>$(XmakeRunArgs)</LocalDebuggerCommandArguments> <LocalDebuggerMergeEnvironment>true</LocalDebuggerMergeEnvironment> <RemoteDebuggerWorkingDirectory>$(XmakeRunDir)</RemoteDebuggerWorkingDirectory> <RemoteDebuggerEnvironment>$(XmakeRunEnvs) $(RemoteDebuggerEnvironment)</RemoteDebuggerEnvironment> <RemoteDebuggerCommandArguments>$(XmakeRunArgs)</RemoteDebuggerCommandArguments> </PropertyGroup> <!-- Common files --> <ItemGroup> <None Condition="Exists('$(MSBuildProjectDirectory)\Xmake.Custom.props')" Include="$(MSBuildProjectDirectory)\Xmake.Custom.props" /> <None Condition="Exists('$(MSBuildProjectDirectory)\Xmake.Custom.targets')" Include="$(MSBuildProjectDirectory)\Xmake.Custom.targets" /> <None Condition="Exists('$(MSBuildProjectDirectory)\Xmake.Custom.items')" Include="$(MSBuildProjectDirectory)\Xmake.Custom.items" /> <None Condition="Exists('$(MSBuildProjectDirectory)\Xmake.Custom.items.filters')" Include="$(MSBuildProjectDirectory)\Xmake.Custom.items.filters" /> <None Condition="'$(XmakeScriptDir)' != '$(XmakeProjectDir)' And Exists('$(XmakeScriptDir)\xmake.lua')" Include="$(XmakeScriptDir)\xmake.lua" /> </ItemGroup> <Import Condition="Exists('$(MSBuildProjectDirectory)\Xmake.Custom.items')" Project="$(MSBuildProjectDirectory)\Xmake.Custom.items" /> </Project>
0
repos/xmake/xmake/scripts/vsxmake
repos/xmake/xmake/scripts/vsxmake/vsproj/Xmake.xml
<?xml version="1.0" encoding="utf-8"?> <ProjectSchemaDefinitions xmlns="clr-namespace:Microsoft.Build.Framework.XamlTypes;assembly=Microsoft.Build.Framework" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly=mscorlib"> <Rule Name="XmakeConfiguration" DisplayName="Xmake" PageTemplate="generic" SwitchPrefix="--" Description="Xmake Properties"> <Rule.Categories> <Category Name="Common" DisplayName="Common" Description="Xmake common configurations"/> <Category Name="Flags" DisplayName="Additional flags" Description="Xmake additional flags"/> <Category Name="Paths" DisplayName="Paths" Description="Xmake configurable paths"/> </Rule.Categories> <Rule.DataSource> <DataSource Persistence="UserFile" Label="XmakeConfiguration"/> </Rule.DataSource> <BoolProperty Name="XmakeVerbose" DisplayName="Print verbose information" Category="Common" Description="Print lots of verbose information for users." Switch="verbose" /> <BoolProperty Name="XmakeDiagnosis" DisplayName="Print diagnosis information" Category="Common" Description="Print lots of diagnosis information (backtrace, check info ..) only for developers." Switch="diagnosis" /> <BoolProperty Name="XmakeCleanAll" DisplayName="Clean all" Category="Common" Description="Clean all auto-generated files by xmake for clean tasks." Switch="all" /> <BoolProperty Name="XmakeRebuildFile" DisplayName="Force rebuild selected files" Category="Common" Description="When use 'compile' command to build selected files, add '--rebuild' flag to force rebuild files." Switch="rebuild" /> <StringProperty Name="XmakeCleanFlags" DisplayName="Clean flags" Category="Flags" Description="Additional flags for 'xmake clean'" /> <StringProperty Name="XmakeBuildFlags" DisplayName="Build flags" Category="Flags" Description="Additional flags for 'xmake build'" /> <StringProperty Name="XmakeConfigFlags" DisplayName="Config flags" Category="Flags" Description="Additional flags for 'xmake config'" /> <StringProperty Name="XmakeCommonFlags" DisplayName="Common flags" Category="Flags" Description="Additional flags for all xmake call" /> <StringProperty Name="XmakeConfigDir" DisplayName="Config dir" Category="Paths" Description="Set environment XMAKE_CONFIGDIR for xmake tasks" Subtype="folder" /> <StringProperty Name="XmakeBuilDir" DisplayName="Build dir" Category="Paths" Description="Set output dir for xmake tasks" Subtype="folder" /> </Rule> </ProjectSchemaDefinitions>
0
repos/xmake/xmake/scripts/vsxmake
repos/xmake/xmake/scripts/vsxmake/vsproj/Xmake.Defaults.props
<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup Label="XmakePathsResolve"> <_XmakeProgramDir>$(XmakeProgramDir)</_XmakeProgramDir> <_XmakeProjectDir>$(XmakeProjectDir)</_XmakeProjectDir> <_XmakeScriptDir>$(XmakeScriptDir)</_XmakeScriptDir> <!-- resolve if they are relative paths --> <_XmakeProgramDir Condition="!$([System.IO.Path]::IsPathRooted('$(_XmakeProgramDir)'))">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(_XmakeProgramDir)'))</_XmakeProgramDir> <_XmakeProjectDir Condition="!$([System.IO.Path]::IsPathRooted('$(_XmakeProjectDir)'))">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(_XmakeProjectDir)'))</_XmakeProjectDir> <_XmakeScriptDir Condition="!$([System.IO.Path]::IsPathRooted('$(_XmakeScriptDir)'))">$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\$(_XmakeScriptDir)'))</_XmakeScriptDir> <!-- normalize paths --> <XmakeProgramDir>$([System.IO.Path]::GetFullPath('$(_XmakeProgramDir)'))</XmakeProgramDir> <XmakeProjectDir>$([System.IO.Path]::GetFullPath('$(_XmakeProjectDir)'))</XmakeProjectDir> <XmakeScriptDir>$([System.IO.Path]::GetFullPath('$(_XmakeScriptDir)'))</XmakeScriptDir> </PropertyGroup> </Project>
0
repos/xmake/xmake/scripts/vsxmake/vsproj
repos/xmake/xmake/scripts/vsxmake/vsproj/templates/Xmake.Custom.props
<?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <!-- inherit parent settings --> <Import Condition="Exists('$(MSBuildThisFileDirectory)\..\Xmake.Custom.props')" Project="$(MSBuildThisFileDirectory)\..\Xmake.Custom.props" /> <PropertyGroup Label="XmakePaths"> <!-- set environment XMAKE_CONFIGDIR for xmake tasks --> <!-- <XmakeConfigDir Condition="'$(XmakeMode)|$(XmakeArch)' == 'release|x86'">$(XmakeProjectDir)\.xmake</XmakeConfigDir> --> <!-- set output dir for xmake tasks --> <!-- <XmakeBuilDir>$(XmakeProjectDir)\build</XmakeBuilDir> --> </PropertyGroup> <PropertyGroup Label="XmakeFlags"> <!-- Configure these flags to customize xmake build process --> <!-- Inherit parents: <XmakeCleanFlags>$(XmakeCleanflags) -D</XmakeCleanFlags> Override parents: <XmakeCleanFlags>-D</XmakeCleanFlags> Respect parents: <XmakeCleanFlags Condition=" '$(XmakeCleanFlags)' == '' ">-D</XmakeCleanFlags> For -v and -D, use <XmakeVerbose> and <XmakeDiagnosis> as its more convenient. --> <!-- Set -a for "xmake clean" --> <!-- <XmakeCleanAll Condition="'$(XmakeCleanAll)' == ''">true</XmakeCleanAll> --> <!-- Set -v for all xmake call --> <!-- <XmakeVerbose Condition="'$(XmakeVerbose)' == ''">false</XmakeVerbose> --> <!-- Set -D for all xmake call --> <!-- <XmakeDiagnosis Condition="'$(XmakeDiagnosis)' == ''">false</XmakeDiagnosis> --> <!-- Set -r for "xmake build" for selected files --> <!-- <XmakeRebuildFile Condition="'$(XmakeRebuildFile)' == ''">false</XmakeRebuildFile> --> <!-- Additional flags for "xmake clean" --> <!-- <XmakeCleanFlags>$(XmakeCleanflags)</XmakeCleanFlags> --> <!-- Additional flags for "xmake build" --> <!-- <XmakeBuildFlags>$(XmakeBuildFlags)</XmakeBuildFlags> --> <!-- Additional flags for "xmake config" --> <!-- <XmakeConfigFlags>$(XmakeConfigFlags)</XmakeConfigFlags> --> <!-- Additional flags for all xmake call --> <!-- <XmakeCommonFlags>$(XmakeCommonFlags)</XmakeCommonFlags> --> </PropertyGroup> </Project>
0
repos/xmake/xmake/scripts
repos/xmake/xmake/scripts/module/xmi.h
/*!A cross-platform build utility based on Lua * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Copyright (C) 2015-present, TBOOX Open Source Group. * * @author ruki * @file xmi.h * */ #ifndef XMI_H #define XMI_H /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #ifndef LUA_VERSION # include "luawrap/luaconf.h" #endif /* ////////////////////////////////////////////////////////////////////////////////////// * macros */ #define XMI_LUA_MULTRET (-1) // thread status #define XMI_LUA_OK 0 #define XMI_LUA_YIELD 1 #define XMI_LUA_ERRRUN 2 #define XMI_LUA_ERRSYNTAX 3 #define XMI_LUA_ERRMEM 4 #define XMI_LUA_ERRERR 5 // basic types #define XMI_LUA_TNONE (-1) #define XMI_LUA_TNIL 0 #define XMI_LUA_TBOOLEAN 1 #define XMI_LUA_TLIGHTUSERDATA 2 #define XMI_LUA_TNUMBER 3 #define XMI_LUA_TSTRING 4 #define XMI_LUA_TTABLE 5 #define XMI_LUA_TFUNCTION 6 #define XMI_LUA_TUSERDATA 7 #define XMI_LUA_TTHREAD 8 #define XMI_LUA_NUMTYPES 9 // pseudo-indices #ifdef XMI_USE_LUAJIT # define XMI_LUA_REGISTRYINDEX (-10000) # define XMI_LUA_ENVIRONINDEX (-10001) # define XMI_LUA_GLOBALSINDEX (-10002) # define xmi_lua_upvalueindex(i) (XMI_LUA_GLOBALSINDEX - (i)) #else # define XMI_LUA_REGISTRYINDEX (-LUAI_MAXSTACK - 1000) # define xmi_lua_upvalueindex(i) (XMI_LUA_REGISTRYINDEX - (i)) #endif // get macros #ifdef XMI_USE_LUAJIT # define xmi_lua_getglobal(lua, s) xmi_lua_getfield(lua, LUA_GLOBALSINDEX, (s)) # define xmi_lua_newuserdata(lua, s) (g_lua_ops)->_lua_newuserdata(lua, s) #else # define xmi_lua_getglobal(lua, name) (g_lua_ops)->_lua_getglobal(lua, name) # define xmi_lua_geti(lua, idx, n) (g_lua_ops)->_lua_geti(lua, idx, n) # define xmi_lua_rawgetp(lua, idx, p) (g_lua_ops)->_lua_rawgetp(lua, idx, p) # define xmi_lua_getiuservalue(lua, idx, n) (g_lua_ops)->_lua_getiuservalue(lua, idx, n) # define xmi_lua_newuserdatauv(lua, sz, nuvalue) (g_lua_ops)->_lua_newuserdatauv(lua, sz, nuvalue) # define xmi_lua_newuserdata(lua, s) xmi_lua_newuserdatauv(lua, s, 1) #endif #define xmi_lua_gettable(lua, idx) (g_lua_ops)->_lua_gettable(lua, idx) #define xmi_lua_getfield(lua, idx, k) (g_lua_ops)->_lua_getfield(lua, idx, k) #define xmi_lua_rawget(lua, idx) (g_lua_ops)->_lua_rawget(lua, idx) #define xmi_lua_rawgeti(lua, idx, n) (g_lua_ops)->_lua_rawgeti(lua, idx, n) #define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec) #define xmi_lua_getmetatable(lua, objindex) (g_lua_ops)->_lua_getmetatable(lua, objindex) #define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0) #define xmi_lua_pop(lua, n) xmi_lua_settop(lua, -(n)-1) #define xmi_lua_getuservalue(lua, idx) xmi_lua_getiuservalue(lua, idx, 1) // set macros #ifdef XMI_USE_LUAJIT # define xmi_lua_setglobal(lua, s) xmi_lua_setfield(lua, LUA_GLOBALSINDEX, (s)) #else # define xmi_lua_setglobal(lua, name) (g_lua_ops)->_lua_setglobal(lua, name) # define xmi_lua_seti(lua, idx, n) (g_lua_ops)->_lua_seti(lua, idx, n) # define xmi_lua_rawsetp(lua, idx, p) (g_lua_ops)->_lua_rawsetp(lua, idx, p) # define xmi_lua_setiuservalue(lua, idx, n) (g_lua_ops)->_lua_setiuservalue(lua, idx, n) #endif #define xmi_lua_settable(lua, idx) (g_lua_ops)->_lua_settable(lua, idx) #define xmi_lua_setfield(lua, idx, k) (g_lua_ops)->_lua_setfield(lua, idx, k) #define xmi_lua_rawset(lua, idx) (g_lua_ops)->_lua_rawset(lua, idx) #define xmi_lua_rawseti(lua, idx, n) (g_lua_ops)->_lua_rawseti(lua, idx, n) #define xmi_lua_setmetatable(lua, objidx) (g_lua_ops)->_lua_setmetatable(lua, objidx) #define xmi_lua_setuservalue(lua, idx) xmi_lua_setiuservalue(lua, idx, 1) // access macros #define xmi_lua_isnumber(lua, idx) (g_lua_ops)->_lua_isnumber(lua, idx) #define xmi_lua_isstring(lua, idx) (g_lua_ops)->_lua_isstring(lua, idx) #define xmi_lua_iscfunction(lua, idx) (g_lua_ops)->_lua_iscfunction(lua, idx) #define xmi_lua_isuserdata(lua, idx) (g_lua_ops)->_lua_isuserdata(lua, idx) #define xmi_lua_type(lua, idx) (g_lua_ops)->_lua_type(lua, idx) #define xmi_lua_typename(lua, idx) (g_lua_ops)->_lua_typename(lua, idx) #ifndef XMI_USE_LUAJIT # define xmi_lua_isinteger(lua, idx) (g_lua_ops)->_lua_isinteger(lua, idx) #endif #define xmi_lua_isfunction(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TFUNCTION) #define xmi_lua_istable(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TTABLE) #define xmi_lua_islightuserdata(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TLIGHTUSERDATA) #define xmi_lua_isnil(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TNIL) #define xmi_lua_isboolean(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TBOOLEAN) #define xmi_lua_isthread(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TTHREAD) #define xmi_lua_isnone(lua, n) (xmi_lua_type(lua, (n)) == XMI_LUA_TNONE) #define xmi_lua_isnoneornil(lua, n) (xmi_lua_type(lua, (n)) <= 0) #define xmi_lua_tonumberx(lua, idx, isnum) (g_lua_ops)->_lua_tonumberx(lua, idx, isnum) #define xmi_lua_tointegerx(lua, idx, isnum) (g_lua_ops)->_lua_tointegerx(lua, idx, isnum) #define xmi_lua_toboolean(lua, idx) (g_lua_ops)->_lua_toboolean(lua, idx) #define xmi_lua_tolstring(lua, idx, len) (g_lua_ops)->_lua_tolstring(lua, idx, len) #define xmi_lua_rawlen(lua, idx) (g_lua_ops)->_lua_rawlen(lua, idx) #define xmi_lua_tocfunction(lua, idx) (g_lua_ops)->_lua_tocfunction(lua, idx) #define xmi_lua_touserdata(lua, idx) (g_lua_ops)->_lua_touserdata(lua, idx) #define xmi_lua_tothread(lua, idx) (g_lua_ops)->_lua_tothread(lua, idx) #define xmi_lua_topointer(lua, idx) (g_lua_ops)->_lua_topointer(lua, idx) #define xmi_lua_tonumber(lua, idx) xmi_lua_tonumberx(lua, (idx), NULL) #define xmi_lua_tostring(lua, idx) xmi_lua_tolstring(lua, (idx), NULL) #define xmi_lua_tointeger(lua, idx) xmi_lua_tointegerx(lua, (idx), NULL) // push macros #define xmi_lua_pushnil(lua) (g_lua_ops)->_lua_pushnil(lua) #define xmi_lua_pushinteger(lua, n) (g_lua_ops)->_lua_pushinteger(lua, n) #define xmi_lua_pushboolean(lua, b) (g_lua_ops)->_lua_pushboolean(lua, b) #define xmi_lua_pushnumber(lua, n) (g_lua_ops)->_lua_pushnumber(lua, n) #define xmi_lua_pushlstring(lua, s, len) (g_lua_ops)->_lua_pushlstring(lua, s, len) #define xmi_lua_pushstring(lua, s) (g_lua_ops)->_lua_pushstring(lua, s) #define xmi_lua_pushvfstring(lua, fmt, argp) (g_lua_ops)->_lua_pushvfstring(lua, fmt, argp) #if defined(_MSC_VER) # define xmi_lua_pushfstring(lua, fmt, ...) (g_lua_ops)->_lua_pushfstring(lua, fmt, __VA_ARGS__) #else # define xmi_lua_pushfstring(lua, fmt, arg ...) (g_lua_ops)->_lua_pushfstring(lua, fmt, ## arg) #endif #define xmi_lua_pushcclosure(lua, fn, n) (g_lua_ops)->_lua_pushcclosure(lua, fn, n) #define xmi_lua_pushlightuserdata(lua, p) (g_lua_ops)->_lua_pushlightuserdata(lua, p) #define xmi_lua_pushthread(lua) (g_lua_ops)->_lua_pushthread(lua) #define xmi_lua_pushcfunction(lua, f) xmi_lua_pushcclosure(lua, (f), 0) #define xmi_lua_pushliteral(lua, s) xmi_lua_pushstring(lua, "" s) // stack functions #ifdef XMI_USE_LUAJIT # define xmi_lua_insert(lua, idx) (g_lua_ops)->_lua_insert(lua, idx) # define xmi_lua_remove(lua, idx) (g_lua_ops)->_lua_remove(lua, idx) # define xmi_lua_replace(lua, idx) (g_lua_ops)->_lua_replace(lua, idx) #else # define xmi_lua_absindex(lua, idx) (g_lua_ops)->_lua_absindex(lua, idx) # define xmi_lua_rotate(lua, idx, n) (g_lua_ops)->_lua_rotate(lua, idx, n) # define xmi_lua_insert(lua, idx) xmi_lua_rotate(lua, (idx), 1) # define xmi_lua_remove(lua, idx) (xmi_lua_rotate(lua, (idx), -1), xmi_lua_pop(lua, 1)) # define xmi_lua_replace(lua, idx) (xmi_lua_copy(lua, -1, (idx)), xmi_lua_pop(lua, 1)) #endif #define xmi_lua_gettop(lua) (g_lua_ops)->_lua_gettop(lua) #define xmi_lua_settop(lua, idx) (g_lua_ops)->_lua_settop(lua, idx) #define xmi_lua_pushvalue(lua, idx) (g_lua_ops)->_lua_pushvalue(lua, idx) #define xmi_lua_copy(lua, fromidx, toidx) (g_lua_ops)->_lua_copy(lua, fromidx, toidx) #define xmi_lua_checkstack(lua, n) (g_lua_ops)->_lua_checkstack(lua, n) #define xmi_lua_xmove(from, to, n) (g_lua_ops)->_lua_xmove(from, to, n) // miscellaneous functions #define xmi_lua_error(lua) (g_lua_ops)->_lua_error(lua) #define xmi_lua_next(lua, idx) (g_lua_ops)->_lua_next(lua, idx) #define xmi_lua_concat(lua, n) (g_lua_ops)->_lua_concat(lua, n) #define xmi_lua_getallocf(lua, ud) (g_lua_ops)->_lua_getallocf(lua, ud) #define xmi_lua_setallocf(lua, f, ud) (g_lua_ops)->_lua_setallocf(lua, f, ud) #ifndef XMI_USE_LUAJIT # define xmi_lua_len(lua, idx) (g_lua_ops)->_lua_len(lua, idx) # define xmi_lua_toclose(lua, idx) (g_lua_ops)->_lua_toclose(lua, idx) # define xmi_lua_closeslot(lua, idx) (g_lua_ops)->_lua_closeslot(lua, idx) # define xmi_lua_stringtonumber(lua, s) (g_lua_ops)->_lua_stringtonumber(lua, s) #endif // 'load' and 'call' functions #ifdef XMI_USE_LUAJIT # define xmi_lua_call(lua, n, nr) (g_lua_ops)->_lua_call(lua, n, nr) # define xmi_lua_pcall(lua, n, nr, ef) (g_lua_ops)->_lua_pcall(lua, n, nr, ef) # define xmi_lua_load(lua, r, dt, ch) (g_lua_ops)->_lua_load(lua, r, dt, ch) # define xmi_lua_dump(lua, w, d) (g_lua_ops)->_lua_dump(lua, r, d) #else # define xmi_lua_callk(lua, n, nr, ctx, k) (g_lua_ops)->_lua_callk(lua, n, nr, ctx, k) # define xmi_lua_pcallk(lua, n, nr, ef, ctx, k) (g_lua_ops)->_lua_pcallk(lua, n, nr, ef, ctx, k) # define xmi_lua_call(lua, n, r) xmi_lua_callk(lua, (n), (r), 0, NULL) # define xmi_lua_pcall(lua, n, r, f) xmi_lua_pcallk(lua, (n), (r), (f), 0, NULL) # define xmi_lua_load(lua, r, dt, ch, mode) (g_lua_ops)->_lua_load(lua, r, dt, ch, mode) # define xmi_lua_dump(lua, w, d, strip) (g_lua_ops)->_lua_dump(lua, r, d, strip) #endif // luaL macros #ifndef XMI_USE_LUAJIT # define xmi_luaL_tolstring(lua, idx, len) (g_lua_ops)->_luaL_tolstring(lua, idx, len) # define xmi_luaL_typeerror(lua, arg, tname) (g_lua_ops)->_luaL_typeerror(lua, arg, tname) #endif #define xmi_luaL_getmetafield(lua, obj, e) (g_lua_ops)->_luaL_getmetafield(lua, obj, e) #define xmi_luaL_callmeta(lua, obj, e) (g_lua_ops)->_luaL_callmeta(lua, obj, e) #define xmi_luaL_argerror(lua, numarg, extramsg) (g_lua_ops)->_luaL_argerror(lua, numarg, extramsg) #define xmi_luaL_checklstring(lua, arg, l) (g_lua_ops)->_luaL_checklstring(lua, arg, l) #define xmi_luaL_optlstring(lua, arg, def, l) (g_lua_ops)->_luaL_optlstring(lua, arg, def, l) #define xmi_luaL_checknumber(lua, arg) (g_lua_ops)->_luaL_checknumber(lua, arg) #define xmi_luaL_optnumber(lua, arg, def) (g_lua_ops)->_luaL_optnumber(lua, arg, def) #define xmi_luaL_checkinteger(lua, idx) (g_lua_ops)->_luaL_checkinteger(lua, idx) #define xmi_luaL_optinteger(lua, arg, def) (g_lua_ops)->_luaL_optinteger(lua, arg, def) #define xmi_luaL_checkstack(lua, sz, msg) (g_lua_ops)->_luaL_checkstack(lua, sz, msg) #define xmi_luaL_checktype(lua, arg, t) (g_lua_ops)->_luaL_checktype(lua, arg, t) #define xmi_luaL_checkany(lua, arg) (g_lua_ops)->_luaL_checkany(lua, arg) #define xmi_luaL_newmetatable(lua, tname) (g_lua_ops)->_luaL_newmetatable(lua, tname) #define xmi_luaL_setmetatable(lua, tname) (g_lua_ops)->_luaL_setmetatable(lua, tname) #define xmi_luaL_testudata(lua, tname) (g_lua_ops)->_luaL_testudata(lua, tname) #define xmi_luaL_checkudata(lua, tname) (g_lua_ops)->_luaL_checkudata(lua, tname) #define xmi_luaL_where(lua, lvl) (g_lua_ops)->_luaL_where(lua, lvl) #if defined(_MSC_VER) # define xmi_luaL_error(lua, fmt, ...) (g_lua_ops)->_luaL_error(lua, fmt, __VA_ARGS__) #else # define xmi_luaL_error(lua, fmt, arg ...) (g_lua_ops)->_luaL_error(lua, fmt, ## arg) #endif #define xmi_luaL_checkoption(lua, arg, def, lst) (g_lua_ops)->_luaL_checkoption(lua, arg, def, lst) #define xmi_luaL_fileresult(lua, stat, fname) (g_lua_ops)->_luaL_fileresult(lua, stat, fname) #define xmi_luaL_execresult(lua, stat) (g_lua_ops)->_luaL_execresult(lua, stat) #define xmi_luaL_setfuncs(lua, l, nup) (g_lua_ops)->_luaL_setfuncs(lua, l, nup) #define xmi_luaL_newlibtable(lua, l) xml_lua_createtable(lua, 0, sizeof(l)/sizeof((l)[0]) - 1) #define xmi_luaL_newlib(lua, l) \ (xmi_luaL_checkversion(lua), xmi_luaL_newlibtable(lua,l), xmi_luaL_setfuncs(lua,l,0)) #define xmi_luaL_argcheck(lua, cond, arg, extramsg) \ ((void)(luai_likely(cond) || xmi_luaL_argerror(lua, (arg), (extramsg)))) #define xmi_luaL_argexpected(lua, cond, arg, tname) \ ((void)(luai_likely(cond) || xmi_luaL_typeerror(lua, (arg), (tname)))) #define xmi_luaL_checkstring(lua, n) (xmi_luaL_checklstring(lua, (n), NULL)) #define xmi_luaL_optstring(lua, n, d) (xmi_luaL_optlstring(lua, (n), (d), NULL)) #define xmi_luaL_typename(lua, i) xmi_lua_typename(lua, xmi_lua_type(lua,(i))) #define xmi_luaL_dofile(lua, fn) \ (xmi_luaL_loadfile(lua, fn) || xmi_lua_pcall(lua, 0, XMI_LUA_MULTRET, 0)) #define xmi_luaL_dostring(lua, s) \ (xmi_luaL_loadstring(lua, s) || xmi_lua_pcall(lua, 0, XMI_LUA_MULTRET, 0)) #define xmi_luaL_getmetatable(lua, n) (xmi_lua_getfield(lua, XMI_LUA_REGISTRYINDEX, (n))) #define xmi_luaL_opt(lua, f, n, d) (xmi_lua_isnoneornil(lua,(n)) ? (d) : f(lua,(n))) #define xmi_luaL_loadbuffer(lua, s, sz, n) xmi_luaL_loadbufferx(lua, s, sz, n, NULL) #define xmi_luaL_pushfail(lua) xmi_lua_pushnil(lua) /* we cannot redefine lua functions in loadxmi.c, * because original lua.h has been included */ #ifndef XM_PREFIX_H // thread status # define LUA_OK XMI_LUA_OK # define LUA_YIELD XMI_LUA_YIELD # define LUA_ERRRUN XMI_LUA_ERRRUN # define LUA_ERRSYNTAX XMI_LUA_ERRSYNTAX # define LUA_ERRMEM XMI_LUA_ERRMEM # define LUA_ERRERR XMI_LUA_ERRERR // basic types # define LUA_TNONE XMI_LUA_TNONE # define LUA_TNIL XMI_LUA_TNIL # define LUA_TBOOLEAN XMI_LUA_TBOOLEAN # define LUA_TLIGHTUSERDATA XMI_LUA_TLIGHTUSERDATA # define LUA_TNUMBER XMI_LUA_TNUMBER # define LUA_TSTRING XMI_LUA_TSTRING # define LUA_TTABLE XMI_LUA_TTABLE # define LUA_TFUNCTION XMI_LUA_TFUNCTION # define LUA_TUSERDATA XMI_LUA_TUSERDATA # define LUA_TTHREAD XMI_LUA_TTHREAD # define LUA_NUMTYPES XMI_LUA_NUMTYPES // get macros # define lua_getglobal xmi_lua_getglobal # define lua_gettable xmi_lua_gettable # define lua_getfield xmi_lua_getfield # define lua_geti xmi_lua_geti # define lua_rawget xmi_lua_rawget # define lua_rawgeti xmi_lua_rawgeti # define lua_rawgetp xmi_lua_rawgetp # define lua_createtable xmi_lua_createtable # define lua_newuserdatauv xmi_lua_newuserdatauv # define lua_getmetatable xmi_lua_getmetatable # define lua_getiuservalue xmi_lua_getiuservalue # define lua_upvalueindex xmi_lua_upvalueindex # define lua_newtable xmi_lua_newtable # define lua_pop xmi_lua_pop # define lua_newuserdata xmi_lua_newuserdata # define lua_getuservalue xmi_lua_getuservalue // set macros # define lua_setglobal xmi_lua_setglobal # define lua_settable xmi_lua_settable # define lua_setfield xmi_lua_setfield # define lua_seti xmi_lua_seti # define lua_rawset xmi_lua_rawset # define lua_rawseti xmi_lua_rawseti # define lua_rawsetp xmi_lua_rawsetp # define lua_setmetatable xmi_lua_setmetatable # define lua_setiuservalue xmi_lua_setiuservalue # define lua_setuservalue xmi_lua_setuservalue // access macros # define lua_isnumber xmi_lua_isnumber # define lua_isstring xmi_lua_isstring # define lua_iscfunction xmi_lua_iscfunction # define lua_isuserdata xmi_lua_isuserdata # define lua_type xmi_lua_type # define lua_typename xmi_lua_typename # ifndef XMI_USE_LUAJIT # define lua_isinteger xmi_lua_isinteger # endif # define lua_isfunction xmi_lua_isfunction # define lua_istable xmi_lua_istable # define lua_islightuserdata xmi_lua_islightuserdata # define lua_isnil xmi_lua_isnil # define lua_isboolean xmi_lua_isboolean # define lua_isthread xmi_lua_isthread # define lua_isnone xmi_lua_isnone # define lua_isnoneornil xmi_lua_isnoneornil # define lua_tonumberx xmi_lua_tonumberx # define lua_tointegerx xmi_lua_tointegerx # define lua_toboolean xmi_lua_toboolean # define lua_tolstring xmi_lua_tolstring # define lua_rawlen xmi_lua_rawlen # define lua_tocfunction xmi_lua_tocfunction # define lua_touserdata xmi_lua_touserdata # define lua_tothread xmi_lua_tothread # define lua_topointer xmi_lua_topointer # define lua_tostring xmi_lua_tostring # define lua_tonumber xmi_lua_tonumber # define lua_tointeger xmi_lua_tointeger // push macros # define lua_pushnil xmi_lua_pushnil # define lua_pushinteger xmi_lua_pushinteger # define lua_pushboolean xmi_lua_pushboolean # define lua_pushnumber xmi_lua_pushnumber # define lua_pushlstring xmi_lua_pushlstring # define lua_pushstring xmi_lua_pushstring # define lua_pushvfstring xmi_lua_pushvfstring # define lua_pushfstring xmi_lua_pushfstring # define lua_pushcclosure xmi_lua_pushcclosure # define lua_pushlightuserdata xmi_lua_pushlightuserdata # define lua_pushthread xmi_lua_pushthread # define lua_pushcfunction xmi_lua_pushcfunction # define lua_pushliteral xmi_lua_pushliteral // stack functions # define lua_absindex xmi_lua_absindex # define lua_gettop xmi_lua_gettop # define lua_settop xmi_lua_settop # define lua_pushvalue xmi_lua_pushvalue # define lua_rotate xmi_lua_rotate # define lua_copy xmi_lua_copy # define lua_checkstack xmi_lua_checkstack # define lua_xmove xmi_lua_xmove # define lua_insert xmi_lua_insert # define lua_remove xmi_lua_remove # define lua_replace xmi_lua_replace // miscellaneous functions # define lua_error xmi_lua_error # define lua_next xmi_lua_next # define lua_concat xmi_lua_concat # define lua_len xmi_lua_len # define lua_stringtonumber xmi_lua_stringtonumber # define lua_getallocf xmi_lua_getallocf # define lua_setallocf xmi_lua_setallocf # define lua_toclose xmi_lua_toclose # define lua_closeslot xmi_lua_closeslot // 'load' and 'call' functions # ifndef XMI_USE_LUAJIT # define lua_callk xmi_lua_callk # define lua_pcallk xmi_lua_pcallk # endif # define lua_call xmi_lua_call # define lua_pcall xmi_lua_pcall # define lua_load xmi_lua_load # define lua_dump xmi_lua_dump // luaL macros # define luaL_getmetafield xmi_luaL_getmetafield # define luaL_callmeta xmi_luaL_callmeta # define luaL_tolstring xmi_luaL_tolstring # define luaL_argerror xmi_luaL_argerror # define luaL_typeerror xmi_luaL_typeerror # define luaL_checklstring xmi_luaL_checklstring # define luaL_optlstring xmi_luaL_optlstring # define luaL_checknumber xmi_luaL_checknumber # define luaL_optnumber xmi_luaL_optnumber # define luaL_checkinteger xmi_luaL_checkinteger # define luaL_optinteger xmi_luaL_optinteger # define luaL_checkstack xmi_luaL_checkstack # define luaL_checktype xmi_luaL_checktype # define luaL_checkany xmi_luaL_checkany # define luaL_newmetatable xmi_luaL_newmetatable # define luaL_setmetatable xmi_luaL_setmetatable # define luaL_testudata xmi_luaL_testudata # define luaL_checkudata xmi_luaL_checkudata # define luaL_where xmi_luaL_where # define luaL_error xmi_luaL_error # define luaL_checkoption xmi_luaL_checkoption # define luaL_fileresult xmi_luaL_fileresult # define luaL_execresult xmi_luaL_execresult # define luaL_setfuncs xmi_luaL_setfuncs # define luaL_newlibtable xmi_luaL_newlibtable # define luaL_newlib xmi_luaL_newlib # define luaL_argcheck xmi_luaL_argcheck # define luaL_argexpected xmi_luaL_argexpected # define luaL_checkstring xmi_luaL_checkstring # define luaL_optstring xmi_luaL_optstring # define luaL_typename xmi_luaL_typename # define luaL_dofile xmi_luaL_dofile # define luaL_dostring xmi_luaL_dostring # define luaL_getmetatable xmi_luaL_getmetatable # define luaL_opt xmi_luaL_opt # define luaL_loadbuffer xmi_luaL_loadbuffer # define luaL_pushfail xmi_luaL_pushfail // types # define luaL_Reg xmi_luaL_Reg # define lua_State xmi_lua_State # define lua_Number xmi_lua_Number # define lua_Integer xmi_lua_Integer # define lua_Unsigned xmi_lua_Unsigned # define lua_KContext xmi_lua_KContext # define lua_CFunction xmi_lua_CFunction # define lua_KFunction xmi_lua_KFunction # define lua_Reader xmi_lua_Reader # define lua_Writer xmi_lua_Writer # define lua_Alloc xmi_lua_Alloc # define lua_WarnFunction xmi_lua_WarnFunction #endif // extern c #ifdef __cplusplus # define xmi_extern_c_enter extern "C" { # define xmi_extern_c_leave } #else # define xmi_extern_c_enter # define xmi_extern_c_leave #endif // define lua module entry function #define luaopen(name, lua) \ __dummy = 1; \ xmi_lua_ops_t* g_lua_ops = NULL; \ xmi_extern_c_enter \ int xmiopen_##name(lua); \ xmi_extern_c_leave \ int xmisetup(xmi_lua_ops_t* ops) { \ g_lua_ops = ops; \ return __dummy; \ } \ int xmiopen_##name(lua) /* ////////////////////////////////////////////////////////////////////////////////////// * types */ typedef LUA_NUMBER xmi_lua_Number; typedef LUA_INTEGER xmi_lua_Integer; #ifndef XMI_USE_LUAJIT typedef LUA_UNSIGNED xmi_lua_Unsigned; typedef LUA_KCONTEXT xmi_lua_KContext; #endif typedef struct xmi_lua_State_ { int dummy; }xmi_lua_State; typedef int (*xmi_lua_CFunction)(lua_State* lua); #ifndef XMI_USE_LUAJIT typedef int (*xmi_lua_KFunction)(lua_State* lua, int status, lua_KContext ctx); #endif typedef const char* (*xmi_lua_Reader)(lua_State* lua, void* ud, size_t* sz); typedef int (*xmi_lua_Writer)(lua_State* lua, const void* p, size_t sz, void* ud); typedef void* (*xmi_lua_Alloc)(void* ud, void* ptr, size_t osize, size_t nsize); typedef void (*xmi_lua_WarnFunction)(void* ud, const char* msg, int tocont); typedef struct xmi_luaL_Reg_ { char const* name; xmi_lua_CFunction func; }xmi_luaL_Reg; typedef struct xmi_lua_ops_t_ { // get functions #ifdef XMI_USE_LUAJIT void* (*_lua_newuserdata)(lua_State* lua, size_t sz); void (*_lua_gettable)(lua_State* lua, int idx); void (*_lua_getfield)(lua_State* lua, int idx, const char* k); void (*_lua_rawgeti)(lua_State* lua, int idx, int n); void (*_lua_rawget)(lua_State* lua, int idx); #else int (*_lua_getglobal)(lua_State* lua, const char* name); int (*_lua_geti)(lua_State* lua, int idx, lua_Integer n); int (*_lua_rawgetp)(lua_State* lua, int idx, const void* p); int (*_lua_getiuservalue)(lua_State* lua, int idx, int n); void* (*_lua_newuserdatauv)(lua_State* lua, size_t sz, int nuvalue); int (*_lua_gettable)(lua_State* lua, int idx); int (*_lua_getfield)(lua_State* lua, int idx, const char* k); int (*_lua_rawgeti)(lua_State* lua, int idx, lua_Integer n); int (*_lua_rawget)(lua_State* lua, int idx); #endif void (*_lua_createtable)(lua_State* lua, int narr, int nrec); int (*_lua_getmetatable)(lua_State* lua, int objindex); // set functions #ifdef XMI_USE_LUAJIT void (*_lua_rawseti)(lua_State* lua, int idx, int n); #else void (*_lua_setglobal)(lua_State* lua, const char* name); void (*_lua_seti)(lua_State* lua, int idx, lua_Integer n); void (*_lua_rawsetp)(lua_State* lua, int idx, const void* p); int (*_lua_setiuservalue)(lua_State* lua, int idx, int n); void (*_lua_rawseti)(lua_State* lua, int idx, lua_Integer n); #endif void (*_lua_settable)(lua_State* lua, int idx); void (*_lua_setfield)(lua_State* lua, int idx, const char* k); void (*_lua_rawset)(lua_State* lua, int idx); int (*_lua_setmetatable)(lua_State* lua, int objindex); // access functions int (*_lua_isnumber)(lua_State* lua, int idx); int (*_lua_isstring)(lua_State* lua, int idx); int (*_lua_iscfunction)(lua_State* lua, int idx); int (*_lua_isuserdata)(lua_State* lua, int idx); int (*_lua_type)(lua_State* lua, int idx); const char* (*_lua_typename)(lua_State* lua, int tp); #ifndef XMI_USE_LUAJIT int (*_lua_isinteger)(lua_State* lua, int idx); #endif lua_Number (*_lua_tonumberx)(lua_State* lua, int idx, int* isnum); lua_Integer (*_lua_tointegerx)(lua_State* lua, int idx, int* isnum); int (*_lua_toboolean)(lua_State* lua, int idx); const char* (*_lua_tolstring)(lua_State* lua, int idx, size_t* len); lua_CFunction (*_lua_tocfunction)(lua_State* lua, int idx); void* (*_lua_touserdata)(lua_State* lua, int idx); lua_State* (*_lua_tothread)(lua_State* lua, int idx); const void* (*_lua_topointer)(lua_State* lua, int idx); #ifndef XMI_USE_LUAJIT lua_Unsigned (*_lua_rawlen)(lua_State* lua, int idx); #endif // push functions void (*_lua_pushnil)(lua_State* lua); void (*_lua_pushinteger)(lua_State* lua, lua_Integer n); void (*_lua_pushboolean)(lua_State* lua, int b); void (*_lua_pushnumber)(lua_State* lua, lua_Number n); #ifdef XMI_USE_LUAJIT void (*_lua_pushlstring)(lua_State* lua, const char* s, size_t len); void (*_lua_pushstring)(lua_State* lua, const char* s); #else const char* (*_lua_pushlstring)(lua_State* lua, const char* s, size_t len); const char* (*_lua_pushstring)(lua_State* lua, const char* s); #endif const char* (*_lua_pushvfstring)(lua_State* lua, const char* fmt, va_list argp); const char* (*_lua_pushfstring)(lua_State* lua, const char* fmt, ...); void (*_lua_pushcclosure)(lua_State* lua, lua_CFunction fn, int n); void (*_lua_pushlightuserdata)(lua_State* lua, void* p); int (*_lua_pushthread)(lua_State* lua); // stack functions #ifdef XMI_USE_LUAJIT void (*_lua_insert)(lua_State* lua, int idx); void (*_lua_remove)(lua_State* lua, int idx); void (*_lua_replace)(lua_State* lua, int idx); #else int (*_lua_absindex)(lua_State* lua, int idx); void (*_lua_rotate)(lua_State* lua, int idx, int n); #endif int (*_lua_gettop)(lua_State* lua); void (*_lua_settop)(lua_State* lua, int idx); void (*_lua_pushvalue)(lua_State* lua, int idx); void (*_lua_copy)(lua_State* lua, int fromidx, int toidx); int (*_lua_checkstack)(lua_State* lua, int n); void (*_lua_xmove)(lua_State* from, lua_State* to, int n); // miscellaneous functions int (*_lua_error)(lua_State* lua); int (*_lua_next)(lua_State* lua, int idx); void (*_lua_concat)(lua_State* lua, int n); lua_Alloc (*_lua_getallocf)(lua_State* lua, void** ud); void (*_lua_setallocf)(lua_State* lua, lua_Alloc f, void* ud); #ifndef XMI_USE_LUAJIT void (*_lua_len)(lua_State* lua, int idx); void (*_lua_toclose)(lua_State* lua, int idx); void (*_lua_closeslot)(lua_State* lua, int idx); size_t (*_lua_stringtonumber)(lua_State* lua, const char* s); #endif // 'load' and 'call' functions #ifdef XMI_USE_LUAJIT void (*_lua_call)(lua_State* lua, int nargs, int nresults); int (*_lua_pcall)(lua_State* lua, int nargs, int nresults, int errfunc); int (*_lua_load)(lua_State* lua, lua_Reader reader, void* dt, const char* chunkname); int (*_lua_dump)(lua_State* lua, lua_Writer writer, void* data); #else void (*_lua_callk)(lua_State* lua, int nargs, int nresults, lua_KContext ctx, lua_KFunction k); int (*_lua_pcallk)(lua_State* lua, int nargs, int nresults, int errfunc, lua_KContext ctx, lua_KFunction k); int (*_lua_load)(lua_State* lua, lua_Reader reader, void* dt, const char* chunkname, const char* mode); int (*_lua_dump)(lua_State* lua, lua_Writer writer, void* data, int strip); #endif // luaL functions #ifndef XMI_USE_LUAJIT const char* (*_luaL_tolstring)(lua_State* lua, int idx, size_t* len); int (*_luaL_typeerror)(lua_State* lua, int arg, const char* tname); #endif int (*_luaL_getmetafield)(lua_State* lua, int obj, const char* e); int (*_luaL_callmeta)(lua_State* lua, int obj, const char* e); int (*_luaL_argerror)(lua_State* lua, int numarg, const char* extramsg); const char* (*_luaL_checklstring)(lua_State* lua, int arg, size_t* l); const char* (*_luaL_optlstring)(lua_State* lua, int arg, const char* def, size_t* l); lua_Number (*_luaL_checknumber)(lua_State* lua, int arg); lua_Number (*_luaL_optnumber)(lua_State* lua, int arg, lua_Number def); lua_Integer (*_luaL_checkinteger)(lua_State* lua, int idx); lua_Integer (*_luaL_optinteger)(lua_State* lua, int arg, lua_Integer def); void (*_luaL_checkstack)(lua_State* lua, int sz, const char* msg); void (*_luaL_checktype)(lua_State* lua, int arg, int t); void (*_luaL_checkany)(lua_State* lua, int arg); int (*_luaL_newmetatable)(lua_State* lua, const char* tname); void (*_luaL_setmetatable)(lua_State* lua, const char* tname); void* (*_luaL_testudata)(lua_State* lua, int ud, const char* tname); void* (*_luaL_checkudata)(lua_State* lua, int ud, const char* tname); void (*_luaL_where)(lua_State* lua, int lvl); int (*_luaL_error)(lua_State* lua, const char* fmt, ...); int (*_luaL_checkoption)(lua_State* lua, int arg, const char* def, const char* const lst[]); int (*_luaL_fileresult)(lua_State* lua, int stat, const char* fname); int (*_luaL_execresult)(lua_State* lua, int stat); void (*_luaL_setfuncs)(lua_State* lua, const luaL_Reg* l, int nup); }xmi_lua_ops_t; /* ////////////////////////////////////////////////////////////////////////////////////// * globals */ extern xmi_lua_ops_t* g_lua_ops; /* ////////////////////////////////////////////////////////////////////////////////////// * interfaces */ xmi_extern_c_enter // setup lua interfaces int xmisetup(xmi_lua_ops_t* ops); xmi_extern_c_leave #endif
0
repos/xmake/xmake/scripts/module
repos/xmake/xmake/scripts/module/luawrap/lauxlib.h
/*!A cross-platform build utility based on Lua * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Copyright (C) 2015-present, TBOOX Open Source Group. * * @author ruki * @file luaxlib.h * */ #ifndef XMI_LUAXLIB_H #define XMI_LUAXLIB_H /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "xmi.h" #endif
0
repos/xmake/xmake/scripts/module
repos/xmake/xmake/scripts/module/luawrap/luaconf.h
/* ** $Id: luaconf.h $ ** Configuration file for Lua ** See Copyright Notice in lua.h */ #ifndef luaconf_h #define luaconf_h #include <limits.h> #include <stddef.h> /* ** =================================================================== ** General Configuration File for Lua ** ** Some definitions here can be changed externally, through the compiler ** (e.g., with '-D' options): They are commented out or protected ** by '#if !defined' guards. However, several other definitions ** should be changed directly here, either because they affect the ** Lua ABI (by making the changes here, you ensure that all software ** connected to Lua, such as C libraries, will be compiled with the same ** configuration); or because they are seldom changed. ** ** Search for "@@" to find all configurable definitions. ** =================================================================== */ /* ** {==================================================================== ** System Configuration: macros to adapt (if needed) Lua to some ** particular platform, for instance restricting it to C89. ** ===================================================================== */ /* @@ LUA_USE_C89 controls the use of non-ISO-C89 features. ** Define it if you want Lua to avoid the use of a few C99 features ** or Windows-specific features on Windows. */ /* #define LUA_USE_C89 */ /* ** By default, Lua on Windows use (some) specific Windows features */ #if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE) #define LUA_USE_WINDOWS /* enable goodies for regular Windows */ #endif #if defined(LUA_USE_WINDOWS) #define LUA_DL_DLL /* enable support for DLL */ #define LUA_USE_C89 /* broadly, Windows is C89 */ #endif #if defined(LUA_USE_LINUX) #define LUA_USE_POSIX #define LUA_USE_DLOPEN /* needs an extra library: -ldl */ #endif #if defined(LUA_USE_MACOSX) #define LUA_USE_POSIX #define LUA_USE_DLOPEN /* MacOS does not need -ldl */ #endif /* @@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits. */ #define LUAI_IS32INT ((UINT_MAX >> 30) >= 3) /* }================================================================== */ /* ** {================================================================== ** Configuration for Number types. These options should not be ** set externally, because any other code connected to Lua must ** use the same configuration. ** =================================================================== */ /* @@ LUA_INT_TYPE defines the type for Lua integers. @@ LUA_FLOAT_TYPE defines the type for Lua floats. ** Lua should work fine with any mix of these options supported ** by your C compiler. The usual configurations are 64-bit integers ** and 'double' (the default), 32-bit integers and 'float' (for ** restricted platforms), and 'long'/'double' (for C compilers not ** compliant with C99, which may not have support for 'long long'). */ /* predefined options for LUA_INT_TYPE */ #define LUA_INT_INT 1 #define LUA_INT_LONG 2 #define LUA_INT_LONGLONG 3 /* predefined options for LUA_FLOAT_TYPE */ #define LUA_FLOAT_FLOAT 1 #define LUA_FLOAT_DOUBLE 2 #define LUA_FLOAT_LONGDOUBLE 3 /* Default configuration ('long long' and 'double', for 64-bit Lua) */ #define LUA_INT_DEFAULT LUA_INT_LONGLONG #define LUA_FLOAT_DEFAULT LUA_FLOAT_DOUBLE /* @@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. */ #define LUA_32BITS 0 /* @@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for ** C89 ('long' and 'double'); Windows always has '__int64', so it does ** not need to use this case. */ #if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS) #define LUA_C89_NUMBERS 1 #else #define LUA_C89_NUMBERS 0 #endif #if LUA_32BITS /* { */ /* ** 32-bit integers and 'float' */ #if LUAI_IS32INT /* use 'int' if big enough */ #define LUA_INT_TYPE LUA_INT_INT #else /* otherwise use 'long' */ #define LUA_INT_TYPE LUA_INT_LONG #endif #define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT #elif LUA_C89_NUMBERS /* }{ */ /* ** largest types available for C89 ('long' and 'double') */ #define LUA_INT_TYPE LUA_INT_LONG #define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE #else /* }{ */ /* use defaults */ #define LUA_INT_TYPE LUA_INT_DEFAULT #define LUA_FLOAT_TYPE LUA_FLOAT_DEFAULT #endif /* } */ /* }================================================================== */ /* ** {================================================================== ** Configuration for Paths. ** =================================================================== */ /* ** LUA_PATH_SEP is the character that separates templates in a path. ** LUA_PATH_MARK is the string that marks the substitution points in a ** template. ** LUA_EXEC_DIR in a Windows path is replaced by the executable's ** directory. */ #define LUA_PATH_SEP ";" #define LUA_PATH_MARK "?" #define LUA_EXEC_DIR "!" /* @@ LUA_PATH_DEFAULT is the default path that Lua uses to look for ** Lua libraries. @@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for ** C libraries. ** CHANGE them if your machine has a non-conventional directory ** hierarchy or if you want to install your libraries in ** non-conventional directories. */ #define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR #if defined(_WIN32) /* { */ /* ** In Windows, any exclamation mark ('!') in the path is replaced by the ** path of the directory of the executable file of the current process. */ #define LUA_LDIR "!\\lua\\" #define LUA_CDIR "!\\" #define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\" #if !defined(LUA_PATH_DEFAULT) #define LUA_PATH_DEFAULT \ LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \ LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \ LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \ ".\\?.lua;" ".\\?\\init.lua" #endif #if !defined(LUA_CPATH_DEFAULT) #define LUA_CPATH_DEFAULT \ LUA_CDIR"?.dll;" \ LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \ LUA_CDIR"loadall.dll;" ".\\?.dll" #endif #else /* }{ */ #define LUA_ROOT "/usr/local/" #define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/" #define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/" #if !defined(LUA_PATH_DEFAULT) #define LUA_PATH_DEFAULT \ LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \ LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \ "./?.lua;" "./?/init.lua" #endif #if !defined(LUA_CPATH_DEFAULT) #define LUA_CPATH_DEFAULT \ LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so" #endif #endif /* } */ /* @@ LUA_DIRSEP is the directory separator (for submodules). ** CHANGE it if your machine does not use "/" as the directory separator ** and is not Windows. (On Windows Lua automatically uses "\".) */ #if !defined(LUA_DIRSEP) #if defined(_WIN32) #define LUA_DIRSEP "\\" #else #define LUA_DIRSEP "/" #endif #endif /* }================================================================== */ /* ** {================================================================== ** Marks for exported symbols in the C code ** =================================================================== */ /* @@ LUA_API is a mark for all core API functions. @@ LUALIB_API is a mark for all auxiliary library functions. @@ LUAMOD_API is a mark for all standard library opening functions. ** CHANGE them if you need to define those functions in some special way. ** For instance, if you want to create one Windows DLL with the core and ** the libraries, you may want to use the following definition (define ** LUA_BUILD_AS_DLL to get it). */ #if defined(LUA_BUILD_AS_DLL) /* { */ #if defined(LUA_CORE) || defined(LUA_LIB) /* { */ #define LUA_API __declspec(dllexport) #else /* }{ */ #define LUA_API __declspec(dllimport) #endif /* } */ #else /* }{ */ #define LUA_API extern #endif /* } */ /* ** More often than not the libs go together with the core. */ #define LUALIB_API LUA_API #define LUAMOD_API LUA_API /* @@ LUAI_FUNC is a mark for all extern functions that are not to be ** exported to outside modules. @@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables, ** none of which to be exported to outside modules (LUAI_DDEF for ** definitions and LUAI_DDEC for declarations). ** CHANGE them if you need to mark them in some special way. Elf/gcc ** (versions 3.2 and later) mark them as "hidden" to optimize access ** when Lua is compiled as a shared library. Not all elf targets support ** this attribute. Unfortunately, gcc does not offer a way to check ** whether the target offers that support, and those without support ** give a warning about it. To avoid these warnings, change to the ** default definition. */ #if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ defined(__ELF__) /* { */ #define LUAI_FUNC __attribute__((visibility("internal"))) extern #else /* }{ */ #define LUAI_FUNC extern #endif /* } */ #define LUAI_DDEC(dec) LUAI_FUNC dec #define LUAI_DDEF /* empty */ /* }================================================================== */ /* ** {================================================================== ** Compatibility with previous versions ** =================================================================== */ /* @@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.3. ** You can define it to get all options, or change specific options ** to fit your specific needs. */ #if defined(LUA_COMPAT_5_3) /* { */ /* @@ LUA_COMPAT_MATHLIB controls the presence of several deprecated ** functions in the mathematical library. ** (These functions were already officially removed in 5.3; ** nevertheless they are still available here.) */ #define LUA_COMPAT_MATHLIB /* @@ LUA_COMPAT_APIINTCASTS controls the presence of macros for ** manipulating other integer types (lua_pushunsigned, lua_tounsigned, ** luaL_checkint, luaL_checklong, etc.) ** (These macros were also officially removed in 5.3, but they are still ** available here.) */ #define LUA_COMPAT_APIINTCASTS /* @@ LUA_COMPAT_LT_LE controls the emulation of the '__le' metamethod ** using '__lt'. */ #define LUA_COMPAT_LT_LE /* @@ The following macros supply trivial compatibility for some ** changes in the API. The macros themselves document how to ** change your code to avoid using them. ** (Once more, these macros were officially removed in 5.3, but they are ** still available here.) */ #define lua_strlen(L,i) lua_rawlen(L, (i)) #define lua_objlen(L,i) lua_rawlen(L, (i)) #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) #endif /* } */ /* }================================================================== */ /* ** {================================================================== ** Configuration for Numbers (low-level part). ** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_* ** satisfy your needs. ** =================================================================== */ /* @@ LUAI_UACNUMBER is the result of a 'default argument promotion' @@ over a floating number. @@ l_floatatt(x) corrects float attribute 'x' to the proper float type ** by prefixing it with one of FLT/DBL/LDBL. @@ LUA_NUMBER_FRMLEN is the length modifier for writing floats. @@ LUA_NUMBER_FMT is the format for writing floats. @@ lua_number2str converts a float to a string. @@ l_mathop allows the addition of an 'l' or 'f' to all math operations. @@ l_floor takes the floor of a float. @@ lua_str2number converts a decimal numeral to a number. */ /* The following definitions are good for most cases here */ #define l_floor(x) (l_mathop(floor)(x)) #define lua_number2str(s,sz,n) \ l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n)) /* @@ lua_numbertointeger converts a float number with an integral value ** to an integer, or returns 0 if float is not within the range of ** a lua_Integer. (The range comparisons are tricky because of ** rounding. The tests here assume a two-complement representation, ** where MININTEGER always has an exact representation as a float; ** MAXINTEGER may not have one, and therefore its conversion to float ** may have an ill-defined value.) */ #define lua_numbertointeger(n,p) \ ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \ (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \ (*(p) = (LUA_INTEGER)(n), 1)) /* now the variable definitions */ #if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */ #define LUA_NUMBER float #define l_floatatt(n) (FLT_##n) #define LUAI_UACNUMBER double #define LUA_NUMBER_FRMLEN "" #define LUA_NUMBER_FMT "%.7g" #define l_mathop(op) op##f #define lua_str2number(s,p) strtof((s), (p)) #elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */ #define LUA_NUMBER long double #define l_floatatt(n) (LDBL_##n) #define LUAI_UACNUMBER long double #define LUA_NUMBER_FRMLEN "L" #define LUA_NUMBER_FMT "%.19Lg" #define l_mathop(op) op##l #define lua_str2number(s,p) strtold((s), (p)) #elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */ #define LUA_NUMBER double #define l_floatatt(n) (DBL_##n) #define LUAI_UACNUMBER double #define LUA_NUMBER_FRMLEN "" #define LUA_NUMBER_FMT "%.14g" #define l_mathop(op) op #define lua_str2number(s,p) strtod((s), (p)) #else /* }{ */ #error "numeric float type not defined" #endif /* } */ /* @@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER. @@ LUAI_UACINT is the result of a 'default argument promotion' @@ over a LUA_INTEGER. @@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers. @@ LUA_INTEGER_FMT is the format for writing integers. @@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER. @@ LUA_MININTEGER is the minimum value for a LUA_INTEGER. @@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED. @@ LUA_UNSIGNEDBITS is the number of bits in a LUA_UNSIGNED. @@ lua_integer2str converts an integer to a string. */ /* The following definitions are good for most cases here */ #define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d" #define LUAI_UACINT LUA_INTEGER #define lua_integer2str(s,sz,n) \ l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n)) /* ** use LUAI_UACINT here to avoid problems with promotions (which ** can turn a comparison between unsigneds into a signed comparison) */ #define LUA_UNSIGNED unsigned LUAI_UACINT #define LUA_UNSIGNEDBITS (sizeof(LUA_UNSIGNED) * CHAR_BIT) /* now the variable definitions */ #if LUA_INT_TYPE == LUA_INT_INT /* { int */ #define LUA_INTEGER int #define LUA_INTEGER_FRMLEN "" #define LUA_MAXINTEGER INT_MAX #define LUA_MININTEGER INT_MIN #define LUA_MAXUNSIGNED UINT_MAX #elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */ #define LUA_INTEGER long #define LUA_INTEGER_FRMLEN "l" #define LUA_MAXINTEGER LONG_MAX #define LUA_MININTEGER LONG_MIN #define LUA_MAXUNSIGNED ULONG_MAX #elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */ /* use presence of macro LLONG_MAX as proxy for C99 compliance */ #if defined(LLONG_MAX) /* { */ /* use ISO C99 stuff */ #define LUA_INTEGER long long #define LUA_INTEGER_FRMLEN "ll" #define LUA_MAXINTEGER LLONG_MAX #define LUA_MININTEGER LLONG_MIN #define LUA_MAXUNSIGNED ULLONG_MAX #elif defined(LUA_USE_WINDOWS) /* }{ */ /* in Windows, can use specific Windows types */ #define LUA_INTEGER __int64 #define LUA_INTEGER_FRMLEN "I64" #define LUA_MAXINTEGER _I64_MAX #define LUA_MININTEGER _I64_MIN #define LUA_MAXUNSIGNED _UI64_MAX #else /* }{ */ #error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \ or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)" #endif /* } */ #else /* }{ */ #error "numeric integer type not defined" #endif /* } */ /* }================================================================== */ /* ** {================================================================== ** Dependencies with C99 and other C details ** =================================================================== */ /* @@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89. ** (All uses in Lua have only one format item.) */ #if !defined(LUA_USE_C89) #define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i) #else #define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i)) #endif /* @@ lua_strx2number converts a hexadecimal numeral to a number. ** In C99, 'strtod' does that conversion. Otherwise, you can ** leave 'lua_strx2number' undefined and Lua will provide its own ** implementation. */ #if !defined(LUA_USE_C89) #define lua_strx2number(s,p) lua_str2number(s,p) #endif /* @@ lua_pointer2str converts a pointer to a readable string in a ** non-specified way. */ #define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p) /* @@ lua_number2strx converts a float to a hexadecimal numeral. ** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that. ** Otherwise, you can leave 'lua_number2strx' undefined and Lua will ** provide its own implementation. */ #if !defined(LUA_USE_C89) #define lua_number2strx(L,b,sz,f,n) \ ((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n))) #endif /* ** 'strtof' and 'opf' variants for math functions are not valid in ** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the ** availability of these variants. ('math.h' is already included in ** all files that use these macros.) */ #if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF)) #undef l_mathop /* variants not available */ #undef lua_str2number #define l_mathop(op) (lua_Number)op /* no variant */ #define lua_str2number(s,p) ((lua_Number)strtod((s), (p))) #endif /* @@ LUA_KCONTEXT is the type of the context ('ctx') for continuation ** functions. It must be a numerical type; Lua will use 'intptr_t' if ** available, otherwise it will use 'ptrdiff_t' (the nearest thing to ** 'intptr_t' in C89) */ #define LUA_KCONTEXT ptrdiff_t #if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \ __STDC_VERSION__ >= 199901L #include <stdint.h> #if defined(INTPTR_MAX) /* even in C99 this type is optional */ #undef LUA_KCONTEXT #define LUA_KCONTEXT intptr_t #endif #endif /* @@ lua_getlocaledecpoint gets the locale "radix character" (decimal point). ** Change that if you do not want to use C locales. (Code using this ** macro must include the header 'locale.h'.) */ #if !defined(lua_getlocaledecpoint) #define lua_getlocaledecpoint() (localeconv()->decimal_point[0]) #endif /* ** macros to improve jump prediction, used mostly for error handling ** and debug facilities. (Some macros in the Lua API use these macros. ** Define LUA_NOBUILTIN if you do not want '__builtin_expect' in your ** code.) */ #if !defined(luai_likely) #if defined(__GNUC__) && !defined(LUA_NOBUILTIN) #define luai_likely(x) (__builtin_expect(((x) != 0), 1)) #define luai_unlikely(x) (__builtin_expect(((x) != 0), 0)) #else #define luai_likely(x) (x) #define luai_unlikely(x) (x) #endif #endif #if defined(LUA_CORE) || defined(LUA_LIB) /* shorter names for Lua's own use */ #define l_likely(x) luai_likely(x) #define l_unlikely(x) luai_unlikely(x) #endif /* }================================================================== */ /* ** {================================================================== ** Language Variations ** ===================================================================== */ /* @@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some ** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from ** numbers to strings. Define LUA_NOCVTS2N to turn off automatic ** coercion from strings to numbers. */ /* #define LUA_NOCVTN2S */ /* #define LUA_NOCVTS2N */ /* @@ LUA_USE_APICHECK turns on several consistency checks on the C API. ** Define it as a help when debugging C code. */ #if defined(LUA_USE_APICHECK) #include <assert.h> #define luai_apicheck(l,e) assert(e) #endif /* }================================================================== */ /* ** {================================================================== ** Macros that affect the API and must be stable (that is, must be the ** same when you compile Lua and when you compile code that links to ** Lua). ** ===================================================================== */ /* @@ LUAI_MAXSTACK limits the size of the Lua stack. ** CHANGE it if you need a different limit. This limit is arbitrary; ** its only purpose is to stop Lua from consuming unlimited stack ** space (and to reserve some numbers for pseudo-indices). ** (It must fit into max(size_t)/32.) */ #if LUAI_IS32INT #define LUAI_MAXSTACK 1000000 #else #define LUAI_MAXSTACK 15000 #endif /* @@ LUA_EXTRASPACE defines the size of a raw memory area associated with ** a Lua state with very fast access. ** CHANGE it if you need a different size. */ #define LUA_EXTRASPACE (sizeof(void *)) /* @@ LUA_IDSIZE gives the maximum size for the description of the source @@ of a function in debug information. ** CHANGE it if you want a different size. */ #define LUA_IDSIZE 60 /* @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system. */ #define LUAL_BUFFERSIZE ((int)(16 * sizeof(void*) * sizeof(lua_Number))) /* @@ LUAI_MAXALIGN defines fields that, when used in a union, ensure ** maximum alignment for the other items in that union. */ #define LUAI_MAXALIGN lua_Number n; double u; void *s; lua_Integer i; long l /* }================================================================== */ /* =================================================================== */ /* ** Local configuration. You can use this space to add your redefinitions ** without modifying the main part of the file. */ #endif
0
repos/xmake/xmake/scripts/module
repos/xmake/xmake/scripts/module/luawrap/lua.h
/*!A cross-platform build utility based on Lua * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Copyright (C) 2015-present, TBOOX Open Source Group. * * @author ruki * @file lua.h * */ #ifndef XMI_LUA_H #define XMI_LUA_H /* ////////////////////////////////////////////////////////////////////////////////////// * includes */ #include "xmi.h" #endif
0
repos/xmake/xmake/scripts/xpack
repos/xmake/xmake/scripts/xpack/runself/setup.sh
#!/bin/sh
0
repos/xmake/xmake/scripts
repos/xmake/xmake/scripts/pac/github_mirror.lua
import("net.fasturl") function mirror(url) local configs = {} local proxyurls = {"hub.nuaa.cf"} fasturl.add(proxyurls) proxyurls = fasturl.sort(proxyurls) if #proxyurls > 0 then return url:replace("/github.com/", "/" .. proxyurls[1] .. "/", {plain = true}) end end
0
repos/xmake/xmake/scripts/xrepo
repos/xmake/xmake/scripts/xrepo/envs/msys2-mingw64.lua
add_requires("msys2", {configs = {msystem = "MINGW64", mingw64_toolchain = true, base_devel = true}})
0
repos/xmake/xmake/scripts/xrepo
repos/xmake/xmake/scripts/xrepo/envs/llvm.lua
add_requires("llvm")
0
repos/xmake/xmake/scripts/xrepo
repos/xmake/xmake/scripts/xrepo/envs/msys2.lua
add_requires("msys2", {configs = {base_devel = true}})
0
repos/xmake/xmake/scripts/xrepo
repos/xmake/xmake/scripts/xrepo/envs/python3.lua
if is_host("windows") and winos.version():le("win7") then add_requires("python 3.7.x") else add_requires("python 3.x") end
0
repos/xmake/xmake/scripts/xrepo
repos/xmake/xmake/scripts/xrepo/envs/python2.lua
add_requires("python 2.x")
0
repos/xmake/xmake/scripts/xrepo
repos/xmake/xmake/scripts/xrepo/envs/devel.lua
add_requires("cmake", "ninja") if is_host("windows") and winos.version():le("win7") then add_requires("python 3.7.x") else add_requires("python 3.x") end if is_host("linux", "bsd", "macosx") then add_requires("pkg-config", "autoconf", "automake", "libtool") elseif is_host("windows") then set_toolchains("msvc") end
0
repos/xmake/xmake/scripts/xrepo
repos/xmake/xmake/scripts/xrepo/envs/mingw-w64.lua
add_requires("mingw-w64")
0
repos/xmake/xmake/scripts/xrepo
repos/xmake/xmake/scripts/xrepo/envs/llvm-mingw.lua
add_requires("llvm-mingw")
0
repos/xmake/xmake/scripts/xrepo
repos/xmake/xmake/scripts/xrepo/envs/msys2-mingw32.lua
add_requires("msys2", {configs = {msystem = "MINGW32", mingw32_toolchain = true, base_devel = true}})
0
repos/xmake/xmake/scripts/xrepo
repos/xmake/xmake/scripts/xrepo/envs/msvc.lua
if is_host("windows") then set_toolchains("msvc") end
0
repos/xmake/xmake/scripts/xrepo
repos/xmake/xmake/scripts/xrepo/envs/depot_tools.lua
add_requires("depot_tools")
0
repos/xmake/xmake/scripts
repos/xmake/xmake/scripts/cmake_importfiles/xxxTargets.cmake
# Generated by XMake if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.5) message(FATAL_ERROR "CMake >= 2.6.0 required") endif() cmake_policy(PUSH) cmake_policy(VERSION 2.6...3.17) #---------------------------------------------------------------- # Generated CMake target import file. #---------------------------------------------------------------- # Commands may need to know the format version. set(CMAKE_IMPORT_FILE_VERSION 1) # Protect against multiple inclusion, which would fail when already imported targets are added once more. set(_targetsDefined) set(_targetsNotDefined) set(_expectedTargets) foreach(_expectedTarget @PROJECTNAME@::@TARGETNAME@) list(APPEND _expectedTargets ${_expectedTarget}) if(NOT TARGET ${_expectedTarget}) list(APPEND _targetsNotDefined ${_expectedTarget}) endif() if(TARGET ${_expectedTarget}) list(APPEND _targetsDefined ${_expectedTarget}) endif() endforeach() if("${_targetsDefined}" STREQUAL "${_expectedTargets}") unset(_targetsDefined) unset(_targetsNotDefined) unset(_expectedTargets) set(CMAKE_IMPORT_FILE_VERSION) cmake_policy(POP) return() endif() if(NOT "${_targetsDefined}" STREQUAL "") message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n") endif() unset(_targetsDefined) unset(_targetsNotDefined) unset(_expectedTargets) # The installation prefix configured by this project. get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) if (_IMPORT_PREFIX STREQUAL "/") set(_IMPORT_PREFIX "") endif() # Create imported target @PROJECTNAME@::@TARGETNAME@ add_library(@PROJECTNAME@::@TARGETNAME@ @TARGETKIND@ IMPORTED) set_target_properties(@PROJECTNAME@::@TARGETNAME@ PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include" ) # Load information for each installed configuration. get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) file(GLOB CONFIG_FILES "${_DIR}/@TARGETNAME@Targets-*.cmake") foreach(f ${CONFIG_FILES}) include(${f}) endforeach() # Cleanup temporary variables. set(_IMPORT_PREFIX) # Loop over all imported files and verify that they actually exist foreach(target ${_IMPORT_CHECK_TARGETS} ) foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} ) if(NOT EXISTS "${file}" ) message(FATAL_ERROR "The imported target \"${target}\" references the file \"${file}\" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained \"${CMAKE_CURRENT_LIST_FILE}\" but not all the files it references. ") endif() endforeach() unset(_IMPORT_CHECK_FILES_FOR_${target}) endforeach() unset(_IMPORT_CHECK_TARGETS) # This file does not depend on other imported targets which have # been exported from the same project but in a separate export set. # Commands beyond this point should not need to know the version. set(CMAKE_IMPORT_FILE_VERSION) cmake_policy(POP)
0
repos/xmake/xmake/scripts
repos/xmake/xmake/scripts/cmake_importfiles/xxxConfig.cmake
####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() ####### ####### Any changes to this file will be overwritten by the next CMake run #### ####### The input file was Config.cmake.in ######## get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE) macro(set_and_check _var _file) set(${_var} "${_file}") if(NOT EXISTS "${_file}") message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !") endif() endmacro() macro(check_required_components _NAME) foreach(comp ${${_NAME}_FIND_COMPONENTS}) if(NOT ${_NAME}_${comp}_FOUND) if(${_NAME}_FIND_REQUIRED_${comp}) set(${_NAME}_FOUND FALSE) endif() endif() endforeach() endmacro() #################################################################################### include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]") check_required_components("@TARGETNAME@")
0
repos/xmake/xmake/scripts
repos/xmake/xmake/scripts/cmake_importfiles/xxxTargets-debug.cmake
#---------------------------------------------------------------- # Generated CMake target import file for configuration "Debug". #---------------------------------------------------------------- # Commands may need to know the format version. set(CMAKE_IMPORT_FILE_VERSION 1) # Import target "@PROJECTNAME@::@TARGETNAME@" for configuration "Debug" set_property(TARGET @PROJECTNAME@::@TARGETNAME@ APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(@PROJECTNAME@::@TARGETNAME@ PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "ASM_NASM;C" IMPORTED_LOCATION_DEBUG "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@" ) list(APPEND _IMPORT_CHECK_TARGETS @PROJECTNAME@::@TARGETNAME@ ) list(APPEND _IMPORT_CHECK_FILES_FOR_@PROJECTNAME@::@TARGETNAME@ "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@" ) # Commands beyond this point should not need to know the version. set(CMAKE_IMPORT_FILE_VERSION)
0
repos/xmake/xmake/scripts
repos/xmake/xmake/scripts/cmake_importfiles/xxxConfigVersion.cmake
# This is a basic version file for the Config-mode of find_package(). # It is used by write_basic_package_version_file() as input file for configure_file() # to create a version-file which can be installed along a config.cmake file. # # The created file sets PACKAGE_VERSION_EXACT if the current version string and # the requested version string are exactly the same and it sets # PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version. # The variable CVF_VERSION must be set before calling configure_file(). set(PACKAGE_VERSION "@PACKAGE_VERSION@") if (PACKAGE_FIND_VERSION_RANGE) # Package version must be in the requested version range if ((PACKAGE_FIND_VERSION_RANGE_MIN STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MIN) OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_GREATER PACKAGE_FIND_VERSION_MAX) OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_GREATER_EQUAL PACKAGE_FIND_VERSION_MAX))) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() set(PACKAGE_VERSION_COMPATIBLE TRUE) endif() else() if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) set(PACKAGE_VERSION_COMPATIBLE FALSE) else() set(PACKAGE_VERSION_COMPATIBLE TRUE) if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) set(PACKAGE_VERSION_EXACT TRUE) endif() endif() endif() # if the installed project requested no architecture check, don't perform the check if("FALSE") return() endif() # if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "") return() endif() # check that the installed version has the same 32/64bit-ness as the one which is currently searching: if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "@TARGET_PTRBYTES@") math(EXPR installedBits "@TARGET_PTRBYTES@ * 8") set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") set(PACKAGE_VERSION_UNSUITABLE TRUE) endif()
0
repos/xmake/xmake/scripts
repos/xmake/xmake/scripts/cmake_importfiles/xxxTargets-release.cmake
#---------------------------------------------------------------- # Generated CMake target import file for configuration "Release". #---------------------------------------------------------------- # Commands may need to know the format version. set(CMAKE_IMPORT_FILE_VERSION 1) # Import target "@PROJECTNAME@::@TARGETNAME@" for configuration "Release" set_property(TARGET @PROJECTNAME@::@TARGETNAME@ APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(@PROJECTNAME@::@TARGETNAME@ PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "ASM_NASM;C" IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@" ) list(APPEND _IMPORT_CHECK_TARGETS @PROJECTNAME@::@TARGETNAME@ ) list(APPEND _IMPORT_CHECK_FILES_FOR_@PROJECTNAME@::@TARGETNAME@ "${_IMPORT_PREFIX}/lib/@TARGETFILENAME@" ) # Commands beyond this point should not need to know the version. set(CMAKE_IMPORT_FILE_VERSION)
0
repos/xmake/xmake/scripts/conan/extensions
repos/xmake/xmake/scripts/conan/extensions/generators/xmake_generator.py
#!/usr/bin/env python # -*- coding: utf-8 -*- from conan import ConanFile from conan.tools.files import save, load from conan.tools.microsoft import unix_path, VCVars, is_msvc from conan.errors import ConanInvalidConfiguration from conan.errors import ConanException from conans.model.build_info import CppInfo class XmakeGenerator: def __init__(self, conanfile): self._conanfile = conanfile def filename(self, pkgname = None): if pkgname: return "conanbuildinfo_%s.xmake.lua" %pkgname else: return "conanbuildinfo.xmake.lua" def generate(self): print("XmakeGenerator: generating build info ..") # extract all dependencies host_req = self._conanfile.dependencies.host test_req = self._conanfile.dependencies.test build_req = self._conanfile.dependencies.build full_req = list(host_req.items()) \ + list(test_req.items()) \ + list(build_req.items()) dep_names = [] pkginfo = None plat = self._conanfile.settings.os arch = self._conanfile.settings.arch mode = self._conanfile.settings.build_type for require, dep in full_req: # get aggregate dependency's cppinfo dep_aggregate = dep.cpp_info.aggregated_components() # format deps deps = XmakeDepsFormatter(dep_aggregate) # get package and deps dep_name = require.ref.name if not pkginfo: pkginfo = deps else: dep_names.append(dep_name) # make content template = (' {plat}_{arch}_{mode} = \n' ' {{\n' ' includedirs = {{{deps.include_paths}}},\n' ' linkdirs = {{{deps.lib_paths}}},\n' ' links = {{{deps.libs}}},\n' ' frameworkdirs = {{{deps.framework_paths}}},\n' ' frameworks = {{{deps.frameworks}}},\n' ' syslinks = {{{deps.system_libs}}},\n' ' defines = {{{deps.defines}}},\n' ' cxxflags = {{{deps.cppflags}}},\n' ' cflags = {{{deps.cflags}}},\n' ' shflags = {{{deps.sharedlinkflags}}},\n' ' ldflags = {{{deps.exelinkflags}}},\n' ' __bindirs = {{{deps.bin_paths}}},\n' ' __resdirs = {{{deps.res_paths}}},\n' ' __srcdirs = {{{deps.src_paths}}}\n' ' }}') sections = [] sections.append(template.format(plat = plat, arch = arch, mode = mode, deps = deps)) content = "{\n" + ",\n".join(sections) + "\n}" print(dep_name, content) # save package content to file with open(self.filename(dep_name), 'w') as file: file.write(content) # save root content to file template = (' {plat}_{arch}_{mode} = \n' ' {{\n' ' includedirs = {{{pkginfo.include_paths}}},\n' ' linkdirs = {{{pkginfo.lib_paths}}},\n' ' links = {{{pkginfo.libs}}},\n' ' frameworkdirs = {{{pkginfo.framework_paths}}},\n' ' frameworks = {{{pkginfo.frameworks}}},\n' ' syslinks = {{{pkginfo.system_libs}}},\n' ' defines = {{{pkginfo.defines}}},\n' ' cxxflags = {{{pkginfo.cppflags}}},\n' ' cflags = {{{pkginfo.cflags}}},\n' ' shflags = {{{pkginfo.sharedlinkflags}}},\n' ' ldflags = {{{pkginfo.exelinkflags}}},\n' ' __bindirs = {{{pkginfo.bin_paths}}},\n' ' __resdirs = {{{pkginfo.res_paths}}},\n' ' __srcdirs = {{{pkginfo.src_paths}}},\n' ' __dep_names = {{{dep_names}}}\n' ' }}') sections = [] dep_names_str = ", ".join('"%s"' % p for p in dep_names) sections.append(template.format(plat = plat, arch = arch, mode = mode, pkginfo = pkginfo, dep_names = dep_names_str)) content = "{\n" + ",\n".join(sections) + "\n}" print(content) # save package content to file with open(self.filename(), 'w') as file: file.write(content) class XmakeDepsFormatter(object): def __prepare_process_escape_character(self, raw_string): if raw_string.find('\"') != -1: raw_string = raw_string.replace("\"","\\\"") return raw_string def __filter_char(self, raw_string): return self.__prepare_process_escape_character(raw_string) def __init__(self, deps_cpp_info): includedirs = deps_cpp_info._includedirs if deps_cpp_info._includedirs else [] libdirs = deps_cpp_info._libdirs if deps_cpp_info._libdirs else [] bindirs = deps_cpp_info._bindirs if deps_cpp_info._bindirs else [] resdirs = deps_cpp_info._resdirs if deps_cpp_info._resdirs else [] srcdirs = deps_cpp_info._srcdirs if deps_cpp_info._srcdirs else [] frameworkdirs = deps_cpp_info._frameworkdirs if deps_cpp_info._frameworkdirs else [] libs = deps_cpp_info._libs if deps_cpp_info._libs else [] frameworks = deps_cpp_info._frameworks if deps_cpp_info._frameworks else [] system_libs = deps_cpp_info._system_libs if deps_cpp_info._system_libs else [] defines = deps_cpp_info._defines if deps_cpp_info._defines else [] cxxflags = deps_cpp_info._cxxflags if deps_cpp_info._cxxflags else [] cflags = deps_cpp_info._cflags if deps_cpp_info._cflags else [] sharedlinkflags = deps_cpp_info._sharedlinkflags if deps_cpp_info._sharedlinkflags else [] exelinkflags = deps_cpp_info._exelinkflags if deps_cpp_info._exelinkflags else [] self.include_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in includedirs) self.lib_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in libdirs) self.bin_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in bindirs) self.res_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in resdirs) self.src_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in srcdirs) self.framework_paths = ",\n".join('"%s"' % self.__filter_char(p.replace("\\", "/")) for p in frameworkdirs) self.libs = ", ".join('"%s"' % p for p in libs) self.frameworks = ", ".join('"%s"' % p for p in frameworks) self.system_libs = ", ".join('"%s"' % p for p in system_libs) self.defines = ", ".join('"%s"' % self.__filter_char(p) for p in defines) self.cppflags = ", ".join('"%s"' % p for p in cxxflags) self.cflags = ", ".join('"%s"' % p for p in cflags) self.sharedlinkflags = ", ".join('"%s"' % p for p in sharedlinkflags) self.exelinkflags = ", ".join('"%s"' % p for p in exelinkflags)
0
repos/xmake/xmake/scripts
repos/xmake/xmake/scripts/completions/register-completions.zsh
# A cross-platform build utility based on Lua # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http:##www.apache.org#licenses#LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Copyright (C) 2022-present, TBOOX Open Source Group. # # @author ruki # @homepage register-completions.zsh # # zsh parameter completion for xmake _xmake_zsh_complete() { local words read -Ac words local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$words")") reply=( "${(ps:\n:)completions}" ) } compctl -f -S "" -K _xmake_zsh_complete xmake # zsh parameter completion for xrepo _xrepo_zsh_complete() { local words read -Ac words local completions=("$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete 0 nospace "$words")") reply=( "${(ps:\n:)completions}" ) } compctl -f -S "" -K _xrepo_zsh_complete xrepo
0
repos/xmake/xmake/scripts
repos/xmake/xmake/scripts/completions/register-completions.fish
# A cross-platform build utility based on Lua # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http:##www.apache.org#licenses#LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Copyright (C) 2022-present, TBOOX Open Source Group. # # @author ruki, Dragon1573 # @homepage register-completions.fish # # fish parameter completion for xmake function _xmake_fish_complete # Read the current command line set -l raw_cmd (commandline) set -l words (commandline -o) # Get the current token set -l token (commandline -ot) # Call XMake built-in completion to get available results set -l result (MAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete 0 nospace "$raw_cmd") if test (count $result) -lt 1 # When there are no available completions, the function ends immediately # Otherwise, the subsequent `contains` command will trigger an error return 1 end # Are there multiple selectable results? # When there are multiple options, the user's current token is definitely incomplete test (count $result) -gt 1 set -l is_multiple_choice $status # Is the only selectable option identical to the current token under the cursor (which may be empty)? # Identical means the user has already completed the process # Repeated option outputs are not completions at the current cursor position contains -- $token $result set -l is_token_incomplete $status # Is the only selectable option identical to the last visible token of the command line array? # When completing without a prefix in every token position, the current token is an empty string # The last item of the command line tokenized array is the token before the cursor # This is mainly used to handle completions triggered after a space without a prefix contains -- $words[-1] $result set -l not_token_completed $status test \( $is_token_incomplete -eq 1 \) -a \( $not_token_completed -eq 1 \) test \( $is_multiple_choice -eq 0 \) -o \( $status -eq 0 \) if test $status -eq 0 # When the completion list has more than one item, or the current token is different from the unique token in the completion list # The user must not have completed the token and needs to be provided with completion options for item in $result # Each result takes up a separate line, and for the "-a" parameter, it needs to be echoed separately # Although the result itself has a newline, "-a" still treats it as a whole, # Without tokenizing it as multiple parameters if not string match -- '*error*' "$item" > /dev/null echo $item end end end end complete -c xmake -f -a "(_xmake_fish_complete)"
0
repos/xmake/xmake/scripts
repos/xmake/xmake/scripts/completions/register-completions.bash
# A cross-platform build utility based on Lua # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http:##www.apache.org#licenses#LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Copyright (C) 2022-present, TBOOX Open Source Group. # # @author ruki # @homepage register-completions.bash # # bash parameter completion for xmake _xmake_bash_complete() { local word=${COMP_WORDS[COMP_CWORD]} local completions completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.utils.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" if [ $? -ne 0 ]; then completions="" fi COMPREPLY=( $(compgen -W "$completions") ) } complete -o default -o nospace -F _xmake_bash_complete xmake # bash parameter completion for xrepo _xrepo_bash_complete() { local word=${COMP_WORDS[COMP_CWORD]} local completions completions="$(XMAKE_SKIP_HISTORY=1 XMAKE_ROOT=y xmake lua private.xrepo.complete "${COMP_POINT}" "nospace-nokey" "${COMP_LINE}")" if [ $? -ne 0 ]; then completions="" fi COMPREPLY=( $(compgen -W "$completions") ) } complete -o default -o nospace -F _xrepo_bash_complete xrepo
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/linux/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("linux") set_os("linux") set_hosts("macosx", "linux", "windows", "bsd") set_archs("i386", "x86_64", "armv7", "armv7s", "arm64-v8a", "mips", "mips64", "mipsel", "mips64el", "loong64") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).so") set_formats("symbol", "$(name).sym") set_installdir("/usr/local") set_toolchains("envs", "cross", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "go", "rust", "swift", "gfortran", "zig", "fpc", "nim") set_menu { config = { {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } , {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" } , {category = "Vcpkg Configuration" } , {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" } } , global = { {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } , {category = "Vcpkg Configuration" } , {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" } } }
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/bsd/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("bsd") set_os("bsd") set_hosts("bsd") set_archs("i386", "x86_64") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).so") set_formats("symbol", "$(name).sym") set_installdir("/usr/local") set_toolchains("envs", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "go", "rust", "gfortran", "zig") set_menu { config = { {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } , {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" } } , global = { {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } } }
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/mingw/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("mingw") set_os("windows") set_hosts("macosx", "linux", "windows", "bsd") -- set archs, arm/arm64 only for llvm-mingw set_archs("i386", "x86_64", "arm", "arm64") set_formats("static", "lib$(name).a") set_formats("object", "$(name).obj") set_formats("shared", "lib$(name).dll") set_formats("binary", "$(name).exe") set_formats("symbol", "$(name).pdb") set_toolchains("envs", "mingw", "yasm", "nasm", "fasm", "go") set_menu { config = { {category = "MingW Configuration" } , {nil, "mingw", "kv", nil, "The MingW SDK Directory" } } , global = { {category = "MingW Configuration" } , {nil, "mingw", "kv", nil, "The MingW SDK Directory" } } }
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/msys/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("msys") set_os("windows") set_hosts("windows") set_archs("i386", "x86_64") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).dll") set_formats("binary", "$(name).exe") set_formats("symbol", "$(name).sym") set_installdir("/usr/local") set_toolchains("envs", "cross", "gcc", "clang", "yasm", "go", "gfortran")
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/iphoneos/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("iphoneos") set_os("ios") set_hosts("macosx") set_archs("arm64", "x86_64") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).dylib") set_formats("symbol", "$(name).dSYM") set_toolchains("envs", "xcode") set_menu { config = { {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" } , {nil, "xcode_bundle_identifier", "kv", "auto", "The Bundle Identifier for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } , {nil, "appledev", "kv", nil, "The Apple Device Type", values = {"simulator", "iphone", "watchtv", "appletv", "catalyst"}} } , global = { {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_bundle_identifier", "kv", "auto", "The Bundle Identifier for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } } }
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/cross/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("cross") set_hosts("macosx", "linux", "windows", "bsd") set_archs("i386", "x86_64", "arm", "arm64", "mips", "mips64", "riscv", "riscv64", "loong64", "s390x", "ppc", "ppc64", "sh4") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).so") set_formats("symbol", "$(name).sym") set_toolchains("envs", "cross")
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/wasm/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("wasm") set_os("web") set_hosts("macosx", "linux", "windows", "bsd") set_archs("wasm32", "wasm64") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).so") set_formats("binary", "$(name).html") set_formats("symbol", "$(name).sym") set_toolchains("emcc") set_menu { config = { {category = "Emscripten Configuration" } , {nil, "emsdk", "kv", nil, "The emsdk directory" } } , global = { {category = "Emscripten Configuration" } , {nil, "emsdk", "kv", nil, "The emsdk directory" } } }
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/windows/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("windows") set_os("windows") set_hosts("windows") set_archs("x86", "x64", "arm", "arm64", "arm64ec") set_formats("static", "$(name).lib") set_formats("object", "$(name).obj") set_formats("shared", "$(name).dll") set_formats("binary", "$(name).exe") set_formats("symbol", "$(name).pdb") set_toolchains("msvc", "clang", "yasm", "nasm", "cuda", "rust", "swift", "go", "gfortran", "zig", "fpc", "nim") set_menu { config = { {category = "Visual Studio SDK Configuration" } , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio" , " e.g. --vs=2017" } , {nil, "vs_toolset", "kv", nil, "The Microsoft Visual Studio Toolset Version" , " e.g. --vs_toolset=14.0" } , {nil, "vs_sdkver", "kv", nil, "The Windows SDK Version of Visual Studio" , " e.g. --vs_sdkver=10.0.15063.0" } , {nil, "vs_runtime", "kv", nil, "The Runtime library of Visual Studio (deprecated, please use --runtimes)" , values = {"MT", "MTd", "MD", "MDd"} } , {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } , {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" } , {category = "WDK Configuration" } , {nil, "wdk", "kv", "auto", "The WDK Directory" } , {nil, "wdk_sdkver", "kv", "auto", "The WDK Version" } , {nil, "wdk_winver", "kv", "auto", "The WDK Windows Version" , values = function (complete) if complete then return {"win10_rs3", "win10", "win81", "win8", "win7_sp3", "win7_sp2", "win7_sp1", "win7"} else return {"win10[|_rs3]", "win81", "win8", "win7[|_sp1|_sp2|_sp3]"} end end } , {category = "Vcpkg Configuration" } , {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" } } , global = { {category = "Visual Studio SDK Configuration" } , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio" } , {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } , {category = "WDK Configuration" } , {nil, "wdk", "kv", "auto", "The WDK Directory" } , {category = "Vcpkg Configuration" } , {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" } } }
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/appletvos/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("appletvos") set_os("ios") set_hosts("macosx") if os.arch() == "arm64" then -- on apple m1 device set_archs("arm64", "x86_64") else set_archs("arm64", "armv7", "armv7s", "i386", "x86_64") end set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).dylib") set_formats("symbol", "$(name).dSYM") set_toolchains("envs", "xcode") set_menu { config = { {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" } , {nil, "xcode_bundle_identifier", "kv", "auto", "The Bundle Identifier for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } , {nil, "appledev", "kv", nil, "The Apple Device Type", values = {"simulator", "iphone", "watchtv", "appletv"}} } , global = { {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_bundle_identifier", "kv", "auto", "The Bundle Identifier for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } } }
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/harmony/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("harmony") set_os("harmony") set_hosts("macosx", "linux", "windows") set_archs("armeabi-v7a", "arm64-v8a", "x86", "x86_64") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).so") set_formats("symbol", "$(name).sym") set_toolchains("envs", "hdk")
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/haiku/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("haiku") set_os("haiku") set_hosts("haiku") set_archs("i386", "x86_64") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).so") set_formats("symbol", "$(name).sym") set_toolchains("envs", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "go", "rust", "gfortran", "zig") set_menu { config = { {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } , {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" } } , global = { {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } } }
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/applexros/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("applexros") set_os("ios") set_hosts("macosx") if os.arch() == "arm64" then -- on apple m1 device set_archs("arm64", "x86_64") else set_archs("arm64", "armv7", "armv7s", "i386", "x86_64") end set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).dylib") set_formats("symbol", "$(name).dSYM") set_toolchains("envs", "xcode") set_menu { config = { {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" } , {nil, "xcode_bundle_identifier", "kv", "auto", "The Bundle Identifier for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } , {nil, "appledev", "kv", nil, "The Apple Device Type", values = {"simulator", "iphone", "watchtv", "applexr"}} } , global = { {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_bundle_identifier", "kv", "auto", "The Bundle Identifier for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } } }
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/watchos/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("watchos") set_os("ios") set_hosts("macosx") set_archs("armv7k", "i386") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).dylib") set_formats("symbol", "$(name).dSYM") set_toolchains("envs", "xcode") set_menu { config = { {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" } , {nil, "xcode_bundle_identifier", "kv", "auto", "The Bundle Identifier for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } , {nil, "appledev", "kv", nil, "The Apple Device Type", values = {"simulator", "iphone", "watchtv", "appletv"}} } , global = { {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_bundle_identifier", "kv", "auto", "The Bundle Identifier for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } } }
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/cygwin/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("cygwin") set_os("windows") set_hosts("windows") set_archs("i386", "x86_64") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "$(name).dll") set_formats("binary", "$(name).exe") set_formats("symbol", "$(name).sym") set_installdir("/usr/local") set_toolchains("envs", "cross", "gcc", "clang", "yasm", "gfortran")
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/macosx/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("macosx") set_os("macosx") set_hosts("macosx") set_archs("x86_64", "arm64") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).dylib") set_formats("symbol", "$(name).dSYM") set_installdir("/usr/local") set_toolchains("envs", "xcode", "clang", "gcc", "yasm", "nasm", "cuda", "rust", "go", "gfortran", "zig", "fpc", "nim") set_menu { config = { {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" } , {nil, "xcode_bundle_identifier", "kv", "auto", "The Bundle Identifier for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } , {nil, "appledev", "kv", nil, "The Apple Device Type", values = {"simulator", "iphone", "watchtv", "appletv", "catalyst"}} , {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } , {nil, "qt_sdkver", "kv", "auto", "The Qt SDK Version" } , {category = "Vcpkg Configuration" } , {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" } } , global = { {category = "XCode SDK Configuration" } , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" } , {nil, "xcode_bundle_identifier", "kv", "auto", "The Bundle Identifier for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {category = "Cuda SDK Configuration" } , {nil, "cuda", "kv", "auto", "The Cuda SDK Directory" } , {category = "Qt SDK Configuration" } , {nil, "qt", "kv", "auto", "The Qt SDK Directory" } , {category = "Vcpkg Configuration" } , {nil, "vcpkg", "kv", "auto", "The Vcpkg Directory" } } }
0
repos/xmake/xmake/platforms
repos/xmake/xmake/platforms/android/xmake.lua
--!A cross-platform build utility based on Lua -- -- Licensed under the Apache License, Version 2.0 (the "License"); -- you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- -- http://www.apache.org/licenses/LICENSE-2.0 -- -- Unless required by applicable law or agreed to in writing, software -- distributed under the License is distributed on an "AS IS" BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- See the License for the specific language governing permissions and -- limitations under the License. -- -- Copyright (C) 2015-present, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua -- platform("android") set_os("android") set_hosts("macosx", "linux", "windows") -- set archs, we use the latest android abi provided in android ndk now. -- we will continue to support the old abi architectures for old version ndk. -- e.g. armv5te(armeabi), armv7-a(armeabi-v7a), mips, mips64, i386 -- -- @see https://developer.android.google.cn/ndk/guides/abis -- @note The NDK previously supported ARMv5 (armeabi) and 32-bit and 64-bit MIPS, but this support has been removed in NDK r17. -- set_archs("armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mip64") set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).so") set_formats("symbol", "$(name).sym") set_toolchains("envs", "ndk", "rust") set_menu { config = { {category = "Android Configuration" } , {nil, "ndk", "kv", nil, "The NDK Directory" } , {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" } , {nil, "android_sdk", "kv", nil, "The Android SDK Directory" } , {nil, "build_toolver", "kv", nil, "The Build Tool Version of Android SDK" } , {nil, "ndk_stdcxx", "kv", true, "Use stdc++ library for NDK" } , {nil, "ndk_cxxstl", "kv", nil, "The stdc++ stl library for NDK, (deprecated, please use --runtimes)", " - c++_static", " - c++_shared", " - gnustl_static", " - gnustl_shared", " - stlport_shared", " - stlport_static" } } , global = { {category = "Android Configuration" } , {nil, "ndk", "kv", nil, "The NDK Directory" } , {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" } , {nil, "android_sdk", "kv", nil, "The Android SDK Directory" } , {nil, "build_toolver", "kv", nil, "The Build Tool Version of Android SDK" } } }
0
repos/xmake/xmake/templates/nim
repos/xmake/xmake/templates/nim/shared/template.lua
template("shared") add_configfiles("xmake.lua")