# wp8_qt_file - Makefile for Windows NT
#
#   This Makefile is added for testing purposes. Normally, the QT plug-in
#   is only used on Unix/X11 systems.
#
# It is assumed that the following environment variables have been set:
# Run vcvars32.bat before attempting to make and have erlang in your path
#

#
# Should one use the MT library as the emulator or the MD library
# like programs that load dll's actually should do? 
# Well, I hold for the later, so I'll try it as long as it works.
# I.E /MD as compiler option and link with msvcrt.lib.
#
ERL_TOP = C:\progra~1\erl5.2
LINK = link
MLFLAGS= /nologo /subsystem:console /machine:I386 /nodefaultlib 
MLIBS = kernel32.lib ws2_32.lib msvcrt.lib user32.lib comdlg32.lib
QTLIBS = $(QTDIR)\lib\qt-mt230nc.lib $(QTDIR)\lib\qtmain.lib \
 $(QTDIR)\lib\qutil.lib
#QTLIBS = -L$(QTDIR)\bin -lqtmain -lqt-mt230nc -lqutil

LIBDIR = ..\..\plugins\win32_file
OBJDIR = .

!if !exist($(LIBDIR)) 
!	if [mkdir $(LIBDIR)]
!	error "wp8_qt_file: cannot create LIBDIR"
!	endif
!endif

!if !exist($(OBJDIR))
!	if [mkdir $(OBJDIR)]
!	error "wp8_qt_file: cannot create OBJDIR"
!	endif
!endif

# Includes
#
INCLUDES = -I. -I$(ERL_TOP)\usr\include -I$(QTDIR)\include -DQT_DLL

# Libraries (static)
#

ERL_DLL_LIB = $(ERL_TOP)\usr\lib\erl_dll.lib

# Compiler options
# 
OPTS = /G5 /Ox /O2 /Ob2
CFLAGS = $(INCLUDES) /nologo /MD $(OPTS) -D__WIN32__ -DWIN32

# Object files
#
OBJS = $(OBJDIR)\qt_wings_file_drv.obj	

DLLS = $(LIBDIR)\qt_wings_file_drv.dll

BEAM = $(LIBDIR)\wp8_qt_file.beam
ERLC = erlc
ERLC_FLAGS = -o $(LIBDIR)
#
# Targets
#

all:	$(DLLS) $(BEAM)

clean: 
	-del $(LIBDIR)\*.dll
	-del $(LIBDIR)\*.exp
	-del $(LIBDIR)\*.lib
	-del $(LIBDIR)\*.beam
	-del $(OBJDIR)\*.obj

$(LIBDIR)\qt_wings_file_drv.dll:qt_wings_file_drv.cpp
	$(CC) $(CFLAGS) /c /Fo$(OBJDIR)\qt_wings_file_drv.obj \
  qt_wings_file_drv.cpp
	$(LINK) $(MLFLAGS) /dll /out:$(LIBDIR)\qt_wings_file_drv.dll \
		$(OBJS) \
		$(ERL_DLL_LIB) \
		$(QTLIBS) \
		$(MLIBS)
	-del $(LIBDIR)\*.exp
	-del $(LIBDIR)\*.lib
	-del $(OBJDIR)\*.obj

$(LIBDIR)\wp8_qt_file.beam: wp8_qt_file.erl
	$(ERLC) $(ERLC_FLAGS) wp8_qt_file.erl
