adapt for NetBSD partially based on pkgsrc patches

This commit is contained in:
Vee Satayamas 2024-01-22 14:36:02 +00:00
parent 9e561d5c2e
commit a259ff61f4
6 changed files with 41 additions and 4 deletions

View file

@ -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)
#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)

View file

@ -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);

2
qjs.c
View file

@ -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

5
qjsc.c
View file

@ -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) {

View file

@ -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

View file

@ -38,6 +38,8 @@
#include <malloc.h>
#elif defined(__FreeBSD__)
#include <malloc_np.h>
#elif defined(__NetBSD__)
#include <malloc.h>
#endif
#include "cutils.h"