##############################################################################
#
# Open Watcom makefile for SDL_ttf
#
# This makefile builds Win32 versions of the SDL_ttf library, only.
# It has been tested on Windows XP SP2, Home and Professional versions.
#
# Author:	Marc Peter <macpete@gmx.de>
#
# Prerequisites:
#  
#  Requires Open Watcom 1.4 or later. (See http://www.openwatcom.org)
#  Needs a version of the freetype library, built with Open Watcom
#
# wmake targets are:
#
#  sdl_ttf  Builds the SDL_ttf library (default target)
#  clean    Cleans up files generated by previous runs of wmake
#  tests    Builds sdl_ttf and puts the test executables in the base directory
#
# Optional build modifiers:
#
#  build=debug   Choose Debug build instead of Release.
#
#  tgt=dll       Build DLL version of SDL instead of the static library.
#                NOTE: Client applications must be compiled using the
#                      -bm and -br switches of Open Watcom.
#
# Examples:
#
#  Default build: Release SDL_ttf static library in subdirectory Release
#     wmake
#       or
#     wmake sdl_ttf
#
#  Default Release build with all test executables:
#     wmake tests
#
#  Release build of the library and one selcted test (see TESTS macro):
#     wmake glfont
#
#  Debug build of DLL library version and all tests:
#     wmake tests build=debug tgt=dll
#
#  Clean up Release build of DLL version and tests:
#     wmake clean tgt=dll
#     (Note: the target clean does NOT remove all possible build targets, only
#     the tests and the library directory selected with build=... and tgt=...)
#
##############################################################################

CC  = wcc386
CPP = wpp386
MTL = midl
RSC = wrc


SRCDIR  = ..
SDL_DIR = ../../SDL-1.2
FT_DIR  = freetype

INCDIRS = -I"$(SDL_DIR)/include" -I"$(FT_DIR)/include"

DEFINES = -DWIN32 -D_WINDOWS -DNO_STDIO_REDIRECT -D_WIN32_WINNT=0x0400 -DENABLE_DIRECTX 

CFLAGS = -zq -6r -s $(DEFINES) $(INCDIRS) -zq -w3 -ei -j -fp6 -fpi87 -bt=nt -bm


TESTS = glfont showfont

LIBS = kernel32.lib user32.lib winmm.lib opengl32.lib $(%DXDIR)/lib/dxguid.lib


!ifndef build
bld = release
!else
bld = $(build)
!endif


!ifeq bld debug

!message Doing Debug build

OUTDIR	= Debug

DEFINES	+= -D_DEBUG
CFLAGS	+= -od -d2

LDOPTS	= DEBUG all OP symf

!else

!message Doing Release build

OUTDIR	= Release

DEFINES	+= -DNDEBUG
CFLAGS	+= -d0 -oaxt

#LDOPTS	=

!endif

LDOPTS += OP quiet LIBR {$(LIBS)}


!ifeq tgt dll
FT_LIB		= $(FT_DIR)/objs/freetyped.lib
OUTDIR		= $+ $(OUTDIR)_DLL $-
CFLAGS_DLL_OPT	= -bd -DBUILD_DLL
CFLAGS		+= -br
LDOPTS_DLL_OPT	= initinstance
COPY_DLL_OPT	= copy_dlls
LIB_DEP		= $(OUTDIR)/SDL_ttf.dll
MK_LIB		= wlib -q -b -n $@ +$[@
!else
FT_LIB		= $(FT_DIR)/objs/freetype.lib
LIB_DEP		= $(OUTDIR)/sdl_ttf.lnk $(OBJS)
MK_LIB		= wlib -q -b -n $@ @$[@ $(FT_LIB)
!endif

SDLLIB_DIR	= $(SDL_DIR)/watcom/$(OUTDIR)

SDL_LIB		= $(SDLLIB_DIR)/SDL.lib
SDLMAIN_LIB	= $(SDLLIB_DIR)/SDLmain.lib

.before
	@if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"

#
# default target: SDL_ttf libraries only (without tests)
#
sdl_ttf : .SYMBOLIC $(OUTDIR)/SDL_ttf.lib


#
# target to build all SDL_ttf tests
#
tests : .SYMBOLIC $(TESTS)
	@echo Test executables have been put into base directory


OBJS  = $(OUTDIR)\SDL_ttf.obj

$(OUTDIR)\SDL_ttf.obj : .AUTODEPEND $(SRCDIR)\SDL_ttf.c
	$(CC) $(CFLAGS) -DBUILD_SDL -fo="$@" "$]@" $(CFLAGS_DLL_OPT)

sdl : .SYMBOLIC
	%create mksdl.bat
	%append mksdl.bat cd $(SDL_DIR)/watcom
	%append mksdl.bat wmake -h tgt=$(tgt) build=$(bld) sdl
	cmd /c mksdl.bat
	rm mksdl.bat


clean : .SYMBOLIC
	-@rm -f $(OUTDIR)/*.obj
	-@rm -f $(OUTDIR)/*.lib
	-@rm -f $(OUTDIR)/*.map
	-@rm -f $(OUTDIR)/*.lnk
	-@rm -f $(OUTDIR)/*.dll
	-@rm -f $(OUTDIR)/*.sym
	-@rd -f $(OUTDIR)
	-@rm -f *.err ../*.exe ../*.dll ../*.sym


$(OUTDIR)/SDL_ttf.lib : $(LIB_DEP)
	$(MK_LIB)

$(OUTDIR)/SDL_ttf.dll : $(OBJS) sdl
	wlink NAM $@ SYS nt_dll $(LDOPTS_DLL_OPT) $(LDOPTS) FIL {$(OBJS)} LIBR {$(FT_LIB) $(SDL_LIB)}

copy_dlls : .SYMBOLIC
	-cp $(OUTDIR)/SDL_ttf.dll ..
	-cp $(OUTDIR)/SDL_ttf.sym ..
	-cp $(SDL_LIB:.lib=.dll) ..
	-cp $(SDL_LIB:.lib=.sym) ..

$(OUTDIR)/sdl_ttf.lnk : makefile
	%create $^@
	@for %i in ($(OBJS)) do @%append $^@ +-%i

$(TESTS) : .SYMBOLIC makefile sdl_ttf $(COPY_DLL_OPT) sdl
	wcc386 $(CFLAGS) -fo="$(OUTDIR)/$@" "../$@.c" -DHAVE_OPENGL &
	       -DSCREENSHOT
	wlink SYS nt NAM ../$@.exe $(LDOPTS) OP M=$(OUTDIR)/$@.map &
	      FIL $(OUTDIR)/$@.obj &
	      LIBF $(SDLMAIN_LIB) LIBR $(SDL_LIB) LIBR $(OUTDIR)/SDL_ttf.lib

# vim: ts=8
