diff --git a/Common/Std/libc.c b/Common/Std/libc.c index eef4f5e..6ad1dd7 100644 --- a/Common/Std/libc.c +++ b/Common/Std/libc.c @@ -28,14 +28,14 @@ com_std_fd com_std_open(char const *path, uint32_t flags) { } bool com_std_write(com_std_fd fd, void const *data, uint32_t bytes) { - com_std_assert(fd != NULL && data != NULL && bytes != 0); + com_std_assert(data != NULL && bytes != 0); bool s = fwrite(data, 1, bytes, fd) == bytes; fflush(fd); return s; } int32_t com_std_read(com_std_fd fd, void *data, uint32_t upto) { - com_std_assert(fd != NULL && data != NULL && upto != 0); + com_std_assert(data != NULL && upto != 0); return fread(data, 1, upto, fd); } diff --git a/Common/std.h b/Common/std.h index 35456bf..938e73e 100644 --- a/Common/std.h +++ b/Common/std.h @@ -10,9 +10,9 @@ #include #include -#if COM_DEF_TARGET == COM_DEF_TARGET_WASM -#define COM_STD_INFD 0 -#define COM_STD_OUTFD 1 +#if COM_DEF_TARGET != COM_DEF_TARGET_COSMO +#define COM_STD_INFD (void *)0 +#define COM_STD_OUTFD (void *)1 #else /* TODO: Make it more graceful, probably with static func. */ #include diff --git a/Player/Display/x11.c b/Player/Display/x11.c index fa0e373..5b1d876 100644 --- a/Player/Display/x11.c +++ b/Player/Display/x11.c @@ -408,6 +408,10 @@ static bool plr_x11_establish_connection(com_std_fd xfd, int argc, char const *const *argv) { com_buf_make_on_stack(char, xauthbuf, 1024, 0); +/* TODO: Genralize inside std? */ +#if COM_DEF_TARGET == COM_DEF_TARGET_COSMO + char const *xauthpath = getenv("XAUTHORITY"); +#else /* First we need to authenticate X11 connection, which requires some funk. */ /* We assume that $XAUTHORITY is set and I hope it is true. */ @@ -419,10 +423,11 @@ static bool plr_x11_establish_connection(com_std_fd xfd, int argc, break; } } +#endif /* Open it and parse. */ com_std_fd const xauthfd = com_std_open(xauthpath, COM_STD_OPEN_READ); - if (xauthfd < 0) { + if (!xauthfd) { com_std_print('c', "Failure to initialize X11"); return false; } @@ -481,8 +486,9 @@ extern int plr_display_x11_main(int argc, char const *const *argv) { // com_vec_t v0 = com_mat_vec_project(com_mat_reoder(m0), com_vec_identity()); // com_fix_print(v0.a[0]); +/* TODO: Move to separate executable maybe? */ #ifndef NDEBUG - com_test_run(); + // com_test_run(); #endif // com_fix_run_tests(); diff --git a/Player/Main/cosmo.c b/Player/Main/cosmo.c index 41b0547..9950bf6 100644 --- a/Player/Main/cosmo.c +++ b/Player/Main/cosmo.c @@ -1,7 +1,5 @@ -#include "../../Common/std.h" #include "../Display/display.h" -#include + extern int main(int argc, char const *const *argv) { - com_std_write(COM_STD_OUTFD, "TEST?", sizeof "TEST?" - 1); return plr_display_x11_main(argc, argv); } diff --git a/Player/Makefile b/Player/Makefile index 19b2eae..ea292f8 100644 --- a/Player/Makefile +++ b/Player/Makefile @@ -8,6 +8,11 @@ RUN ?= 0 ISCLANG = 1 ifeq ($(MAKECMDGOALS),cosmo) ISCLANG = 0 + ifeq ($(DEBUG), 1) + CFLAGS += -mdbg + else + CFLAGS += -mtiny + endif endif CFLAGS = -Wall -std=gnu99 -ffast-math -fno-ident -fvisibility=hidden ifeq ($(ISCLANG), 1) @@ -40,13 +45,15 @@ endif ifeq ($(DEBUG), 1) CFLAGS += -g3 else - CFLAGS += -DNDEBUG -Wl,--strip-all + CFLAGS += -DNDEBUG -s endif ifeq ($(RELEASE), 1) CFLAGS += -O3 -fmerge-all-constants -Wl,-O3 \ - -ffunction-sections -fdata-sections -Wl,--gc-sections \ - -Wl,-mllvm,--vectorize-slp=true \ - -Wl,-mllvm,--enable-gvn-hoist=true + -ffunction-sections -fdata-sections -Wl,--gc-sections + ifeq ($(ISCLANG), 1) + CFLAGS += -Wl,-mllvm,--vectorize-slp=true \ + -Wl,-mllvm,--enable-gvn-hoist=true + endif endif linux: CFLAGS += -static -mbmi2 -nostdlib @@ -59,9 +66,10 @@ wasm: $(CC) -o player.wasm ./amalgam.c $(CFLAGS) # todo: Add -mtiny for release without debug -cosmo: CC = ./Cosmo/bin/cosmocc -I /usr/include/X11 -mdbg +cosmo: CC = ./Cosmo/bin/cosmocc +cosmo: CFLAGS += -I /usr/include/X11 -mclang cosmo: ./amalgam.c - $(CC) -o ./Out/Cosmo/player $^ + $(CC) $(CFLAGS) -o ./Out/Cosmo/player $^ ifeq ($(RUN), 1) ifeq ($(DEBUG), 1) gdb ./Out/Cosmo/player.com.dbg