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/modules/core/tools/fpc.lua | 142 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 xmake/modules/core/tools/fpc.lua (limited to 'xmake/modules/core/tools/fpc.lua') 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 + -- 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(-) (limited to 'xmake/modules/core/tools/fpc.lua') 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(-) (limited to 'xmake/modules/core/tools/fpc.lua') 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 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 (limited to 'xmake/modules/core/tools/fpc.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(-) (limited to 'xmake/modules/core/tools/fpc.lua') 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(-) (limited to 'xmake/modules/core/tools/fpc.lua') 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 91a2ebc3edf46a26c00807953e3a22d716bdeb95 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 3 Sep 2021 00:14:46 +0800 Subject: add static library for pascal --- tests/projects/pascal/static/src/foo.pas | 23 +++++++++++++++++++++++ tests/projects/pascal/static/src/main.pas | 14 ++++++++++++++ tests/projects/pascal/static/xmake.lua | 9 +++++++++ xmake/modules/core/tools/fpc.lua | 1 + 4 files changed, 47 insertions(+) create mode 100644 tests/projects/pascal/static/src/foo.pas create mode 100644 tests/projects/pascal/static/src/main.pas create mode 100644 tests/projects/pascal/static/xmake.lua (limited to 'xmake/modules/core/tools/fpc.lua') diff --git a/tests/projects/pascal/static/src/foo.pas b/tests/projects/pascal/static/src/foo.pas new file mode 100644 index 000000000..d1952cf21 --- /dev/null +++ b/tests/projects/pascal/static/src/foo.pas @@ -0,0 +1,23 @@ +library foo; + +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/static/src/main.pas b/tests/projects/pascal/static/src/main.pas new file mode 100644 index 000000000..ccf2e179b --- /dev/null +++ b/tests/projects/pascal/static/src/main.pas @@ -0,0 +1,14 @@ +uses strings; + +function SubStr(const CString: PChar; FromPos, ToPos: longint): PChar; + cdecl; external 'foo'; + +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/static/xmake.lua b/tests/projects/pascal/static/xmake.lua new file mode 100644 index 000000000..759cf69ad --- /dev/null +++ b/tests/projects/pascal/static/xmake.lua @@ -0,0 +1,9 @@ +add_rules("mode.debug", "mode.release") +target("foo") + set_kind("static") + add_files("src/foo.pas") + +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 de5b349c6..378c4175a 100644 --- a/xmake/modules/core/tools/fpc.lua +++ b/xmake/modules/core/tools/fpc.lua @@ -25,6 +25,7 @@ import("core.project.project") -- init it function init(self) + self:set("pcarflags", "-Xt") end -- make the optimize flag -- cgit v1.3.1 From d65446740b572217af9a96dd908ba8397752a65a Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 4 Sep 2021 21:23:01 +0800 Subject: add fpic to pascal --- xmake/modules/core/tools/fpc.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'xmake/modules/core/tools/fpc.lua') diff --git a/xmake/modules/core/tools/fpc.lua b/xmake/modules/core/tools/fpc.lua index 378c4175a..c22386fbb 100644 --- a/xmake/modules/core/tools/fpc.lua +++ b/xmake/modules/core/tools/fpc.lua @@ -26,6 +26,9 @@ import("core.project.project") -- init it function init(self) self:set("pcarflags", "-Xt") + if not is_plat("windows", "mingw") then + self:add("shared.pcflags", "-Cg") + end end -- make the optimize flag -- cgit v1.3.1 From 718c75717bab367194ee3220cdef3d64f17962d8 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 4 Sep 2021 22:15:23 +0800 Subject: remove static library for pascal --- tests/projects/pascal/static/src/foo.pas | 18 ------------------ tests/projects/pascal/static/src/main.pas | 12 ------------ tests/projects/pascal/static/xmake.lua | 9 --------- xmake/languages/pascal/xmake.lua | 4 ++-- xmake/modules/core/tools/fpc.lua | 1 - xmake/toolchains/fpc/xmake.lua | 5 +---- 6 files changed, 3 insertions(+), 46 deletions(-) delete mode 100644 tests/projects/pascal/static/src/foo.pas delete mode 100644 tests/projects/pascal/static/src/main.pas delete mode 100644 tests/projects/pascal/static/xmake.lua (limited to 'xmake/modules/core/tools/fpc.lua') diff --git a/tests/projects/pascal/static/src/foo.pas b/tests/projects/pascal/static/src/foo.pas deleted file mode 100644 index 1fb4d7d6e..000000000 --- a/tests/projects/pascal/static/src/foo.pas +++ /dev/null @@ -1,18 +0,0 @@ -library foo; - -{$mode objfpc}{$H+} - -function fib(n : Int64) : Int64; cdecl; -begin - if n > 1 then - begin - Result := fib(n - 1) + fib(n - 2); - end - else - Result := 1; -end; - -exports - fib; -end. - diff --git a/tests/projects/pascal/static/src/main.pas b/tests/projects/pascal/static/src/main.pas deleted file mode 100644 index ce34e4af9..000000000 --- a/tests/projects/pascal/static/src/main.pas +++ /dev/null @@ -1,12 +0,0 @@ -program hello; - -function fib(n: Int64): Int64; - cdecl; external 'foo'; - -var - Value: Integer; -begin - Value := 5; - WriteLn(fib(Value)); -end. - diff --git a/tests/projects/pascal/static/xmake.lua b/tests/projects/pascal/static/xmake.lua deleted file mode 100644 index 759cf69ad..000000000 --- a/tests/projects/pascal/static/xmake.lua +++ /dev/null @@ -1,9 +0,0 @@ -add_rules("mode.debug", "mode.release") -target("foo") - set_kind("static") - add_files("src/foo.pas") - -target("test") - set_kind("binary") - add_deps("foo") - add_files("src/main.pas") diff --git a/xmake/languages/pascal/xmake.lua b/xmake/languages/pascal/xmake.lua index 68d6b5daf..298b9752f 100644 --- a/xmake/languages/pascal/xmake.lua +++ b/xmake/languages/pascal/xmake.lua @@ -22,8 +22,8 @@ language("pascal") add_rules("pascal") set_sourcekinds {pc = {".pas", ".pp", ".ppu", ".lpr"}} set_sourceflags {pc = "pcflags"} - set_targetkinds {binary = "pcld", static = "pcar", shared = "pcsh"} - set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} + set_targetkinds {binary = "pcld", shared = "pcsh"} + set_targetflags {binary = "ldflags", shared = "shflags"} set_langkinds {pascal = "pc"} set_mixingkinds("pc") diff --git a/xmake/modules/core/tools/fpc.lua b/xmake/modules/core/tools/fpc.lua index c22386fbb..98b746c8a 100644 --- a/xmake/modules/core/tools/fpc.lua +++ b/xmake/modules/core/tools/fpc.lua @@ -25,7 +25,6 @@ import("core.project.project") -- init it function init(self) - self:set("pcarflags", "-Xt") if not is_plat("windows", "mingw") then self:add("shared.pcflags", "-Cg") end diff --git a/xmake/toolchains/fpc/xmake.lua b/xmake/toolchains/fpc/xmake.lua index d84a383cc..cb2855625 100644 --- a/xmake/toolchains/fpc/xmake.lua +++ b/xmake/toolchains/fpc/xmake.lua @@ -29,13 +29,10 @@ toolchain("fpc") set_toolset("pc", "$(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", "") - if toolchain:is_plat("linux") then - toolchain:add("pcldflags", "-k-lc") - end + toolchain:add("syslinks", "c") end) -- cgit v1.3.1