From 265e2aaaa13bdeeb030f1f91faa7631f04382189 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 2 Feb 2024 17:13:33 -0600 Subject: [PATCH] Make Jaunch actually support the os-arch suffix --- README.md | 5 +++-- src/c/jaunch.c | 16 ++++++++++++++++ src/c/linux.h | 2 ++ src/c/macos.h | 2 ++ src/c/posix.h | 3 +-- src/c/win32.h | 4 ++-- src/commonMain/kotlin/Jaunch.kt | 12 ++++++++++-- 7 files changed, 36 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b761835..5c26847 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,9 @@ The build process will: * Three TOML configuration files, `jaunch.toml`, `jy.toml`, and `parsy.toml`; * The `Props.class` helper program. -Then try running `app/jy` or `app/parsy` and watch the fireworks. If it doesn't -work, try `app/parsy --debug`, which will show what's happening under the hood. +Then run the `jy` or `parsy` binary in the `app` folder and watch the fireworks. +If it doesn't work, try appending the `--debug` flag, which will show what's +happening under the hood. Note that these `jy` and `parsy` launchers are binary identical—each is merely an illustration of how your native launcher could be named and work. diff --git a/src/c/jaunch.c b/src/c/jaunch.c index e9a7df4..b800f10 100644 --- a/src/c/jaunch.c +++ b/src/c/jaunch.c @@ -44,6 +44,14 @@ #include "posix.h" #endif +#ifdef __x86_64__ +#define OS_ARCH "x64" +#endif + +#ifdef __aarch64__ +#define OS_ARCH "aarch64" +#endif + // List of places to search for the jaunch configurator executable. // // NB: This list should align with the configDirs list in Jaunch.kt, @@ -189,8 +197,16 @@ int main(const int argc, const char *argv[]) { char *command = NULL; size_t search_path_count = sizeof(JAUNCH_SEARCH_PATHS) / sizeof(char *); for (size_t i = 0; i < search_path_count; i++) { + // First, look for jaunch configurator with a `--` suffix. + command = path(argc == 0 ? NULL : argv[0], JAUNCH_SEARCH_PATHS[i], JAUNCH_EXE"-"OS_NAME"-"OS_ARCH); + if (file_exists(command)) break; + + // If not found, look for plain jaunch configurator with no suffix. + free(command); command = path(argc == 0 ? NULL : argv[0], JAUNCH_SEARCH_PATHS[i], JAUNCH_EXE); if (file_exists(command)) break; + + // Nothing at this search path; clean up and move on to the next one. free(command); command = NULL; } diff --git a/src/c/linux.h b/src/c/linux.h index f12f80d..3457c5c 100644 --- a/src/c/linux.h +++ b/src/c/linux.h @@ -1,5 +1,7 @@ #include +#define OS_NAME "linux" + int isCommandAvailable(const char *command) { return access(command, X_OK) == 0; } diff --git a/src/c/macos.h b/src/c/macos.h index 4b3ac44..eebeba0 100644 --- a/src/c/macos.h +++ b/src/c/macos.h @@ -1,6 +1,8 @@ #include #include +#define OS_NAME "macos" + void show_alert(const char *title, const char *message) { /* TODO: Get this objc code working. // Create an NSString from the C string diff --git a/src/c/posix.h b/src/c/posix.h index 5751fd0..c14c5d8 100644 --- a/src/c/posix.h +++ b/src/c/posix.h @@ -4,8 +4,7 @@ #include "common.h" #define SLASH "/" - -const char* JAUNCH_EXE = "jaunch"; +#define JAUNCH_EXE "jaunch" int file_exists(const char *path) { return access(path, F_OK) == 0; diff --git a/src/c/win32.h b/src/c/win32.h index 11fc57e..b4c9e1c 100644 --- a/src/c/win32.h +++ b/src/c/win32.h @@ -2,9 +2,9 @@ #include "common.h" +#define OS_NAME "windows" #define SLASH "\\" - -const char* JAUNCH_EXE = "jaunch.exe"; +#define JAUNCH_EXE "jaunch.exe" void dlclose(void* library) { FreeLibrary(library); } char* dlerror() { return "error" /*TODO: GetLastError()*/; } diff --git a/src/commonMain/kotlin/Jaunch.kt b/src/commonMain/kotlin/Jaunch.kt index e30c63a..a5a6c59 100644 --- a/src/commonMain/kotlin/Jaunch.kt +++ b/src/commonMain/kotlin/Jaunch.kt @@ -76,9 +76,17 @@ fun main(args: Array) { // Load the configuration from the TOML file(s). var config = readConfig(configDir / "jaunch.toml") + config += readConfig(configDir / "jaunch-$$OS_NAME.toml") + config += readConfig(configDir / "jaunch-$$OS_NAME-$CPU_ARCH.toml") if (exeFile != null) { - // Parse and merge the app-specific TOML file as well. - config += readConfig(configDir / "${exeFile.base.name}.toml") + // Parse and merge the app-specific TOML file(s) as well. + var fileName = exeFile.base.name + while (true) { + config += readConfig(configDir / "$fileName.toml") + val dash = fileName.lastIndexOf("-") + if (dash < 0) break + fileName = fileName.substring(0, dash) + } } val programName = config.programName ?: exeFile?.base?.name ?: "Jaunch"