Convert to a true DLL engine

This commit is contained in:
2023-02-21 15:28:45 -05:00
parent 3eebe7dc33
commit 98c1b2d599
4 changed files with 62 additions and 25 deletions

6
luprex/.gitignore vendored
View File

@@ -1,5 +1,8 @@
a.out
gprof.out
gmon.out
luprex
*~
\#*#
.#*
@@ -7,8 +10,9 @@ gmon.out
*.o
*.dll
*.exe
*.so
*.a
main
obj/**
.vscode/**
ext/eris-master/src/lua

View File

@@ -1,23 +1,42 @@
#######################################################################
##
## Auto detect Operating System
##
#######################################################################
ifneq "" "$(findstring -linux-,$(MAKE_HOST))"
OS=linux
EXE=main
LIBS=-L./ext/openssl-linux -lssl -lcrypto -ldl
EXE=luprex
DLL=luprex.so
LIBS=-L./ext/openssl-mingw -lssl -lcrypto -ldl
LUAFLAGS=-DLUA_USE_APICHECK -DLUA_USE_POSIX
OPT=-g -O0
else ifneq "" "$(findstring cmd.exe,$(COMSPEC))"
OS=mingw
EXE=main.exe
EXE=luprex.exe
DLL=luprex.dll
LIBS=-L./ext/openssl-mingw -lssl -lcrypto -lws2_32 -lcrypt32 -lcryptui
LUAFLAGS=-DLUA_USE_APICHECK -DLUA_COMPAT_ALL
OPT=-g -O0
else
$(error Cannot figure out whether to build the linux or mingw version)
endif
$(info Building for $(OS)...)
#######################################################################
##
## List of all OBJ files
##
#######################################################################
OBJ_ERIS=\
obj/eris/lapi.o \
obj/eris/lcode.o \
@@ -91,25 +110,47 @@ OBJ_CORE=\
OBJ_DRV=\
obj/drv/drvutil.o\
obj/drv/sslutil.o\
obj/drv/driver-$(OS).o
obj/drv/driver-$(OS).o\
$(EXE): $(OBJ_ERIS) $(OBJ_CORE) $(OBJ_DRV)
g++ $(OPT) -std=c++17 -export-dynamic -Wall -o $@ $(OBJ_ERIS) $(OBJ_CORE) $(OBJ_DRV) $(LIBS)
#######################################################################
##
## Make rules
##
#######################################################################
GPP=g++ -Wall -fvisibility=hidden $(OPT) -std=c++17 -MMD
all: $(EXE) $(DLL)
$(EXE): $(OBJ_DRV)
$(GPP) -o $@ $(OBJ_DRV) -L./ext/openssl-linux -lssl -lcrypto -ldl
$(DLL): $(OBJ_ERIS) $(OBJ_CORE)
$(GPP) -export-dynamic -Wl,--no-allow-shlib-undefined -Wl,-z,defs -shared -o $@ $^
obj/eris/%.o: ext/eris-master/src/%.c
gcc $(OPT) -Wall -fvisibility=hidden $(LUAFLAGS) -c -MMD $< -o $@
$(GPP) -fPIC $(LUAFLAGS) -o $@ -c $<
obj/core/%.o: cpp/core/%.cpp
g++ $(OPT) -Wall -fvisibility=hidden -std=c++17 -I./ext/eris-master/src -I./cpp/wrap -I./cpp/core -c -MMD $< -o $@
$(GPP) -fPIC -I./ext/eris-master/src -I./cpp/wrap -I./cpp/core -o $@ -c $<
obj/drv/%.o: cpp/drv/%.cpp
g++ $(OPT) -Wall -fvisibility=hidden -std=c++17 -I./ext -I./src/drv -c -MMD $< -o $@
$(GPP) -I./ext -I./src/drv -o $@ -c $<
clean:
rm -f main.exe main obj/core/*.* obj/drv/*.* obj/eris/*.*
rm -f luprex luprex.exe luprex.so luprex.dll obj/core/*.* obj/drv/*.* obj/eris/*.*
#######################################################################
##
## Automatically generated Make Dependencies
##
#######################################################################
-include $(OBJ_ERIS:%.o=%.d)
-include $(OBJ_ERIS:%.o=%.d)
-include $(OBJ_CORE:%.o=%.d)
-include $(OBJ_DRV:%.o=%.d)

View File

@@ -158,12 +158,10 @@
#include "wrap-set.hpp"
#include <cstring>
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "eris.h"
}
class LuaSlot : public eng::nevernew {
protected:

View File

@@ -217,17 +217,11 @@ static int console_read(char *bytes, int nbytes) {
return read(0, bytes, nbytes);
}
// Load the DLL if it's not already loaded. Stores
// the handle in a global variable.
static void load_engine_dll() {
// Not actually implemented yet. Currently, the engine
// is linked right into the executable.
}
static void call_init_engine_wrapper(EngineWrapper *w) {
load_engine_dll();
using InitFn = void (*)(EngineWrapper *);
InitFn initfn = (InitFn)dlsym(RTLD_DEFAULT, "init_engine_wrapper");
void *dll_handle = dlopen("./luprex.so", RTLD_NOW | RTLD_LOCAL);
assert(dll_handle != nullptr);
InitFn initfn = (InitFn)dlsym(dll_handle, "init_engine_wrapper");
assert(initfn != nullptr);
initfn(w);
}