diff --git a/Makefile b/Makefile index 57cdd7e..076180f 100644 --- a/Makefile +++ b/Makefile @@ -25,10 +25,19 @@ ifeq ($(shell uname -s),Darwin) CONFIG_DARWIN=y endif +ifeq ($(shell uname -s),NetBSD) +CONFIG_NETBSD=y +endif # Windows cross compilation from Linux #CONFIG_WIN32=y # use link time optimization (smaller and faster executables but slower build) -CONFIG_LTO=y +#ifndef +ifndef CONFIG_NETBSD + CONFIG_LTO=y + CONFIG_LDL=y +else + CONFIG_JEMALLOC=y +endif # consider warnings as errors (for development) #CONFIG_WERROR=y # force 32 bit build for some utilities @@ -197,7 +206,12 @@ endif HOST_LIBS=-lm -ldl -lpthread LIBS=-lm ifndef CONFIG_WIN32 -LIBS+=-ldl -lpthread +LIBS+=-lpthread +endif +ifndef CONFIG_NETBSD +LIBS+=-ldl +else +LIBS+=-ljemalloc endif LIBS+=$(EXTRA_LIBS) @@ -225,6 +239,12 @@ QJSC_DEFINES:=-DCONFIG_CC=\"$(QJSC_CC)\" -DCONFIG_PREFIX=\"$(PREFIX)\" ifdef CONFIG_LTO QJSC_DEFINES+=-DCONFIG_LTO endif +ifdef CONFIG_LDL +QJSC_DEFINES+=-DCONFIG_LDL +endif +ifdef CONFIG_JEMALLOC +QJSC_DEFINES+=-DCONFIG_JEMALLOC +endif QJSC_HOST_DEFINES:=-DCONFIG_CC=\"$(HOST_CC)\" -DCONFIG_PREFIX=\"$(PREFIX)\" $(OBJDIR)/qjsc.o: CFLAGS+=$(QJSC_DEFINES) diff --git a/cutils.h b/cutils.h index 8399d61..165a96a 100644 --- a/cutils.h +++ b/cutils.h @@ -210,17 +210,22 @@ static inline void put_u8(uint8_t *tab, uint8_t val) *tab = val; } +#ifndef bswap16 static inline uint16_t bswap16(uint16_t x) { return (x >> 8) | (x << 8); } +#endif +#ifndef bswap32 static inline uint32_t bswap32(uint32_t v) { return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) | ((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24); } +#endif +#ifndef bswap64 static inline uint64_t bswap64(uint64_t v) { return ((v & ((uint64_t)0xff << (7 * 8))) >> (7 * 8)) | @@ -232,6 +237,7 @@ static inline uint64_t bswap64(uint64_t v) ((v & ((uint64_t)0xff << (1 * 8))) << (5 * 8)) | ((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8)); } +#endif /* XXX: should take an extra argument to pass slack information to the caller */ typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size); diff --git a/qjs.c b/qjs.c index 22d5f32..1338871 100644 --- a/qjs.c +++ b/qjs.c @@ -34,7 +34,7 @@ #include #if defined(__APPLE__) #include -#elif defined(__linux__) +#elif defined(__linux__) || defined(__NetBSD__) #include #endif diff --git a/qjsc.c b/qjsc.c index f8e60b3..1599495 100644 --- a/qjsc.c +++ b/qjsc.c @@ -449,8 +449,13 @@ static int output_executable(const char *out_filename, const char *cfilename, lib_dir, bn_suffix, lto_suffix); *arg++ = libjsname; *arg++ = "-lm"; +#ifdef CONFIG_LDL *arg++ = "-ldl"; +#endif *arg++ = "-lpthread"; +#ifdef CONFIG_JEMALLOC + *arg++ = "-ljemalloc"; +#endif *arg = NULL; if (verbose) { diff --git a/quickjs-libc.c b/quickjs-libc.c index 67fe2f6..18f9585 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -57,6 +57,10 @@ typedef sig_t sighandler_t; #endif +#if defined(__NetBSD__) +extern char **environ; +#endif + #if !defined(_WIN32) /* enable the os.Worker API. IT relies on POSIX threads */ #define USE_WORKER @@ -1919,7 +1923,7 @@ static void os_signal_handler(int sig_num) os_pending_signals |= ((uint64_t)1 << sig_num); } -#if defined(_WIN32) +#if defined(_WIN32) || defined(__NetBSD__) typedef void (*sighandler_t)(int sig_num); #endif diff --git a/quickjs.c b/quickjs.c index 4e58a98..0b51c68 100644 --- a/quickjs.c +++ b/quickjs.c @@ -38,6 +38,8 @@ #include #elif defined(__FreeBSD__) #include +#elif defined(__NetBSD__) +#include #endif #include "cutils.h"