From 261069f131d5114eecfa8f1aac5af0a971327e20 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Sun, 31 Jan 2021 16:56:35 -0800 Subject: [PATCH] Detect byte order from preprocessor definition (#330) Rather than having to specify or omit -DBYTESWAP in the Makefile fragment for each system we can detect whether the system requires byte swapping based on the __BYTE_ORDER__ C preprocessor definition. Update CMakeLists.txt to account for this as well. --- CMakeLists.txt | 13 ------------- bin/legacy/makefile-sunos4.1.i386 | 2 +- bin/legacy/makefile-sunos4.1.i386-multi | 2 +- bin/legacy/makefile-sunos4.i386 | 2 +- bin/legacy/makefile-sunos4.i386-multi | 2 +- bin/makefile-cygwin.x86_64-x | 2 +- bin/makefile-darwin.386-x | 2 +- bin/makefile-darwin.aarch64-x | 2 +- bin/makefile-darwin.x86_64-x | 2 +- bin/makefile-dos | 2 +- bin/makefile-freebsd.386-x | 2 +- bin/makefile-init.386 | 2 +- bin/makefile-linux.386-x | 2 +- bin/makefile-linux.armv7l-x | 2 +- bin/makefile-linux.x86_64-x | 2 +- bin/makefile-openbsd.x86_64-x | 2 +- bin/makefile-sunos5.386-x | 2 +- bin/makefile-sunos5.i386-x | 2 +- bin/makefile-sunos5.x86_64-x | 2 +- inc/maiko/platform.h | 12 ++++++++++++ 20 files changed, 30 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38d9407..d9fa4ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,19 +65,6 @@ IF(MAIKO_DISPLAY_X11) ) ENDIF() -IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR - CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64" OR - CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR - CMAKE_SYSTEM_PROCESSOR STREQUAL "x86" OR - CMAKE_SYSTEM_PROCESSOR STREQUAL "i386" OR - CMAKE_SYSTEM_PROCESSOR STREQUAL "i686" OR - CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*" OR - CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") - LIST(APPEND MAIKO_DEFINITIONS - "-DBYTESWAP" - ) -ENDIF() - IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS") LIST(APPEND MAIKO_DEFINITIONS "-DOS5" diff --git a/bin/legacy/makefile-sunos4.1.i386 b/bin/legacy/makefile-sunos4.1.i386 index f882ce2..eb8ea55 100644 --- a/bin/legacy/makefile-sunos4.1.i386 +++ b/bin/legacy/makefile-sunos4.1.i386 @@ -5,7 +5,7 @@ OEXT = .o #For debugging OPTFLAGS = -g FPFLAGS = -DFLAGS = -DKBINT -DFLTINT -DNOASM -DOS4 -DI386 -DBYTESWAP -DCHECK -DLOGINT -DSUNDISPLAY +DFLAGS = -DKBINT -DFLTINT -DNOASM -DOS4 -DI386 -DCHECK -DLOGINT -DSUNDISPLAY LDFLAGS = -lsuntool -lsunwindow -lpixrect -lc -lm INLINE = $(SRCDIR)disp386i.il diff --git a/bin/legacy/makefile-sunos4.1.i386-multi b/bin/legacy/makefile-sunos4.1.i386-multi index d03189c..0309680 100644 --- a/bin/legacy/makefile-sunos4.1.i386-multi +++ b/bin/legacy/makefile-sunos4.1.i386-multi @@ -6,7 +6,7 @@ OEXT = .o OPTFLAGS = -O DISPOPTFLAGS = -O FPFLAGS = -DFLAGS = -DKBINT -DOS4 -DI386 -DBYTESWAP -DCHECK -DLOGINT -DDISPLAYBUFFER -DSUNDISPLAY -DNEWBITBLT -DOPDISP +DFLAGS = -DKBINT -DOS4 -DI386 -DCHECK -DLOGINT -DDISPLAYBUFFER -DSUNDISPLAY -DNEWBITBLT -DOPDISP LDFLAGS = -lsuntool -lsunwindow -lpixrect -lc -lm INLINE = $(SRCDIR)disp386i.il BITBLTFILE=$(OBJECTDIR)bitblt386i.o diff --git a/bin/legacy/makefile-sunos4.i386 b/bin/legacy/makefile-sunos4.i386 index f882ce2..eb8ea55 100644 --- a/bin/legacy/makefile-sunos4.i386 +++ b/bin/legacy/makefile-sunos4.i386 @@ -5,7 +5,7 @@ OEXT = .o #For debugging OPTFLAGS = -g FPFLAGS = -DFLAGS = -DKBINT -DFLTINT -DNOASM -DOS4 -DI386 -DBYTESWAP -DCHECK -DLOGINT -DSUNDISPLAY +DFLAGS = -DKBINT -DFLTINT -DNOASM -DOS4 -DI386 -DCHECK -DLOGINT -DSUNDISPLAY LDFLAGS = -lsuntool -lsunwindow -lpixrect -lc -lm INLINE = $(SRCDIR)disp386i.il diff --git a/bin/legacy/makefile-sunos4.i386-multi b/bin/legacy/makefile-sunos4.i386-multi index 422dbf9..805aaf2 100644 --- a/bin/legacy/makefile-sunos4.i386-multi +++ b/bin/legacy/makefile-sunos4.i386-multi @@ -6,7 +6,7 @@ OEXT = .o OPTFLAGS = -O -traditional DISPOPTFLAGS = -O -traditional FPFLAGS = -DFLAGS = -DKBINT -DOS4 -DI386 -DBYTESWAP -DCHECK -DLOGINT -DDISPLAYBUFFER -DSUNDISPLAY -DNEWBITBLT -DOPDISP +DFLAGS = -DKBINT -DOS4 -DI386 -DCHECK -DLOGINT -DDISPLAYBUFFER -DSUNDISPLAY -DNEWBITBLT -DOPDISP LDFLAGS = -lsuntool -lsunwindow -lpixrect -lc -lm INLINE = $(SRCDIR)disp386i.il BITBLTFILE=$(OBJECTDIR)bitblt386i.o diff --git a/bin/makefile-cygwin.x86_64-x b/bin/makefile-cygwin.x86_64-x index 06e6e69..181c91a 100644 --- a/bin/makefile-cygwin.x86_64-x +++ b/bin/makefile-cygwin.x86_64-x @@ -20,7 +20,7 @@ XFLAGS = -DXWINDOW OEXT = .o # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 -DFLAGS = -DBYTESWAP -DLOGINT $(XFLAGS) -DRELEASE=351 +DFLAGS = -DLOGINT $(XFLAGS) -DRELEASE=351 LDFLAGS = -L/usr/X11/lib -lX11 -lc -lm LDELDFLAGS = -L/usr/X11/lib -lX11 -lc -lm diff --git a/bin/makefile-darwin.386-x b/bin/makefile-darwin.386-x index 636086c..85ee3a8 100644 --- a/bin/makefile-darwin.386-x +++ b/bin/makefile-darwin.386-x @@ -20,7 +20,7 @@ XFLAGS = -I/opt/X11/include -DXWINDOW OPTFLAGS = -O2 -g DEBUGFLAGS = # -DDEBUG -DOPTRACE DFLAGS = $(DEBUGFLAGS) \ - -DBYTESWAP -DLOGINT $(XFLAGS) \ + -DLOGINT $(XFLAGS) \ -DRELEASE=351 -DSTACKCHECK -DFSBCHECK -DPCTRACE LDFLAGS = -L/opt/X11/lib -lX11 -lm diff --git a/bin/makefile-darwin.aarch64-x b/bin/makefile-darwin.aarch64-x index edecd7e..006e9a1 100644 --- a/bin/makefile-darwin.aarch64-x +++ b/bin/makefile-darwin.aarch64-x @@ -20,7 +20,7 @@ XFLAGS = -I/opt/local/include -DXWINDOW OPTFLAGS = -O1 -g DEBUGFLAGS = # -DDEBUG -DOPTRACE DFLAGS = $(DEBUGFLAGS) \ - -DBYTESWAP -DLOGINT $(XFLAGS) \ + -DLOGINT $(XFLAGS) \ -DRELEASE=351 LDFLAGS = -L/opt/local/lib -lX11 -lm diff --git a/bin/makefile-darwin.x86_64-x b/bin/makefile-darwin.x86_64-x index e011f85..f369af9 100644 --- a/bin/makefile-darwin.x86_64-x +++ b/bin/makefile-darwin.x86_64-x @@ -20,7 +20,7 @@ XFLAGS = -I/opt/X11/include -DXWINDOW OPTFLAGS = -O1 -g DEBUGFLAGS = # -DDEBUG -DOPTRACE DFLAGS = $(DEBUGFLAGS) \ - -DBYTESWAP -DLOGINT $(XFLAGS) \ + -DLOGINT $(XFLAGS) \ -DRELEASE=351 LDFLAGS = -L/opt/X11/lib -lX11 -lm diff --git a/bin/makefile-dos b/bin/makefile-dos index ac9de51..2924429 100644 --- a/bin/makefile-dos +++ b/bin/makefile-dos @@ -6,7 +6,7 @@ ADMINFILES = makefile mkvdate.c LPFILES = lpmain.obj lpread.obj lpsolve.obj lpwrite.obj lpdual.obj lptran.obj -CFLAGS = -DDOS -DBYTESWAP -DKBINT -DNOPIXRECT \ +CFLAGS = -DDOS -DKBINT -DNOPIXRECT \ -DNOVERSION -DLPSOLVE -g LDFLAGS = -g graphics.lib binmode.lib mouse.lib diff --git a/bin/makefile-freebsd.386-x b/bin/makefile-freebsd.386-x index ba88fa7..54a1270 100644 --- a/bin/makefile-freebsd.386-x +++ b/bin/makefile-freebsd.386-x @@ -19,7 +19,7 @@ XFLAGS = -I/usr/local/include -DXWINDOW OEXT = .o # OPTFLAGS is normally -O2. OPTFLAGS = -O1 -gdwarf-2 -DFLAGS = -DBYTESWAP -DLOGINT $(XFLAGS) \ +DFLAGS = -DLOGINT $(XFLAGS) \ -DRELEASE=351 LDFLAGS = -L/usr/local/lib -lX11 -lc -lm diff --git a/bin/makefile-init.386 b/bin/makefile-init.386 index 4ad712a..1c60c1f 100644 --- a/bin/makefile-init.386 +++ b/bin/makefile-init.386 @@ -18,7 +18,7 @@ XFLAGS = -I/opt/X11/include -DXWINDOW # OPTFLAGS is normally -O2, for INIT we want unoptimized in case we need to debug it OPTFLAGS = -O0 -g -DFLAGS = -DBYTESWAP -DLOGINT $(XFLAGS) \ +DFLAGS = -DLOGINT $(XFLAGS) \ -DRELEASE=351 -DNOVERSION -DINIT -DTRACE -DOPTRACE LDFLAGS = -L/usr/X11/lib -lX11 -lm diff --git a/bin/makefile-linux.386-x b/bin/makefile-linux.386-x index 0e6b9d9..27f8d41 100644 --- a/bin/makefile-linux.386-x +++ b/bin/makefile-linux.386-x @@ -19,7 +19,7 @@ XFLAGS = -DXWINDOW OEXT = .o # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 -DFLAGS = -DBYTESWAP -DLOGINT $(XFLAGS) -DRELEASE=351 +DFLAGS = -DLOGINT $(XFLAGS) -DRELEASE=351 LDFLAGS = -L/usr/X11/lib -lX11 -lc -lm LDELDFLAGS = -L/usr/X11/lib -lX11 -lc -lm diff --git a/bin/makefile-linux.armv7l-x b/bin/makefile-linux.armv7l-x index ee37771..db1cd14 100644 --- a/bin/makefile-linux.armv7l-x +++ b/bin/makefile-linux.armv7l-x @@ -19,7 +19,7 @@ XFLAGS = -DXWINDOW OEXT = .o # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 -DFLAGS = -DBYTESWAP -DLOGINT $(XFLAGS) -DRELEASE=351 +DFLAGS = -DLOGINT $(XFLAGS) -DRELEASE=351 LDFLAGS = -L/usr/X11/lib -lX11 -lc -lm LDELDFLAGS = -L/usr/X11/lib -lX11 -lc -lm diff --git a/bin/makefile-linux.x86_64-x b/bin/makefile-linux.x86_64-x index 06e6e69..181c91a 100644 --- a/bin/makefile-linux.x86_64-x +++ b/bin/makefile-linux.x86_64-x @@ -20,7 +20,7 @@ XFLAGS = -DXWINDOW OEXT = .o # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 -DFLAGS = -DBYTESWAP -DLOGINT $(XFLAGS) -DRELEASE=351 +DFLAGS = -DLOGINT $(XFLAGS) -DRELEASE=351 LDFLAGS = -L/usr/X11/lib -lX11 -lc -lm LDELDFLAGS = -L/usr/X11/lib -lX11 -lc -lm diff --git a/bin/makefile-openbsd.x86_64-x b/bin/makefile-openbsd.x86_64-x index 7a238b4..b3b10ac 100644 --- a/bin/makefile-openbsd.x86_64-x +++ b/bin/makefile-openbsd.x86_64-x @@ -19,7 +19,7 @@ XFLAGS = -I/usr/X11R6/include -DXWINDOW OEXT = .o # OPTFLAGS is normally -O2. OPTFLAGS = -O2 -g3 -DFLAGS = -DBYTESWAP -DLOGINT $(XFLAGS) -DRELEASE=351 +DFLAGS = -DLOGINT $(XFLAGS) -DRELEASE=351 LDFLAGS = -L/usr/X11R6/lib -lX11 -lc -lm LDELDFLAGS = -L/usr/X11R6/lib -lX11 -lc -lm diff --git a/bin/makefile-sunos5.386-x b/bin/makefile-sunos5.386-x index 44e0eb3..c9acceb 100644 --- a/bin/makefile-sunos5.386-x +++ b/bin/makefile-sunos5.386-x @@ -37,7 +37,7 @@ DEBUGFLAGS = # -DSTACKCHECK -DFNSTKCHECK DFLAGS = $(XFLAGS) \ $(DEBUGFLAGS) \ - -DOS5 -DBYTESWAP -DLOGINT \ + -DOS5 -DLOGINT \ -DLOCK_X_UPDATES \ -DRELEASE=351 diff --git a/bin/makefile-sunos5.i386-x b/bin/makefile-sunos5.i386-x index bbf05dc..f6c065a 100644 --- a/bin/makefile-sunos5.i386-x +++ b/bin/makefile-sunos5.i386-x @@ -38,7 +38,7 @@ DEBUGFLAGS = # -DSTACKCHECK -DFNSTKCHECK DFLAGS = $(XFLAGS) \ $(DEBUGFLAGS) \ -DOS5 -DUSE_DLPI \ - -DBYTESWAP -DLOGINT \ + -DLOGINT \ -DLOCK_X_UPDATES \ -I$(OPENWINHOME)/include \ -DRELEASE=210 diff --git a/bin/makefile-sunos5.x86_64-x b/bin/makefile-sunos5.x86_64-x index d8fd63a..7d4f310 100644 --- a/bin/makefile-sunos5.x86_64-x +++ b/bin/makefile-sunos5.x86_64-x @@ -37,7 +37,7 @@ DEBUGFLAGS = # -DSTACKCHECK -DFNSTKCHECK DFLAGS = $(XFLAGS) \ $(DEBUGFLAGS) \ - -DOS5 -DBYTESWAP -DLOGINT \ + -DOS5 -DLOGINT \ -DLOCK_X_UPDATES \ -DUSE_DLPI \ -DRELEASE=351 diff --git a/inc/maiko/platform.h b/inc/maiko/platform.h index f5f79a5..2d7c326 100644 --- a/inc/maiko/platform.h +++ b/inc/maiko/platform.h @@ -137,6 +137,18 @@ # define MAIKO_ARCH_DETECTED 1 #endif +#if defined(__BYTE_ORDER__) +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define BYTESWAP 1 +# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# undef BYTESWAP +# else +# error "Unknown byte order" +# endif +#else +# error "Could not detect byte order" +#endif + #ifndef MAIKO_OS_DETECTED # error "Could not detect OS." #endif