From c00b8d8aa6470e7e83681f7bff061cc4e89c919e Mon Sep 17 00:00:00 2001 From: Lily Date: Sun, 3 Dec 2023 18:05:03 +0300 Subject: [PATCH 1/3] [MAIN] Making same as box64 output and fix termux make install --- CMakeLists.txt | 19 +++++++++++++++++-- src/main.c | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 19 deletions(-) mode change 100755 => 100644 src/main.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 05b26605b..b2be860f3 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,8 @@ string(COMPARE EQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}" "i686" _x86) string(COMPARE EQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}" "x86_64" _x86_64) string(COMPARE EQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}" "aarch64" _aarch64) string(COMPARE EQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}" "armhf" _armhf) +string(COMPARE EQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}" "arm" _arm) +string(COMPARE EQUAL "${CMAKE_HOST_SYSTEM_PROCESSOR}" "armv8l" _armv8l) if(_aarch64 AND (RK3399 OR ODROIDN2 OR TEGRAX1 OR RPI3ARM64 OR RPI4ARM64 OR PHYTIUM OR SD845 OR SD888 OR ADLINK OR A64 OR LX2160A OR RK3588 OR ARM64)) set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) @@ -754,8 +756,13 @@ else() endif() if(NOT _x86 AND NOT _x86_64) - install(TARGETS ${BOX86} + if(NOT TERMUX) + install(TARGETS ${BOX86} RUNTIME DESTINATION bin) + else() + install(TARGETS ${BOX86} + RUNTIME DESTINATION ${TERMUX_PATH}/usr/bin) + endif() if(NOT NO_CONF_INSTALL) configure_file(system/box86.conf.cmake system/box86.conf) if(NOT TERMUX) @@ -798,7 +805,11 @@ set(CPACK_GENERATOR "DEB") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "ptitSeb") set(CPACK_PACKAGE_CONTACT "ptitSeb@box86.org") set(CPACK_PACKAGE_DESCRIPTION "Box86 - Linux Userspace x86 Emulator with a twist") +if(TERMUX) +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libandroid-sysv-semaphore" "libandroid-spawn") +else() set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6") +endif() set(CPACK_PACKAGE_HOMEPAGE_URL, "https://box86.org") file(STRINGS "${BOX86_ROOT}/src/box86version.h" TEMP_STRING REGEX "BOX86_MAJOR\\s*") string(REGEX REPLACE "BOX86_MAJOR" "" TEMP_STRING ${TEMP_STRING}) @@ -813,8 +824,12 @@ set(CPACK_PACKAGE_VERSION_MAJOR ${BOX86_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${BOX86_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${BOX86_REVISION}) set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/postinst") -if(_aarch64 OR _armhf) +if(_aarch64 OR _armhf OR _arm OR _armv8l) + if(TERMUX) + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "arm") + else() set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "armhf") + endif() elseif(_x86_64 OR _x86) set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386") else() diff --git a/src/main.c b/src/main.c old mode 100755 new mode 100644 index b26151c37..50e3582a9 --- a/src/main.c +++ b/src/main.c @@ -44,7 +44,7 @@ #include "rcfile.h" box86context_t *my_context = NULL; -int box86_log = LOG_NONE; +int box86_log = 1; int box86_dump = 0; int box86_nobanner = 0; int box86_dynarec_log = LOG_NONE; @@ -842,14 +842,8 @@ int GatherEnv(char*** dest, char** env, const char* prog) } -void PrintHelp() { - printf("\n\nThis is Box86, the Linux x86 emulator with a twist\n"); - printf("\nUsage is box86 [options] path/to/software [args]\n"); - printf("to launch x86 software\n"); - printf(" options can be :\n"); - printf(" '-v'|'--version' to print box86 version and quit\n"); - printf(" '-h'|'--help' to print box86 help and quit\n"); - printf("You can also set some environment variables:\n"); +void PrintFlags() { + printf("Environment Variables:\n"); printf(" BOX86_PATH is the box86 version of PATH (default is '.:bin')\n"); printf(" BOX86_LD_LIBRARY_PATH is the box86 version LD_LIBRARY_PATH (default is '.:lib')\n"); printf(" BOX86_LOG with 0/1/2/3 or NONE/INFO/DEBUG/DUMP to set the printed debug info (level 3 is level 2 + BOX86_DUMP)\n"); @@ -877,7 +871,7 @@ void PrintHelp() { printf(" BOX86_DYNAREC_TRACE with 0/1 to disable or enable Trace on generated code too\n"); #endif #endif - printf(" BOX86_TRACE_FILE with FileName to redirect logs in a file (or stderr to use stderr instead of stdout)"); + printf(" BOX86_TRACE_FILE with FileName to redirect logs in a file (or stderr to use stderr instead of stdout)\n"); printf(" BOX86_DLSYM_ERROR with 1 to log dlsym errors\n"); printf(" BOX86_LOAD_ADDR=0xXXXXXX try to load at 0xXXXXXX main binary (if binary is a PIE)\n"); printf(" BOX86_NOSIGSEGV=1 to disable handling of SigSEGV\n"); @@ -886,11 +880,11 @@ void PrintHelp() { #ifdef PANDORA printf(" BOX86_X11COLOR16=1 to try convert X11 color from 32 bits to 16 bits (to avoid light green on light cyan windows\n"); #endif - printf(" BOX86_X11THREADS=1 to call XInitThreads when loading X11 (for old Loki games with Loki_Compat lib)"); + printf(" BOX86_X11THREADS=1 to call XInitThreads when loading X11 (for old Loki games with Loki_Compat lib)\n"); printf(" BOX86_LIBGL=libXXXX set the name (and optionnaly full path) for libGL.so.1\n"); printf(" BOX86_LD_PRELOAD=XXXX[:YYYYY] force loading XXXX (and YYYY...) libraries with the binary\n"); - printf(" BOX86_ALLOWMISSINGLIBS with 1 to allow to continue even if a lib is missing (unadvised, will probably crash later)\n"); - printf(" BOX64_PREFER_EMULATED=1 to prefer emulated libs first (execpt for glibc, alsa, pulse, GL, vulkan and X11\n"); + printf(" BOX86_ALLOWMISSINGLIBS with 1 to allow to continue even if a lib is missing (unadvised, will probably crash later)\n"); + printf(" BOX64_PREFER_EMULATED=1 to prefer emulated libs first (execpt for glibc, alsa, pulse, GL, vulkan and X11)\n"); printf(" BOX64_PREFER_WRAPPED if box86 will use wrapped libs even if the lib is specified with absolute path\n"); printf(" BOX86_NOPULSE=1 to disable the loading of pulseaudio libs\n"); printf(" BOX86_NOGTK=1 to disable the loading of wrapped gtk libs\n"); @@ -900,6 +894,15 @@ void PrintHelp() { printf(" BOX86_JITGDB with 1 to launch \"gdb\" when a segfault is trapped, attached to the offending process\n"); } +void PrintHelp() { + printf("This is Box86, the Linux x86 emulator with a twist\n"); + printf("\nUsage is 'box86 [options] path/to/software [args]' to launch x86 software.\n"); + printf(" options are:\n"); + printf(" '-v'|'--version' to print box86 version and quit\n"); + printf(" '-h'|'--help' to print this and quit\n"); + printf(" '-f'|'--flags' to print box86 flags and quit\n"); +} + void addNewEnvVar(const char* s) { if(!s) @@ -1236,9 +1239,12 @@ int main(int argc, const char **argv, char **env) init_auxval(argc, argv, environ?environ:env); // trying to open and load 1st arg if(argc==1) { - PrintBox86Version(); + /*PrintBox86Version(); PrintHelp(); - return 1; + return 1;*/ + printf("BOX86: Missing operand after 'box86'\n"); + printf("See 'box86 --help' for more information.\n"); + exit(0); } if(argc>1 && !strcmp(argv[1], "/usr/bin/gdb")) exit(0); @@ -1292,6 +1298,10 @@ int main(int argc, const char **argv, char **env) PrintHelp(); exit(0); } + if(!strcmp(prog, "-f") || !strcmp(prog, "--flags")) { + PrintFlags(); + exit(0); + } // other options? if(!strcmp(prog, "--")) { prog = argv[++nextarg]; @@ -1546,7 +1556,7 @@ int main(int argc, const char **argv, char **env) if(!elf_header) { int x64 = my_context->box64path?FileIsX64ELF(my_context->fullpath):0; int script = my_context->bashpath?FileIsShell(my_context->fullpath):0; - printf_log(LOG_NONE, "Error: reading elf header of %s, try to launch %s instead\n", my_context->fullpath, x64?"using box64":(script?"using bash":"natively")); + printf_log(LOG_NONE, "Error: reading elf header of %s, trying to launch %s instead\n", my_context->fullpath, x64?"using box64":(script?"using bash":"natively")); fclose(f); FreeCollection(&ld_preload); int ret; @@ -1742,7 +1752,7 @@ int main(int argc, const char **argv, char **env) needed_libs_t* tmp = new_neededlib(1); tmp->names[0] = ld_preload.paths[i]; if(AddNeededLib(my_context->maplib, 0, 0, tmp, elf_header, my_context, emu)) { - printf_log(LOG_INFO, "Warning, cannot pre-load of %s\n", tmp->names[0]); + printf_log(LOG_INFO, "Warning, cannot pre-load %s\n", tmp->names[0]); RemoveNeededLib(my_context->maplib, 0, tmp, my_context, emu); } else { for(int j=0; jsize; ++j) From e663d381d47b8c14f356fcd8e46e10191c23847d Mon Sep 17 00:00:00 2001 From: Lily Date: Sun, 3 Dec 2023 18:31:02 +0300 Subject: [PATCH 2/3] [MAIN] Revert default log level --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 50e3582a9..2601e1b1a 100644 --- a/src/main.c +++ b/src/main.c @@ -44,7 +44,7 @@ #include "rcfile.h" box86context_t *my_context = NULL; -int box86_log = 1; +int box86_log = LOG_NONE; int box86_dump = 0; int box86_nobanner = 0; int box86_dynarec_log = LOG_NONE; From bf6685e13263cc27c79e4a2ee5a6a09cbc53f5c4 Mon Sep 17 00:00:00 2001 From: Lily Date: Sun, 3 Dec 2023 19:26:49 +0300 Subject: [PATCH 3/3] [TERMUX] Fix debian packaging --- CMakeLists.txt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2be860f3..3a6506cfe 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -769,7 +769,7 @@ if(NOT _x86 AND NOT _x86_64) install(FILES ${CMAKE_BINARY_DIR}/system/box86.conf DESTINATION /etc/binfmt.d/) install(FILES ${CMAKE_SOURCE_DIR}/system/box86.box86rc DESTINATION /etc/) else() - install(FILES ${CMAKE_BINARY_DIR}/system/box86.conf DESTINATION ${TERMUX_PATH}/usr/etc/binfmt.d/) + #install(FILES ${CMAKE_BINARY_DIR}/system/box86.conf DESTINATION ${TERMUX_PATH}/usr/etc/binfmt.d/) install(FILES ${CMAKE_SOURCE_DIR}/system/box86.box86rc DESTINATION ${TERMUX_PATH}/usr/etc/) endif() endif() @@ -823,7 +823,9 @@ string(REGEX MATCH "[0-9]" BOX86_REVISION ${TEMP_STRING}) set(CPACK_PACKAGE_VERSION_MAJOR ${BOX86_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${BOX86_MINOR}) set(CPACK_PACKAGE_VERSION_PATCH ${BOX86_REVISION}) +if(NOT TERMUX) set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/postinst") +endif() if(_aarch64 OR _armhf OR _arm OR _armv8l) if(TERMUX) set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "arm") @@ -836,7 +838,14 @@ else() #probably wrong... execute_process(COMMAND "dpkg --print-architecture" OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE) endif() -set(CPACK_DEBIAN_FILE_NAME "${BOX86}-${BOX86_MAJOR}.${BOX86_MINOR}.${BOX86_REVISION}_Linux-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") +if(TERMUX) +set(CPACK_PACKAGING_INSTALL_PREFIX "${TERMUX_PATH}/usr") +endif() +if(NOT TERMUX) +set(CPACK_DEBIAN_FILE_NAME "${BOX86}-${BOX86_MAJOR}.${BOX86_MINOR}.${BOX86_REVISION}_${CMAKE_SYSTEM_NAME}-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") +else() +set(CPACK_DEBIAN_FILE_NAME "${BOX86}-${BOX86_MAJOR}.${BOX86_MINOR}.${BOX86_REVISION}_Termux-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") +endif() INCLUDE(CPack) add_test(NAME bootSyscall COMMAND ${CMAKE_COMMAND} -D TEST_PROGRAM=${CMAKE_BINARY_DIR}/${BOX86}