From e54d0fe1a3e4fe3243dcef11d1b2759343015c33 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 22:48:36 +0800 Subject: add find_fpc --- xmake/modules/detect/tools/find_fpc.lua | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 xmake/modules/detect/tools/find_fpc.lua diff --git a/xmake/modules/detect/tools/find_fpc.lua b/xmake/modules/detect/tools/find_fpc.lua new file mode 100644 index 000000000..8414acba8 --- /dev/null +++ b/xmake/modules/detect/tools/find_fpc.lua @@ -0,0 +1,52 @@ +--!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 find_fpc.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find fpc +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local fpc = find_fpc() +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + opt.check = opt.check or "-h" + + -- find program + local program = find_program(opt.program or "fpc", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + return program, version +end -- cgit v1.3.1 From f131f88e73c2c9718f61dee0aac451e00d63f64f Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 22:54:52 +0800 Subject: add pascal tests --- tests/projects/pascal/console/src/main.pas | 4 ++++ tests/projects/pascal/console/xmake.lua | 5 +++++ 2 files changed, 9 insertions(+) create mode 100644 tests/projects/pascal/console/src/main.pas create mode 100644 tests/projects/pascal/console/xmake.lua diff --git a/tests/projects/pascal/console/src/main.pas b/tests/projects/pascal/console/src/main.pas new file mode 100644 index 000000000..a908ffab7 --- /dev/null +++ b/tests/projects/pascal/console/src/main.pas @@ -0,0 +1,4 @@ +program Hello; +begin + writeln ('Hello, world.'); +end. diff --git a/tests/projects/pascal/console/xmake.lua b/tests/projects/pascal/console/xmake.lua new file mode 100644 index 000000000..32fd531a2 --- /dev/null +++ b/tests/projects/pascal/console/xmake.lua @@ -0,0 +1,5 @@ +add_rules("mode.debug", "mode.release") +target("test") + set_kind("binary") + add_files("src/*.pas") + -- cgit v1.3.1 From 3d595c5f5f91bd380d3b43bd0dfc8c1f738c325b Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:04:28 +0800 Subject: add pascal stub --- xmake/languages/pascal/check_main.lua | 40 ++++++++++ xmake/languages/pascal/load.lua | 80 +++++++++++++++++++ xmake/languages/pascal/xmake.lua | 96 +++++++++++++++++++++++ xmake/modules/core/tools/fpc.lua | 142 ++++++++++++++++++++++++++++++++++ xmake/rules/pascal/xmake.lua | 46 +++++++++++ xmake/toolchains/fpc/xmake.lua | 34 ++++++++ 6 files changed, 438 insertions(+) create mode 100644 xmake/languages/pascal/check_main.lua create mode 100644 xmake/languages/pascal/load.lua create mode 100644 xmake/languages/pascal/xmake.lua create mode 100644 xmake/modules/core/tools/fpc.lua create mode 100644 xmake/rules/pascal/xmake.lua create mode 100644 xmake/toolchains/fpc/xmake.lua diff --git a/xmake/languages/pascal/check_main.lua b/xmake/languages/pascal/check_main.lua new file mode 100644 index 000000000..a66f70427 --- /dev/null +++ b/xmake/languages/pascal/check_main.lua @@ -0,0 +1,40 @@ +--!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 check_main.lua +-- + +-- check it +function main(sourcefile) + + -- load source code + local sourcecode = io.readfile(sourcefile) + + -- remove comment first + sourcecode = sourcecode:gsub("{%*.-%*}", "") + sourcecode = sourcecode:gsub("//.-\n", "\n") + + -- find 'program xxx' + if sourcecode:find("program%s*%(.-%)") then + return true + end + + -- no main function + return false +end + + diff --git a/xmake/languages/pascal/load.lua b/xmake/languages/pascal/load.lua new file mode 100644 index 000000000..997fc504a --- /dev/null +++ b/xmake/languages/pascal/load.lua @@ -0,0 +1,80 @@ +--!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 load.lua +-- + +function _get_apis() + local apis = {} + apis.values = { + -- target.add_xxx + "target.add_links" + , "target.add_syslinks" + , "target.add_pcflags" + , "target.add_ldflags" + , "target.add_arflags" + , "target.add_shflags" + , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + -- option.add_xxx + , "option.add_links" + , "option.add_syslinks" + , "option.add_pcflags" + , "option.add_ldflags" + , "option.add_arflags" + , "option.add_shflags" + , "option.add_rpathdirs" + -- package.add_xxx + , "package.add_links" + , "package.add_syslinks" + , "package.add_pcflags" + , "package.add_ldflags" + , "package.add_arflags" + , "package.add_shflags" + , "package.add_rpathdirs" + , "package.add_linkdirs" + , "package.add_includedirs" + , "package.add_sysincludedirs" + -- toolchain.add_xxx + , "toolchain.add_links" + , "toolchain.add_syslinks" + , "toolchain.add_pcflags" + , "toolchain.add_ldflags" + , "toolchain.add_arflags" + , "toolchain.add_shflags" + , "toolchain.add_rpathdirs" + , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_sysincludedirs" + } + apis.paths = { + -- target.add_xxx + "target.add_linkdirs" + , "target.add_includedirs" + , "target.add_sysincludedirs" + -- option.add_xxx + , "option.add_linkdirs" + , "option.add_includedirs" + , "option.add_sysincludedirs" + } + return apis +end + +function main() + return {apis = _get_apis()} +end + + diff --git a/xmake/languages/pascal/xmake.lua b/xmake/languages/pascal/xmake.lua new file mode 100644 index 000000000..f61a7db38 --- /dev/null +++ b/xmake/languages/pascal/xmake.lua @@ -0,0 +1,96 @@ +--!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 +-- + +language("pascal") + add_rules("pascal") + set_sourcekinds {pc = {".pas", ".pp"}} + set_sourceflags {pc = "pcflags"} + set_targetkinds {binary = "pcld", static = "ar", shared = "pcsh"} + set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + set_langkinds {pascal = "pc"} + set_mixingkinds("pc", "cc", "cxx", "as") + + on_load("load") + on_check_main("check_main") + + set_nameflags { + object = { + "config.includedirs" + , "target.symbols" + , "target.warnings" + , "target.optimize:check" + , "target.vectorexts:check" + , "target.includedirs" + , "toolchain.includedirs" + , "target.sysincludedirs" + , "toolchain.sysincludedirs" + } + , binary = { + "config.linkdirs" + , "target.linkdirs" + , "target.rpathdirs" + , "target.strip" + , "target.symbols" + , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "config.links" + , "target.links" + , "toolchain.links" + , "config.syslinks" + , "target.syslinks" + , "toolchain.syslinks" + } + , shared = { + "config.linkdirs" + , "target.linkdirs" + , "target.strip" + , "target.symbols" + , "toolchain.linkdirs" + , "config.links" + , "target.links" + , "toolchain.links" + , "config.syslinks" + , "target.syslinks" + , "toolchain.syslinks" + } + , static = { + "target.strip" + , "target.symbols" + } + } + + set_menu { + config = + { + {category = "Cross Complation Configuration/Compiler Configuration" } + , {nil, "pc", "kv", nil, "The Pascal Compiler" } + + , {category = "Cross Complation Configuration/Linker Configuration" } + , {nil, "pcld", "kv", nil, "The Pascal Linker" } + , {nil, "pcsh", "kv", nil, "The Pascal Shared Library Linker" } + + , {category = "Cross Complation Configuration/Builtin Flags Configuration" } + , {nil, "links", "kv", nil, "The Link Libraries" } + , {nil, "syslinks", "kv", nil, "The System Link Libraries" } + , {nil, "linkdirs", "kv", nil, "The Link Search Directories" } + , {nil, "includedirs","kv", nil, "The Include Search Directories" } + } + } + diff --git a/xmake/modules/core/tools/fpc.lua b/xmake/modules/core/tools/fpc.lua new file mode 100644 index 000000000..1e66b9ad5 --- /dev/null +++ b/xmake/modules/core/tools/fpc.lua @@ -0,0 +1,142 @@ +--!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 fpc.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("core.project.project") +import("core.project.target") + +-- init it +function init(self) + + -- init shflags + self:set("zcshflags", "-dynamic", "-fPIC") + + -- init zcflags for the kind: shared + self:set("shared.zcflags", "-fPIC") +end + +-- make the strip flag +function nf_strip(self, level) + local maps = + { + debug = "--strip" + , all = "--strip" + } + return maps[level] +end + +-- make the define flag +function nf_define(self, macro) + return "-D" .. macro +end + +-- make the optimize flag +function nf_optimize(self, level) + local maps = + { + none = "-O Debug" + , fast = "-O ReleaseSafe" + , aggressive = "-O ReleaseFast" + , fastest = "-O ReleaseFast" + , smallest = "-O ReleaseSmall" + , aggressive = "-O ReleaseFast" + } + return maps[level] +end + +-- make the link flag +function nf_link(self, lib) + return "-l" .. lib +end + +-- make the syslink flag +function nf_syslink(self, lib) + return nf_link(self, lib) +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return {"-L", dir} +end + +-- make the framework flag +function nf_framework(self, framework) + return {"-framework", framework} +end + +-- make the frameworkdir flag +function nf_frameworkdir(self, frameworkdir) + return {"-F", path.translate(frameworkdir)} +end + +-- make the rpathdir flag +function nf_rpathdir(self, dir) + dir = path.translate(dir) + if is_plat("macosx") then + return {"-rpath", (dir:gsub("%$ORIGIN", "@loader_path"))} + else + return {"-rpath", (dir:gsub("@[%w_]+", function (name) + local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"} + return maps[name] + end))} + end +end + +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags) + local argv = {} + if targetkind == "binary" then + table.insert(argv, "build-exe") + elseif targetkind == "static" or targetkind == "shared" then + table.insert(argv, "build-lib") + else + raise("unknown target kind(%s)!", targetkind) + end + table.join2(argv, flags, "-femit-bin=" .. targetfile, objectfiles) + return self:program(), argv +end + +-- link the target file +function link(self, objectfiles, targetkind, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags)) +end + +-- make the compile arguments list +function compargv(self, sourcefile, objectfile, flags) + return self:program(), table.join("build-obj", flags, "-femit-bin=" .. objectfile, sourcefile) +end + +-- compile the source file +function compile(self, sourcefile, objectfile, dependinfo, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + os.runv(compargv(self, sourcefile, objectfile, flags)) +end + diff --git a/xmake/rules/pascal/xmake.lua b/xmake/rules/pascal/xmake.lua new file mode 100644 index 000000000..bca2bc3ce --- /dev/null +++ b/xmake/rules/pascal/xmake.lua @@ -0,0 +1,46 @@ +--!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: pascal.build +rule("pascal.build") + set_sourcekinds("pc") + 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: pascal +rule("pascal") + + -- add build rules + add_deps("pascal.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") diff --git a/xmake/toolchains/fpc/xmake.lua b/xmake/toolchains/fpc/xmake.lua new file mode 100644 index 000000000..d3499867a --- /dev/null +++ b/xmake/toolchains/fpc/xmake.lua @@ -0,0 +1,34 @@ +--!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 toolchain +toolchain("fpc") + + -- set homepage + set_homepage("https://www.freepascal.org/") + set_description("Free Pascal Programming Language Compiler") + + -- on check + on_check(function (toolchain) + end) + + -- on load + on_load(function (toolchain) + end) -- cgit v1.3.1 From 7a73071fac11db852be636b6855b5013599cc3ea Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:18:25 +0800 Subject: improve fpc toolchain --- xmake/platforms/linux/xmake.lua | 2 +- xmake/platforms/macosx/xmake.lua | 2 +- xmake/toolchains/fpc/xmake.lua | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 7ba068687..f855903f3 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -40,7 +40,7 @@ platform("linux") set_installdir("/usr/local") -- set toolchains - set_toolchains("envs", "cross", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust", "gfortran", "zig") + set_toolchains("envs", "cross", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust", "gfortran", "zig", "fpc") -- set menu set_menu { diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 2ff9a10b6..792a5cad3 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -40,7 +40,7 @@ platform("macosx") set_installdir("/usr/local") -- set toolchains - set_toolchains("envs", "xcode", "clang", "gcc", "yasm", "nasm", "cuda", "dlang", "rust", "go", "gfortran", "zig") + set_toolchains("envs", "xcode", "clang", "gcc", "yasm", "nasm", "cuda", "dlang", "rust", "go", "gfortran", "zig", "fpc") -- set menu set_menu { diff --git a/xmake/toolchains/fpc/xmake.lua b/xmake/toolchains/fpc/xmake.lua index d3499867a..6ce2bf401 100644 --- a/xmake/toolchains/fpc/xmake.lua +++ b/xmake/toolchains/fpc/xmake.lua @@ -25,9 +25,10 @@ toolchain("fpc") set_homepage("https://www.freepascal.org/") set_description("Free Pascal Programming Language Compiler") - -- on check - on_check(function (toolchain) - end) + -- set toolset + set_toolset("pc", "$(env PC)", "fpc") + set_toolset("pcld", "$(env PC)", "fpc") + set_toolset("pcsh", "$(env PC)", "fpc") -- on load on_load(function (toolchain) -- cgit v1.3.1 From ae7c9e6398f72b314d6601a324d5fbf3829c547b Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:29:09 +0800 Subject: improve fpc --- xmake/languages/pascal/xmake.lua | 2 +- xmake/modules/core/tools/fpc.lua | 64 ++-------------------------------------- xmake/toolchains/fpc/xmake.lua | 4 +-- 3 files changed, 5 insertions(+), 65 deletions(-) diff --git a/xmake/languages/pascal/xmake.lua b/xmake/languages/pascal/xmake.lua index f61a7db38..bdf82f290 100644 --- a/xmake/languages/pascal/xmake.lua +++ b/xmake/languages/pascal/xmake.lua @@ -22,7 +22,7 @@ language("pascal") add_rules("pascal") set_sourcekinds {pc = {".pas", ".pp"}} set_sourceflags {pc = "pcflags"} - set_targetkinds {binary = "pcld", static = "ar", shared = "pcsh"} + set_targetkinds {binary = "ld", static = "ar", shared = "sh"} set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} set_langkinds {pascal = "pc"} set_mixingkinds("pc", "cc", "cxx", "as") diff --git a/xmake/modules/core/tools/fpc.lua b/xmake/modules/core/tools/fpc.lua index 1e66b9ad5..b83fd6ea8 100644 --- a/xmake/modules/core/tools/fpc.lua +++ b/xmake/modules/core/tools/fpc.lua @@ -26,22 +26,10 @@ import("core.project.target") -- init it function init(self) - - -- init shflags - self:set("zcshflags", "-dynamic", "-fPIC") - - -- init zcflags for the kind: shared - self:set("shared.zcflags", "-fPIC") end -- make the strip flag function nf_strip(self, level) - local maps = - { - debug = "--strip" - , all = "--strip" - } - return maps[level] end -- make the define flag @@ -51,16 +39,6 @@ end -- make the optimize flag function nf_optimize(self, level) - local maps = - { - none = "-O Debug" - , fast = "-O ReleaseSafe" - , aggressive = "-O ReleaseFast" - , fastest = "-O ReleaseFast" - , smallest = "-O ReleaseSmall" - , aggressive = "-O ReleaseFast" - } - return maps[level] end -- make the link flag @@ -78,65 +56,27 @@ function nf_linkdir(self, dir) return {"-L", dir} end --- make the framework flag -function nf_framework(self, framework) - return {"-framework", framework} -end - --- make the frameworkdir flag -function nf_frameworkdir(self, frameworkdir) - return {"-F", path.translate(frameworkdir)} -end - --- make the rpathdir flag -function nf_rpathdir(self, dir) - dir = path.translate(dir) - if is_plat("macosx") then - return {"-rpath", (dir:gsub("%$ORIGIN", "@loader_path"))} - else - return {"-rpath", (dir:gsub("@[%w_]+", function (name) - local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"} - return maps[name] - end))} - end -end - -- make the link arguments list function linkargv(self, objectfiles, targetkind, targetfile, flags) local argv = {} - if targetkind == "binary" then - table.insert(argv, "build-exe") - elseif targetkind == "static" or targetkind == "shared" then - table.insert(argv, "build-lib") - else - raise("unknown target kind(%s)!", targetkind) - end - table.join2(argv, flags, "-femit-bin=" .. targetfile, objectfiles) return self:program(), argv end -- link the target file function link(self, objectfiles, targetkind, targetfile, flags) - - -- ensure the target directory os.mkdir(path.directory(targetfile)) - - -- link it os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags)) end -- make the compile arguments list function compargv(self, sourcefile, objectfile, flags) - return self:program(), table.join("build-obj", flags, "-femit-bin=" .. objectfile, sourcefile) + return self:program(), table.join("-Sd", "-Cn", flags, "-FE" .. path.directory(objectfile), sourcefile) end -- compile the source file function compile(self, sourcefile, objectfile, dependinfo, flags) - - -- ensure the object directory os.mkdir(path.directory(objectfile)) - - -- compile it os.runv(compargv(self, sourcefile, objectfile, flags)) + os.mv(path.join(path.directory(objectfile), path.basename(sourcefile) .. ".o"), objectfile) end diff --git a/xmake/toolchains/fpc/xmake.lua b/xmake/toolchains/fpc/xmake.lua index 6ce2bf401..b59f21376 100644 --- a/xmake/toolchains/fpc/xmake.lua +++ b/xmake/toolchains/fpc/xmake.lua @@ -27,8 +27,8 @@ toolchain("fpc") -- set toolset set_toolset("pc", "$(env PC)", "fpc") - set_toolset("pcld", "$(env PC)", "fpc") - set_toolset("pcsh", "$(env PC)", "fpc") +-- set_toolset("pcld", "$(env PC)", "fpc") +-- set_toolset("pcsh", "$(env PC)", "fpc") -- on load on_load(function (toolchain) -- cgit v1.3.1 From b47154e928d5fa960365a205420912ae1363ba53 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:34:28 +0800 Subject: use build mode for fpc --- xmake/languages/pascal/xmake.lua | 2 +- xmake/modules/core/tools/fpc.lua | 47 ++++++++-------------------------------- xmake/rules/pascal/xmake.lua | 15 +------------ xmake/toolchains/fpc/xmake.lua | 7 ++++-- 4 files changed, 16 insertions(+), 55 deletions(-) diff --git a/xmake/languages/pascal/xmake.lua b/xmake/languages/pascal/xmake.lua index bdf82f290..ba052ef36 100644 --- a/xmake/languages/pascal/xmake.lua +++ b/xmake/languages/pascal/xmake.lua @@ -22,7 +22,7 @@ language("pascal") add_rules("pascal") set_sourcekinds {pc = {".pas", ".pp"}} set_sourceflags {pc = "pcflags"} - set_targetkinds {binary = "ld", static = "ar", shared = "sh"} + set_targetkinds {binary = "pcld", static = "pcar", shared = "pcsh"} set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} set_langkinds {pascal = "pc"} set_mixingkinds("pc", "cc", "cxx", "as") diff --git a/xmake/modules/core/tools/fpc.lua b/xmake/modules/core/tools/fpc.lua index b83fd6ea8..65662de4c 100644 --- a/xmake/modules/core/tools/fpc.lua +++ b/xmake/modules/core/tools/fpc.lua @@ -22,61 +22,32 @@ import("core.base.option") import("core.project.config") import("core.project.project") -import("core.project.target") -- init it function init(self) end --- make the strip flag -function nf_strip(self, level) -end - --- make the define flag -function nf_define(self, macro) - return "-D" .. macro -end - -- make the optimize flag function nf_optimize(self, level) end --- make the link flag -function nf_link(self, lib) - return "-l" .. lib -end - --- make the syslink flag -function nf_syslink(self, lib) - return nf_link(self, lib) +-- make the symbol flag +function nf_symbol(self, level) end -- make the linkdir flag function nf_linkdir(self, dir) - return {"-L", dir} + return {"-L" .. dir} end --- make the link arguments list -function linkargv(self, objectfiles, targetkind, targetfile, flags) - local argv = {} - return self:program(), argv +-- make the build arguments list +function buildargv(self, sourcefiles, targetkind, targetfile, flags) + return self:program(), table.join(flags, "-o" .. targetfile, sourcefiles) end --- link the target file -function link(self, objectfiles, targetkind, targetfile, flags) +-- build the target file +function build(self, sourcefiles, targetkind, targetfile, flags) os.mkdir(path.directory(targetfile)) - os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags)) -end - --- make the compile arguments list -function compargv(self, sourcefile, objectfile, flags) - return self:program(), table.join("-Sd", "-Cn", flags, "-FE" .. path.directory(objectfile), sourcefile) -end - --- compile the source file -function compile(self, sourcefile, objectfile, dependinfo, flags) - os.mkdir(path.directory(objectfile)) - os.runv(compargv(self, sourcefile, objectfile, flags)) - os.mv(path.join(path.directory(objectfile), path.basename(sourcefile) .. ".o"), objectfile) + os.runv(buildargv(self, sourcefiles, targetkind, targetfile, flags)) end diff --git a/xmake/rules/pascal/xmake.lua b/xmake/rules/pascal/xmake.lua index bca2bc3ce..5961c08d3 100644 --- a/xmake/rules/pascal/xmake.lua +++ b/xmake/rules/pascal/xmake.lua @@ -21,13 +21,7 @@ -- define rule: pascal.build rule("pascal.build") set_sourcekinds("pc") - 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) + on_build("build.target") -- define rule: pascal rule("pascal") @@ -37,10 +31,3 @@ rule("pascal") -- 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") diff --git a/xmake/toolchains/fpc/xmake.lua b/xmake/toolchains/fpc/xmake.lua index b59f21376..5fab445af 100644 --- a/xmake/toolchains/fpc/xmake.lua +++ b/xmake/toolchains/fpc/xmake.lua @@ -27,9 +27,12 @@ toolchain("fpc") -- set toolset set_toolset("pc", "$(env PC)", "fpc") --- set_toolset("pcld", "$(env PC)", "fpc") --- set_toolset("pcsh", "$(env PC)", "fpc") + set_toolset("pcld", "$(env PC)", "fpc") + set_toolset("pcsh", "$(env PC)", "fpc") + set_toolset("pcar", "$(env PC)", "fpc") -- on load on_load(function (toolchain) + toolchain:set("pcshflags", "") + toolchain:set("pcldflags", "") end) -- cgit v1.3.1 From 1306c34442e6089f05ef54b0772d4fb629c25117 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:37:05 +0800 Subject: add shared test for pascal --- tests/projects/pascal/shared/src/foo.pas | 23 +++++++++++++++++++++++ tests/projects/pascal/shared/src/main.pas | 14 ++++++++++++++ tests/projects/pascal/shared/xmake.lua | 10 ++++++++++ 3 files changed, 47 insertions(+) create mode 100644 tests/projects/pascal/shared/src/foo.pas create mode 100644 tests/projects/pascal/shared/src/main.pas create mode 100644 tests/projects/pascal/shared/xmake.lua diff --git a/tests/projects/pascal/shared/src/foo.pas b/tests/projects/pascal/shared/src/foo.pas new file mode 100644 index 000000000..2d12d39f5 --- /dev/null +++ b/tests/projects/pascal/shared/src/foo.pas @@ -0,0 +1,23 @@ +library subs; + +function SubStr(CString: PChar;FromPos,ToPos: Longint): PChar; cdecl; + +var + Length: Integer; + +begin + Length := StrLen(CString); + SubStr := CString + Length; + if (FromPos > 0) and (ToPos >= FromPos) then + begin + if Length >= FromPos then + SubStr := CString + FromPos; + if Length > ToPos then + CString[ToPos+1] := #0; + end; +end; + +exports + SubStr; + +end. diff --git a/tests/projects/pascal/shared/src/main.pas b/tests/projects/pascal/shared/src/main.pas new file mode 100644 index 000000000..9ee983a12 --- /dev/null +++ b/tests/projects/pascal/shared/src/main.pas @@ -0,0 +1,14 @@ +uses strings; + +function SubStr(const CString: PChar; FromPos, ToPos: longint): PChar; + cdecl; external 'subs'; + +var + s: PChar; + FromPos, ToPos: Integer; +begin + s := strnew('TestMe'); + FromPos := 2; + ToPos := 3; + WriteLn(SubStr(s, FromPos, ToPos)); +end. diff --git a/tests/projects/pascal/shared/xmake.lua b/tests/projects/pascal/shared/xmake.lua new file mode 100644 index 000000000..96697bcbd --- /dev/null +++ b/tests/projects/pascal/shared/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.debug", "mode.release") +target("foo") + set_kind("shared") + add_files("src/foo.pas") + +target("test") + set_kind("binary") + add_deps("foo") + add_files("src/main.pas") + -- cgit v1.3.1 From 684ba799f95d3f8832a9e220ce2743aa2ecb505f Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:38:26 +0800 Subject: improve fpc link --- tests/projects/pascal/shared/xmake.lua | 1 - xmake/modules/core/tools/fpc.lua | 12 +++- xmake/modules/detect/tools/fpc/has_flags.lua | 98 ++++++++++++++++++++++++++++ xmake/toolchains/fpc/xmake.lua | 4 +- 4 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 xmake/modules/detect/tools/fpc/has_flags.lua diff --git a/tests/projects/pascal/shared/xmake.lua b/tests/projects/pascal/shared/xmake.lua index 96697bcbd..d96c29d5f 100644 --- a/tests/projects/pascal/shared/xmake.lua +++ b/tests/projects/pascal/shared/xmake.lua @@ -7,4 +7,3 @@ target("test") set_kind("binary") add_deps("foo") add_files("src/main.pas") - diff --git a/xmake/modules/core/tools/fpc.lua b/xmake/modules/core/tools/fpc.lua index 65662de4c..7062228cc 100644 --- a/xmake/modules/core/tools/fpc.lua +++ b/xmake/modules/core/tools/fpc.lua @@ -35,9 +35,19 @@ end function nf_symbol(self, level) end +-- make the link flag +function nf_link(self, lib) + return "-k-l" .. lib +end + +-- make the syslink flag +function nf_syslink(self, lib) + return nf_link(self, lib) +end + -- make the linkdir flag function nf_linkdir(self, dir) - return {"-L" .. dir} + return {"-k-L" .. dir} end -- make the build arguments list diff --git a/xmake/modules/detect/tools/fpc/has_flags.lua b/xmake/modules/detect/tools/fpc/has_flags.lua new file mode 100644 index 000000000..9f66939cc --- /dev/null +++ b/xmake/modules/detect/tools/fpc/has_flags.lua @@ -0,0 +1,98 @@ +--!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 has_flags.lua +-- + +-- imports +import("core.cache.detectcache") + +-- try running +function _try_running(...) + + local argv = {...} + local errors = nil + return try { function () os.runv(unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors +end + +-- attempt to check it from the argument list +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end + + -- make cache key + local key = "detect.tools.fpc.has_flags" + + -- make allflags key + local flagskey = opt.program .. "_" .. (opt.programver or "") + + -- get all allflags from argument list + local allflags = detectcache:get2(key, flagskey) + if not allflags then + + -- get argument list + allflags = {} + local arglist = os.iorunv(opt.program, {"-h"}) + if arglist then + for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do + allflags[arg] = true + end + end + + -- save cache + detectcache:set2(key, flagskey, allflags) + detectcache:save() + end + return allflags[flags[1]] +end + +-- try running to check flags +function _check_try_running(flags, opt) + + -- make an stub source file + local sourcefile = path.join(os.tmpdir(), "detect", "fpc_has_flags.pas") + if not os.isfile(sourcefile) then + io.writefile(sourcefile, "program Hello;\nbegin\nend.") + end + + -- check it + local binaryfile = os.tmpfile() + local ok, errors = _try_running(opt.program, table.join(flags, "-o" .. binaryfile, sourcefile)) + os.tryrm(binaryfile) + return ok, errors +end + +-- has_flags(flags)? +-- +-- @param opt the argument options, e.g. {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +function main(flags, opt) + + -- attempt to check it from the argument list + if _check_from_arglist(flags, opt) then + return true + end + + -- try running to check it + return _check_try_running(flags, opt) +end + diff --git a/xmake/toolchains/fpc/xmake.lua b/xmake/toolchains/fpc/xmake.lua index 5fab445af..82c7f6dc8 100644 --- a/xmake/toolchains/fpc/xmake.lua +++ b/xmake/toolchains/fpc/xmake.lua @@ -33,6 +33,6 @@ toolchain("fpc") -- on load on_load(function (toolchain) - toolchain:set("pcshflags", "") - toolchain:set("pcldflags", "") + toolchain:set("pcshflags", "-Sd") + toolchain:set("pcldflags", "-Sd") end) -- cgit v1.3.1 From 13acaccc305ef18631601d1d23bfae1c9faef490 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:42:22 +0800 Subject: add rpath for pascal --- xmake/languages/pascal/load.lua | 10 ++------- xmake/languages/pascal/xmake.lua | 24 ++++++++-------------- xmake/modules/core/tools/fpc.lua | 44 ++++++++++++++++++++++++++++++++++++++++ xmake/modules/core/tools/zig.lua | 1 - 4 files changed, 55 insertions(+), 24 deletions(-) diff --git a/xmake/languages/pascal/load.lua b/xmake/languages/pascal/load.lua index 997fc504a..6a1f1ca5b 100644 --- a/xmake/languages/pascal/load.lua +++ b/xmake/languages/pascal/load.lua @@ -23,6 +23,7 @@ function _get_apis() apis.values = { -- target.add_xxx "target.add_links" + , "target.add_frameworks" , "target.add_syslinks" , "target.add_pcflags" , "target.add_ldflags" @@ -46,8 +47,6 @@ function _get_apis() , "package.add_shflags" , "package.add_rpathdirs" , "package.add_linkdirs" - , "package.add_includedirs" - , "package.add_sysincludedirs" -- toolchain.add_xxx , "toolchain.add_links" , "toolchain.add_syslinks" @@ -57,18 +56,13 @@ function _get_apis() , "toolchain.add_shflags" , "toolchain.add_rpathdirs" , "toolchain.add_linkdirs" - , "toolchain.add_includedirs" - , "toolchain.add_sysincludedirs" } apis.paths = { -- target.add_xxx "target.add_linkdirs" - , "target.add_includedirs" - , "target.add_sysincludedirs" + , "target.add_frameworkdirs" -- option.add_xxx , "option.add_linkdirs" - , "option.add_includedirs" - , "option.add_sysincludedirs" } return apis end diff --git a/xmake/languages/pascal/xmake.lua b/xmake/languages/pascal/xmake.lua index ba052ef36..a3e1fb5b3 100644 --- a/xmake/languages/pascal/xmake.lua +++ b/xmake/languages/pascal/xmake.lua @@ -25,22 +25,17 @@ language("pascal") set_targetkinds {binary = "pcld", static = "pcar", shared = "pcsh"} set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} set_langkinds {pascal = "pc"} - set_mixingkinds("pc", "cc", "cxx", "as") + set_mixingkinds("pc") on_load("load") on_check_main("check_main") set_nameflags { object = { - "config.includedirs" - , "target.symbols" + "target.symbols" , "target.warnings" , "target.optimize:check" , "target.vectorexts:check" - , "target.includedirs" - , "toolchain.includedirs" - , "target.sysincludedirs" - , "toolchain.sysincludedirs" } , binary = { "config.linkdirs" @@ -52,6 +47,8 @@ language("pascal") , "toolchain.rpathdirs" , "config.links" , "target.links" + , "target.frameworks" + , "target.frameworkdirs" , "toolchain.links" , "config.syslinks" , "target.syslinks" @@ -65,32 +62,29 @@ language("pascal") , "toolchain.linkdirs" , "config.links" , "target.links" + , "target.frameworks" + , "target.frameworkdirs" , "toolchain.links" , "config.syslinks" , "target.syslinks" , "toolchain.syslinks" } - , static = { - "target.strip" - , "target.symbols" - } } set_menu { config = { {category = "Cross Complation Configuration/Compiler Configuration" } - , {nil, "pc", "kv", nil, "The Pascal Compiler" } + , {nil, "pc", "kv", nil, "The Pascal Compiler" } , {category = "Cross Complation Configuration/Linker Configuration" } - , {nil, "pcld", "kv", nil, "The Pascal Linker" } - , {nil, "pcsh", "kv", nil, "The Pascal Shared Library Linker" } + , {nil, "pcld", "kv", nil, "The Pascal Linker" } + , {nil, "pcsh", "kv", nil, "The Pascal Shared Library Linker" } , {category = "Cross Complation Configuration/Builtin Flags Configuration" } , {nil, "links", "kv", nil, "The Link Libraries" } , {nil, "syslinks", "kv", nil, "The System Link Libraries" } , {nil, "linkdirs", "kv", nil, "The Link Search Directories" } - , {nil, "includedirs","kv", nil, "The Include Search Directories" } } } diff --git a/xmake/modules/core/tools/fpc.lua b/xmake/modules/core/tools/fpc.lua index 7062228cc..0f2d3025f 100644 --- a/xmake/modules/core/tools/fpc.lua +++ b/xmake/modules/core/tools/fpc.lua @@ -29,10 +29,33 @@ end -- make the optimize flag function nf_optimize(self, level) + local maps = + { + none = "-O-" + , fast = "-O1" + , fastest = "-O3" + , smallest = "-O2" + , aggressive = "-O4" + } + return maps[level] +end + +-- make the strip flag +function nf_strip(self, level) + if level == "all" then + return "-Xs" + end end -- make the symbol flag function nf_symbol(self, level) + if level == "debug" and self:kind() == "pc" then + if self:plat() == "windows" then + return {"-gw3", "-WN"} + else + return "-gw3" + end + end end -- make the link flag @@ -50,6 +73,27 @@ function nf_linkdir(self, dir) return {"-k-L" .. dir} end +-- make the rpathdir flag +function nf_rpathdir(self, dir) + dir = path.translate(dir) + if self:has_flags("-k,-rpath=" .. dir, "ldflags") then + return {"-k,-rpath=" .. (dir:gsub("@[%w_]+", function (name) + local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"} + return maps[name] + end))} + end +end + +-- make the framework flag +function nf_framework(self, framework) + return {"-k-framework", framework} +end + +-- make the frameworkdir flag +function nf_frameworkdir(self, frameworkdir) + return {"-k-F", path.translate(frameworkdir)} +end + -- make the build arguments list function buildargv(self, sourcefiles, targetkind, targetfile, flags) return self:program(), table.join(flags, "-o" .. targetfile, sourcefiles) diff --git a/xmake/modules/core/tools/zig.lua b/xmake/modules/core/tools/zig.lua index 2270e2a3e..140e1ae0a 100644 --- a/xmake/modules/core/tools/zig.lua +++ b/xmake/modules/core/tools/zig.lua @@ -55,7 +55,6 @@ function nf_optimize(self, level) { none = "-O Debug" , fast = "-O ReleaseSafe" - , aggressive = "-O ReleaseFast" , fastest = "-O ReleaseFast" , smallest = "-O ReleaseSmall" , aggressive = "-O ReleaseFast" -- cgit v1.3.1 From ef248c45a806beb1347f3080cb521c4141da4682 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:47:31 +0800 Subject: improve rpath for fpc --- tests/projects/pascal/shared/src/foo.pas | 2 +- tests/projects/pascal/shared/src/main.pas | 2 +- xmake/modules/core/tools/fpc.lua | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/projects/pascal/shared/src/foo.pas b/tests/projects/pascal/shared/src/foo.pas index 2d12d39f5..d1952cf21 100644 --- a/tests/projects/pascal/shared/src/foo.pas +++ b/tests/projects/pascal/shared/src/foo.pas @@ -1,4 +1,4 @@ -library subs; +library foo; function SubStr(CString: PChar;FromPos,ToPos: Longint): PChar; cdecl; diff --git a/tests/projects/pascal/shared/src/main.pas b/tests/projects/pascal/shared/src/main.pas index 9ee983a12..ccf2e179b 100644 --- a/tests/projects/pascal/shared/src/main.pas +++ b/tests/projects/pascal/shared/src/main.pas @@ -1,7 +1,7 @@ uses strings; function SubStr(const CString: PChar; FromPos, ToPos: longint): PChar; - cdecl; external 'subs'; + cdecl; external 'foo'; var s: PChar; diff --git a/xmake/modules/core/tools/fpc.lua b/xmake/modules/core/tools/fpc.lua index 0f2d3025f..de5b349c6 100644 --- a/xmake/modules/core/tools/fpc.lua +++ b/xmake/modules/core/tools/fpc.lua @@ -76,8 +76,8 @@ end -- make the rpathdir flag function nf_rpathdir(self, dir) dir = path.translate(dir) - if self:has_flags("-k,-rpath=" .. dir, "ldflags") then - return {"-k,-rpath=" .. (dir:gsub("@[%w_]+", function (name) + if self:has_flags("-k-rpath=" .. dir, "ldflags") then + return {"-k-rpath=" .. (dir:gsub("@[%w_]+", function (name) local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"} return maps[name] end))} -- cgit v1.3.1 From 593406d1f642fd2c5b83264b0b2f60cf7fdbc8ca Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:48:08 +0800 Subject: add pascal template --- xmake/templates/pascal/console/project/src/main.pas | 4 ++++ xmake/templates/pascal/console/project/xmake.lua | 7 +++++++ xmake/templates/pascal/console/template.lua | 2 ++ 3 files changed, 13 insertions(+) create mode 100644 xmake/templates/pascal/console/project/src/main.pas create mode 100644 xmake/templates/pascal/console/project/xmake.lua create mode 100644 xmake/templates/pascal/console/template.lua diff --git a/xmake/templates/pascal/console/project/src/main.pas b/xmake/templates/pascal/console/project/src/main.pas new file mode 100644 index 000000000..a908ffab7 --- /dev/null +++ b/xmake/templates/pascal/console/project/src/main.pas @@ -0,0 +1,4 @@ +program Hello; +begin + writeln ('Hello, world.'); +end. diff --git a/xmake/templates/pascal/console/project/xmake.lua b/xmake/templates/pascal/console/project/xmake.lua new file mode 100644 index 000000000..155005840 --- /dev/null +++ b/xmake/templates/pascal/console/project/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.debug", "mode.release") + +target("${TARGETNAME}") + set_kind("binary") + add_files("src/*.pas") + +${FAQ} diff --git a/xmake/templates/pascal/console/template.lua b/xmake/templates/pascal/console/template.lua new file mode 100644 index 000000000..ed2e13b57 --- /dev/null +++ b/xmake/templates/pascal/console/template.lua @@ -0,0 +1,2 @@ +template("console") + add_configfiles("xmake.lua") -- cgit v1.3.1 From 53e79a864277f085803cd605b9807bd19a499aad Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:49:05 +0800 Subject: add vala template --- xmake/templates/vala/console/project/src/main.vala | 21 +++++++++++++++++++++ xmake/templates/vala/console/project/xmake.lua | 12 ++++++++++++ xmake/templates/vala/console/template.lua | 2 ++ xmake/templates/vala/shared/project/src/main.vala | 6 ++++++ xmake/templates/vala/shared/project/src/mymath.vala | 9 +++++++++ xmake/templates/vala/shared/project/xmake.lua | 18 ++++++++++++++++++ xmake/templates/vala/shared/template.lua | 2 ++ xmake/templates/vala/static/project/src/main.vala | 6 ++++++ xmake/templates/vala/static/project/src/mymath.vala | 9 +++++++++ xmake/templates/vala/static/project/xmake.lua | 18 ++++++++++++++++++ xmake/templates/vala/static/template.lua | 2 ++ 11 files changed, 105 insertions(+) create mode 100644 xmake/templates/vala/console/project/src/main.vala create mode 100644 xmake/templates/vala/console/project/xmake.lua create mode 100644 xmake/templates/vala/console/template.lua create mode 100644 xmake/templates/vala/shared/project/src/main.vala create mode 100644 xmake/templates/vala/shared/project/src/mymath.vala create mode 100644 xmake/templates/vala/shared/project/xmake.lua create mode 100644 xmake/templates/vala/shared/template.lua create mode 100644 xmake/templates/vala/static/project/src/main.vala create mode 100644 xmake/templates/vala/static/project/src/mymath.vala create mode 100644 xmake/templates/vala/static/project/xmake.lua create mode 100644 xmake/templates/vala/static/template.lua diff --git a/xmake/templates/vala/console/project/src/main.vala b/xmake/templates/vala/console/project/src/main.vala new file mode 100644 index 000000000..8e8a32da0 --- /dev/null +++ b/xmake/templates/vala/console/project/src/main.vala @@ -0,0 +1,21 @@ +using Lua; + +static int my_func (LuaVM vm) { + stdout.printf ("Vala Code From Lua Code! (%f)\n", vm.to_number (1)); + return 1; +} + +static int main (string[] args) { + + string code = """ + print "Lua Code From Vala Code!" + my_func(33) + """; + + var vm = new LuaVM (); + vm.open_libs (); + vm.register ("my_func", my_func); + vm.do_string (code); + + return 0; +} diff --git a/xmake/templates/vala/console/project/xmake.lua b/xmake/templates/vala/console/project/xmake.lua new file mode 100644 index 000000000..474572597 --- /dev/null +++ b/xmake/templates/vala/console/project/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") + +add_requires("lua", "glib") + +target("${TARGETNAME}") + set_kind("binary") + add_rules("vala") + add_files("src/*.vala") + add_packages("lua", "glib") + add_values("vala.packages", "lua") + +${FAQ} diff --git a/xmake/templates/vala/console/template.lua b/xmake/templates/vala/console/template.lua new file mode 100644 index 000000000..ed2e13b57 --- /dev/null +++ b/xmake/templates/vala/console/template.lua @@ -0,0 +1,2 @@ +template("console") + add_configfiles("xmake.lua") diff --git a/xmake/templates/vala/shared/project/src/main.vala b/xmake/templates/vala/shared/project/src/main.vala new file mode 100644 index 000000000..da9fd895e --- /dev/null +++ b/xmake/templates/vala/shared/project/src/main.vala @@ -0,0 +1,6 @@ +using MyMath; + +public void main() { + stdout.printf("\n\t2 + 3 is %d", sum(2, 3)); + stdout.printf("\n\t8 squared is %d\n", square(8)); +} diff --git a/xmake/templates/vala/shared/project/src/mymath.vala b/xmake/templates/vala/shared/project/src/mymath.vala new file mode 100644 index 000000000..4f4e761c5 --- /dev/null +++ b/xmake/templates/vala/shared/project/src/mymath.vala @@ -0,0 +1,9 @@ +namespace MyMath { + public int sum(int a, int b) { + return(a + b); + } + + public int square(int a) { + return(a * a); + } +} diff --git a/xmake/templates/vala/shared/project/xmake.lua b/xmake/templates/vala/shared/project/xmake.lua new file mode 100644 index 000000000..e9148106c --- /dev/null +++ b/xmake/templates/vala/shared/project/xmake.lua @@ -0,0 +1,18 @@ +add_rules("mode.release", "mode.debug") + +add_requires("glib") + +target("mymath") + set_kind("shared") + add_rules("vala") + add_files("src/mymath.vala") + add_values("vala.header", "mymath.h") + add_values("vala.vapi", "mymath-1.0.vapi") + add_packages("glib") + +target("${TARGETNAME}") + set_kind("binary") + add_deps("mymath") + add_rules("vala") + add_files("src/main.vala") + add_packages("glib") diff --git a/xmake/templates/vala/shared/template.lua b/xmake/templates/vala/shared/template.lua new file mode 100644 index 000000000..d7ec5bae4 --- /dev/null +++ b/xmake/templates/vala/shared/template.lua @@ -0,0 +1,2 @@ +template("shared") + add_configfiles("xmake.lua") diff --git a/xmake/templates/vala/static/project/src/main.vala b/xmake/templates/vala/static/project/src/main.vala new file mode 100644 index 000000000..da9fd895e --- /dev/null +++ b/xmake/templates/vala/static/project/src/main.vala @@ -0,0 +1,6 @@ +using MyMath; + +public void main() { + stdout.printf("\n\t2 + 3 is %d", sum(2, 3)); + stdout.printf("\n\t8 squared is %d\n", square(8)); +} diff --git a/xmake/templates/vala/static/project/src/mymath.vala b/xmake/templates/vala/static/project/src/mymath.vala new file mode 100644 index 000000000..4f4e761c5 --- /dev/null +++ b/xmake/templates/vala/static/project/src/mymath.vala @@ -0,0 +1,9 @@ +namespace MyMath { + public int sum(int a, int b) { + return(a + b); + } + + public int square(int a) { + return(a * a); + } +} diff --git a/xmake/templates/vala/static/project/xmake.lua b/xmake/templates/vala/static/project/xmake.lua new file mode 100644 index 000000000..143566fcb --- /dev/null +++ b/xmake/templates/vala/static/project/xmake.lua @@ -0,0 +1,18 @@ +add_rules("mode.release", "mode.debug") + +add_requires("glib") + +target("mymath") + set_kind("static") + add_rules("vala") + add_files("src/mymath.vala") + add_values("vala.header", "mymath.h") + add_values("vala.vapi", "mymath-1.0.vapi") + add_packages("glib") + +target("${TARGETNAME}") + set_kind("binary") + add_deps("mymath") + add_rules("vala") + add_files("src/main.vala") + add_packages("glib") diff --git a/xmake/templates/vala/static/template.lua b/xmake/templates/vala/static/template.lua new file mode 100644 index 000000000..abfe91a4b --- /dev/null +++ b/xmake/templates/vala/static/template.lua @@ -0,0 +1,2 @@ +template("static") + add_configfiles("xmake.lua") -- cgit v1.3.1 From 5742d2bd4c4b7e760c22531c37d8c9eb5d7df709 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:51:22 +0800 Subject: add missing files --- xmake/rules/pascal/build/target.lua | 98 +++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 xmake/rules/pascal/build/target.lua diff --git a/xmake/rules/pascal/build/target.lua b/xmake/rules/pascal/build/target.lua new file mode 100644 index 000000000..8d7662055 --- /dev/null +++ b/xmake/rules/pascal/build/target.lua @@ -0,0 +1,98 @@ +--!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 target.lua +-- + +-- imports +import("core.base.option") +import("core.base.hashset") +import("core.theme.theme") +import("core.tool.compiler") +import("core.project.depend") + +-- build the source files +function build_sourcefiles(target, sourcebatch, opt) + + -- is verbose? + local verbose = option.get("verbose") + + -- get progress range + local progress = assert(opt.progress, "no progress!") + + -- get the target file + local targetfile = target:targetfile() + + -- get source files and kind + local sourcefiles = sourcebatch.sourcefiles + local sourcekind = sourcebatch.sourcekind + + -- get depend file + local dependfile = target:dependfile(targetfile) + + -- 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(targetfile), values = depvalues}) then + return + end + + -- trace progress into + cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", progress) + if verbose then + cprint("${dim color.build.target}linking.$(mode) %s", path.filename(targetfile)) + else + cprint("${color.build.target}linking.$(mode) %s", path.filename(targetfile)) + end + + -- trace verbose info + if verbose then + print(compinst:buildcmd(sourcefiles, targetfile, {target = target, compflags = compflags})) + end + + -- flush io buffer to update progress info + io.flush() + + -- compile it + dependinfo.files = {} + assert(compinst:build(sourcefiles, targetfile, {target = target, 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 + +-- build target +function main(target, opt) + + -- @note only support one source kind! + for _, sourcebatch in pairs(target:sourcebatches()) do + if sourcebatch.sourcekind == "pc" then + build_sourcefiles(target, sourcebatch, opt) + break + end + end +end -- cgit v1.3.1 From 5375f19a262a32e9cc9464ed578350026b5b1867 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:51:40 +0800 Subject: add fpc to windows --- xmake/platforms/windows/xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index fb075adbe..caf707d50 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -38,7 +38,7 @@ platform("windows") set_formats("symbol", "$(name).pdb") -- set toolchains - set_toolchains("msvc", "clang", "yasm", "nasm", "cuda", "dlang", "rust", "go", "gfortran", "zig") + set_toolchains("msvc", "clang", "yasm", "nasm", "cuda", "dlang", "rust", "go", "gfortran", "zig", "fpc") -- set menu set_menu { -- cgit v1.3.1 From 767219ac1f3fb11f592d5a84b62cc2f199ab893a Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 2 Sep 2021 23:52:56 +0800 Subject: update readme and changelog --- CHANGELOG.md | 8 ++++++++ README.md | 2 ++ README_zh.md | 2 ++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d620e954..4524d2b69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### New features + +* [#388](https://github.com/xmake-io/xmake/issues/388): Pascal Language Support + ### Change * [#1618](https://github.com/xmake-io/xmake/issues/1618): Improve vala to support to generate libraries and bindings @@ -1066,6 +1070,10 @@ ## master (开发中) +### 新特性 + +* [#388](https://github.com/xmake-io/xmake/issues/388): Pascal 语言支持,可以使用 fpc 来编译 free pascal + ### 改进 * [#1618](https://github.com/xmake-io/xmake/issues/1618): 改进 vala 支持构建动态库和静态库程序 diff --git a/README.md b/README.md index bbff9155f..425860f22 100644 --- a/README.md +++ b/README.md @@ -223,6 +223,7 @@ emcc A toolchain for compiling to asm.js and WebAssembly icc Intel C/C++ Compiler ifort Intel Fortran Compiler muslcc The musl-based cross-compilation toolchains +fpc Free Pascal Programming Language Compiler ``` ## Supported Languages @@ -239,6 +240,7 @@ muslcc The musl-based cross-compilation toolchains * Cuda * Zig * Vala +* Pascal ## Support Features diff --git a/README_zh.md b/README_zh.md index 2ef9752cf..14ef4938d 100644 --- a/README_zh.md +++ b/README_zh.md @@ -231,6 +231,7 @@ emcc A toolchain for compiling to asm.js and WebAssembly icc Intel C/C++ Compiler ifort Intel Fortran Compiler muslcc The musl-based cross-compilation toolchains +fpc Free Pascal Programming Language Compiler ``` ## 支持语言 @@ -246,6 +247,7 @@ muslcc The musl-based cross-compilation toolchains * Cuda * Zig * Vala +* Pascal ## 支持特性 -- cgit v1.3.1