Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions cutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)) |
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <time.h>
#if defined(__APPLE__)
#include <malloc/malloc.h>
#elif defined(__linux__)
#elif defined(__linux__) || defined(__NetBSD__)
#include <malloc.h>
#endif

Expand Down
5 changes: 5 additions & 0 deletions qjsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion quickjs-libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <malloc.h>
#elif defined(__FreeBSD__)
#include <malloc_np.h>
#elif defined(__NetBSD__)
#include <malloc.h>
#endif

#include "cutils.h"
Expand Down