#  Copyright (c) 2001 Dan Gudmundsson
#  See the file "license.terms" for information on usage and redistribution
#  of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# 
#     $Id: Makefile.win32,v 1.14 2003/05/19 19:31:58 bjorng Exp $
#
#    "vsvars32" sets up the env for visual C++ 6
#    "omake -E -EN -f Makefile.win32" builds

#  With alot of help from Patrik Nyblom and Jakob Cederlund

# OpenGLDir 
GL_LIBS		= OpenGL32.lib GLU32.lib

!if !defined(ERL_DIR)
ERL_DIR         = c:/progra~1/erl5.2.3.3
!endif
ERLINCS         = -I$(ERL_DIR)/usr/include
ERL_LIBS         = $(ERL_DIR)/usr/lib/erl_dll.lib

!if !defined(SDL_DIR)
SDL_DIR         = ..\..\SDL-1.2.5
!endif

#SDL_DEBUG_DIR   = C:/JC/Div/SDL-1.1.5/src/SDL-1.1.5/VisualC
SDL_DEBUG_DIR    = $(SDL_DIR)\VisualC\

!if !defined(DEBUG)
#SDL_LIBS	= $(SDL_DIR)/VisualC/SDL/RELEASE/sdl.lib $(SDL_DIR)/VisualC/SDLmain/RELEASE/sdlmain.lib
SDL_LIBS	= $(SDL_DIR)/lib/sdl.lib $(SDL_DIR)/lib/sdlmain.lib
!else
SDL_LIBS        = $(SDL_DEBUG_DIR)/SDLmain/Debug/SDLmain.lib $(SDL_DEBUG_DIR)/SDL/Debug/SDL.lib 
!endif
LIBS		= $(SDL_LIBS) $(GL_LIBS) $(ERL_LIBS) User32.lib
SDLINCS		= -I$(SDL_DIR)/Include

INCS		= $(SDLINCS) $(ERLINCS)

!if !defined(DEBUG)
CFLAGS = -nologo -MD -W3 -Ox -Oy -DWIN32 -D__WIN32__ $(INCS)
!else
CFLAGS = -nologo -MDd -W3 -Zi -DWIN32 -D__WIN32__ $(INCS)
!endif

!if !exist(..\priv)
!	if [mkdir ..\priv]
!	error "esdl: cannot create ..\priv"
!	endif
!endif

# Files

Helpers		=  esdl_gen.c esdl_wrapper.c esdl_spec.c \
			esdl_util.c \
			esdl_video.c esdl_events.c esdl_audio.c \
			esdl_gl.c esdl_glu.c esdl_glext.c

HelpersObjects = $(Helpers:.c=.obj)

# Targets

#target: ../priv/sdlwrapper.exe ../priv/sdl_driver.dll ../priv/SDL.dll
target:  ../priv/sdl_driver.dll ../priv/SDL.dll

../priv/SDL.dll: $(SDL_DIR)\lib\SDL.dll 
	copy $(SDL_DIR)\lib\SDL.dll ..\priv\SDL.dll

clean:  
	del ..\priv\sdlwrapper.exe
	del ..\priv\sdl.dll
	del ..\priv\sdl_driver.dll
	del *.obj
	del *~ 
	del erl_crash.dump


#../priv/sdlwrapper.exe: esdl_main.c esdl_stream.c $(HelpersObjects) 
#	$(CC) $(CFLAGS)  $(INCS) $** $(LIBS) -Fe$@ -link -subsystem:windows

../priv/sdl_driver.dll: esdl_driver.c $(HelpersObjects) 
	$(CC) $(CFLAGS) -LD  $(INCS) $** $(LIBS) -Fe$@
