Skip to content

Commit

Permalink
Use xmake pack to produce the deb package
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii authored Nov 24, 2024
1 parent a38a0c1 commit 91cf776
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 27 deletions.
112 changes: 97 additions & 15 deletions Goldfish.tmu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<TMU|<tuple|1.0.5|1.2.9.7-rc2>>
<TMU|<tuple|1.0.5|1.2.9.7-rc3>>

<style|<tuple|book|chinese|literate|goldfish|reduced-margins|guile|smart-ref|preview-ref|python>>

Expand Down Expand Up @@ -119,7 +119,7 @@
<item>中国科学技术大学-德清阿尔法创新研究院
</itemize>

<chapter|boot.scm>
<chapter|boot.scm><label|chapter:scheme_boot>

S7 Scheme默认并不遵循R7RS,在启动S7 Scheme之后,我们需要做的第一件事就是加载<scm|boot.scm>,实现R7RS的<scm|define-library>和<scm|import>。

Expand Down Expand Up @@ -17272,6 +17272,8 @@

#include \<less\>cstdlib\<gtr\>

#include \<less\>cstring\<gtr\>

#include \<less\>iostream\<gtr\>

#include \<less\>s7.h\<gtr\>
Expand Down Expand Up @@ -18591,12 +18593,32 @@

<paragraph|REPL>

<\cpp-chunk|src/goldfish.hpp|true|true>
int
<subparagraph|find_goldfish_library>

repl_for_community_edition (int argc, char** argv) {
定位Goldfish的函数库的目录,如果不存在,直接以-1为返回值退出,如果存在,则返回目录对应的完整路径。

<\description>
<item*|开发者模式>在这种模式下,Goldfish的可执行文件的路径是<shell|$(projectdir)/bin/goldfish>,而函数库的路径是<shell|$(projectdir)/goldfish)>。这种情况仅用于开发或者集成Goldfish。

<item*|Linux>

<\description>
<item*|/usr/bin/goldfish>

<item*|/usr/local/goldfish>

\ \ // Check if the standard library and boot.scm exists
这两种情况可以通过相对路径分别定位到Goldfish的函数库目录是<shell|/usr/share/goldfish>和<shell|/usr/local/share/goldfish>。

<item*|/bin/goldfish>

在这种情况下,我们直接将函数库目录设置为<shell|/usr/share/goldfish>。
</description>
</description>

<\cpp-chunk|src/goldfish.hpp|true|true>
string

find_goldfish_library (char** argv) {

\ \ tb_char_t \ \ \ \ \ \ \ data_goldfish[TB_PATH_MAXN]= {0};

Expand Down Expand Up @@ -18624,30 +18646,66 @@

\ \ tb_char_t \ \ \ \ \ \ \ data_lib[TB_PATH_MAXN]= {0};

\ \ tb_char_t const* gf_lib=
\ \ tb_char_t const* gf_lib= tb_path_absolute_to (gf_root, "share/goldfish",

\ \ \ \ \ \ tb_path_absolute_to (gf_root, "goldfish", data_lib, sizeof (data_lib));
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ data_lib, sizeof (data_lib));

\;
#ifdef TB_CONFIG_OS_LINUX

\ \ tb_char_t \ \ \ \ \ \ \ data_boot[TB_PATH_MAXN]= {0};
\ \ if (strcmp (gf_root, "/") == 0) {

\ \ tb_char_t const* gf_boot= tb_path_absolute_to (gf_lib, "scheme/boot.scm",
\ \ \ \ gf_lib= "/usr/share/goldfish";

\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ data_boot, sizeof (data_boot));
\ \ }

#endif

\;

\ \ if (!tb_file_access (gf_lib, TB_FILE_MODE_RO)) {

\ \ \ \ cerr \<less\>\<less\> "The load path for Goldfish Scheme Standard Library does not exist"
\ \ \ \ gf_lib=

\ \ \ \ \ \ \ \ \ \<less\>\<less\> endl;
\ \ \ \ \ \ \ \ tb_path_absolute_to (gf_root, "goldfish", data_lib, sizeof (data_lib));

\ \ \ \ exit (-1);
\ \ \ \ if (!tb_file_access (gf_lib, TB_FILE_MODE_RO)) {

\ \ \ \ \ \ cerr \<less\>\<less\> "The load path for Goldfish standard library does not exist"

\ \ \ \ \ \ \ \ \ \ \ \<less\>\<less\> endl;

\ \ \ \ \ \ exit (-1);

\ \ \ \ }

\ \ }

\;

\ \ return string (gf_lib);

}

\;
</cpp-chunk>

<subparagraph|find_goldfish_boot>

定位Goldfish用于启动的Scheme脚本文件,如果不存在,直接以-1为返回值退出,如果存在,则返回改文件对应的完整路径。关于<shell|boot.scm>的具体细节,见<smart-ref|chapter:scheme_boot>。

<\cpp-chunk|src/goldfish.hpp|true|true>
string

find_goldfish_boot (const char* gf_lib) {

\ \ tb_char_t \ \ \ \ \ \ \ data_boot[TB_PATH_MAXN]= {0};

\ \ tb_char_t const* gf_boot= tb_path_absolute_to (gf_lib, "scheme/boot.scm",

\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ data_boot, sizeof (data_boot));

\;

\ \ if (!tb_file_access (gf_boot, TB_FILE_MODE_RO)) {

\ \ \ \ cerr \<less\>\<less\> "The boot.scm for Goldfish Scheme does not exist" \<less\>\<less\> endl;
Expand All @@ -18656,6 +18714,30 @@

\ \ }

\ \ return string (gf_boot);

}

\;
</cpp-chunk>

<subparagraph|repl_for_community_edition>

<\cpp-chunk|src/goldfish.hpp|true|true>
int

repl_for_community_edition (int argc, char** argv) {

\ \ string \ \ \ \ \ gf_lib_dir \ = find_goldfish_library (argv);

\ \ const char* gf_lib \ \ \ \ \ = gf_lib_dir.c_str ();

\ \ string \ \ \ \ \ gf_boot_path= find_goldfish_boot (gf_lib);

\ \ const char* gf_boot \ \ \ \ = gf_boot_path.c_str ();

\;

\ \ vector\<less\>string\<gtr\> all_args (argv, argv + argc);

\ \ int \ \ \ \ \ \ \ \ \ \ \ all_args_N= all_args.size ();
Expand Down
45 changes: 35 additions & 10 deletions src/goldfish.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <s7.h>
#include <string>
Expand Down Expand Up @@ -564,9 +565,8 @@ customize_goldfish_by_mode (s7_scheme* sc, string mode,
}
}

int
repl_for_community_edition (int argc, char** argv) {
// Check if the standard library and boot.scm exists
string
find_goldfish_library (char** argv) {
tb_char_t data_goldfish[TB_PATH_MAXN]= {0};
tb_char_t const* goldfish=
tb_path_absolute (argv[0], data_goldfish, sizeof (data_goldfish));
Expand All @@ -580,22 +580,47 @@ repl_for_community_edition (int argc, char** argv) {
tb_path_directory (ret_bin, data_root, sizeof (data_root));

tb_char_t data_lib[TB_PATH_MAXN]= {0};
tb_char_t const* gf_lib=
tb_path_absolute_to (gf_root, "goldfish", data_lib, sizeof (data_lib));
tb_char_t const* gf_lib= tb_path_absolute_to (gf_root, "share/goldfish",
data_lib, sizeof (data_lib));
#ifdef TB_CONFIG_OS_LINUX
if (strcmp (gf_root, "/") == 0) {
gf_lib= "/usr/share/goldfish";
}
#endif

if (!tb_file_access (gf_lib, TB_FILE_MODE_RO)) {
gf_lib=
tb_path_absolute_to (gf_root, "goldfish", data_lib, sizeof (data_lib));
if (!tb_file_access (gf_lib, TB_FILE_MODE_RO)) {
cerr << "The load path for Goldfish standard library does not exist"
<< endl;
exit (-1);
}
}

return string (gf_lib);
}

string
find_goldfish_boot (const char* gf_lib) {
tb_char_t data_boot[TB_PATH_MAXN]= {0};
tb_char_t const* gf_boot= tb_path_absolute_to (gf_lib, "scheme/boot.scm",
data_boot, sizeof (data_boot));

if (!tb_file_access (gf_lib, TB_FILE_MODE_RO)) {
cerr << "The load path for Goldfish Scheme Standard Library does not exist"
<< endl;
exit (-1);
}
if (!tb_file_access (gf_boot, TB_FILE_MODE_RO)) {
cerr << "The boot.scm for Goldfish Scheme does not exist" << endl;
exit (-1);
}
return string (gf_boot);
}

int
repl_for_community_edition (int argc, char** argv) {
string gf_lib_dir = find_goldfish_library (argv);
const char* gf_lib = gf_lib_dir.c_str ();
string gf_boot_path= find_goldfish_boot (gf_lib);
const char* gf_boot = gf_boot_path.c_str ();

vector<string> all_args (argv, argv + argc);
int all_args_N= all_args.size ();
for (int i= 0; i < all_args_N; i++) {
Expand Down
23 changes: 21 additions & 2 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
set_version ("17.11.0")

-- mode
set_allowedmodes("releasedbg", "release", "debug", "profile")
add_rules("mode.releasedbg", "mode.release", "mode.debug", "mode.profile")
Expand Down Expand Up @@ -39,7 +41,24 @@ target ("goldfish") do
add_packages("s7")
add_packages("tbox")

add_installfiles("goldfish/(scheme/*.scm)", {prefixdir = "goldfish"})
add_installfiles("goldfish/(srfi/*.scm)", {prefixdir = "goldfish"})
add_installfiles("$(projectdir)/goldfish/(scheme/*.scm)", {prefixdir = "share/goldfish"})
add_installfiles("$(projectdir)/goldfish/(srfi/*.scm)", {prefixdir = "share/goldfish"})
add_installfiles("$(projectdir)/goldfish/(liii/*.scm)", {prefixdir = "share/goldfish"})
end

includes("@builtin/xpack")
xpack ("goldfish")
set_formats("deb")
set_author("Da Shen <[email protected]>")
set_license("Apache-2.0")
set_title("Goldfish Scheme")
set_description("A Python-like Scheme Interpreter")
add_targets ("goldfish")

on_load(function (package)
if package:with_source() then
package:set("basename", "goldfish-$(plat)-src-v$(version)")
else
package:set("basename", "goldfish-$(plat)-$(arch)-v$(version)")
end
end)

0 comments on commit 91cf776

Please sign in to comment.