Commit 9dfa000bc059c5430d3ea60afd26989e5d1475cf

Cameron Cawley 2022-05-18T20:20:03

Initial support for building for Windows with OpenWatcom

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
diff --git a/.github/workflows/os2.yml b/.github/workflows/os2.yml
deleted file mode 100644
index 2ae1064..0000000
--- a/.github/workflows/os2.yml
+++ /dev/null
@@ -1,22 +0,0 @@
-name: Build (OS/2)
-
-on: [push, pull_request]
-
-jobs:
-  os2:
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v2
-      - uses: open-watcom/setup-watcom@v0
-      - name: Build SDL2
-        run: |
-          wmake -f Makefile.os2
-      - name: Build tests
-        run: |
-          cd test && wmake -f Makefile.os2
-          cd ..
-      - name: distclean
-        run: |
-          wmake -f Makefile.os2 distclean
-          cd test && wmake -f Makefile.os2 distclean
-          cd ..
diff --git a/.github/workflows/watcom.yml b/.github/workflows/watcom.yml
new file mode 100644
index 0000000..4650246
--- /dev/null
+++ b/.github/workflows/watcom.yml
@@ -0,0 +1,30 @@
+name: Build (OpenWatcom)
+
+on: [push, pull_request]
+
+jobs:
+  os2:
+    name: ${{ matrix.platform.name }}
+    runs-on: windows-latest
+
+    strategy:
+      matrix:
+        platform:
+        - { name: Windows, makefile: Makefile.w32 }
+        - { name: OS/2,    makefile: Makefile.os2 }
+
+    steps:
+      - uses: actions/checkout@v2
+      - uses: open-watcom/setup-watcom@v0
+      - name: Build SDL2
+        run: |
+          wmake -f ${{ matrix.platform.makefile }}
+      - name: Build tests
+        run: |
+          cd test && wmake -f ${{ matrix.platform.makefile }}
+          cd ..
+      - name: distclean
+        run: |
+          wmake -f ${{ matrix.platform.makefile }} distclean
+          cd test && wmake -f ${{ matrix.platform.makefile }} distclean
+          cd ..
diff --git a/.gitignore b/.gitignore
index fd27cb7..1f5e724 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,7 @@ buildbot
 *.exe
 *.o
 *.obj
+*.res
 *.lib
 *.a
 *.la
diff --git a/Makefile.w32 b/Makefile.w32
new file mode 100644
index 0000000..780593f
--- /dev/null
+++ b/Makefile.w32
@@ -0,0 +1,219 @@
+# Open Watcom makefile to build SDL2.dll for Win32
+# wmake -f Makefile.w32
+
+LIBNAME = SDL2
+MAJOR_VERSION = 2
+MINOR_VERSION = 23
+MICRO_VERSION = 0
+VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(MICRO_VERSION)
+DESCRIPTION = Simple DirectMedia Layer 2
+
+LIBHOME = .
+DLLFILE = $(LIBHOME)/$(LIBNAME).dll
+LIBFILE = $(LIBHOME)/$(LIBNAME).lib
+LNKFILE = $(LIBNAME).lnk
+
+INCPATH = -I"$(%WATCOM)/h/nt" -I"$(%WATCOM)/h/nt/directx" -I"$(%WATCOM)/h"
+INCPATH+= -Iinclude
+INCPATH+= -I"src/video/khronos"
+
+TLIB = SDL2test.lib
+LIBS = user32.lib gdi32.lib winmm.lib imm32.lib ole32.lib oleaut32.lib shell32.lib setupapi.lib version.lib uuid.lib dxguid.lib
+
+CFLAGS = -bt=nt -d0 -q -bm -5s -fp5 -fpi87 -sg -oeatxhn -ei
+# max warnings:
+CFLAGS+= -wx
+# newer OpenWatcom versions enable W303 by default
+CFLAGS+= -wcd=303
+# the include paths :
+CFLAGS+= $(INCPATH)
+CFLAGS_STATIC=$(CFLAGS)
+# building dll:
+CFLAGS_DLL =$(CFLAGS)
+CFLAGS_DLL+= -bd
+# building SDL itself (for DECLSPEC):
+CFLAGS_DLL+= -DDLL_EXPORT
+
+CFLAGS_DLL+= -DSDL_BUILD_MAJOR_VERSION=$(MAJOR_VERSION)
+CFLAGS_DLL+= -DSDL_BUILD_MINOR_VERSION=$(MINOR_VERSION)
+CFLAGS_DLL+= -DSDL_BUILD_MICRO_VERSION=$(MICRO_VERSION)
+
+RCFLAGS = -q -r -bt=nt $(INCPATH)
+
+SRCS = SDL.c SDL_assert.c SDL_error.c SDL_log.c SDL_dataqueue.c SDL_hints.c SDL_list.c
+SRCS+= SDL_getenv.c SDL_iconv.c SDL_malloc.c SDL_qsort.c SDL_stdlib.c SDL_string.c SDL_strtokr.c SDL_crc32.c
+SRCS+= SDL_cpuinfo.c SDL_atomic.c SDL_spinlock.c SDL_thread.c SDL_timer.c
+SRCS+= SDL_rwops.c SDL_power.c
+SRCS+= SDL_audio.c SDL_audiocvt.c SDL_audiodev.c SDL_audiotypecvt.c SDL_mixer.c SDL_wave.c
+SRCS+= SDL_events.c SDL_quit.c SDL_keyboard.c SDL_mouse.c SDL_windowevents.c &
+       SDL_clipboardevents.c SDL_dropevents.c SDL_displayevents.c SDL_gesture.c &
+       SDL_sensor.c SDL_touch.c
+SRCS+= SDL_haptic.c SDL_hidapi.c SDL_gamecontroller.c SDL_joystick.c
+SRCS+= SDL_render.c yuv_rgb.c SDL_yuv.c SDL_yuv_sw.c SDL_blendfillrect.c &
+       SDL_blendline.c SDL_blendpoint.c SDL_drawline.c SDL_drawpoint.c &
+       SDL_render_sw.c SDL_rotate.c SDL_triangle.c
+SRCS+= SDL_blit.c SDL_blit_0.c SDL_blit_1.c SDL_blit_A.c SDL_blit_auto.c &
+       SDL_blit_copy.c SDL_blit_N.c SDL_blit_slow.c SDL_fillrect.c SDL_bmp.c &
+       SDL_pixels.c SDL_rect.c SDL_RLEaccel.c SDL_shape.c SDL_stretch.c &
+       SDL_surface.c SDL_video.c SDL_clipboard.c SDL_vulkan_utils.c SDL_egl.c
+
+SRCS+= e_atan2.c e_exp.c e_fmod.c e_log10.c e_log.c e_pow.c e_rem_pio2.c e_sqrt.c &
+       k_cos.c k_rem_pio2.c k_sin.c k_tan.c &
+       s_atan.c s_copysign.c s_cos.c s_fabs.c s_floor.c s_scalbn.c s_sin.c s_tan.c
+
+SRCS+= SDL_syscond.c SDL_sysmutex.c SDL_syssem.c SDL_systhread.c SDL_systls.c
+SRCS+= SDL_systimer.c
+SRCS+= SDL_sysloadso.c
+SRCS+= SDL_sysfilesystem.c
+SRCS+= SDL_syshaptic.c SDL_sysjoystick.c SDL_virtualjoystick.c
+SRCS+= SDL_hidapijoystick.c SDL_hidapi_rumble.c SDL_hidapi_gamecube.c SDL_hidapi_luna.c SDL_hidapi_ps4.c SDL_hidapi_ps5.c SDL_hidapi_stadia.c SDL_hidapi_switch.c SDL_hidapi_xbox360.c SDL_hidapi_xbox360w.c SDL_hidapi_xboxone.c SDL_hidapi_steam.c
+SRCS+= SDL_dummyaudio.c SDL_diskaudio.c
+SRCS+= SDL_nullvideo.c SDL_nullframebuffer.c SDL_nullevents.c
+SRCS+= SDL_dummysensor.c
+SRCS+= SDL_locale.c SDL_syslocale.c
+SRCS+= SDL_url.c SDL_sysurl.c
+
+SRCS+= SDL_winmm.c SDL_directsound.c SDL_wasapi.c SDL_wasapi_win32.c
+SRCS+= SDL_hid.c SDL_windows.c SDL_xinput.c
+SRCS+= SDL_dinputhaptic.c SDL_windowshaptic.c SDL_xinputhaptic.c
+SRCS+= SDL_dinputjoystick.c SDL_rawinputjoystick.c SDL_windowsjoystick.c SDL_windows_gaming_input.c SDL_xinputjoystick.c
+SRCS+= SDL_syspower.c
+SRCS+= SDL_d3dmath.c
+SRCS+= SDL_render_d3d.c SDL_shaders_d3d.c
+SRCS+= SDL_render_d3d11.c SDL_shaders_d3d11.c
+SRCS+= SDL_render_gl.c SDL_shaders_gl.c
+SRCS+= SDL_render_gles2.c SDL_shaders_gles2.c
+SRCS+= SDL_windowssensor.c
+SRCS+= SDL_syscond_cv.c
+SRCS+= SDL_windowsclipboard.c SDL_windowsevents.c SDL_windowsframebuffer.c SDL_windowskeyboard.c SDL_windowsmessagebox.c SDL_windowsmodes.c SDL_windowsmouse.c SDL_windowsopengl.c SDL_windowsopengles.c SDL_windowsshape.c SDL_windowsvideo.c SDL_windowsvulkan.c SDL_windowswindow.c
+
+SRCS+= SDL_dynapi.c
+
+RCSRCS+= version.rc
+
+OBJS = $(SRCS:.c=.obj)
+RCOBJS= $(RCSRCS:.rc=.res)
+
+.extensions:
+.extensions: .lib .dll .obj .res .c .rc .asm
+
+.c: ./src/libm;
+.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/atomic;./src/audio/disk;
+.c: ./src/haptic/dummy;./src/joystick/dummy;./src/joystick/virtual;./src/audio/dummy;./src/video/dummy;./src/sensor/dummy;
+.c: ./src/core/windows;./src/audio/winmm;./src/audio/directsound;./src/audio/wasapi;./src/loadso/windows;./src/filesystem/windows;./src/haptic/windows;./src/joystick/windows;./src/sensor/windows;./src/thread/windows;./src/timer/windows;./src/video/windows;
+.c: ./src/locale/;./src/locale/windows;./src/misc;./src/misc/windows;./src/power/windows;./src/joystick/hidapi;./src/hidapi;./src/render/direct3d;./src/render/direct3d11;./src/render/opengl;./src/render/opengles2
+.rc: ./src/main/windows
+
+all: $(DLLFILE) $(LIBFILE) $(TLIB) .symbolic
+
+build_dll: .symbolic
+    @echo * Compiling dll objects
+
+$(DLLFILE): build_dll $(OBJS) $(MOBJS) $(RCOBJS) $(LNKFILE)
+    @echo * Linking: $@
+    wlink @$(LNKFILE)
+    wrc $(RCOBJS) $^@
+
+$(LIBFILE): $(DLLFILE)
+    @echo * Creating LIB file: $@
+    wlib -q -b -n -c -pa -s -t -zld -ii -io $* $(DLLFILE)
+
+.c.obj:
+    wcc386 $(CFLAGS_DLL) -fo=$^@ $<
+
+.rc.res:
+    wrc $(RCFLAGS) -fo=$^@ $<
+
+SDL_syscond.obj: "src/thread/generic/SDL_syscond.c"
+    wcc386 $(CFLAGS_DLL) -fo=$^@ $<
+SDL_cpuinfo.obj: SDL_cpuinfo.c
+    wcc386 $(CFLAGS_DLL) -wcd=200 -fo=$^@ $<
+SDL_wave.obj: SDL_wave.c
+    wcc386 $(CFLAGS_DLL) -wcd=124 -fo=$^@ $<
+SDL_blendfillrect.obj: SDL_blendfillrect.c
+    wcc386 $(CFLAGS_DLL) -wcd=200 -fo=$^@ $<
+SDL_blendline.obj: SDL_blendline.c
+    wcc386 $(CFLAGS_DLL) -wcd=200 -fo=$^@ $<
+SDL_blendpoint.obj: SDL_blendpoint.c
+    wcc386 $(CFLAGS_DLL) -wcd=200 -fo=$^@ $<
+SDL_RLEaccel.obj: SDL_RLEaccel.c
+    wcc386 $(CFLAGS_DLL) -wcd=201 -fo=$^@ $<
+# c99 mode needed because of structs with flexible array members in libusb.h
+SDL_hidapi.obj: SDL_hidapi.c
+    wcc386 $(CFLAGS_DLL) -za99 -fo=$^@ $<
+
+# SDL2test
+TSRCS = SDL_test_assert.c SDL_test_common.c SDL_test_compare.c &
+        SDL_test_crc32.c SDL_test_font.c SDL_test_fuzzer.c SDL_test_harness.c &
+        SDL_test_imageBlit.c SDL_test_imageBlitBlend.c SDL_test_imageFace.c &
+        SDL_test_imagePrimitives.c SDL_test_imagePrimitivesBlend.c &
+        SDL_test_log.c SDL_test_md5.c SDL_test_random.c SDL_test_memory.c
+TOBJS= $(TSRCS:.c=.obj)
+
+.c: ./src/test;
+SDL_test_assert.obj: SDL_test_assert.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_common.obj: SDL_test_common.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_compare.obj: SDL_test_compare.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_crc32.obj: SDL_test_crc32.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_font.obj: SDL_test_font.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_fuzzer.obj: SDL_test_fuzzer.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_harness.obj: SDL_test_harness.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_imageBlit.obj: SDL_test_imageBlit.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_imageBlitBlend.obj: SDL_test_imageBlitBlend.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_imageFace.obj: SDL_test_imageFace.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_imagePrimitives.obj: SDL_test_imagePrimitives.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_imagePrimitivesBlend.obj: SDL_test_imagePrimitivesBlend.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_log.obj: SDL_test_log.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_md5.obj: SDL_test_md5.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_random.obj: SDL_test_random.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+SDL_test_memory.obj: SDL_test_memory.c
+    wcc386 $(CFLAGS_STATIC) -fo=$^@ $<
+
+build_tlib: .symbolic
+    @echo * Compiling testlib objects
+$(TLIB): build_tlib $(TOBJS)
+    @echo * Creating: $@
+    wlib -q -b -n -c -pa -s -t -zld -ii -io $@ $(TOBJS)
+
+$(LNKFILE): Makefile.w32
+    @echo * Creating linker file: $@
+    @%create $@
+    @%append $@ SYSTEM nt_dll INITINSTANCE TERMINSTANCE
+    @%append $@ NAME $(DLLFILE)
+    @for %i in ($(OBJS)) do @%append $@ FILE %i
+    @for %i in ($(LIBS)) do @%append $@ LIB %i
+    @%append $@ OPTION QUIET
+    @%append $@ OPTION IMPF=$(LIBHOME)/$^&.exp
+    @%append $@ OPTION MAP=$(LIBHOME)/$^&.map
+    @%append $@ OPTION DESCRIPTION '@$#libsdl org:$(VERSION)$#@$(DESCRIPTION)'
+    @%append $@ OPTION ELIMINATE
+    @%append $@ OPTION OSNAME='Windows NT'
+    @%append $@ OPTION SHOWDEAD
+
+clean: .SYMBOLIC
+    @echo * Clean: $(LIBNAME)
+    @if exist *.obj rm *.obj
+    @if exist *.err rm *.err
+    @if exist $(LNKFILE) rm $(LNKFILE)
+
+distclean: .SYMBOLIC clean
+    @if exist $(LIBHOME)/*.exp rm $(LIBHOME)/*.exp
+    @if exist $(LIBHOME)/*.map rm $(LIBHOME)/*.map
+    @if exist $(LIBFILE) rm $(LIBFILE)
+    @if exist $(DLLFILE) rm $(DLLFILE)
+    @if exist $(TLIB) rm $(TLIB)
diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h
index 90f5ddc..81fde40 100644
--- a/include/SDL_config_windows.h
+++ b/include/SDL_config_windows.h
@@ -97,6 +97,7 @@ typedef unsigned int uintptr_t;
 #define HAVE_DDRAW_H 1
 #define HAVE_DINPUT_H 1
 #define HAVE_DSOUND_H 1
+#ifndef __WATCOMC__
 #define HAVE_DXGI_H 1
 #define HAVE_XINPUT_H 1
 #if defined(_WIN32_MAXVER) && _WIN32_MAXVER >= 0x0A00  /* Windows 10 SDK */
@@ -110,6 +111,7 @@ typedef unsigned int uintptr_t;
 #define HAVE_AUDIOCLIENT_H 1
 #define HAVE_TPCSHRD_H 1
 #define HAVE_SENSORSAPI_H 1
+#endif
 #if (defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64)) && (defined(_MSC_VER) && _MSC_VER >= 1600)
 #define HAVE_IMMINTRIN_H 1
 #elif defined(__has_include) && (defined(__i386__) || defined(__x86_64))
@@ -136,8 +138,11 @@ typedef unsigned int uintptr_t;
 #define HAVE_REALLOC 1
 #define HAVE_FREE 1
 #define HAVE_ALLOCA 1
+/* OpenWatcom requires specific calling conventions for qsort and bsearch */
+#ifndef __WATCOMC__
 #define HAVE_QSORT 1
 #define HAVE_BSEARCH 1
+#endif
 #define HAVE_ABS 1
 #define HAVE_MEMSET 1
 #define HAVE_MEMCPY 1
@@ -168,37 +173,40 @@ typedef unsigned int uintptr_t;
 #define HAVE__WCSNICMP 1
 #define HAVE__WCSDUP 1
 #define HAVE_ACOS   1
-#define HAVE_ACOSF  1
 #define HAVE_ASIN   1
-#define HAVE_ASINF  1
 #define HAVE_ATAN   1
-#define HAVE_ATANF  1
 #define HAVE_ATAN2  1
+#define HAVE_CEIL   1
+#define HAVE_COS    1
+#define HAVE_EXP    1
+#define HAVE_FABS   1
+#define HAVE_FLOOR  1
+#define HAVE_FMOD   1
+#define HAVE_LOG    1
+#define HAVE_LOG10  1
+#define HAVE_POW    1
+#define HAVE_SIN    1
+#define HAVE_SQRT   1
+#define HAVE_TAN    1
+#ifndef __WATCOMC__
+#define HAVE_ACOSF  1
+#define HAVE_ASINF  1
+#define HAVE_ATANF  1
 #define HAVE_ATAN2F 1
 #define HAVE_CEILF  1
 #define HAVE__COPYSIGN 1
-#define HAVE_COS    1
 #define HAVE_COSF   1
-#define HAVE_EXP    1
 #define HAVE_EXPF   1
-#define HAVE_FABS   1
 #define HAVE_FABSF  1
-#define HAVE_FLOOR  1
 #define HAVE_FLOORF 1
-#define HAVE_FMOD   1
 #define HAVE_FMODF  1
-#define HAVE_LOG    1
 #define HAVE_LOGF   1
-#define HAVE_LOG10  1
 #define HAVE_LOG10F 1
-#define HAVE_POW    1
 #define HAVE_POWF   1
-#define HAVE_SIN    1
 #define HAVE_SINF   1
-#define HAVE_SQRT   1
 #define HAVE_SQRTF  1
-#define HAVE_TAN    1
 #define HAVE_TANF   1
+#endif
 #if defined(_MSC_VER)
 /* These functions were added with the VC++ 2013 C runtime library */
 #if _MSC_VER >= 1800
@@ -218,8 +226,18 @@ typedef unsigned int uintptr_t;
 #if _MSC_VER >= 1400
 #define HAVE__FSEEKI64 1
 #endif
+#ifdef _USE_MATH_DEFINES
+#define HAVE_M_PI 1
 #endif
-#if !defined(_MSC_VER) || defined(_USE_MATH_DEFINES)
+#elif defined(__WATCOMC__)
+#define HAVE__FSEEKI64 1
+#define HAVE_STRTOLL 1
+#define HAVE_STRTOULL 1
+#define HAVE_VSSCANF 1
+#define HAVE_ROUND 1
+#define HAVE_SCALBN 1
+#define HAVE_TRUNC  1
+#else
 #define HAVE_M_PI 1
 #endif
 #else
@@ -228,7 +246,9 @@ typedef unsigned int uintptr_t;
 #endif
 
 /* Enable various audio drivers */
+#if defined(HAVE_MMDEVICEAPI_H) && defined(HAVE_AUDIOCLIENT_H)
 #define SDL_AUDIO_DRIVER_WASAPI 1
+#endif
 #define SDL_AUDIO_DRIVER_DSOUND 1
 #define SDL_AUDIO_DRIVER_WINMM  1
 #define SDL_AUDIO_DRIVER_DISK   1
@@ -249,7 +269,11 @@ typedef unsigned int uintptr_t;
 #define SDL_HAPTIC_XINPUT   1
 
 /* Enable the sensor driver */
+#ifdef HAVE_SENSORSAPI_H
 #define SDL_SENSOR_WINDOWS  1
+#else
+#define SDL_SENSOR_DUMMY    1
+#endif
 
 /* Enable various shared object loading systems */
 #define SDL_LOADSO_WINDOWS  1
diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h
index 917a825..681f01b 100644
--- a/src/core/windows/SDL_windows.h
+++ b/src/core/windows/SDL_windows.h
@@ -30,6 +30,8 @@
 #ifndef UNICODE
 #define UNICODE 1
 #endif
+#undef WINVER
+#define WINVER 0x0501
 #undef _WIN32_WINNT
 #define _WIN32_WINNT  0x501   /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input */
 #endif
diff --git a/src/dynapi/SDL_dynapi.h b/src/dynapi/SDL_dynapi.h
index dddc094..330b342 100644
--- a/src/dynapi/SDL_dynapi.h
+++ b/src/dynapi/SDL_dynapi.h
@@ -61,7 +61,7 @@
 #define SDL_DYNAMIC_API 0  /* vitasdk doesn't support dynamic linking */
 #elif defined(__NGAGE__)
 #define SDL_DYNAMIC_API 0  /* The N-Gage doesn't support dynamic linking either */
-#elif defined(__OS2__)
+#elif defined(__OS2__) || defined(__WATCOMC__)
 #define SDL_DYNAMIC_API 0  /* see github bugs #5667 and #5669 */
 #elif defined(DYNAPI_NEEDS_DLOPEN) && !defined(HAVE_DLOPEN)
 #define SDL_DYNAMIC_API 0  /* we need dlopen(), but don't have it.... */
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index 51f6c77..97047f4 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -41,6 +41,13 @@
 
 #include "SDL_shaders_d3d.h"
 
+#ifdef __WATCOMC__
+/* FIXME: Remove this once https://github.com/open-watcom/open-watcom-v2/pull/868 is merged */
+#define D3DBLENDOP_REVSUBTRACT 3
+/* FIXME: Remove this once https://github.com/open-watcom/open-watcom-v2/pull/869 is merged */
+#define D3DERR_UNSUPPORTEDCOLOROPERATION MAKE_D3DHRESULT( 2073 )
+#endif
+
 typedef struct
 {
     SDL_Rect viewport;
diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c
index 4bd2a98..93a6bfa 100644
--- a/src/video/windows/SDL_windowsvideo.c
+++ b/src/video/windows/SDL_windowsvideo.c
@@ -35,6 +35,22 @@
 #include "SDL_windowsshape.h"
 #include "SDL_windowsvulkan.h"
 
+#ifdef D3D_DEBUG_INFO
+#ifndef D3D_SDK_VERSION
+#define D3D_SDK_VERSION   (32 | 0x80000000)
+#endif
+#ifndef D3D9b_SDK_VERSION
+#define D3D9b_SDK_VERSION (31 | 0x80000000)
+#endif
+#else /**/
+#ifndef D3D_SDK_VERSION
+#define D3D_SDK_VERSION   32
+#endif
+#ifndef D3D9b_SDK_VERSION
+#define D3D9b_SDK_VERSION 31
+#endif
+#endif
+
 /* Initialization/Query functions */
 static int WIN_VideoInit(_THIS);
 static void WIN_VideoQuit(_THIS);
diff --git a/test/Makefile.w32 b/test/Makefile.w32
new file mode 100644
index 0000000..5e3e6bc
--- /dev/null
+++ b/test/Makefile.w32
@@ -0,0 +1,17 @@
+# Open Watcom makefile to build SDL2 tests for Win32
+# wmake -f Makefile.w32
+
+SYSTEM = nt
+
+INCPATH = -I"$(%WATCOM)/h/nt" -I"$(%WATCOM)/h" -I"../src/video/khronos"
+
+CFLAGS = -bt=nt -d0 -q -bm -5s -fp5 -fpi87 -sg -oteanbmier -ei
+CFLAGS+= -wx -wcd=303
+CFLAGS+= -DSDL_MAIN_HANDLED
+
+CFLAGS+= -DHAVE_OPENGL
+GLLIBS = opengl32.lib
+
+TNSRCS = testnative.obj testnativew32.obj
+
+!include watcom.mif
diff --git a/test/versioning.sh b/test/versioning.sh
index 1e160bc..3a05c62 100755
--- a/test/versioning.sh
+++ b/test/versioning.sh
@@ -56,6 +56,17 @@ else
     not_ok "Makefile.os2 $version disagrees with SDL_version.h $ref_version"
 fi
 
+major=$(sed -ne 's/^MAJOR_VERSION *= *//p' Makefile.w32)
+minor=$(sed -ne 's/^MINOR_VERSION *= *//p' Makefile.w32)
+micro=$(sed -ne 's/^MICRO_VERSION *= *//p' Makefile.w32)
+version="${major}.${minor}.${micro}"
+
+if [ "$ref_version" = "$version" ]; then
+    ok "Makefile.w32 $version"
+else
+    not_ok "Makefile.w32 $version disagrees with SDL_version.h $ref_version"
+fi
+
 version=$(sed -Ene 's/^[$]SDLVersion = "([0-9.]+)"\r?$/\1/p' build-scripts/winrtbuild.ps1)
 
 if [ "$ref_version" = "$version" ]; then
diff --git a/test/watcom.mif b/test/watcom.mif
index 5bf10be..4cc8e7e 100644
--- a/test/watcom.mif
+++ b/test/watcom.mif
@@ -64,6 +64,9 @@ testoverlay2.exe: testoverlay2.obj testyuv_cvt.obj
 testyuv.exe: testyuv.obj testyuv_cvt.obj
   wlink SYS $(SYSTEM) libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
 
+testshader.exe: testshader.obj
+  wlink SYS $(SYSTEM) libpath $(LIBPATH) lib {$(LIBS) $(GLLIBS)} op q op el file {$<} name $@
+
 testime.exe: testime.obj
   wlink SYS $(SYSTEM) libpath $(LIBPATH) lib {$(LIBS) $(TTFLIBS)} op q op el file {$<} name $@