Add an endian.c program which will be used at compile time to generate
an endian.h file with the information about the endianness of the
architecture. This way we do not depend on any particular build system
to retrieve this information (libfreenect knows the endianness with the
help of Cmake, for instance).
This is inspired from the rdesktop project[1] and looks more portable
than relying on the system endian.h as its use is relatively new and not
standardized yet, even though there are proposals in that direction[2].
Finally fn_le32() implementation is ripped off from libfreenect.
[1] http://www.rdesktop.org/archive/2001/msg00722.html
[2] http://austingroupbugs.net/view.php?id=162
PREFIX ?= /usr/local
bindir := $(PREFIX)/sbin
-kinect_upload_fw: kinect_upload_fw.o
+all: kinect_upload_fw
+
+
+endian: endian.o
+
+endian.h: endian
+ rm -f endian.h
+ ./endian > endian.h
+
+kinect_upload_fw: endian.h kinect_upload_fw.o
+
install: kinect_upload_fw
install -d $(DESTDIR)$(bindir)
install -m 755 kinect_upload_fw $(DESTDIR)$(bindir)
clean:
- rm -rf *~ *.o kinect_upload_fw
+ rm -rf *~ *.o kinect_upload_fw endian endian.h
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+
+static int litend(void) {
+ int i = 0;
+ ((char *) (&i))[0] = 1;
+ return (i == 1);
+}
+
+static int bigend(void) {
+ return !litend();
+}
+
+int main(void) {
+ printf("#ifndef __ENDIAN_H\n");
+ printf("#define __ENDIAN_H\n");
+ printf("\n");
+ printf("#define __LITTLE_ENDIAN 1234\n");
+ printf("#define __BIG_ENDIAN 4321\n");
+ printf("#define __BYTE_ORDER __%s_ENDIAN\n",
+ litend() ? "LITTLE" : "BIG");
+ printf("\n");
+ printf("#endif /* __ENDIAN_H */\n");
+ exit(0);
+}
#include <errno.h>
#include <libusb.h>
+#include "endian.h"
+
static libusb_device_handle *dev;
unsigned int seq;
} status_code;
#define LOG(...) printf(__VA_ARGS__)
+
+#if __BYTE_ORDER == __BIG_ENDIAN
+static inline uint32_t fn_le32(uint32_t d)
+{
+ return (d<<24) | ((d<<8)&0xFF0000) | ((d>>8)&0xFF00) | (d>>24);
+}
+#else
#define fn_le32(x) (x)
-// TODO: support architectures that aren't little-endian
+#endif
static void dump_bl_cmd(bootloader_command cmd) {
int i;