NAME=luafar3
VERSION_LUASDK=20241113

ifdef SYS_LUA
LUA=lua
else
LUA=$(WINE_CMD)$(strip $(call os_name, luasdk/$(VERSION_LUASDK)/32/lua.exe))
endif

SRCS = \
	luafar/bit64.c \
	luafar/exported.c \
	luafar/farhost.c \
	luafar/flags.c \
	luafar/keysandcolors.c \
	luafar/lflua.c \
	luafar/lregex.c \
	luafar/luamacro.c \
	luafar/lusercontrol.c \
	luafar/reg.c \
	luafar/service.c \
	luafar/slnunico.c \
	luafar/lutf8lib.c \
	luafar/uliolib51.c \
	luafar/uloadlib51.c \
	luafar/ustring.c \
	luafar/util.c \
	luafar/win.c \
	luafar/LPeg/lpcap.c \
	luafar/LPeg/lpcode.c \
	luafar/LPeg/lpcset.c \
	luafar/LPeg/lpprint.c \
	luafar/LPeg/lptree.c \
	luafar/LPeg/lpvm.c \

USERLIBS = \
	luasdk/$(VERSION_LUASDK)/$(BITPREFIX)$(DIRBIT)/lua51.lib \
	-Wl,--out-implib,$(OBJDIR)/luafar3.lib \

USERC = \
	-Iluasdk/include \
	-DBUILD_DLL \
	-DWINVER=0x500 \
	-DLUADLL=\"lua51.dll\" \
	-Wno-cast-function-type \
	-Wno-cast-qual \
	-Wno-format-nonliteral \
	-Wno-implicit-fallthrough \
	-Wno-missing-declarations \
	-Wno-pedantic \

ifdef CLANG
USERC += \
	-Wno-bad-function-cast \
	-Wno-cast-align \
	-Wno-comma \
	-Wno-conditional-uninitialized \
	-Wno-float-equal \
	-Wno-format-non-iso \
	-Wno-missing-prototypes \
	-Wno-missing-variable-declarations \
	-Wno-shadow \
	-Wno-strict-prototypes \
	-Wno-unused-macros \

endif

USERTARGETS = luasdk/$(VERSION_LUASDK)/$(BITPREFIX)$(DIRBIT)/lua51.dll

RC_NAME = luafar/$(NAME)
DEF_NAME = -

include ../makefile_gcc_def_inc

DOCS = \
	luasdk/$(VERSION_LUASDK)/$(BITPREFIX)$(DIRBIT)/lua51.dll \

include ../makefile_gcc_target_inc

luafar/flags.c: $(COMINC)/plugin.hpp luafar/makeflags.lua luasdk/$(VERSION_LUASDK)/$(BITPREFIX)$(DIRBIT)/lua51.dll
	@echo generating $@
	@$(LUA) luafar/makeflags.lua $(COMINC)/plugin.hpp > $@

luafar/keysandcolors.c: luafar/makefarkeys.lua $(COMINC)/farcolor.hpp $(FARDIR)/uuids.far.dialogs.hpp luasdk/$(VERSION_LUASDK)/$(BITPREFIX)$(DIRBIT)/lua51.dll
	@echo generating $@
	@$(LUA) luafar/makefarkeys.lua $(COMINC)/farcolor.hpp $(FARDIR)/uuids.far.dialogs.hpp $@

$(LUA): luasdk/$(VERSION_LUASDK)/$(BITPREFIX)$(DIRBIT)/lua51.dll
luasdk/$(VERSION_LUASDK)/$(BITPREFIX)$(DIRBIT)/lua51.lib: luasdk/$(VERSION_LUASDK)/$(BITPREFIX)$(DIRBIT)/lua51.dll
luasdk/$(VERSION_LUASDK)/$(BITPREFIX)$(DIRBIT)/lua51.dll:
	@echo Downloading 7-Zip binaries
	curl -o luasdk/LuaSDK-$(VERSION_LUASDK).zip https://raw.githubusercontent.com/FarGroup/thirdparty/master/LuaSDK-$(VERSION_LUASDK).zip && unzip luasdk/LuaSDK-$(VERSION_LUASDK).zip -d luasdk/$(VERSION_LUASDK)

clean::
	@$(RM) $(DLLDIR)/lua*.* $(OBJS) $(DEPS)
