
ifeq ($(OS),mingw)
  EXE=main.exe
  LIBS=-L../mingwlib -lssl -lcrypto -lws2_32 -lcrypt32 -lcryptui
  INCS=-I../mingwlib
  LUAFLAGS=-DLUA_COMPAT_ALL
  OPT=-g -O0
  DRIVER=driver-mingw
else ifeq ($(OS),linux)
  EXE=main
  LIBS=-L../linuxlib -lssl -lcrypto
  INCS=-I../linuxlib
  LUAFLAGS=-DLUA_USE_POSIX
  OPT=-g -O1
  DRIVER=driver-linux
else
  # In this case, any attempt to build luprex will trigger an error,
  # But making 'clean' will still work.
  ERROR=$(error You must specify OS=linux or OS=mingw)
  EXE=main
  LIBS=$(ERROR)
  INCS=$(ERROR)
  LUAFLAGS=$(ERROR)
  OPT=$(ERROR)
  DRIVER=driver-xxx
endif


LUA_OBJ_FILES=\
	lobj/lapi.o \
	lobj/lcode.o \
	lobj/lctype.o \
	lobj/ldebug.o \
	lobj/ldo.o \
	lobj/ldump.o \
	lobj/lfunc.o \
	lobj/lgc.o \
	lobj/llex.o \
	lobj/lmem.o \
	lobj/lobject.o \
	lobj/lopcodes.o \
	lobj/lparser.o \
	lobj/lstate.o \
	lobj/lstring.o \
	lobj/ltable.o \
	lobj/ltm.o \
	lobj/lundump.o \
	lobj/lvm.o \
	lobj/lzio.o \
	lobj/lauxlib.o \
	lobj/lbaselib.o \
	lobj/lbitlib.o \
	lobj/lcorolib.o \
	lobj/ldblib.o \
	lobj/liolib.o \
	lobj/lmathlib.o \
	lobj/loslib.o \
	lobj/lstrlib.o \
	lobj/ltablib.o \
	lobj/loadlib.o \
	lobj/linit.o \
	lobj/eris.o \


CORE_OBJ_FILES=\
	obj/invocation.o\
	obj/spookyv2.o\
	obj/eng-malloc.o\
	obj/debugcollector.o\
	obj/drivenengine.o\
	obj/util.o\
	obj/luastack.o\
	obj/traceback.o\
	obj/planemap.o\
	obj/pprint.o\
	obj/luaconsole.o\
	obj/idalloc.o\
	obj/globaldb.o\
	obj/sched.o\
	obj/table.o\
	obj/gui.o\
	obj/luasnap.o\
	obj/animqueue.o\
	obj/streambuffer.o\
	obj/source.o\
	obj/world-core.o\
	obj/world-accessor.o\
	obj/world-difftab.o\
	obj/world-diffxmit.o\
	obj/world-pairtab.o\
	obj/world-testing.o\
	obj/textgame.o\
	obj/lpxserver.o\
	obj/lpxclient.o\
	obj/eng-tests.o\
	obj/printbuffer.o\
	obj/driver-util.o\
	obj/driver-ssl.o\
	obj/$(DRIVER).o\


lobj/%.o: ../eris-master/src/%.c
	gcc -Wall $(OPT) -DLUA_USE_APICHECK $(LUAFLAGS) -c -MMD $< -o $@

obj/%.o: cpp/%.cpp
	g++ -std=c++17 -Wall $(OPT) -I../eris-master/src -Iwrap -Icpp $(INCS) -c -MMD $< -o $@

$(EXE): $(CORE_OBJ_FILES) $(LUA_OBJ_FILES)
	g++ -std=c++17 -Wall $(OPT) -o $@ $(CORE_OBJ_FILES) $(LUA_OBJ_FILES) $(LIBS)

clean:
	rm -f main.exe main obj/* lobj/*

-include $(CORE_OBJ_FILES:%.o=%.d)
-include $(LUA_OBJ_FILES:%.o=%.d)
