From 3d313c5956510a807c2ce7d1ffd9c3bfbb708444 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 19 May 2025 14:47:03 -0400 Subject: Add --prefix flag --- CHANGES.md | 1 + docs/tomo.1.md | 3 +++ man/man1/tomo.1 | 3 +++ src/tomo.c | 7 +++++++ 4 files changed, 14 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 8524fd9d..f071f7fa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ configuration for module aliases. - Programs can use `--version` as a CLI flag to print a Tomo program's version number and exit. +- Added `tomo --prefix` to print the Tomo install prefix. - Added Path.sibling() ## v0.2 diff --git a/docs/tomo.1.md b/docs/tomo.1.md index 7ccf0397..4207de6a 100644 --- a/docs/tomo.1.md +++ b/docs/tomo.1.md @@ -62,5 +62,8 @@ C code, which is then compiled using a C compiler of your choice. `--version` : Print the compiler version and exit. +`--prefix` +: Print the Tomo installation prefix and exit. + `-r`, `--run` : Run an installed tomo program from `~/.local/share/tomo_vX.Y/installed`. diff --git a/man/man1/tomo.1 b/man/man1/tomo.1 index 32b366a6..4b4f16bd 100644 --- a/man/man1/tomo.1 +++ b/man/man1/tomo.1 @@ -60,6 +60,9 @@ Print extra verbose output. \f[B]\-\-version\f[R] Print the compiler version and exit. .TP +\f[B]\-\-prefix\f[R] +Print the Tomo installation prefix and exit. +.TP \f[B]\-r\f[R], \f[B]\-\-run\f[R] Run an installed tomo program from \f[B]\[ti]/.local/share/tomo_vX.Y/installed\f[R]. diff --git a/src/tomo.c b/src/tomo.c index 24a407a4..a2ccc84a 100644 --- a/src/tomo.c +++ b/src/tomo.c @@ -64,6 +64,7 @@ static OptionalList_t files = NONE_LIST, static OptionalBool_t verbose = false, quiet = false, show_parse_tree = false, + show_prefix = false, stop_at_transpile = false, stop_at_obj_compilation = false, compile_exe = false, @@ -189,6 +190,7 @@ int main(int argc, char *argv[]) {"v", false, &Bool$info, &verbose}, {"parse", false, &Bool$info, &show_parse_tree}, {"p", false, &Bool$info, &show_parse_tree}, + {"prefix", false, &Bool$info, &show_prefix}, {"quiet", false, &Bool$info, &quiet}, {"q", false, &Bool$info, &quiet}, {"transpile", false, &Bool$info, &stop_at_transpile}, @@ -213,6 +215,11 @@ int main(int argc, char *argv[]) {"m", false, &Bool$info, &source_mapping}, ); + if (show_prefix) { + print(TOMO_PREFIX); + return 0; + } + bool is_gcc = (system(String(cc, " -v 2>&1 | grep -q 'gcc version'")) == 0); if (is_gcc) { cflags = Texts(cflags, Text(" -fsanitize=signed-integer-overflow -fno-sanitize-recover" -- cgit v1.2.3