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) ifeq ($(shell uname -s),Darwin)
CONFIG_DARWIN=y CONFIG_DARWIN=y
endif endif
ifeq ($(shell uname -s),NetBSD)
CONFIG_NETBSD=y
endif
# Windows cross compilation from Linux # Windows cross compilation from Linux
#CONFIG_WIN32=y #CONFIG_WIN32=y
# use link time optimization (smaller and faster executables but slower build) # 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) # consider warnings as errors (for development)
#CONFIG_WERROR=y #CONFIG_WERROR=y
# force 32 bit build for some utilities # force 32 bit build for some utilities
@ -197,7 +206,12 @@ endif
HOST_LIBS=-lm -ldl -lpthread HOST_LIBS=-lm -ldl -lpthread
LIBS=-lm LIBS=-lm
ifndef CONFIG_WIN32 ifndef CONFIG_WIN32
LIBS+=-ldl -lpthread LIBS+=-lpthread
endif
ifndef CONFIG_NETBSD
LIBS+=-ldl
else
LIBS+=-ljemalloc
endif endif
LIBS+=$(EXTRA_LIBS) LIBS+=$(EXTRA_LIBS)
@ -225,6 +239,12 @@ QJSC_DEFINES:=-DCONFIG_CC=\"$(QJSC_CC)\" -DCONFIG_PREFIX=\"$(PREFIX)\"
ifdef CONFIG_LTO ifdef CONFIG_LTO
QJSC_DEFINES+=-DCONFIG_LTO QJSC_DEFINES+=-DCONFIG_LTO
endif 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)\" QJSC_HOST_DEFINES:=-DCONFIG_CC=\"$(HOST_CC)\" -DCONFIG_PREFIX=\"$(PREFIX)\"
$(OBJDIR)/qjsc.o: CFLAGS+=$(QJSC_DEFINES) $(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; *tab = val;
} }
#ifndef bswap16
static inline uint16_t bswap16(uint16_t x) static inline uint16_t bswap16(uint16_t x)
{ {
return (x >> 8) | (x << 8); return (x >> 8) | (x << 8);
} }
#endif
#ifndef bswap32
static inline uint32_t bswap32(uint32_t v) static inline uint32_t bswap32(uint32_t v)
{ {
return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) | return ((v & 0xff000000) >> 24) | ((v & 0x00ff0000) >> 8) |
((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24); ((v & 0x0000ff00) << 8) | ((v & 0x000000ff) << 24);
} }
#endif
#ifndef bswap64
static inline uint64_t bswap64(uint64_t v) static inline uint64_t bswap64(uint64_t v)
{ {
return ((v & ((uint64_t)0xff << (7 * 8))) >> (7 * 8)) | 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 << (1 * 8))) << (5 * 8)) |
((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8)); ((v & ((uint64_t)0xff << (0 * 8))) << (7 * 8));
} }
#endif
/* XXX: should take an extra argument to pass slack information to the caller */ /* XXX: should take an extra argument to pass slack information to the caller */
typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size); typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size);

2
qjs.c
View File

@ -34,7 +34,7 @@
#include <time.h> #include <time.h>
#if defined(__APPLE__) #if defined(__APPLE__)
#include <malloc/malloc.h> #include <malloc/malloc.h>
#elif defined(__linux__) #elif defined(__linux__) || defined(__NetBSD__)
#include <malloc.h> #include <malloc.h>
#endif #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); lib_dir, bn_suffix, lto_suffix);
*arg++ = libjsname; *arg++ = libjsname;
*arg++ = "-lm"; *arg++ = "-lm";
#ifdef CONFIG_LDL
*arg++ = "-ldl"; *arg++ = "-ldl";
#endif
*arg++ = "-lpthread"; *arg++ = "-lpthread";
#ifdef CONFIG_JEMALLOC
*arg++ = "-ljemalloc";
#endif
*arg = NULL; *arg = NULL;
if (verbose) { if (verbose) {

View File

@ -57,6 +57,10 @@ typedef sig_t sighandler_t;
#endif #endif
#if defined(__NetBSD__)
extern char **environ;
#endif
#if !defined(_WIN32) #if !defined(_WIN32)
/* enable the os.Worker API. IT relies on POSIX threads */ /* enable the os.Worker API. IT relies on POSIX threads */
#define USE_WORKER #define USE_WORKER
@ -1919,7 +1923,7 @@ static void os_signal_handler(int sig_num)
os_pending_signals |= ((uint64_t)1 << 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); typedef void (*sighandler_t)(int sig_num);
#endif #endif

View File

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