[PATCH v2] drm/fourcc: introduce DRM_FOURCC_STANDALONE guard

Emil Velikov emil.l.velikov at gmail.com
Thu Feb 4 11:37:42 UTC 2021


Currently, the drm_fourcc.h header depends on drm.h for __u32 and __u64.
At the same time drm.h pulls a lot of unneeded symbols.

Add new guard DRM_FOURCC_STANDALONE, which when set will use local
declaration of said symbols.

When used on linux - we pull linux/types.h which is used either way.
On other platforms, BSDs et al, we need a couple of typedefs.

Since those can trigger a warning in some corner-cases*, add some GCC
magic to silence them. Note that incorrect type redefinitions will still
be flagged, and the GCC pragma is ignored by other compilers.

*Corner-case:
If one sets DRM_FOURCC_STANDALONE and compiles with C99 or earlier while
also using -pedantic _and_ the header lives outside of the standard
/usr/include (like BSDs normally do).

v2:
 - Add corner-case handling, based on popular demand.

Cc: James Park <james.park at lagfreegames.com>
Cc: Pekka Paalanen <pekka.paalanen at collabora.com>
Cc: Simon Ser <contact at emersion.fr>
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 include/uapi/drm/drm.h        | 10 ++++++++++
 include/uapi/drm/drm_fourcc.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index 808b48a93330..cd78950e05ce 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -53,6 +53,15 @@ typedef unsigned int drm_handle_t;
 #include <stdint.h>
 #include <sys/ioccom.h>
 #include <sys/types.h>
+
+/*
+ * When using C99 -pedantic the typedefs will trigger a warning.
+ * If the header is considered a system one (-isystem) those will be
+ * ignored, yet on the target platforms BSDs, et al - the headers live
+ * in a non-system location.
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpedantic"
 typedef int8_t   __s8;
 typedef uint8_t  __u8;
 typedef int16_t  __s16;
@@ -63,6 +72,7 @@ typedef int64_t  __s64;
 typedef uint64_t __u64;
 typedef size_t   __kernel_size_t;
 typedef unsigned long drm_handle_t;
+#pragma GCC diagnostic pop
 
 #endif
 
diff --git a/include/uapi/drm/drm_fourcc.h b/include/uapi/drm/drm_fourcc.h
index 6f0628eb13a6..84a1f96cc4ef 100644
--- a/include/uapi/drm/drm_fourcc.h
+++ b/include/uapi/drm/drm_fourcc.h
@@ -24,7 +24,36 @@
 #ifndef DRM_FOURCC_H
 #define DRM_FOURCC_H
 
+/*
+ * Define DRM_FOURCC_STANDALONE you're interested only FOURCC and do not want
+ * to pull drm.h into your application.
+ */
+#ifdef DRM_FOURCC_STANDALONE
+#if defined(__linux__)
+
+#include <linux/types.h>
+
+#else /* One of the BSDs */
+
+#include <stdint.h>
+
+/*
+ * When using C99 -pedantic the typedefs will trigger a warning.
+ * If the header is considered a system one (-isystem) those will be
+ * ignored, yet on the target platforms BSDs, et al - the headers live
+ * in a non-system location.
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpedantic"
+typedef uint32_t __u32;
+typedef uint64_t __u64;
+#pragma GCC diagnostic pop
+
+#endif /* __linux __ */
+
+#else
 #include "drm.h"
+#endif /* DRM_FOURCC_STANDALONE */
 
 #if defined(__cplusplus)
 extern "C" {
-- 
2.30.0



More information about the dri-devel mailing list