diff options
| author | ruki <[email protected]> | 2020-02-26 22:36:32 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-02-26 09:39:12 +0800 |
| commit | ad15bd3efa81795baf0b99f69c9150b1763647c2 (patch) | |
| tree | 64656a9ca5bee10e6370be5700880a0dacb06613 | |
| parent | 510eccaf9ff776077b75ae189ac850035c6d3680 (diff) | |
improve make install
| -rw-r--r-- | core/src/xmake/machine.c | 29 | ||||
| -rw-r--r-- | makefile | 19 |
2 files changed, 19 insertions, 29 deletions
diff --git a/core/src/xmake/machine.c b/core/src/xmake/machine.c index f8704ff7f..f086dd17f 100644 --- a/core/src/xmake/machine.c +++ b/core/src/xmake/machine.c @@ -487,7 +487,6 @@ static tb_bool_t xm_machine_get_program_directory(xm_machine_t* machine, tb_char tb_char_t data[TB_PATH_MAXN] = {0}; if (tb_environment_first("XMAKE_PROGRAM_DIR", data, sizeof(data)) && tb_path_absolute(data, path, maxn)) { - // ok ok = tb_true; break; } @@ -495,19 +494,25 @@ static tb_bool_t xm_machine_get_program_directory(xm_machine_t* machine, tb_char // get it from program file path if (programfile) { - tb_size_t size = tb_strlcpy(data, programfile, sizeof(data)); - if (size < sizeof(data)) + // get the root directory + tb_char_t data[TB_PATH_MAXN]; + tb_char_t const* rootdir = tb_path_directory(programfile, data, sizeof(data)); + tb_assert_and_check_break(rootdir); + + // find the program (lua) directory + tb_size_t i; + tb_file_info_t info; + tb_char_t scriptpath[TB_PATH_MAXN]; + tb_char_t const* subdirs[] = {"", "../share/xmake"}; + for (i = 0; i < tb_arrayn(subdirs); i++) { - // get the directory - while (size-- > 0) + // get program directory + if (tb_path_absolute_to(rootdir, subdirs[i], path, maxn) && + tb_path_absolute_to(path, "core/_xmake_main.lua", scriptpath, sizeof(scriptpath)) && + tb_file_info(scriptpath, &info) && info.type == TB_FILE_TYPE_FILE) { - if (data[size] == '\\' || data[size] == '/') - { - data[size] = '\0'; - tb_strlcpy(path, data, maxn); - ok = tb_true; - break; - } + ok = tb_true; + break; } } } @@ -81,19 +81,12 @@ endif destdir :=$(if $(DESTDIR),$(DESTDIR)/$(prefix),$(prefix)) xmake_dir_install :=$(destdir)/share/xmake -xmake_dir_install2 :=$(prefix)/share/xmake xmake_core :=./core/src/demo/demo.b ifdef iswin -# we need load msys-2.0.dll or cygwin1.dll on bin directory -# and we use the xmake_core.exe, because xmake script and exe are in same directory -xmake_core_install :=$(destdir)/bin/xmake_core.exe -xmake_core_install2 :=$(prefix)/bin/xmake_core.exe +xmake_core_install :=$(destdir)/bin/xmake.exe else -xmake_core_install :=$(xmake_dir_install)/xmake -xmake_core_install2 :=$(xmake_dir_install2)/xmake +xmake_core_install :=$(destdir)/bin/xmake endif -xmake_loader :=$(TMP_DIR)/xmake_loader -xmake_loader_install:=$(destdir)/bin/xmake tip: @echo 'Usage: ' @@ -118,13 +111,6 @@ install: @if [ ! -d $(destdir)/bin ]; then mkdir -p $(destdir)/bin; fi @# install the xmake directory @cp -r xmake/* $(xmake_dir_install) - @# make the xmake loader - @echo '#!/bin/bash' > $(xmake_loader) - @echo 'export XMAKE_PROGRAM_DIR=$(xmake_dir_install2)' >> $(xmake_loader) - @echo '$(xmake_core_install2) $(verbose) "$$@"' >> $(xmake_loader) - @# install the xmake loader - @mv $(xmake_loader) $(xmake_loader_install) - @chmod 777 $(xmake_loader_install) @# install the xmake core file @cp $(xmake_core) $(xmake_core_install) @chmod 777 $(xmake_core_install) @@ -135,7 +121,6 @@ install: uninstall: @echo uninstalling from $(destdir) ... - @if [ -f $(xmake_loader_install) ]; then rm $(xmake_loader_install); fi @if [ -d $(xmake_dir_install) ]; then rm -rf $(xmake_dir_install); fi @echo ok! |
