# detect target architecture
!IF "$(CPU)" == ""
CPU=$(PROCESSOR_ARCHITECTURE)
!ENDIF

!IF "$(CPU)" == "i386"
TARGETDIR = ..\..\..\bin\win32\dev
ADD_LFLAGS = /MACHINE:X86

!ELSEIF "$(CPU)" == "AMD64"
TARGETDIR = ..\..\..\bin\win64\dev
ADD_LFLAGS = /MACHINE:X64

!ELSE
!ERROR Unsupported CPU architecture: $(CPU)
!ENDIF

PROJECTNAME = zabbix_sender
PROJECTDIR = ..\..\..\src\$(PROJECTNAME)
TARGETNAME = zabbix_sender
TARGETEXT = dll
PROGNAME = $(TARGETDIR)\$(TARGETNAME).$(TARGETEXT)
ADD_CFLAGS = $(ADD_CFLAGS) /D NDEBUG /D ZBX_EXPORT /Fd$(TARGETNAME).$(TARGETEXT).pdb
ADD_LFLAGS = $(ADD_LFLAGS) /DLL

POSTBUILD = post-build
POSTCLEAN = post-clean

ADD_CFLAGS = $(ADD_CFLAGS) /D NDEBUG
ADD_RFLAGS = /d "ZABBIX_SENDER"

!INCLUDE Makefile_common.inc

# the main object file must be already added in master Makefile
OBJS = \
	..\..\..\src\libs\zbxcommon\comms.o \
	..\..\..\src\libs\zbxcommon\iprange.o \
	..\..\..\src\libs\zbxcommon\misc.o \
	..\..\..\src\libs\zbxcommon\str.o \
	..\..\..\src\libs\zbxcommon\xml.o \
	..\..\..\src\libs\zbxcommon\zbxgetopt.o \
	..\..\..\src\libs\zbxcomms\comms.o \
	..\..\..\src\libs\zbxconf\cfg.o \
	..\..\..\src\libs\zbxcrypto\base64.o \
	..\..\..\src\libs\zbxjson\json.o \
	..\..\..\src\libs\zbxjson\json_parser.o \
	..\..\..\src\libs\zbxlog\log.o \
	..\..\..\src\libs\zbxsys\mutexs.o \
	..\..\..\src\libs\zbxsys\symbols.o \
	..\..\..\src\libs\zbxsys\threads.o \
	..\..\..\src\libs\zbxwin32\fatal.o \
	..\..\..\src\zabbix_sender\win32\zabbix_sender.o

LIBS = ws2_32.lib psapi.lib pdh.lib Wldap32.lib advapi32.lib uuid.lib Iphlpapi.lib

!INCLUDE Makefile_tls.inc
!INCLUDE Makefile_targets.inc

# zabbix_sender dynamic link library support
{$(PROJECTDIR)/win32}.c{$(PROJECTDIR)/win32}.o:
	$(CC) $? /Fo"$@" $(CFLAGS)

$(TARGETDIR)\zabbix_sender.h: $(PROJECTDIR)\win32\zabbix_sender.h
	@copy /Y $(PROJECTDIR)\win32\zabbix_sender.h $(TARGETDIR)\

post-build: $(TARGETDIR)\zabbix_sender.h
	@del /Q $(TARGETDIR)\zabbix_sender.exp 2>NUL

post-clean:
	@del /Q $(TARGETDIR)\zabbix_sender.h 2>NUL
	@del /Q $(TARGETDIR)\zabbix_sender.lib 2>NUL
