From 594d58b6e21854a985bc90f2292a7879d1db186a Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 17 Mar 2024 21:42:38 -0400 Subject: When compiling .o files, put the .c and .h files on disk --- tomo.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/tomo.c b/tomo.c index 465c37e1..b559ecbd 100644 --- a/tomo.c +++ b/tomo.c @@ -95,19 +95,30 @@ int main(int argc, char *argv[]) switch (mode) { case MODE_COMPILE: { - const char *run = heap_strf("%s | %s -x c %s -c - -o %s.o", autofmt, cc, cflags, f->filename); - FILE *runner = popen(run, "w"); + FILE *prog = popen(heap_strf("%s > %s.h", autofmt, f->filename), "w"); + CORD_put("#pragma once\n", prog); + CORD_put(module.header, prog); + int status = pclose(prog); + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) + printf("Transpiled to %s.h\n", f->filename); + else + return WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE; - CORD program = CORD_all( - "// File: ", f->filename, ".h\n", - module.header, - "\n", - "// File: ", f->filename, ".c\n", - module.c_file - ); + prog = popen(heap_strf("%s > %s.c", autofmt, f->filename), "w"); + CORD_put(CORD_all("#include \"", module.module_name, ".tm.h\"\n\n", module.c_file), prog); + status = pclose(prog); + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) + printf("Transpiled to %s.c\n", f->filename); + else + return WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE; - CORD_put(program, runner); - int status = pclose(runner); + const char *cmd = heap_strf("%s %s -c %s.c -o %s.o", cc, cflags, f->filename, f->filename); + if (verbose) + printf("Running: %s\n", cmd); + prog = popen(cmd, "w"); + status = pclose(prog); + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) + printf("Compiled to %s.o\n", f->filename); return WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE; } case MODE_RUN: { -- cgit v1.2.3