summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-09-02 18:16:11 +0800
committerGitHub <[email protected]>2021-09-02 18:16:11 +0800
commit20c34dcaf9ff92ecf08a1cec7e4d1be9836e6067 (patch)
tree69f67a0667475a27ad05178bfbe25746bc060bef
parentce527abaa4e78b5d2d194512f875681e501794ac (diff)
parent767219ac1f3fb11f592d5a84b62cc2f199ab893a (diff)
Merge pull request #1629 from xmake-io/pascal
Add Pascal language support
-rw-r--r--CHANGELOG.md8
-rw-r--r--README.md2
-rw-r--r--README_zh.md2
-rw-r--r--tests/projects/pascal/console/src/main.pas4
-rw-r--r--tests/projects/pascal/console/xmake.lua5
-rw-r--r--tests/projects/pascal/shared/src/foo.pas23
-rw-r--r--tests/projects/pascal/shared/src/main.pas14
-rw-r--r--tests/projects/pascal/shared/xmake.lua9
-rw-r--r--xmake/languages/pascal/check_main.lua40
-rw-r--r--xmake/languages/pascal/load.lua74
-rw-r--r--xmake/languages/pascal/xmake.lua90
-rw-r--r--xmake/modules/core/tools/fpc.lua107
-rw-r--r--xmake/modules/core/tools/zig.lua1
-rw-r--r--xmake/modules/detect/tools/find_fpc.lua52
-rw-r--r--xmake/modules/detect/tools/fpc/has_flags.lua98
-rw-r--r--xmake/platforms/linux/xmake.lua2
-rw-r--r--xmake/platforms/macosx/xmake.lua2
-rw-r--r--xmake/platforms/windows/xmake.lua2
-rw-r--r--xmake/rules/pascal/build/target.lua98
-rw-r--r--xmake/rules/pascal/xmake.lua33
-rw-r--r--xmake/templates/pascal/console/project/src/main.pas4
-rw-r--r--xmake/templates/pascal/console/project/xmake.lua7
-rw-r--r--xmake/templates/pascal/console/template.lua2
-rw-r--r--xmake/templates/vala/console/project/src/main.vala21
-rw-r--r--xmake/templates/vala/console/project/xmake.lua12
-rw-r--r--xmake/templates/vala/console/template.lua2
-rw-r--r--xmake/templates/vala/shared/project/src/main.vala6
-rw-r--r--xmake/templates/vala/shared/project/src/mymath.vala9
-rw-r--r--xmake/templates/vala/shared/project/xmake.lua18
-rw-r--r--xmake/templates/vala/shared/template.lua2
-rw-r--r--xmake/templates/vala/static/project/src/main.vala6
-rw-r--r--xmake/templates/vala/static/project/src/mymath.vala9
-rw-r--r--xmake/templates/vala/static/project/xmake.lua18
-rw-r--r--xmake/templates/vala/static/template.lua2
-rw-r--r--xmake/toolchains/fpc/xmake.lua38
35 files changed, 818 insertions, 4 deletions
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
## 支持特性
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")
+
diff --git a/tests/projects/pascal/shared/src/foo.pas b/tests/projects/pascal/shared/src/foo.pas
new file mode 100644
index 000000000..d1952cf21
--- /dev/null
+++ b/tests/projects/pascal/shared/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/shared/src/main.pas b/tests/projects/pascal/shared/src/main.pas
new file mode 100644
index 000000000..ccf2e179b
--- /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 '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/shared/xmake.lua b/tests/projects/pascal/shared/xmake.lua
new file mode 100644
index 000000000..d96c29d5f
--- /dev/null
+++ b/tests/projects/pascal/shared/xmake.lua
@@ -0,0 +1,9 @@
+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")
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..6a1f1ca5b
--- /dev/null
+++ b/xmake/languages/pascal/load.lua
@@ -0,0 +1,74 @@
+--!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_frameworks"
+ , "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"
+ -- 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"
+ }
+ apis.paths = {
+ -- target.add_xxx
+ "target.add_linkdirs"
+ , "target.add_frameworkdirs"
+ -- option.add_xxx
+ , "option.add_linkdirs"
+ }
+ 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..a3e1fb5b3
--- /dev/null
+++ b/xmake/languages/pascal/xmake.lua
@@ -0,0 +1,90 @@
+--!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 = "pcar", shared = "pcsh"}
+ set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"}
+ set_langkinds {pascal = "pc"}
+ set_mixingkinds("pc")
+
+ on_load("load")
+ on_check_main("check_main")
+
+ set_nameflags {
+ object = {
+ "target.symbols"
+ , "target.warnings"
+ , "target.optimize:check"
+ , "target.vectorexts:check"
+ }
+ , binary = {
+ "config.linkdirs"
+ , "target.linkdirs"
+ , "target.rpathdirs"
+ , "target.strip"
+ , "target.symbols"
+ , "toolchain.linkdirs"
+ , "toolchain.rpathdirs"
+ , "config.links"
+ , "target.links"
+ , "target.frameworks"
+ , "target.frameworkdirs"
+ , "toolchain.links"
+ , "config.syslinks"
+ , "target.syslinks"
+ , "toolchain.syslinks"
+ }
+ , shared = {
+ "config.linkdirs"
+ , "target.linkdirs"
+ , "target.strip"
+ , "target.symbols"
+ , "toolchain.linkdirs"
+ , "config.links"
+ , "target.links"
+ , "target.frameworks"
+ , "target.frameworkdirs"
+ , "toolchain.links"
+ , "config.syslinks"
+ , "target.syslinks"
+ , "toolchain.syslinks"
+ }
+ }
+
+ 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" }
+ }
+ }
+
diff --git a/xmake/modules/core/tools/fpc.lua b/xmake/modules/core/tools/fpc.lua
new file mode 100644
index 000000000..de5b349c6
--- /dev/null
+++ b/xmake/modules/core/tools/fpc.lua
@@ -0,0 +1,107 @@
+--!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")
+
+-- init it
+function init(self)
+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
+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 {"-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)
+end
+
+-- build the target file
+function build(self, sourcefiles, targetkind, targetfile, flags)
+ os.mkdir(path.directory(targetfile))
+ os.runv(buildargv(self, sourcefiles, targetkind, targetfile, flags))
+end
+
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"
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
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/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/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 {
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
diff --git a/xmake/rules/pascal/xmake.lua b/xmake/rules/pascal/xmake.lua
new file mode 100644
index 000000000..5961c08d3
--- /dev/null
+++ b/xmake/rules/pascal/xmake.lua
@@ -0,0 +1,33 @@
+--!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_build("build.target")
+
+-- 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")
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")
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")
diff --git a/xmake/toolchains/fpc/xmake.lua b/xmake/toolchains/fpc/xmake.lua
new file mode 100644
index 000000000..82c7f6dc8
--- /dev/null
+++ b/xmake/toolchains/fpc/xmake.lua
@@ -0,0 +1,38 @@
+--!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")
+
+ -- set toolset
+ 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", "-Sd")
+ toolchain:set("pcldflags", "-Sd")
+ end)