From e3ad5fdaaae075b4080c86bd243f5c7f3b09972b Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 1 May 2024 13:25:19 -0400 Subject: Fix up some path issues during compilation/running/installation --- Makefile | 2 +- tomo.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 36ffd0c7..d8a659fd 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -PREFIX=/usr/local +PREFIX=/usr VERSION=0.0.1 CCONFIG=-std=c11 -Werror -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L -fPIC -I. \ -fsanitize=signed-integer-overflow -fno-sanitize-recover -fvisibility=hidden -fdollars-in-identifiers diff --git a/tomo.c b/tomo.c index d78b4308..0aed42ba 100644 --- a/tomo.c +++ b/tomo.c @@ -25,7 +25,7 @@ static const char *autofmt; static const char *cconfig; static const char *cflags; static const char *ldlibs; -static const char *ldflags = "-Wl,-rpath '-Wl,$ORIGIN' -L/usr/local/lib"; +static const char *ldflags; static const char *cc; static array_t get_file_dependencies(const char *filename); @@ -82,6 +82,9 @@ int main(int argc, char *argv[]) return 0; } + if (strlen(filename) < strlen(".tm") + 1 || strncmp(filename + strlen(filename) - strlen(".tm"), ".tm", strlen(".tm")) != 0) + errx(1, "Not a valid .tm file: %s", filename); + cconfig = getenv("CCONFIG"); if (!cconfig) cconfig = "-std=c11 -fdollars-in-identifiers -fsanitize=signed-integer-overflow -fno-sanitize-recover" @@ -95,12 +98,12 @@ int main(int argc, char *argv[]) if (!cflags) cflags = heap_strf("%s %s -ggdb -I./include -D_DEFAULT_SOURCE", cconfig, optimization); - ldlibs = "-lgc -lcord -lm -L. -ltomo"; + ldflags = "-Wl,-rpath '-Wl,$ORIGIN' -L/usr/local/lib -L."; + + ldlibs = "-lgc -lcord -lm -ltomo"; if (getenv("LDLIBS")) ldlibs = heap_strf("%s %s", ldlibs, getenv("LDLIBS")); - ldflags = "-Wl,-rpath '-Wl,$ORIGIN' -L/usr/local/lib"; - cc = getenv("CC"); if (!cc) cc = "tcc"; @@ -127,7 +130,7 @@ int main(int argc, char *argv[]) if (mode == MODE_COMPILE_EXE || executable_status != 0) return executable_status; - char *exe_name = file_base_name(filename); + char *exe_name = heap_strn(filename, strlen(filename) - strlen(".tm")); int num_args = argc - program_arg_index; char *prog_args[num_args + 2]; prog_args[0] = exe_name; @@ -136,7 +139,7 @@ int main(int argc, char *argv[]) prog_args[num_args+1] = NULL; execv(exe_name, prog_args); - return 0; + errx(1, "Failed to run compiled program"); } static void build_file_dependency_graph(const char *filename, table_t *dependencies) @@ -307,7 +310,7 @@ int compile_object_file(const char *filename, bool force_recompile) int compile_executable(const char *filename, const char *object_files, module_code_t *module_code) { - const char *bin_name = file_base_name(filename); + const char *bin_name = heap_strn(filename, strlen(filename) - strlen(".tm")); const char *run = heap_strf("%s | %s %s %s %s %s -x c - -o %s", autofmt, cc, cflags, ldflags, ldlibs, object_files, bin_name); if (verbose) printf("%s\n", run); -- cgit v1.2.3