summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-25 18:24:05 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-25 18:24:05 +0000
commite3ab29bb4d7174cae65de2275f19105eb3d93d91 (patch)
tree89970111c1be4c3ddd291b720d4fdf496f10b2d5 /src/main.c
parent489336b2101bf16edeec7bfc4379408eb19b936e (diff)
APE shall never kill APE
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 3f6a51f..62bb98d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -56,7 +56,11 @@ void print_usage()
int main(int argc, char **argv)
{
memset(&g_config, 0, sizeof(g_config));
+#ifdef __COSMOPOLITAN__
+ strcpy(g_config.cc, "cosmocc");
+#else
strcpy(g_config.cc, "gcc");
+#endif
if (argc < 2)
{
@@ -339,9 +343,23 @@ int main(int argc, char **argv)
char cmd[8192];
char *outfile = g_config.output_file ? g_config.output_file : "a.out";
- snprintf(cmd, sizeof(cmd), "%s %s %s %s %s -o %s %s -lm %s -I./src %s", g_config.cc,
+ const char *thread_flag = g_parser_ctx->has_async ? "-lpthread" : "";
+ const char *math_flag = "-lm";
+
+#ifdef _WIN32
+ // Windows might use different flags or none for math/threads
+ math_flag = "";
+ if (g_parser_ctx->has_async)
+ {
+ thread_flag = "";
+ }
+#endif
+
+ // If using cosmocc, it handles these usually, but keeping them is okay for Linux targets
+
+ snprintf(cmd, sizeof(cmd), "%s %s %s %s %s -o %s %s %s %s -I./src %s", g_config.cc,
g_config.gcc_flags, g_cflags, g_config.is_freestanding ? "-ffreestanding" : "", "",
- outfile, temp_source_file, g_parser_ctx->has_async ? "-lpthread" : "", g_link_flags);
+ outfile, temp_source_file, math_flag, thread_flag, g_link_flags);
if (g_config.verbose)
{
@@ -368,7 +386,11 @@ int main(int argc, char **argv)
if (g_config.mode_run)
{
char run_cmd[2048];
+#ifdef _WIN32
+ sprintf(run_cmd, "%s", outfile);
+#else
sprintf(run_cmd, "./%s", outfile);
+#endif
ret = system(run_cmd);
remove(outfile);
zptr_plugin_mgr_cleanup();