--- setup.py
+++ setup.py
@@ -5,7 +5,7 @@
 # Usage: python setup.py install
 #
 
-import glob, os, re, struct, string, sys
+import glob, os, re, string, sys
 
 # make it possible to run the setup script from another directory
 try:
@@ -282,8 +282,11 @@
             defs.append(("HAVE_LIBZ", None))
         if sys.platform == "win32":
             libs.extend(["kernel32", "user32", "gdi32"])
-        if struct.unpack("h", "\0\1")[0] == 1:
+        target_arch = os.getenv('TARGET_ARCH', '')
+        if target_arch == "mips":     # big endian
             defs.append(("WORDS_BIGENDIAN", None))
+        elif target_arch != "mipsel": # little endian
+            raise AssertionError("Unknown/unsupported TARGET_ARCH")
 
         exts = [(Extension(
             "_imaging", files, libraries=libs, define_macros=defs
