# Build application with GUI (tray, main window)
USE_WIN32_APP := yes

WINDRES = windres

CXXFLAGS := $(CXX_DEBUG) -fPIC -msse
INCFLAGS := -I$(DAEMON_SRC_DIR) -IWin32
LDFLAGS := ${LD_DEBUG} -static -fPIC -msse

NEEDED_CXXFLAGS += -std=c++23

DEFINES += -DWIN32_LEAN_AND_MEAN

# UPNP Support
ifeq ($(USE_UPNP),yes)
	DEFINES += -DUSE_UPNP -DMINIUPNP_STATICLIB
	LDLIBS = -lminiupnpc
endif

ifeq ($(USE_WINXP_FLAGS), yes)
	DEFINES += -DWINVER=0x0501 -D_WIN32_WINNT=0x0501
endif

LDLIBS += \
	$(MINGW_PREFIX)/lib/libboost_filesystem-mt.a \
	$(MINGW_PREFIX)/lib/libboost_program_options-mt.a \
	$(MINGW_PREFIX)/lib/libboost_json-mt.a \
	$(MINGW_PREFIX)/lib/libssl.a \
	$(MINGW_PREFIX)/lib/libcrypto.a \
	$(MINGW_PREFIX)/lib/libz.a \
	-lwsock32 \
	-lws2_32 \
	-liphlpapi \
	-lcrypt32 \
	-lgdi32 \
	-lole32 \
	-luuid \
	-lpthread

ifeq ($(USE_WIN32_APP), yes)
	DEFINES += -DWIN32_APP
	LDFLAGS += -mwindows
	DAEMON_RC += Win32/Resource.rc
	DAEMON_OBJS += $(patsubst %.rc,obj/%.o,$(DAEMON_RC))
endif

ifeq ($(USE_ASLR),yes)
	LDFLAGS += -Wl,--nxcompat -Wl,--high-entropy-va -Wl,--dynamicbase,--export-all-symbols
endif

obj/%.o : %.rc | mk_obj_dir
	$(WINDRES) $(DEFINES) $(INCFLAGS) --preprocessor-arg=-MMD --preprocessor-arg=-MP --preprocessor-arg=-MF$@.d -i $< -o $@
