#CONFIG_WERROR=y
# force 32 bit build for some utilities
#CONFIG_M32=y
-
-ifdef CONFIG_DARWIN
-# use clang instead of gcc
-CONFIG_CLANG=y
-CONFIG_DEFAULT_AR=y
-endif
+# cosmopolitan build (see https://github.com/jart/cosmopolitan)
+#CONFIG_COSMO=y
# installation directory
prefix=/usr/local
OBJDIR=.obj
+ifdef CONFIG_DARWIN
+# use clang instead of gcc
+CONFIG_CLANG=y
+CONFIG_DEFAULT_AR=y
+endif
+
ifdef CONFIG_WIN32
ifdef CONFIG_M32
CROSS_PREFIX=i686-w64-mingw32-
CROSS_PREFIX=
EXE=
endif
+
ifdef CONFIG_CLANG
HOST_CC=clang
CC=$(CROSS_PREFIX)clang
AR=$(CROSS_PREFIX)ar
endif
endif
+else ifdef CONFIG_COSMO
+ CONFIG_LTO=
+ HOST_CC=gcc
+ CC=cosmocc
+ # cosmocc does not correct support -MF
+ CFLAGS=-g -Wall #-MMD -MF $(OBJDIR)/$(@F).d
+ CFLAGS += -Wno-array-bounds -Wno-format-truncation
+ AR=cosmoar
else
HOST_CC=gcc
CC=$(CROSS_PREFIX)gcc
CFLAGS_SMALL=$(CFLAGS) -Os
CFLAGS_OPT=$(CFLAGS) -O2
CFLAGS_NOLTO:=$(CFLAGS_OPT)
+ifdef CONFIG_COSMO
+LDFLAGS=-s # better to strip by default
+else
LDFLAGS=-g
+endif
ifdef CONFIG_LTO
CFLAGS_SMALL+=-flto
CFLAGS_OPT+=-flto
LDEXPORT=-rdynamic
endif
+ifndef CONFIG_COSMO
+ifndef CONFIG_DARWIN
+CONFIG_SHARED_LIBS=y # building shared libraries is supported
+endif
+endif
+
PROGS=qjs$(EXE) qjsc$(EXE) run-test262
ifneq ($(CROSS_PREFIX),)
QJSC_CC=gcc
ifeq ($(CROSS_PREFIX),)
PROGS+=examples/hello
ifndef CONFIG_ASAN
-PROGS+=examples/hello_module examples/test_fib
-ifndef CONFIG_DARWIN
-PROGS+=examples/fib.so examples/point.so
+PROGS+=examples/hello_module
endif
+ifdef CONFIG_SHARED_LIBS
+PROGS+=examples/test_fib examples/fib.so examples/point.so
endif
endif
###############################################################################
# tests
-ifndef CONFIG_DARWIN
+ifdef CONFIG_SHARED_LIBS
test: tests/bjson.so examples/point.so
endif
ifdef CONFIG_M32
./qjs tests/test_loop.js
./qjs tests/test_std.js
./qjs tests/test_worker.js
-ifndef CONFIG_DARWIN
+ifdef CONFIG_SHARED_LIBS
ifdef CONFIG_BIGNUM
./qjs --bignum tests/test_bjson.js
else
}
/* default memory allocation functions with memory limitation */
-static inline size_t js_trace_malloc_usable_size(void *ptr)
+static size_t js_trace_malloc_usable_size(const void *ptr)
{
#if defined(__APPLE__)
return malloc_size(ptr);
#elif defined(_WIN32)
- return _msize(ptr);
+ return _msize((void *)ptr);
#elif defined(EMSCRIPTEN)
return 0;
#elif defined(__linux__)
- return malloc_usable_size(ptr);
+ return malloc_usable_size((void *)ptr);
#else
/* change this to `return 0;` if compilation fails */
- return malloc_usable_size(ptr);
+ return malloc_usable_size((void *)ptr);
#endif
}
js_trace_malloc,
js_trace_free,
js_trace_realloc,
-#if defined(__APPLE__)
- malloc_size,
-#elif defined(_WIN32)
- (size_t (*)(const void *))_msize,
-#elif defined(EMSCRIPTEN)
- NULL,
-#elif defined(__linux__)
- (size_t (*)(const void *))malloc_usable_size,
-#else
- /* change this to `NULL,` if compilation fails */
- malloc_usable_size,
-#endif
+ js_trace_malloc_usable_size,
};
#define PROG_NAME "qjs"
}
/* default memory allocation functions with memory limitation */
-static inline size_t js_def_malloc_usable_size(void *ptr)
+static size_t js_def_malloc_usable_size(const void *ptr)
{
#if defined(__APPLE__)
return malloc_size(ptr);
#elif defined(_WIN32)
- return _msize(ptr);
+ return _msize((void *)ptr);
#elif defined(EMSCRIPTEN)
return 0;
#elif defined(__linux__)
- return malloc_usable_size(ptr);
+ return malloc_usable_size((void *)ptr);
#else
/* change this to `return 0;` if compilation fails */
- return malloc_usable_size(ptr);
+ return malloc_usable_size((void *)ptr);
#endif
}
js_def_malloc,
js_def_free,
js_def_realloc,
-#if defined(__APPLE__)
- malloc_size,
-#elif defined(_WIN32)
- (size_t (*)(const void *))_msize,
-#elif defined(EMSCRIPTEN)
- NULL,
-#elif defined(__linux__)
- (size_t (*)(const void *))malloc_usable_size,
-#else
- /* change this to `NULL,` if compilation fails */
- malloc_usable_size,
-#endif
+ js_def_malloc_usable_size,
};
JSRuntime *JS_NewRuntime(void)