aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-03-17 21:42:38 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-03-17 21:42:38 -0400
commit594d58b6e21854a985bc90f2292a7879d1db186a (patch)
treeb0cbfa20de5ed6cbfdf21190859221894377e1c4
parent655b6778955c8da782365d86326d3afceccc9a6b (diff)
When compiling .o files, put the .c and .h files on disk
-rw-r--r--tomo.c33
1 files 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: {