From f355d307de19bc3f498d2edb4ac945cccfb4b5d2 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 17 Jun 2024 07:56:00 +0100 Subject: [PATCH] Support MacOS (#20) Fix build issues to allow use with MacOS. - Fix compiler warnings, type casting stuff. - Require GNU sed. MacOS version silently produces wrong results as it doesn't support GNU escapes. NB. Can this be rewritten, perhaps with python script? - Fix #include path issue. MacOS uses case-insensitive filenames and warns about conflict between "jerryscript.h" and "Jerryscript.h". Refactor to isolate jerryscript paths which aren't required by applications --- component.mk | 11 ++++++++++- src/Context.cpp | 3 +-- src/Debug.cpp | 5 ++--- src/Types.cpp | 2 +- src/include/Jerryscript.h | 8 -------- src/include/Jerryscript/Debug.h | 2 +- src/include/Jerryscript/Types.h | 2 +- src/jerry-port.cpp | 4 ++-- test/modules/types.cpp | 1 - 9 files changed, 18 insertions(+), 20 deletions(-) diff --git a/component.mk b/component.mk index 44e7b2f..f0562a7 100644 --- a/component.mk +++ b/component.mk @@ -10,6 +10,9 @@ COMPONENT_SRCDIRS := \ COMPONENT_INCDIRS := \ src/include \ + $(JERRYSCRIPT_ROOT) + +EXTRA_INCDIR := \ $(JERRYSCRIPT_ROOT)/jerry-core \ $(JERRYSCRIPT_SRCDIRS) @@ -137,6 +140,12 @@ endif JERRY_TYPES_H := $(COMPONENT_PATH)/src/include/Jerryscript/.typemaps.h +ifeq ($(UNAME),Darwin) +SED ?= gsed +else +SED ?= sed +endif + # Generate MAP #define for a jerryscript C enumeration # $1 -> e.g. JERRY_FUNCTION_TYPE_ # $2 -> source file @@ -145,7 +154,7 @@ define JerryGetTypes $(Q) printf "#define $(if $3,$3_,$1)MAP(XX)" >> $@ $(Q) $(foreach v,\ $(shell $(AWK) -F " |,|=" '/$1/ { sub(/^ +$1/,""); print $$1 }' $(JERRYSCRIPT_ROOT)/jerry-core/include/jerryscript-$2.h),\ -printf " \\\\\n\tXX($1$v, %s)" $$( echo "$v" | sed -E 's/(.*)/\L\1/; s/(^|_)([a-z0-9])/\U\2/g' ) >> $@; ) +printf " \\\\\n\tXX($1$v, %s)" $$( echo "$v" | $(SED) -E 's/(.*)/\L\1/; s/(^|_)([a-z0-9])/\U\2/g' ) >> $@; ) $(Q) printf "\n\n" >> $@ endef diff --git a/src/Context.cpp b/src/Context.cpp index 4879a7d..a4c160b 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -11,7 +11,6 @@ */ #include "include/Jerryscript/Context.h" -#include namespace Jerryscript { @@ -23,7 +22,7 @@ Context::Context() : Context(JERRY_GLOBAL_HEAP_SIZE * 1024) Context::Context(size_t heapSize) { - auto ctx = jerry_create_context(std::max(heapSize, 1024U), alloc, this); + auto ctx = jerry_create_context(std::max(heapSize, size_t(1024U)), alloc, this); context.reset(reinterpret_cast(ctx)); } diff --git a/src/Debug.cpp b/src/Debug.cpp index cbf33e1..44d041d 100644 --- a/src/Debug.cpp +++ b/src/Debug.cpp @@ -8,7 +8,6 @@ */ #include "include/Jerryscript/Debug.h" -#include #include namespace Jerryscript @@ -21,8 +20,8 @@ bool printHeap() return false; } - m_printf(_F("[JS] Heap size %u, allocated %u, peak %u\r\n"), stats.size, stats.allocated_bytes, - stats.peak_allocated_bytes); + m_printf(_F("[JS] Heap size %u, allocated %u, peak %u\r\n"), unsigned(stats.size), unsigned(stats.allocated_bytes), + unsigned(stats.peak_allocated_bytes)); return true; } diff --git a/src/Types.cpp b/src/Types.cpp index b90e5e2..8938925 100644 --- a/src/Types.cpp +++ b/src/Types.cpp @@ -15,7 +15,7 @@ #include extern "C" { -#include +#include } // Check Ecma values are correct diff --git a/src/include/Jerryscript.h b/src/include/Jerryscript.h index adc5877..17272bf 100644 --- a/src/include/Jerryscript.h +++ b/src/include/Jerryscript.h @@ -1,15 +1,7 @@ #pragma once -#ifdef __cplusplus - #include "Jerryscript/Task.h" #include "Jerryscript/Debug.h" #include "Jerryscript/Function.h" #include "Jerryscript/Except.h" #include "Jerryscript/Context.h" - -#else - -#include_next - -#endif diff --git a/src/include/Jerryscript/Debug.h b/src/include/Jerryscript/Debug.h index 5e4b927..d61cf37 100644 --- a/src/include/Jerryscript/Debug.h +++ b/src/include/Jerryscript/Debug.h @@ -9,7 +9,7 @@ #pragma once -#include +#include namespace Jerryscript { diff --git a/src/include/Jerryscript/Types.h b/src/include/Jerryscript/Types.h index bff4e82..9019436 100644 --- a/src/include/Jerryscript/Types.h +++ b/src/include/Jerryscript/Types.h @@ -12,7 +12,7 @@ #pragma once -#include +#include #include ".typemaps.h" #include #include diff --git a/src/jerry-port.cpp b/src/jerry-port.cpp index 0b01ab5..31d0253 100644 --- a/src/jerry-port.cpp +++ b/src/jerry-port.cpp @@ -14,8 +14,8 @@ #include "include/Jerryscript/Except.h" #include "include/Jerryscript/Context.h" -#include -#include +#include +#include #include "include/jerry_port_vm.h" #include #include diff --git a/test/modules/types.cpp b/test/modules/types.cpp index 803d1e1..823f5f7 100644 --- a/test/modules/types.cpp +++ b/test/modules/types.cpp @@ -1,5 +1,4 @@ #include -#include namespace {