Hi List,
Firstly, thanks for this amazing project, enabling many possibles, here’s my
little patch for quickjs to build on Freebsd which is OS of my choice. The only
two problems left are /example/hello_module and /example/c_module, they fails
to link, I don’t know how to fix them, other than that everything pass make
test
diff -u quickjs-2019-09-01/Makefile quickjs-2019-09-01-freebsd/Makefile
--- quickjs-2019-09-01/Makefile 2019-09-15 19:32:20.963860000 +0000
+++ quickjs-2019-09-01-freebsd/Makefile 2019-09-15 19:33:45.280783000 +0000
@@ -42,6 +42,11 @@
CONFIG_DEFAULT_AR=y
endif
+ifeq ($(shell uname -s),FreeBSD)
+CONFIG_CLANG=y
+CONFIG_DEFAULT_AR=y
+CONFIG_M32=
+endif
# installation directory
prefix=/usr/local
@@ -117,7 +122,6 @@
else
LDEXPORT=-rdynamic
endif
-
PROGS=qjs$(EXE) qjsbn$(EXE) qjsc qjsbnc run-test262 run-test262-bn
ifndef CONFIG_WIN32
PROGS+=qjscalc
@@ -134,6 +138,8 @@
PROGS+=
else ifdef CONFIG_WIN32
PROGS+=
+else ifeq ($(shell uname -s),FreeBSD)
+PROGS+=examples/hello #TODO: hello_module and c_module fail to link
else
PROGS+=examples/hello examples/hello_module examples/c_module
endif
Common subdirectories: quickjs-2019-09-01/doc and quickjs-2019-09-01-freebsd/doc
Common subdirectories: quickjs-2019-09-01/examples and
quickjs-2019-09-01-freebsd/examples
diff -u quickjs-2019-09-01/qjs.c quickjs-2019-09-01-freebsd/qjs.c
--- quickjs-2019-09-01/qjs.c 2019-09-15 19:32:20.965504000 +0000
+++ quickjs-2019-09-01-freebsd/qjs.c 2019-09-15 19:33:45.271042000 +0000
@@ -36,6 +36,8 @@
#include <malloc/malloc.h>
#elif defined(__linux__)
#include <malloc.h>
+#elif defined(__FreeBSD__)
+#include <malloc_np.h>
#endif
#include "cutils.h"
@@ -128,6 +130,8 @@
return 0;
#elif defined(__linux__)
return malloc_usable_size(ptr);
+#elif defined(__FreeBSD__)
+ return __malloc_usable_size(ptr);
#else
/* change this to `return 0;` if compilation fails */
return malloc_usable_size(ptr);
@@ -244,6 +248,8 @@
NULL,
#elif defined(__linux__)
(size_t (*)(const void *))malloc_usable_size,
+#elif defined(__FreeBSD__)
+ (size_t (*)(const void *))__malloc_usable_size,
#else
/* change this to `NULL,` if compilation fails */
malloc_usable_size,
diff -u quickjs-2019-09-01/quickjs-libc.c
quickjs-2019-09-01-freebsd/quickjs-libc.c
--- quickjs-2019-09-01/quickjs-libc.c 2019-09-15 19:32:20.971462000 +0000
+++ quickjs-2019-09-01-freebsd/quickjs-libc.c 2019-09-15 19:33:45.279494000
+0000
@@ -46,6 +46,8 @@
#include <sys/ioctl.h>
#if defined(__APPLE__)
typedef sig_t sighandler_t;
+#elif defined(__FreeBSD)
+typedef sig_t __sighandler_t;
#endif
#endif
@@ -1622,7 +1624,7 @@
JSOSSignalHandler *sh;
uint32_t sig_num;
JSValueConst func;
- sighandler_t handler;
+ sig_t handler;
if (JS_ToUint32(ctx, &sig_num, argv[0]))
return JS_EXCEPTION;
diff -u quickjs-2019-09-01/quickjs.c quickjs-2019-09-01-freebsd/quickjs.c
--- quickjs-2019-09-01/quickjs.c 2019-09-15 19:32:20.970003000 +0000
+++ quickjs-2019-09-01-freebsd/quickjs.c 2019-09-15 19:33:45.269703000
+0000
@@ -36,6 +36,8 @@
#include <malloc/malloc.h>
#elif defined(__linux__)
#include <malloc.h>
+#elif defined(__FreeBSD__)
+#include <malloc_np.h>
#endif
#include "cutils.h"
@@ -1344,6 +1346,8 @@
return 0;
#elif defined(__linux__)
return malloc_usable_size(ptr);
+#elif defined(__FreeBSD__)
+ return __malloc_usable_size(ptr);
#else
/* change this to `return 0;` if compilation fails */
return malloc_usable_size(ptr);
@@ -1418,6 +1422,8 @@
NULL,
#elif defined(__linux__)
(size_t (*)(const void *))malloc_usable_size,
+#elif defined(__FreeBSD__)
+ (size_t (*)(const void *))__malloc_usable_size,
#else
/* change this to `NULL,` if compilation fails */
malloc_usable_size,
Common subdirectories: quickjs-2019-09-01/tests and
quickjs-2019-09-01-freebsd/tests
and the error for make /example/hello_module
clang -g -flto -rdynamic -o qjs .obj/qjs.o .obj/repl.o .obj/quickjs.o
.obj/libregexp.o .obj/libunicode.o .obj/cutils.o .obj/quickjs-libc.o -lm -ldl
ld: error: undefined symbol: JS_NewRuntime
referenced by ld-temp.o
lto.tmp:(main)