diff mbox series

[FFmpeg-devel,v3,1/1] configure: Set WIN32_LEAN_AND_MEAN at configure time

Message ID 62ee336f-50f7-4986-b820-f50ec71492b6@amyspark.me
State New
Headers show
Series [FFmpeg-devel,v3,1/1] configure: Set WIN32_LEAN_AND_MEAN at configure time | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

L. E. Segovia Aug. 5, 2023, 8:47 p.m. UTC
Including winsock2.h or windows.h without WIN32_LEAN_AND_MEAN cause
bzlib.h to parse as nonsense, due to an instance of #define char small
in rpcndr.h.

See:

https://stackoverflow.com/a/27794577

Signed-off-by: L. E. Segovia <amy@amyspark.me>
---
 compat/atomics/win32/stdatomic.h | 1 -
 compat/w32pthreads.h             | 1 -
 configure                        | 1 +
 libavdevice/dshow_capture.h      | 1 -
 libavdevice/opengl_enc.c         | 1 -
 libavfilter/vsrc_ddagrab.c       | 1 -
 libavformat/os_support.c         | 6 ++----
 libavutil/wchar_filename.h       | 1 -
 libswscale/utils.c               | 1 -
 9 files changed, 3 insertions(+), 11 deletions(-)

Comments

Martin Storsjö Aug. 14, 2023, 11:30 a.m. UTC | #1
On Sat, 5 Aug 2023, L. E. Segovia wrote:

> Including winsock2.h or windows.h without WIN32_LEAN_AND_MEAN cause
> bzlib.h to parse as nonsense, due to an instance of #define char small
> in rpcndr.h.
>
> See:
>
> https://stackoverflow.com/a/27794577
>
> Signed-off-by: L. E. Segovia <amy@amyspark.me>
> ---
> compat/atomics/win32/stdatomic.h | 1 -
> compat/w32pthreads.h             | 1 -
> configure                        | 1 +
> libavdevice/dshow_capture.h      | 1 -
> libavdevice/opengl_enc.c         | 1 -
> libavfilter/vsrc_ddagrab.c       | 1 -
> libavformat/os_support.c         | 6 ++----
> libavutil/wchar_filename.h       | 1 -
> libswscale/utils.c               | 1 -
> 9 files changed, 3 insertions(+), 11 deletions(-)
>
> diff --git a/configure b/configure
> index 99388e7664..881a10bc0c 100755
> --- a/configure
> +++ b/configure
> @@ -5716,6 +5716,7 @@ case $target_os in
>         fi
>         ! enabled small && test_cmd $windres --version && enable gnu_windres
>         enabled x86_32 && check_ldflags -LARGEADDRESSAWARE
> +        add_cppflags -DWIN32_LEAN_AND_MEAN
>         shlibdir_default="$bindir_default"
>         SLIBPREF=""
>         SLIBSUF=".dll"

This is in the block for target_os = win32/win64 - but that's only used 
for MSVC (or clang-cl) based builds - not for mingw or cygwin.

We'd want this define set for mingw and cygwin too.

Cygwin itself doesn't define _WIN32 and generally is mostly treated as 
unix, but there are some codepaths that check for HAVE_WINDOWS_H and 
include that header, and that's true in Cygwin too, so we'd like to keep 
the WIN32_LEAN_AND_MEAN there too.

Other than that, this looks fine to me!

// Martin
diff mbox series

Patch

diff --git a/compat/atomics/win32/stdatomic.h b/compat/atomics/win32/stdatomic.h
index 28a627bfd3..4f8ac2bb60 100644
--- a/compat/atomics/win32/stdatomic.h
+++ b/compat/atomics/win32/stdatomic.h
@@ -19,7 +19,6 @@ 
 #ifndef COMPAT_ATOMICS_WIN32_STDATOMIC_H
 #define COMPAT_ATOMICS_WIN32_STDATOMIC_H
 
-#define WIN32_LEAN_AND_MEAN
 #include <stddef.h>
 #include <stdint.h>
 #include <windows.h>
diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h
index 6405e72b64..4ea0ce1ff4 100644
--- a/compat/w32pthreads.h
+++ b/compat/w32pthreads.h
@@ -35,7 +35,6 @@ 
  * As most functions here are used without checking return values,
  * only implement return values as necessary. */
 
-#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <process.h>
 #include <time.h>
diff --git a/configure b/configure
index 99388e7664..881a10bc0c 100755
--- a/configure
+++ b/configure
@@ -5716,6 +5716,7 @@  case $target_os in
         fi
         ! enabled small && test_cmd $windres --version && enable gnu_windres
         enabled x86_32 && check_ldflags -LARGEADDRESSAWARE
+        add_cppflags -DWIN32_LEAN_AND_MEAN
         shlibdir_default="$bindir_default"
         SLIBPREF=""
         SLIBSUF=".dll"
diff --git a/libavdevice/dshow_capture.h b/libavdevice/dshow_capture.h
index b548cd7afc..81e684b9be 100644
--- a/libavdevice/dshow_capture.h
+++ b/libavdevice/dshow_capture.h
@@ -27,7 +27,6 @@ 
 #include "avdevice.h"
 
 #define COBJMACROS
-#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #define NO_DSHOW_STRSAFE
 #include <dshow.h>
diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index f9dc846bf1..1b0cf5aa8f 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -30,7 +30,6 @@ 
 #include "config.h"
 
 #if HAVE_WINDOWS_H
-#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #endif
 #if HAVE_OPENGL_GL3_H
diff --git a/libavfilter/vsrc_ddagrab.c b/libavfilter/vsrc_ddagrab.c
index 525d48110a..9093b89c5b 100644
--- a/libavfilter/vsrc_ddagrab.c
+++ b/libavfilter/vsrc_ddagrab.c
@@ -22,7 +22,6 @@ 
 #undef _WIN32_WINNT
 #define _WIN32_WINNT 0x0A00
 #endif
-#define WIN32_LEAN_AND_MEAN
 
 #include <windows.h>
 
diff --git a/libavformat/os_support.c b/libavformat/os_support.c
index 15cea7fa5b..2de6a7c3d9 100644
--- a/libavformat/os_support.c
+++ b/libavformat/os_support.c
@@ -34,11 +34,9 @@ 
 #if HAVE_SYS_TIME_H
 #include <sys/time.h>
 #endif /* HAVE_SYS_TIME_H */
-#if HAVE_WINSOCK2_H
-#include <winsock2.h>
-#elif HAVE_SYS_SELECT_H
+#if HAVE_SYS_SELECT_H
 #include <sys/select.h>
-#endif /* HAVE_WINSOCK2_H */
+#endif /* HAVE_SYS_SELECT_H */
 #endif /* !HAVE_POLL_H */
 
 #include "network.h"
diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h
index fbc0a55146..4f87e6f88b 100644
--- a/libavutil/wchar_filename.h
+++ b/libavutil/wchar_filename.h
@@ -21,7 +21,6 @@ 
 
 #ifdef _WIN32
 
-#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include "mem.h"
 
diff --git a/libswscale/utils.c b/libswscale/utils.c
index 8fe34a3437..8e74c6603e 100644
--- a/libswscale/utils.c
+++ b/libswscale/utils.c
@@ -34,7 +34,6 @@ 
 #endif
 #endif
 #if HAVE_VIRTUALALLOC
-#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #endif