Make it easier to bundle C modules
This commit is contained in:
parent
5e0e3e0e22
commit
0a71a954c2
7
Makefile
7
Makefile
@ -84,6 +84,13 @@ ifdef KRK_HEAP_TAG_BYTE
|
||||
CFLAGS += -DKRK_HEAP_TAG_BYTE=${KRK_HEAP_TAG_BYTE}
|
||||
endif
|
||||
|
||||
ifdef KRK_BUNDLE_LIBS
|
||||
KRK_BUNDLE_LIBS_CFLAG=$(patsubst %,BUNDLED(%);,${KRK_BUNDLE_LIBS})
|
||||
KRK_BUNDLE_LIBS_BOBJS=$(patsubst %,src/modules/module_%.o,${KRK_BUNDLE_LIBS})
|
||||
BIN_OBJS += ${KRK_BUNDLE_LIBS_BOBJS}
|
||||
CFLAGS += -DKRK_BUNDLE_LIBS="${KRK_BUNDLE_LIBS_CFLAG}"
|
||||
endif
|
||||
|
||||
.PHONY: help
|
||||
|
||||
help:
|
||||
|
26
src/kuroko.c
26
src/kuroko.c
@ -744,16 +744,6 @@ static int compileFile(char * argv[], int flags, char * fileName) {
|
||||
return func == NULL;
|
||||
}
|
||||
|
||||
#ifdef BUNDLE_LIBS
|
||||
#define BUNDLED(name) do { \
|
||||
extern KrkValue krk_module_onload_ ## name (); \
|
||||
KrkValue moduleOut = krk_module_onload_ ## name (); \
|
||||
krk_attachNamedValue(&vm.modules, # name, moduleOut); \
|
||||
krk_attachNamedObject(&AS_INSTANCE(moduleOut)->fields, "__name__", (KrkObj*)krk_copyString(#name, sizeof(#name)-1)); \
|
||||
krk_attachNamedValue(&AS_INSTANCE(moduleOut)->fields, "__file__", NONE_VAL()); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
#ifdef _WIN32
|
||||
SetConsoleOutputCP(65001);
|
||||
@ -885,11 +875,17 @@ _finishArgs:
|
||||
/* Bind interrupt signal */
|
||||
bindSignalHandlers();
|
||||
|
||||
#ifdef BUNDLE_LIBS
|
||||
/* Add any other modules you want to include that are normally built as shared objects. */
|
||||
BUNDLED(math);
|
||||
BUNDLED(socket);
|
||||
BUNDLED(timeit);
|
||||
#ifdef KRK_BUNDLE_LIBS
|
||||
/* Define KRK_BUNDLE_LIBS like "BUNDLE(os);BUNDLE(math);", etc. */
|
||||
#define BUNDLED(name) do { \
|
||||
extern KrkValue krk_module_onload_ ## name (KrkString*); \
|
||||
KrkValue moduleOut = krk_module_onload_ ## name (NULL); \
|
||||
krk_attachNamedValue(&vm.modules, # name, moduleOut); \
|
||||
krk_attachNamedObject(&AS_INSTANCE(moduleOut)->fields, "__name__", (KrkObj*)krk_copyString(#name, sizeof(#name)-1)); \
|
||||
krk_attachNamedValue(&AS_INSTANCE(moduleOut)->fields, "__file__", NONE_VAL()); \
|
||||
} while (0)
|
||||
KRK_BUNDLE_LIBS
|
||||
#undef BUNDLED
|
||||
#endif
|
||||
|
||||
KrkValue result = INTEGER_VAL(0);
|
||||
|
Loading…
Reference in New Issue
Block a user