diff options
| author | ruki <[email protected]> | 2021-09-04 00:58:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-09-04 00:58:26 +0800 |
| commit | c4b3c9836293e77fcfc87b3e8f788cc974b1e59a (patch) | |
| tree | ce9d93b6a99b750d31d73982e929f16e122a3cb6 | |
| parent | 836284af26a6d4edb1670cd6266d31c16b43ba2c (diff) | |
add pascal shared template
| -rw-r--r-- | tests/projects/pascal/shared/src/foo.pas | 24 | ||||
| -rw-r--r-- | tests/projects/pascal/shared/src/main.pas | 15 | ||||
| -rw-r--r-- | tests/projects/pascal/static/src/foo.pas | 23 | ||||
| -rw-r--r-- | tests/projects/pascal/static/src/main.pas | 14 | ||||
| -rw-r--r-- | xmake/templates/pascal/shared/project/src/foo.pas | 19 | ||||
| -rw-r--r-- | xmake/templates/pascal/shared/project/src/main.pas | 13 | ||||
| -rw-r--r-- | xmake/templates/pascal/shared/project/xmake.lua | 12 | ||||
| -rw-r--r-- | xmake/templates/pascal/shared/template.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/fpc/xmake.lua | 3 |
9 files changed, 81 insertions, 44 deletions
diff --git a/tests/projects/pascal/shared/src/foo.pas b/tests/projects/pascal/shared/src/foo.pas index d1952cf21..788950f46 100644 --- a/tests/projects/pascal/shared/src/foo.pas +++ b/tests/projects/pascal/shared/src/foo.pas @@ -1,23 +1,19 @@ library foo; -function SubStr(CString: PChar;FromPos,ToPos: Longint): PChar; cdecl; - -var - Length: Integer; +{$mode objfpc}{$H+} +function fib(n : Int64) : Int64; cdecl; begin - Length := StrLen(CString); - SubStr := CString + Length; - if (FromPos > 0) and (ToPos >= FromPos) then + if n > 1 then begin - if Length >= FromPos then - SubStr := CString + FromPos; - if Length > ToPos then - CString[ToPos+1] := #0; - end; + Result := fib(n - 1) + fib(n - 2); + end + else + Result := 1; end; exports - SubStr; - + fib; end. + + diff --git a/tests/projects/pascal/shared/src/main.pas b/tests/projects/pascal/shared/src/main.pas index ccf2e179b..02d5e88d0 100644 --- a/tests/projects/pascal/shared/src/main.pas +++ b/tests/projects/pascal/shared/src/main.pas @@ -1,14 +1,13 @@ -uses strings; +program hello; -function SubStr(const CString: PChar; FromPos, ToPos: longint): PChar; +function fib(n: Int64): Int64; cdecl; external 'foo'; var - s: PChar; - FromPos, ToPos: Integer; + Value: Integer; begin - s := strnew('TestMe'); - FromPos := 2; - ToPos := 3; - WriteLn(SubStr(s, FromPos, ToPos)); + Value := 5; + WriteLn(fib(Value)); end. + + diff --git a/tests/projects/pascal/static/src/foo.pas b/tests/projects/pascal/static/src/foo.pas index d1952cf21..1fb4d7d6e 100644 --- a/tests/projects/pascal/static/src/foo.pas +++ b/tests/projects/pascal/static/src/foo.pas @@ -1,23 +1,18 @@ library foo; -function SubStr(CString: PChar;FromPos,ToPos: Longint): PChar; cdecl; - -var - Length: Integer; +{$mode objfpc}{$H+} +function fib(n : Int64) : Int64; cdecl; begin - Length := StrLen(CString); - SubStr := CString + Length; - if (FromPos > 0) and (ToPos >= FromPos) then + if n > 1 then begin - if Length >= FromPos then - SubStr := CString + FromPos; - if Length > ToPos then - CString[ToPos+1] := #0; - end; + Result := fib(n - 1) + fib(n - 2); + end + else + Result := 1; end; exports - SubStr; - + fib; end. + diff --git a/tests/projects/pascal/static/src/main.pas b/tests/projects/pascal/static/src/main.pas index ccf2e179b..ce34e4af9 100644 --- a/tests/projects/pascal/static/src/main.pas +++ b/tests/projects/pascal/static/src/main.pas @@ -1,14 +1,12 @@ -uses strings; +program hello; -function SubStr(const CString: PChar; FromPos, ToPos: longint): PChar; +function fib(n: Int64): Int64; cdecl; external 'foo'; var - s: PChar; - FromPos, ToPos: Integer; + Value: Integer; begin - s := strnew('TestMe'); - FromPos := 2; - ToPos := 3; - WriteLn(SubStr(s, FromPos, ToPos)); + Value := 5; + WriteLn(fib(Value)); end. + diff --git a/xmake/templates/pascal/shared/project/src/foo.pas b/xmake/templates/pascal/shared/project/src/foo.pas new file mode 100644 index 000000000..788950f46 --- /dev/null +++ b/xmake/templates/pascal/shared/project/src/foo.pas @@ -0,0 +1,19 @@ +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/xmake/templates/pascal/shared/project/src/main.pas b/xmake/templates/pascal/shared/project/src/main.pas new file mode 100644 index 000000000..02d5e88d0 --- /dev/null +++ b/xmake/templates/pascal/shared/project/src/main.pas @@ -0,0 +1,13 @@ +program hello; + +function fib(n: Int64): Int64; + cdecl; external 'foo'; + +var + Value: Integer; +begin + Value := 5; + WriteLn(fib(Value)); +end. + + diff --git a/xmake/templates/pascal/shared/project/xmake.lua b/xmake/templates/pascal/shared/project/xmake.lua new file mode 100644 index 000000000..dd29cf486 --- /dev/null +++ b/xmake/templates/pascal/shared/project/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") +target("foo") + set_kind("shared") + add_files("src/foo.pas") + +target("${TARGETNAME}") + set_kind("binary") + add_deps("foo") + add_files("src/main.pas") + + +${FAQ} diff --git a/xmake/templates/pascal/shared/template.lua b/xmake/templates/pascal/shared/template.lua new file mode 100644 index 000000000..d7ec5bae4 --- /dev/null +++ b/xmake/templates/pascal/shared/template.lua @@ -0,0 +1,2 @@ +template("shared") + add_configfiles("xmake.lua") diff --git a/xmake/toolchains/fpc/xmake.lua b/xmake/toolchains/fpc/xmake.lua index 82c7f6dc8..0d9cba292 100644 --- a/xmake/toolchains/fpc/xmake.lua +++ b/xmake/toolchains/fpc/xmake.lua @@ -35,4 +35,7 @@ toolchain("fpc") on_load(function (toolchain) toolchain:set("pcshflags", "-Sd") toolchain:set("pcldflags", "-Sd") + if toolchain:is_plat("linux") then + toolchain:add("pcldflags", "-k-lc") + end end) |
