diff --git a/Makefile b/Makefile index c84bc44..2ccabfe 100644 --- a/Makefile +++ b/Makefile @@ -136,7 +136,7 @@ CFLAGS+=-fwrapv # ensure that signed overflows behave as expected ifdef CONFIG_WERROR CFLAGS+=-Werror endif -DEFINES:=-D_GNU_SOURCE -DCONFIG_VERSION=\"$(shell cat VERSION)\" +DEFINES:=-D_GNU_SOURCE -DCONFIG_VERSION=\"$(shell grep JS_VERSION_STR quickjs.h | sed -e 's#.*"\(.*\)".*#\1#')\" ifdef CONFIG_BIGNUM DEFINES+=-DCONFIG_BIGNUM endif diff --git a/VERSION b/VERSION deleted file mode 100644 index e32e065..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -2024-02-14 diff --git a/quickjs.c b/quickjs.c index f000ff7..70a7980 100644 --- a/quickjs.c +++ b/quickjs.c @@ -1286,6 +1286,21 @@ static const JSClassExoticMethods js_proxy_exotic_methods; static const JSClassExoticMethods js_module_ns_exotic_methods; static JSClassID js_class_id_alloc = JS_CLASS_INIT_COUNT; +const char* JS_GetVersion(void) +{ +#define JS_STRINGIFY_(x) #x +#define JS_STRINGIFY(x) JS_STRINGIFY_(x) + + return JS_VERSION_STR +#ifdef JS_VERSION_SUFFIX + "-" JS_STRINGIFY(JS_VERSION_SUFFIX) +#endif + ; + +#undef JS_STRINGIFY +#undef JS_STRINGIFY_ +} + static void js_trigger_gc(JSRuntime *rt, size_t size) { BOOL force_gc; diff --git a/quickjs.h b/quickjs.h index edc7b47..5001759 100644 --- a/quickjs.h +++ b/quickjs.h @@ -32,6 +32,15 @@ extern "C" { #endif +#define JS_MKVERSION(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch)) +#define JS_VERSION JS_MKVERSION(0, 5, 0) +#define JS_VERSION_STR "0.5.0" +#define JS_VERSION_MAJOR(v) (((v) >> 16)) +#define JS_VERSION_MINOR(v) (((v) >> 8) & 0xff) +#define JS_VERSION_PATCH(v) ((v) & 0xff) + +const char *JS_GetVersion(void); + #if defined(__GNUC__) || defined(__clang__) #define js_likely(x) __builtin_expect(!!(x), 1) #define js_unlikely(x) __builtin_expect(!!(x), 0)