#  OpenWatcom makefile to build SDL for OS/2
#
!ifndef %WATCOM
!error Environment variable WATCOM is not specified!
!endif

DLLNAME = SDL12
VERSION = 1.2.60

# change SDL2INC to point to the SDL2 headers
SDL2INC = include
INCPATH = -I"$(%WATCOM)/h/os2" -I"$(%WATCOM)/h" -I"$(SDL2INC)"
LIBNAME = $(DLLNAME)

DLLFILE = $(LIBNAME).dll
LIBFILE = $(LIBNAME).lib
LNKFILE = $(LIBNAME).lnk

CFLAGS = -bt=os2 -d0 -zq -bm -5s -fp5 -fpi87 -sg -oeatxhn -ei
# max warnings:
CFLAGS+= -wx
# avoid bogus W200 from cpuid code
CFLAGS+= -wcd=200
# newer OpenWatcom versions enable W303 by default
CFLAGS+= -wcd=303
# the include paths :
CFLAGS+= $(INCPATH)
# building dll:
CFLAGS+= -bd
# for DECLSPEC
CFLAGS+= -DBUILD_SDL
# misc
CFLAGS+= -DNDEBUG -DSDL_DISABLE_IMMINTRIN_H

DESCRIPTION = Simple DirectMedia Layer 1.2

object_files= SDL12_compat.obj

.extensions:
.extensions: .lib .dll .obj .c .asm

.c.obj:
	wcc386 $(CFLAGS) -fo=$^@ $<

all: $(DLLFILE) $(LIBFILE) .symbolic

$(DLLFILE): compiling_info $(object_files) $(LNKFILE)
	@echo * Linking: $@
	@wlink @$(LNKFILE)

$(LIBFILE): $(DLLFILE)
	@echo * Creating LIB file: $@
	wlib -q -b -n -c -pa -s -t -zld -ii -io $* $(DLLFILE)

compiling_info : .symbolic
	@echo * Compiling...

$(LNKFILE):
	@echo * Creating linker file: $@
	@%create $@
	@%append $@ SYSTEM os2v2_dll INITINSTANCE TERMINSTANCE
	@%append $@ NAME $(DLLFILE)
	@for %i in ($(object_files)) do @%append $@ FILE %i
	@%append $@ OPTION QUIET
	@%append $@ OPTION IMPF=$^&.exp
	@%append $@ OPTION MAP=$^&.map
	@%append $@ OPTION DESCRIPTION '@$#libsdl org:$(VERSION)$#@$(DESCRIPTION)'
	@%append $@ OPTION ELIMINATE
	@%append $@ OPTION MANYAUTODATA
	@%append $@ OPTION OSNAME='OS/2 and eComStation'
	@%append $@ OPTION SHOWDEAD

clean: .SYMBOLIC
	@echo * Clean: $(LIBNAME) $(VERSION)
	@if exist *.obj rm *.obj
	@if exist *.map rm *.map
	@if exist *.exp rm *.exp
	@if exist $(LNKFILE) rm $(LNKFILE)

distclean: clean .SYMBOLIC
	@if exist *.err rm *.err
	@if exist $(DLLFILE) rm $(DLLFILE)
	@if exist $(LIBFILE) rm $(LIBFILE)
