diff --git a/build/init.mk b/build/init.mk index aeb1540..16c580f 100644 --- a/build/init.mk +++ b/build/init.mk @@ -15,7 +15,7 @@ CFLAGS ?= -O2 -fomit-frame-pointer ${cflags_stack_protect} cflags := ${CFLAGS} ${cflags_includes} -SOURCES := src/file.o src/cjit.o \ +SOURCES := src/file.o src/cjit.o src/elflinker.o \ src/main.o src/assets.o \ src/cwalk.o src/array.o \ src/muntar.o src/tinflate.o src/tinfgzip.o \ diff --git a/build/linux.mk b/build/linux.mk index b34a3f5..d97f843 100644 --- a/build/linux.mk +++ b/build/linux.mk @@ -5,7 +5,6 @@ cc := gcc cflags += -DLIBC_GNU -D_GNU_SOURCE cflags += -DKILO_SUPPORTED cflags += -DCJIT_BUILD_LINUX -SOURCES += src/elflinker.o all: embed-posix cjit diff --git a/src/cjit.c b/src/cjit.c index 8ca5963..50fd473 100644 --- a/src/cjit.c +++ b/src/cjit.c @@ -216,7 +216,7 @@ static bool cjit_setup(CJITState *cjit) { } #endif -#if defined(POSIX) +#if defined(UNIX) read_ldsoconf(cjit->libpaths,"/etc/ld.so.conf"); read_ldsoconf_dir(cjit->libpaths,"/etc/ld.so.conf.d"); #endif @@ -593,7 +593,7 @@ void cjit_define_symbol(CJITState *cjit, const char *sym, const char *value) { if(cjit->verbose)_err("+D %s %s",sym,value?value:""); } void cjit_add_include_path(CJITState *cjit, const char *path) { - const char *restrict toadd = new_abspath(path); + char *restrict toadd = new_abspath(path); if(!toadd) { _err("%s: absolute path error: %s",__func__,path); return; @@ -604,7 +604,7 @@ void cjit_add_include_path(CJITState *cjit, const char *path) { } // TODO: temporary, to be reimplemented in linker.c void cjit_add_library_path(CJITState *cjit, const char *path) { - const char *restrict toadd = new_abspath(path); + char *restrict toadd = new_abspath(path); if(!toadd) { _err("%s: absolute path error: %s",__func__,path); return; diff --git a/src/cjit.h b/src/cjit.h index 9e12b40..5e9fef7 100644 --- a/src/cjit.h +++ b/src/cjit.h @@ -91,10 +91,6 @@ extern bool extract_assets(CJITState *CJIT); ///////////// // from file.c extern char* file_load(const char *filename, unsigned int *len); -extern char *load_stdin(); -extern char* dir_load(const char *path); -extern bool write_to_file(const char *path, const char *filename, - const char *buf, unsigned int len); // terminal printing functions extern void _out(const char *fmt, ...); @@ -103,8 +99,5 @@ extern void _err(const char *fmt, ...); ///////////// // from repl.c extern int cjit_cli_tty(CJITState *cjit); -#ifdef KILO_SUPPORTED -extern int cjit_cli_kilo(CJITState *cjit); -#endif #endif diff --git a/src/file.c b/src/file.c index a90e5dd..61bfde9 100644 --- a/src/file.c +++ b/src/file.c @@ -171,6 +171,7 @@ bool write_to_file(const char *path, const char *filename, const char *buf, unsi return true; } +#if 0 // unused for now, dangerous to have if unnecessary static int rm_ftw(const char *pathname, const struct stat *sbuf, int type, struct FTW *ftwb) { @@ -205,7 +206,10 @@ bool rm_recursive(char *path) { } return true; } +#endif + +#if 0 #if !defined(WINDOWS) static char *full_content = NULL; @@ -273,3 +277,4 @@ char *dir_load(const char *path) #endif +#endif // 0 diff --git a/src/main.c b/src/main.c index 7fdc2d0..23d2e46 100644 --- a/src/main.c +++ b/src/main.c @@ -31,6 +31,8 @@ #include #include +extern char *load_stdin(); + #define MAX_ARG_STRING 1024 static int parse_value(char *str) { int i = 0; @@ -141,19 +143,19 @@ int main(int argc, char **argv) { strcpy(CJIT->output_filename,opt.arg); cjit_set_output(CJIT, EXE); } else if (c == 'L') { // library path - if(!CJIT->quiet)_err("lib path: %s",opt.arg); + if(CJIT->verbose)_err("arg lib path: %s",opt.arg); cjit_add_library_path(CJIT, opt.arg); } else if (c == 'l') { // library link - if(!CJIT->quiet)_err("lib: %s",opt.arg); + if(CJIT->verbose)_err("arg lib: %s",opt.arg); cjit_add_library(CJIT, opt.arg); } else if (c == 'C') { // cflags compiler options - if(!CJIT->quiet)_err("cflags: %s",opt.arg); + if(CJIT->verbose)_err("arg cflags: %s",opt.arg); cjit_set_tcc_options(CJIT->TCC, opt.arg); } else if (c == 'I') { // include paths in cflags - if(!CJIT->quiet)_err("inc: %s",opt.arg); + if(CJIT->verbose)_err("arg inc: %s",opt.arg); cjit_add_include_path(CJIT, opt.arg); } else if (c == 'e') { // entry point (default main) - if(!CJIT->quiet)_err("entry: %s",opt.arg); + if(!CJIT->quiet)_err("entry function: %s",opt.arg); if(CJIT->entry) free(CJIT->entry); CJIT->entry = malloc(strlen(opt.arg)+1); strcpy(CJIT->entry,opt.arg); diff --git a/src/platforms.h b/src/platforms.h index 7308d61..31bb0e9 100644 --- a/src/platforms.h +++ b/src/platforms.h @@ -19,18 +19,24 @@ #endif #if defined(__linux__) #define LINUX + #define POSIX + #define UNIX #define PLATFORM "GNU/Linux" #endif #if defined(__APPLE__) #define APPLE + #define POSIX #define PLATFORM "Apple/OSX" #endif #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) #define BSD + #define POSIX + #define UNIX #define PLATFORM "BSD" #endif #if defined(__ANDROID__) #define ANDROID + #define POSIX #define PLATFORM "Android" #endif #if defined(__EMSCRIPTEN__) @@ -39,10 +45,12 @@ #endif #if defined(__BEOS__) || defined(__HAIKU__) #define BEOS + #define POSIX #define PLATFORM "BEOS" #endif #if defined(__HAIKU__) #define HAIKU + #define POSIX #define PLATFORM "Haiku" #endif #endif diff --git a/test/windows.bats b/test/windows.bats index 955387a..656302c 100644 --- a/test/windows.bats +++ b/test/windows.bats @@ -3,26 +3,26 @@ load bats_setup @test "Timeb.h inclusion for clock() in Windows" { # see https://www.reddit.com/r/C_Programming/comments/1h1g4gc/comment/lzc9fta/ # /sys/timeb.h:132: error: include file 'sec_api/sys/timeb_s.h' not found - run ${CJIT} test/win_timeb.c + run ./cjit.exe test/win_timeb.c assert_success } @test "BOM source file UTF8" { - run ${CJIT} -q test/hello-bom-utf8.c + run ./cjit.exe -q test/hello-bom-utf8.c assert_failure assert_line --partial 'UTF BOM detected in file: test/hello-bom-utf8.c' assert_line --partial 'Encoding is not yet supported, execution aborted.' } @test "BOM source file UTF16 big endian" { - run ${CJIT} -q test/hello-bom-utf16-be.c + run ./cjit.exe -q test/hello-bom-utf16-be.c assert_failure assert_line --partial 'UTF BOM detected in file: test/hello-bom-utf16-be.c' assert_line --partial 'Encoding is not yet supported, execution aborted.' } @test "BOM source file UTF16 little endian" { - run ${CJIT} -q test/hello-bom-utf16-le.c + run ./cjit.exe -q test/hello-bom-utf16-le.c assert_failure assert_line --partial 'UTF BOM detected in file: test/hello-bom-utf16-le.c' assert_line --partial 'Encoding is not yet supported, execution aborted.'