From 1a1e631ccd561afdea31e2fb2f4982b3fdc81432 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 10 Jul 2014 00:49:01 +0200 Subject: [PATCH] build: deal with endian mess There is no standard mechanism for detecting endianess. Doing it at compile time in a portable way is probably hard. Doing it properly with a configure check is probably hard too. Using the endian definitions in (usually includes , which is not available everywhere) works under circumstances, but the previous commit broke it on OSX. Ideally all code should be endian dependent, but that is not possible due to the dependencies (such as FFmpeg, some video output APIs, some audio output APIs). Create a header osdep/endian.h, which contains various fallbacks. Note that the last fallback uses libavutil; however, it's not clear whether AV_HAVE_BIGENDIAN is a public symbol, or whether including really makes it visible. And in fact we don't want to pollute the namespace with libavutil definitions either. Thus it's only the last fallback. --- audio/format.h | 2 +- osdep/endian.h | 31 +++++++++++++++++++++++++++++++ stream/stream_cdda.c | 3 ++- video/img_format.h | 3 ++- video/img_fourcc.h | 2 +- waftools/detections/compiler.py | 3 --- 6 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 osdep/endian.h diff --git a/audio/format.h b/audio/format.h index 6821f27ab6..788f4ed1c1 100644 --- a/audio/format.h +++ b/audio/format.h @@ -24,8 +24,8 @@ #define MPLAYER_AF_FORMAT_H #include -#include +#include "osdep/endian.h" #include "bstr/bstr.h" #if BYTE_ORDER == BIG_ENDIAN diff --git a/osdep/endian.h b/osdep/endian.h new file mode 100644 index 0000000000..b600f1c281 --- /dev/null +++ b/osdep/endian.h @@ -0,0 +1,31 @@ +#ifndef MP_ENDIAN_H_ +#define MP_ENDIAN_H_ + +#include + +#if !defined(BYTE_ORDER) + +#if defined(__BYTE_ORDER) +#define BYTE_ORDER __BYTE_ORDER +#define LITTLE_ENDIAN __LITTLE_ENDIAN +#define BIG_ENDIAN __BIG_ENDIAN +#elif defined(__DARWIN_BYTE_ORDER) +#define BYTE_ORDER __DARWIN_BYTE_ORDER +#define LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN +#define BIG_ENDIAN __DARWIN_BIG_ENDIAN +#else +#include +#if AV_HAVE_BIGENDIAN +#define BYTE_ORDER 1234 +#define LITTLE_ENDIAN 4321 +#define BIG_ENDIAN 1234 +#else +#define BYTE_ORDER 1234 +#define LITTLE_ENDIAN 1234 +#define BIG_ENDIAN 4321 +#endif +#endif + +#endif /* !defined(BYTE_ORDER) */ + +#endif diff --git a/stream/stream_cdda.c b/stream/stream_cdda.c index 953cc812f6..1a03c443df 100644 --- a/stream/stream_cdda.c +++ b/stream/stream_cdda.c @@ -37,7 +37,8 @@ #include #include #include -#include + +#include "osdep/endian.h" #include "talloc.h" diff --git a/video/img_format.h b/video/img_format.h index c6c26e7fab..03ae1e91d3 100644 --- a/video/img_format.h +++ b/video/img_format.h @@ -20,7 +20,8 @@ #define MPLAYER_IMG_FORMAT_H #include -#include + +#include "osdep/endian.h" #include "bstr/bstr.h" #if BYTE_ORDER == BIG_ENDIAN diff --git a/video/img_fourcc.h b/video/img_fourcc.h index ee30ff0c26..1539a7b4f3 100644 --- a/video/img_fourcc.h +++ b/video/img_fourcc.h @@ -1,7 +1,7 @@ #ifndef MPV_IMG_FOURCC_H #define MPV_IMG_FOURCC_H -#include +#include "osdep/endian.h" #define MP_FOURCC(a,b,c,d) ((a) | ((b)<<8) | ((c)<<16) | ((unsigned)(d)<<24)) diff --git a/waftools/detections/compiler.py b/waftools/detections/compiler.py index 064c805b6c..96b7571a54 100644 --- a/waftools/detections/compiler.py +++ b/waftools/detections/compiler.py @@ -44,9 +44,6 @@ def __add_clang_flags__(ctx): def __add_mingw_flags__(ctx): ctx.env.CFLAGS += ['-D__USE_MINGW_ANSI_STDIO=1'] - ctx.env.CFLAGS += ['-DBYTE_ORDER=1234'] - ctx.env.CFLAGS += ['-DLITLE_ENDIAN=1234'] - ctx.env.CFLAGS += ['-DBIG_ENDIAN=4321'] ctx.env.LAST_LINKFLAGS += ['-mwindows'] def __add_cygwin_flags__(ctx):