Skip to content

Commit

Permalink
fix: various cleanups and refining of POSIX platform definition
Browse files Browse the repository at this point in the history
build elf linker everywhere (selected by define)

don't check ld.so.conf on apple/osx
  • Loading branch information
jaromil committed Jan 3, 2025
1 parent ceab4be commit e2db907
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build/init.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion build/linux.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/cjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions src/cjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);
Expand All @@ -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
5 changes: 5 additions & 0 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -205,7 +206,10 @@ bool rm_recursive(char *path) {
}
return true;
}
#endif


#if 0
#if !defined(WINDOWS)

static char *full_content = NULL;
Expand Down Expand Up @@ -273,3 +277,4 @@ char *dir_load(const char *path)


#endif
#endif // 0
12 changes: 7 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <muntar.h>
#include <assets.h>

extern char *load_stdin();

#define MAX_ARG_STRING 1024
static int parse_value(char *str) {
int i = 0;
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/platforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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
Expand Down

0 comments on commit e2db907

Please sign in to comment.